File tree 1 file changed +51
-0
lines changed
1 file changed +51
-0
lines changed Original file line number Diff line number Diff line change 1
1
# Doctrine Query Checker
2
+
3
+ Doctrine Query Tree Walker that perform additional checks on the query AST in addition to the default checks performed by Doctrine.
4
+
5
+ Currently it checks that the types of the parameters passed to the query are correct. For example the following will result in exception:
6
+
7
+ ``` php
8
+ // throws 'Parameter "created_at" is of type "string", but expected "datetime" (because it\'s used in expression with u.createdAt)'
9
+ $this->entityManager->createQueryBuilder()
10
+ ->select('u')
11
+ ->from(User::class, 'u')
12
+ ->where('u.createdAt < :created_at')
13
+ ->setParameter('created_at', 'not a date')
14
+ ->getQuery()
15
+ ->setHint(Query::HINT_CUSTOM_TREE_WALKERS, [QueryCheckerTreeWalker::class]);
16
+ ->getResult();
17
+ ```
18
+
19
+ If you want to log the exceptions instead of throwing them, you can pass a logger to the QueryCheckerTreeWalker:
20
+
21
+ ``` php
22
+ QueryCheckerTreeWalker::setLogger($logger);
23
+ ```
24
+
25
+ ## Installation
26
+
27
+ ``` bash
28
+ composer require shipmonk/doctrine-query-checker
29
+ ```
30
+
31
+ ## Enabling for a specific query
32
+
33
+ ``` php
34
+ use Doctrine\ORM\Query;
35
+ use ShipMonk\DoctrineQueryChecker\QueryCheckerTreeWalker;
36
+
37
+ $query = $this->entityManager->createQueryBuilder()
38
+ ->select('u')
39
+ ->from(User::class, 'u')
40
+ ->getQuery()
41
+ ->setHint(Query::HINT_CUSTOM_TREE_WALKERS, [QueryCheckerTreeWalker::class]);
42
+ ```
43
+
44
+ ## Enabling for all queries
45
+
46
+ ``` php
47
+ use Doctrine\ORM\Query;
48
+ use ShipMonk\DoctrineQueryChecker\QueryCheckerTreeWalker;
49
+
50
+ $this->entityManager->getConfiguration()
51
+ ->setDefaultQueryHint(Query::HINT_CUSTOM_TREE_WALKERS, [QueryCheckerTreeWalker::class]);
52
+ ```
You can’t perform that action at this time.
0 commit comments