sqlite-database-integration
/
wp-includes
/
database
/
mysql
/
native
/
trait-wp-mysql-native-parser-impl.php
trait-wp-mysql-native-parser-impl.php in SQLite Database Integration 3.1.0, at wp-includes/database/mysql/native/trait-wp-mysql-native-parser-impl.php
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Native-mode `WP_MySQL_Parser` implementation, delivered as a trait. |
| 5 | * |
| 6 | * The class that uses this trait (`WP_MySQL_Parser` in native mode) |
| 7 | * extends the pure-PHP `WP_Parser` so callers' `instanceof WP_Parser` |
| 8 | * checks keep working, while the actual parsing work is delegated to |
| 9 | * the Rust-registered `WP_MySQL_Native_Parser` instance held in |
| 10 | * `$this->native`. `WP_Parser`'s state (`$grammar`, `$tokens`, |
| 11 | * `$position`) stays inert in native mode — the trait's overrides |
| 12 | * never read it. |
| 13 | * |
| 14 | * Adding a public method here is enough to plumb a new public method |
| 15 | * through to the native parser; the using class does not need touching. |
| 16 | * |
| 17 | * @access private |
| 18 | */ |
| 19 | trait WP_MySQL_Native_Parser_Impl { |
| 20 | /** |
| 21 | * @var WP_MySQL_Native_Parser |
| 22 | */ |
| 23 | private $native; |
| 24 | |
| 25 | /** |
| 26 | * @param WP_Parser_Grammar $grammar |
| 27 | * @param array<WP_Parser_Token>|WP_MySQL_Native_Token_Stream $tokens |
| 28 | */ |
| 29 | public function __construct( WP_Parser_Grammar $grammar, $tokens ) { |
| 30 | // WP_Parser's `array $tokens` constructor signature can't accept |
| 31 | // the native token stream object; its `$this->tokens` / |
| 32 | // `$this->position` state is inert in native mode anyway, so we |
| 33 | // pass an empty array to satisfy the parent contract and keep |
| 34 | // the actual tokens on the native parser. |
| 35 | parent::__construct( $grammar, array() ); |
| 36 | $this->native = new WP_MySQL_Native_Parser( $grammar, $tokens ); |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * @param array<WP_Parser_Token>|WP_MySQL_Native_Token_Stream $tokens |
| 41 | */ |
| 42 | public function reset_tokens( $tokens ): void { |
| 43 | $this->native->reset_tokens( $tokens ); |
| 44 | } |
| 45 | |
| 46 | public function next_query(): bool { |
| 47 | return $this->native->next_query(); |
| 48 | } |
| 49 | |
| 50 | public function get_query_ast(): ?WP_Parser_Node { |
| 51 | return $this->native->get_query_ast(); |
| 52 | } |
| 53 | |
| 54 | public function parse() { |
| 55 | return $this->native->parse(); |
| 56 | } |
| 57 | } |
| 58 |