55namespace Respect \Data ;
66
77use Respect \Data \Collections \Collection ;
8- use Respect \Data \Collections \Filtered ;
98use SplObjectStorage ;
109
11- use function array_flip ;
12- use function array_intersect_key ;
1310use function count ;
1411use function ctype_digit ;
1512use function is_int ;
@@ -82,13 +79,6 @@ public function markTracked(object $entity, Collection $collection): bool
8279
8380 public function persist (object $ object , Collection $ onCollection ): object
8481 {
85- $ connectsTo = $ onCollection ->connectsTo ;
86- if ($ onCollection instanceof Filtered && $ connectsTo !== null ) {
87- $ this ->persist ($ object , $ connectsTo );
88-
89- return $ object ;
90- }
91-
9282 if ($ this ->isTracked ($ object )) {
9383 $ currentOp = $ this ->pending [$ object ] ?? null ;
9484 if ($ currentOp !== 'insert ' ) {
@@ -128,31 +118,9 @@ public function isTracked(object $entity): bool
128118
129119 public function registerCollection (string $ alias , Collection $ collection ): void
130120 {
131- $ collection ->bindMapper ($ this );
132121 $ this ->collections [$ alias ] = $ collection ;
133122 }
134123
135- /**
136- * @param array<string, mixed> $columns
137- *
138- * @return array<string, mixed>
139- */
140- protected function filterColumns (array $ columns , Collection $ collection ): array
141- {
142- if (
143- !$ collection instanceof Filtered
144- || !$ collection ->filters
145- || $ collection ->identifierOnly
146- || $ collection ->name === null
147- ) {
148- return $ columns ;
149- }
150-
151- $ id = $ this ->style ->identifier ($ collection ->name );
152-
153- return array_intersect_key ($ columns , array_flip ([...$ collection ->filters , $ id ]));
154- }
155-
156124 protected function registerInIdentityMap (object $ entity , Collection $ coll ): void
157125 {
158126 if ($ coll ->name === null ) {
@@ -183,11 +151,11 @@ protected function evictFromIdentityMap(object $entity, Collection $coll): void
183151
184152 protected function findInIdentityMap (Collection $ collection ): object |null
185153 {
186- if ($ collection ->name === null || !is_scalar ($ collection ->condition ) || $ collection ->hasMore ) {
154+ if ($ collection ->name === null || !is_scalar ($ collection ->filter ) || $ collection ->hasChildren ) {
187155 return null ;
188156 }
189157
190- $ condition = $ this ->normalizeIdValue ($ collection ->condition );
158+ $ condition = $ this ->normalizeIdValue ($ collection ->filter );
191159 if ($ condition === null ) {
192160 return null ;
193161 }
@@ -202,7 +170,7 @@ private function tryMergeWithIdentityMap(object $entity, Collection $coll): obje
202170 }
203171
204172 $ entityId = $ this ->entityIdValue ($ entity , $ coll ->name );
205- $ idValue = $ entityId ?? $ this ->normalizeIdValue ($ coll ->condition );
173+ $ idValue = $ entityId ?? $ this ->normalizeIdValue ($ coll ->filter );
206174
207175 if ($ idValue === null ) {
208176 return null ;
@@ -269,36 +237,22 @@ private function normalizeIdValue(mixed $value): int|string|null
269237 return null ;
270238 }
271239
272- public function __get (string $ name ): Collection
273- {
274- if (isset ($ this ->collections [$ name ])) {
275- return $ this ->collections [$ name ];
276- }
277-
278- $ coll = new Collection ($ name );
279-
280- return $ coll ->bindMapper ($ this );
281- }
282-
283240 public function __isset (string $ alias ): bool
284241 {
285242 return isset ($ this ->collections [$ alias ]);
286243 }
287244
288- public function __set (string $ alias , Collection $ collection ): void
289- {
290- $ this ->registerCollection ($ alias , $ collection );
291- }
292-
293- /** @param list<Collection|array<scalar, mixed>|scalar|null> $arguments */
245+ /** @param list<mixed> $arguments */
294246 public function __call (string $ name , array $ arguments ): Collection
295247 {
296248 if (isset ($ this ->collections [$ name ])) {
297- $ collection = clone $ this ->collections [$ name ];
249+ if (empty ($ arguments )) {
250+ return clone $ this ->collections [$ name ];
251+ }
298252
299- return $ collection -> bindMapper ( $ this )-> with (...$ arguments );
253+ return $ this -> collections [ $ name ]-> derive (...$ arguments );
300254 }
301255
302- return Collection:: __callstatic ($ name , $ arguments)-> bindMapper ( $ this );
256+ return new Collection ($ name , ... $ arguments );
303257 }
304258}
0 commit comments