Пример #1
0
 /**
  * {@inheritdoc}
  */
 public function factory($entityType)
 {
     if ($this->factoryContainer instanceof FactoryContainerInterface) {
         return $this->factoryContainer->getFactory($entityType);
     }
     throw new \Exception('No factory container set.');
 }
Пример #2
0
 /**
  * Sanitizes an object property based on this definition.
  *
  * @param \stdClass $object
  *   The object of which to sanitize the property.
  * @param \TheSportsDb\Entity\Factory\FactoryContainerInterface $factoryContainer
  *   The factory container.
  *
  * @return void
  */
 public function sanitizeProperty(\stdClass &$object, FactoryContainerInterface $factoryContainer)
 {
     if (($entityType = $this->getEntityType()) && isset($object->{$this->getName()})) {
         $value =& $object->{$this->getName()};
         if ($this->isArray()) {
             foreach ($value as &$val) {
                 if ($val instanceof EntityInterface) {
                     continue;
                 }
                 $val = $factoryContainer->getFactory($entityType)->create($val, $entityType);
             }
         } elseif (!$value instanceof EntityInterface) {
             $value = $factoryContainer->getFactory($entityType)->create($value, $entityType);
         }
     }
 }