Server IP : 85.214.239.14 / Your IP : 3.21.93.29 Web Server : Apache/2.4.62 (Debian) System : Linux h2886529.stratoserver.net 4.9.0 #1 SMP Tue Jan 9 19:45:01 MSK 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.18 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : OFF | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /var/www/wordpress/phpMyAdmin/vendor/phpmyadmin/sql-parser/src/Statements/ |
Upload File : |
<?php /** * `PURGE` statement. */ declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Statements; use PhpMyAdmin\SqlParser\Components\Expression; use PhpMyAdmin\SqlParser\Parser; use PhpMyAdmin\SqlParser\Statement; use PhpMyAdmin\SqlParser\Token; use PhpMyAdmin\SqlParser\TokensList; use function in_array; use function trim; /** * `PURGE` statement. * * PURGE { BINARY | MASTER } LOGS * { TO 'log_name' | BEFORE datetime_expr } */ class PurgeStatement extends Statement { /** * The type of logs * * @var String */ public $log_type; /** * The end option of this query. * * @var String */ public $end_option; /** * The end expr of this query. * * @var String */ public $end_expr; /** * @return string */ public function build() { $ret = 'PURGE ' . $this->log_type . ' LOGS ' . ($this->end_option !== null ? ($this->end_option . ' ' . $this->end_expr) : ''); return trim($ret); } /** * @param Parser $parser the instance that requests parsing * @param TokensList $list the list of tokens to be parsed */ public function parse(Parser $parser, TokensList $list) { ++$list->idx; // Skipping `PURGE`. /** * The state of the parser. * * @var int */ $state = 0; $prevToken = null; for (; $list->idx < $list->count; ++$list->idx) { /** * Token parsed at this moment. * * @var Token */ $token = $list->tokens[$list->idx]; // End of statement. if ($token->type === Token::TYPE_DELIMITER) { break; } // Skipping whitespaces and comments. if (($token->type === Token::TYPE_WHITESPACE) || ($token->type === Token::TYPE_COMMENT)) { continue; } switch ($state) { case 0: // parse `{ BINARY | MASTER }` $this->log_type = self::parseExpectedKeyword($parser, $token, ['BINARY', 'MASTER']); break; case 1: // parse `LOGS` self::parseExpectedKeyword($parser, $token, ['LOGS']); break; case 2: // parse `{ TO | BEFORE }` $this->end_option = self::parseExpectedKeyword($parser, $token, ['TO', 'BEFORE']); break; case 3: // parse `expr` $this->end_expr = Expression::parse($parser, $list, []); break; default: $parser->error('Unexpected token.', $token); break; } $state++; $prevToken = $token; } // Only one possible end state if ($state !== 4) { $parser->error('Unexpected token.', $prevToken); } } /** * Parse expected keyword (or throw relevant error) * * @param Parser $parser the instance that requests parsing * @param Token $token token to be parsed * @param Array $expected_keywords array of possibly expected keywords at this point */ private static function parseExpectedKeyword($parser, $token, $expected_keywords) { if ($token->type === Token::TYPE_KEYWORD) { if (in_array($token->keyword, $expected_keywords)) { return $token->keyword; } else { $parser->error('Unexpected keyword', $token); } } else { $parser->error('Unexpected token.', $token); } return null; } }