} public function get($count = 0, $start = 0) { return print_r($this->conditions, true); } public function store(EntityInterface $entity) { echo "Storing {$entity->type()}#{$entity->id}\n"; } public function delete(EntityInterface $entity) { echo "Deleting {$entity->type()}#{$entity->id}\n"; } } $locator = new Locator([new RecursiveDirectoryStrategy(__DIR__)]); $repository = new Repository('Article', $locator); /** @var Entity $entity */ $entity = $repository->create(); echo "\nInternal structure:\n"; print_r($entity->getDefinition()); echo "\nResetting\n"; $entity = $repository->create(); echo "\nbelongTo: "; print_r($entity->parent); echo "\n"; echo "\nSetting parent_id = 23\n"; $entity->parent_id = '23'; echo "\nbelongsTo (first access): "; print_r($entity->parent); echo "\nbelongsTo (other access): "; print_r($entity->parent);
/** * Parser callback for onAfterHasManyThrough event * * @param HasManyThrough $relation The data structure * @param LocatorInterface $locator The XML description file locator * * @return void */ public function handleHasManyThrough(HasManyThrough $relation, LocatorInterface $locator) { $basename = $this->getBasename($relation->name); $this->reflector->addHandler($basename, function () use($relation, $locator) { $id = $this->reflector->getId(); if (empty($id)) { return null; } $basename = $this->getBasename($relation->name); // Records from {$relation->entity} with {$relation->reference} IN ids from {$relation->joinTable} with {$relation->joinRef}={$id} $map = new Repository($relation->joinTable, $locator); $entries = $map->findAll()->with($relation->joinRef, Operator::EQUAL, $id)->get(); $repository = new Repository($relation->entity, $locator); $entities = $repository->findAll()->with($relation->reference, Operator::IN, $entries->getIds()); $this->reflector->addField(new Field(['name' => $basename, 'type' => 'relationData', 'value' => $entities])); return $entities; }); }