1<?php 2/** 3 * `RENAME` statement. 4 */ 5 6declare(strict_types=1); 7 8namespace PhpMyAdmin\SqlParser\Statements; 9 10use PhpMyAdmin\SqlParser\Components\RenameOperation; 11use PhpMyAdmin\SqlParser\Parser; 12use PhpMyAdmin\SqlParser\Statement; 13use PhpMyAdmin\SqlParser\Token; 14use PhpMyAdmin\SqlParser\TokensList; 15 16/** 17 * `RENAME` statement. 18 * 19 * RENAME TABLE tbl_name TO new_tbl_name 20 * [, tbl_name2 TO new_tbl_name2] ... 21 */ 22class RenameStatement extends Statement 23{ 24 /** 25 * The old and new names of the tables. 26 * 27 * @var RenameOperation[] 28 */ 29 public $renames; 30 31 /** 32 * Function called before the token is processed. 33 * 34 * Skips the `TABLE` keyword after `RENAME`. 35 * 36 * @param Parser $parser the instance that requests parsing 37 * @param TokensList $list the list of tokens to be parsed 38 * @param Token $token the token that is being parsed 39 */ 40 public function before(Parser $parser, TokensList $list, Token $token) 41 { 42 if (($token->type !== Token::TYPE_KEYWORD) || ($token->keyword !== 'RENAME')) { 43 return; 44 } 45 46 // Checking if it is the beginning of the query. 47 $list->getNextOfTypeAndValue(Token::TYPE_KEYWORD, 'TABLE'); 48 } 49 50 /** 51 * @return string 52 */ 53 public function build() 54 { 55 return 'RENAME TABLE ' . RenameOperation::build($this->renames); 56 } 57} 58