File tree Expand file tree Collapse file tree 2 files changed +56
-0
lines changed
Expand file tree Collapse file tree 2 files changed +56
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Icinga \Module \X509 \Model \Behavior ;
4+
5+ use ipl \Orm \Contract \QueryAwareBehavior ;
6+ use ipl \Orm \Contract \RewriteFilterBehavior ;
7+ use ipl \Orm \Query ;
8+ use ipl \Stdlib \Filter ;
9+
10+ class ExpressionInjector implements RewriteFilterBehavior, QueryAwareBehavior
11+ {
12+ /** @var array */
13+ protected $ columns ;
14+
15+ /** @var Query */
16+ protected $ query ;
17+
18+ public function __construct (...$ columns )
19+ {
20+ $ this ->columns = $ columns ;
21+ }
22+
23+ public function setQuery (Query $ query )
24+ {
25+ $ this ->query = $ query ;
26+
27+ return $ this ;
28+ }
29+
30+ public function rewriteCondition (Filter \Condition $ condition , $ relation = null )
31+ {
32+ $ columnName = $ condition ->metaData ()->get ('columnName ' );
33+ if (in_array ($ columnName , $ this ->columns , true )) {
34+ $ relationPath = $ condition ->metaData ()->get ('relationPath ' );
35+ if ($ relationPath && $ relationPath !== $ this ->query ->getModel ()->getTableAlias ()) {
36+ $ subject = $ this ->query ->getResolver ()->resolveRelation ($ relationPath )->getTarget ();
37+ } else {
38+ $ subject = $ this ->query ->getModel ();
39+ }
40+
41+ $ expression = clone $ subject ->getColumns ()[$ columnName ];
42+ $ expression ->setColumns ($ this ->query ->getResolver ()->qualifyColumns (
43+ $ this ->query ->getResolver ()->requireAndResolveColumns (
44+ $ expression ->getColumns (),
45+ $ subject
46+ ),
47+ $ subject
48+ ));
49+
50+ $ condition ->setColumn ($ this ->query ->getDb ()->getQueryBuilder ()->buildExpression ($ expression ));
51+ }
52+ }
53+ }
Original file line number Diff line number Diff line change 44
55use Icinga \Module \X509 \Model \Behavior \BoolCast ;
66use Icinga \Module \X509 \Model \Behavior \DistinguishedEncodingRules ;
7+ use Icinga \Module \X509 \Model \Behavior \ExpressionInjector ;
78use ipl \Orm \Behavior \Binary ;
89use ipl \Orm \Behaviors ;
910use ipl \Orm \Model ;
@@ -103,6 +104,8 @@ public function createBehaviors(Behaviors $behaviors)
103104 'trusted ' ,
104105 'self_signed '
105106 ]));
107+
108+ $ behaviors ->add (new ExpressionInjector ('duration ' , 'expires ' ));
106109 }
107110
108111 public function createRelations (Relations $ relations )
You can’t perform that action at this time.
0 commit comments