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 | /** |
||
96 | * {@inheritdoc} |
||
97 | */ |
||
98 | 5 | public function createRootNode($data = array(), $scope = null) |
|
114 | |||
115 | /** |
||
116 | * {@inheritdoc} |
||
117 | */ |
||
118 | 2 | public function updateNode($nodeId, array $data): void |
|
123 | |||
124 | /** |
||
125 | * {@inheritdoc} |
||
126 | */ |
||
127 | 10 | public function addNode($targetNodeId, array $data = array(), string $placement = self::PLACEMENT_CHILD_TOP) |
|
131 | |||
132 | /** |
||
133 | * @param string $placement |
||
134 | * |
||
135 | * @return AddStrategyInterface |
||
136 | * |
||
137 | * @throws InvalidArgumentException |
||
138 | */ |
||
139 | 10 | protected function getAddStrategy(string $placement): AddStrategyInterface |
|
156 | |||
157 | /** |
||
158 | * {@inheritdoc} |
||
159 | */ |
||
160 | 13 | public function moveNode($sourceNodeId, $targetNodeId, string $placement = self::PLACEMENT_CHILD_TOP): void |
|
164 | |||
165 | /** |
||
166 | * @param string $placement |
||
167 | * |
||
168 | * @return MoveStrategyInterface |
||
169 | * |
||
170 | * @throws InvalidArgumentException |
||
171 | */ |
||
172 | 13 | protected function getMoveStrategy(string $placement): MoveStrategyInterface |
|
189 | |||
190 | /** |
||
191 | * {@inheritdoc} |
||
192 | */ |
||
193 | 3 | public function deleteBranch($nodeId): void |
|
225 | |||
226 | /** |
||
227 | * {@inheritdoc} |
||
228 | */ |
||
229 | 3 | public function getNode($nodeId): ?array |
|
234 | |||
235 | /** |
||
236 | * {@inheritdoc} |
||
237 | */ |
||
238 | 5 | public function getAncestorsQueryBuilder(): AncestorQueryBuilderInterface |
|
242 | |||
243 | /** |
||
244 | * {@inheritdoc} |
||
245 | */ |
||
246 | 9 | public function getDescendantsQueryBuilder(): DescendantQueryBuilderInterface |
|
250 | |||
251 | /** |
||
252 | * {@inheritdoc} |
||
253 | */ |
||
254 | 7 | public function getRootNode($scope = null): array |
|
259 | |||
260 | /** |
||
261 | * {@inheritdoc} |
||
262 | */ |
||
263 | 1 | public function getRoots(): array |
|
268 | |||
269 | /** |
||
270 | * {@inheritdoc} |
||
271 | */ |
||
272 | 5 | public function isValid($rootNodeId): bool |
|
277 | |||
278 | /** |
||
279 | * {@inheritdoc} |
||
280 | */ |
||
281 | 3 | public function rebuild($rootNodeId): void |
|
286 | } |
||
287 |