1 | <?php |
||
33 | class MagicQuery |
||
34 | { |
||
35 | private $connection; |
||
36 | private $cache; |
||
37 | private $schemaAnalyzer; |
||
38 | /** |
||
39 | * @var AbstractPlatform |
||
40 | */ |
||
41 | private $platform; |
||
42 | /** |
||
43 | * @var \Twig_Environment |
||
44 | */ |
||
45 | private $twigEnvironment; |
||
46 | private $enableTwig = false; |
||
47 | |||
48 | /** |
||
49 | * @param \Doctrine\DBAL\Connection $connection |
||
50 | * @param \Doctrine\Common\Cache\Cache $cache |
||
51 | * @param SchemaAnalyzer $schemaAnalyzer (optional). If not set, it is initialized from the connection. |
||
52 | */ |
||
53 | public function __construct($connection = null, $cache = null, SchemaAnalyzer $schemaAnalyzer = null) |
||
66 | |||
67 | /** |
||
68 | * Whether Twig parsing should be enabled or not. |
||
69 | * Defaults to false. |
||
70 | * |
||
71 | * @param bool $enableTwig |
||
72 | * |
||
73 | * @return $this |
||
74 | */ |
||
75 | public function setEnableTwig($enableTwig = true) |
||
81 | |||
82 | /** |
||
83 | * Overrides the output dialect used to generate SQL. By default, the dialect of the connection is used. |
||
84 | * If no connection is used, MySQL platform is used by default. |
||
85 | * |
||
86 | * @param AbstractPlatform $platform |
||
87 | */ |
||
88 | public function setOutputDialect(AbstractPlatform $platform): self |
||
94 | |||
95 | /** |
||
96 | * Returns merged SQL from $sql and $parameters. Any parameters not available will be striped down |
||
97 | * from the SQL. |
||
98 | * |
||
99 | * This is equivalent to calling `parse` and `toSql` successively. |
||
100 | * |
||
101 | * @param string $sql |
||
102 | * @param array $parameters |
||
103 | * |
||
104 | * @return string |
||
105 | */ |
||
106 | public function build($sql, array $parameters = array()) |
||
117 | |||
118 | /** |
||
119 | * Returns modified SQL from $sql and $parameters. Any parameters not available will be striped down |
||
120 | * from the SQL. Unlike with the `build` method, the parameters are NOT merged into the SQL. |
||
121 | * This method is more efficient than `build` (because result is cached and statements interpolation |
||
122 | * can be delegated to the database. |
||
123 | * |
||
124 | * @param string $sql |
||
125 | * @param array $parameters |
||
126 | * |
||
127 | * @return string |
||
128 | */ |
||
129 | public function buildPreparedStatement(string $sql, array $parameters = []): string |
||
148 | |||
149 | /** |
||
150 | * Parses the $sql passed in parameter and returns a tree representation of it. |
||
151 | * This tree representation can be used to manipulate the SQL. |
||
152 | * |
||
153 | * @param string $sql |
||
154 | * |
||
155 | * @return NodeInterface |
||
156 | * |
||
157 | * @throws MagicQueryMissingConnectionException |
||
158 | * @throws MagicQueryParserException |
||
159 | */ |
||
160 | public function parse($sql) |
||
185 | |||
186 | /** |
||
187 | * Transforms back a tree of SQL node into a SQL string. |
||
188 | * |
||
189 | * @param NodeInterface $sqlNode |
||
190 | * @param array $parameters |
||
191 | * @param bool $extrapolateParameters Whether the parameters should be fed into the returned SQL query |
||
192 | |||
193 | * @return string |
||
194 | */ |
||
195 | public function toSql(NodeInterface $sqlNode, array $parameters = array(), bool $extrapolateParameters = true) |
||
199 | |||
200 | /** |
||
201 | * Scans the SQL statement and replaces the "magicjoin" part with the correct joins. |
||
202 | * |
||
203 | * @param NodeInterface $select |
||
204 | * |
||
205 | * @throws MagicQueryMissingConnectionException |
||
206 | */ |
||
207 | private function magicJoin(NodeInterface $select) |
||
222 | |||
223 | /** |
||
224 | * For one given MagicJoin select, let's apply MagicJoin. |
||
225 | * |
||
226 | * @param MagicJoinSelect $magicJoinSelect |
||
227 | * |
||
228 | * @return Select |
||
229 | */ |
||
230 | private function magicJoinOnOneQuery(MagicJoinSelect $magicJoinSelect) |
||
297 | |||
298 | /** |
||
299 | * @return SchemaAnalyzer |
||
300 | */ |
||
301 | private function getSchemaAnalyzer() |
||
313 | |||
314 | private function getConnectionUniqueId(Connection $connection) |
||
318 | |||
319 | /** |
||
320 | * @return \Twig_Environment |
||
321 | */ |
||
322 | private function getTwigEnvironment() |
||
330 | } |
||
331 |