コード例 #1
0
 /**
  * Parser callback for onAfterHasOne event
  *
  * @param   HasOne            $relation  The data structure
  * @param   LocatorInterface  $locator   The XML description file locator
  *
  * @return  void
  */
 public function handleHasOne(HasOne $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);
         // The record from {$relation->entity} with {$relation->reference}={$id}
         $repository = new Repository($relation->entity, $locator);
         $entity = $repository->findOne()->with($relation->reference, Operator::EQUAL, $id)->get();
         $this->reflector->addField(new Field(['name' => $basename, 'type' => 'relationData', 'value' => $entity]));
         return $entity;
     });
 }