1 | <?php |
||
11 | class CollectionsAgent implements AgentInterface |
||
12 | { |
||
13 | private $store; |
||
14 | |||
15 | public function __construct(Store $store) |
||
19 | |||
20 | /** |
||
21 | * {@inheritdoc} |
||
22 | */ |
||
23 | public function supports(string $classFqn): bool |
||
27 | |||
28 | /** |
||
29 | * {@inheritdoc} |
||
30 | */ |
||
31 | public function find($identifier, string $classFqn = null) |
||
48 | |||
49 | /** |
||
50 | * {@inheritdoc} |
||
51 | */ |
||
52 | public function save($object) |
||
53 | { |
||
54 | } |
||
55 | |||
56 | /** |
||
57 | * {@inheritdoc} |
||
58 | */ |
||
59 | public function delete($object) |
||
60 | { |
||
61 | $this->store->delete($object); |
||
62 | } |
||
63 | |||
64 | /** |
||
65 | * {@inheritdoc} |
||
66 | */ |
||
67 | public function query(Query $query): \Traversable |
||
68 | { |
||
69 | $collection = $this->store->getCollection($query->getClassFqn()); |
||
70 | $expressionBuilder = Criteria::expr(); |
||
71 | $visitor = new CollectionsVisitor($expressionBuilder); |
||
72 | $doctrineExpression = $visitor->dispatch($query->getExpression()); |
||
73 | $criteria = new Criteria($doctrineExpression); |
||
74 | |||
75 | return $collection->matching($criteria); |
||
76 | } |
||
77 | |||
78 | /** |
||
79 | * {@inheritdoc} |
||
80 | */ |
||
81 | public function getIdentifier($object) |
||
82 | { |
||
83 | foreach ($this->store->getCollection(get_class($object)) as $identifier => $element) { |
||
84 | if ($element === $object) { |
||
85 | return $identifier; |
||
86 | } |
||
87 | } |
||
88 | |||
89 | throw new \RuntimeException(sprintf( |
||
90 | 'Could not find identifier for object of class "%s"', |
||
91 | get_class($object) |
||
92 | )); |
||
93 | } |
||
94 | |||
95 | /** |
||
96 | * {@inheritdoc} |
||
97 | */ |
||
98 | public function setParent($object, $parent) |
||
102 | } |
||
103 |