1 | <?php |
||
33 | class NestedSet implements TreeInterface |
||
34 | { |
||
35 | private $manipulator; |
||
36 | |||
37 | private $validator; |
||
38 | |||
39 | /** |
||
40 | * @param Options|array $options |
||
41 | * @param object $dbAdapter |
||
42 | * |
||
43 | * @throws InvalidArgumentException |
||
44 | */ |
||
45 | 69 | public function __construct($options, $dbAdapter) |
|
46 | { |
||
47 | 69 | if (is_array($options)) { |
|
48 | 4 | $options = new Options($options); |
|
49 | 65 | } elseif (!$options instanceof Options) { |
|
50 | throw new InvalidArgumentException( |
||
51 | sprintf('Options must be an array or instance of %s', Options::class) |
||
52 | ); |
||
53 | } |
||
54 | |||
55 | 69 | if ($dbAdapter instanceof AdapterInterface) { |
|
56 | 60 | $adapter = $dbAdapter; |
|
57 | 9 | } elseif ($dbAdapter instanceof Zend2DbAdapter) { |
|
58 | 2 | $adapter = new Zend2($options, $dbAdapter); |
|
59 | 7 | } elseif ($dbAdapter instanceof DoctrineConnection) { |
|
60 | 2 | $adapter = new Doctrine2DBAL($options, $dbAdapter); |
|
61 | 5 | } elseif ($dbAdapter instanceof \Zend_Db_Adapter_Abstract) { |
|
62 | 2 | $adapter = new Zend1($options, $dbAdapter); |
|
63 | 3 | } elseif ($dbAdapter instanceof \PDO) { |
|
64 | 2 | $adapter = new Pdo($options, $dbAdapter); |
|
65 | } else { |
||
66 | 1 | throw new InvalidArgumentException('Db adapter "'.get_class($dbAdapter) |
|
67 | 1 | .'" is not supported'); |
|
68 | } |
||
69 | |||
70 | 68 | $adapter = new NestedTransactionDecorator($adapter); |
|
71 | |||
72 | 68 | $this->manipulator = new Manipulator($options, $adapter); |
|
73 | 68 | } |
|
74 | |||
75 | /** |
||
76 | * @return ManipulatorInterface |
||
77 | */ |
||
78 | 68 | public function getManipulator(): ManipulatorInterface |
|
82 | |||
83 | /** |
||
84 | * @return ValidatorInterface |
||
85 | */ |
||
86 | 8 | private function getValidator(): ValidatorInterface |
|
94 | |||
95 | 1 | public function setDbSelectBuilder(callable $builder): void |
|
100 | |||
101 | /** |
||
102 | * {@inheritdoc} |
||
103 | */ |
||
104 | 5 | public function createRootNode($data = array(), $scope = null) |
|
120 | |||
121 | /** |
||
122 | * {@inheritdoc} |
||
123 | */ |
||
124 | 2 | public function updateNode($nodeId, array $data): void |
|
129 | |||
130 | /** |
||
131 | * {@inheritdoc} |
||
132 | */ |
||
133 | 10 | public function addNode($targetNodeId, array $data = array(), string $placement = self::PLACEMENT_CHILD_TOP) |
|
137 | |||
138 | /** |
||
139 | * @param string $placement |
||
140 | * |
||
141 | * @return AddStrategyInterface |
||
142 | * |
||
143 | * @throws InvalidArgumentException |
||
144 | */ |
||
145 | 10 | protected function getAddStrategy(string $placement): AddStrategyInterface |
|
162 | |||
163 | /** |
||
164 | * {@inheritdoc} |
||
165 | */ |
||
166 | 13 | public function moveNode($sourceNodeId, $targetNodeId, string $placement = self::PLACEMENT_CHILD_TOP): void |
|
170 | |||
171 | /** |
||
172 | * @param string $placement |
||
173 | * |
||
174 | * @return MoveStrategyInterface |
||
175 | * |
||
176 | * @throws InvalidArgumentException |
||
177 | */ |
||
178 | 13 | protected function getMoveStrategy(string $placement): MoveStrategyInterface |
|
195 | |||
196 | /** |
||
197 | * {@inheritdoc} |
||
198 | */ |
||
199 | 3 | public function deleteBranch($nodeId): void |
|
231 | |||
232 | /** |
||
233 | * {@inheritdoc} |
||
234 | */ |
||
235 | 3 | public function getNode($nodeId): ?array |
|
240 | |||
241 | /** |
||
242 | * {@inheritdoc} |
||
243 | */ |
||
244 | 5 | public function getAncestorsQueryBuilder(): AncestorQueryBuilderInterface |
|
248 | |||
249 | /** |
||
250 | * {@inheritdoc} |
||
251 | */ |
||
252 | 9 | public function getDescendantsQueryBuilder(): DescendantQueryBuilderInterface |
|
256 | |||
257 | /** |
||
258 | * {@inheritdoc} |
||
259 | */ |
||
260 | 7 | public function getRootNode($scope = null): array |
|
265 | |||
266 | /** |
||
267 | * {@inheritdoc} |
||
268 | */ |
||
269 | 1 | public function getRoots(): array |
|
274 | |||
275 | /** |
||
276 | * {@inheritdoc} |
||
277 | */ |
||
278 | 5 | public function isValid($rootNodeId): bool |
|
283 | |||
284 | /** |
||
285 | * {@inheritdoc} |
||
286 | */ |
||
287 | 3 | public function rebuild($rootNodeId): void |
|
292 | } |
||
293 |