예제 #1
0
 /**
  * Resolve and if necessary initialize the property definition collection.
  *
  * @param PropertyDefinitionCollectionInterface $propertyDefinitionCollection
  *
  * @return PropertyDefinitionCollectionInterface
  */
 protected function resolveDefitions(PropertyDefinitionCollectionInterface $propertyDefinitionCollection = null)
 {
     if ($propertyDefinitionCollection instanceof PropertyDefinitionCollectionInterface) {
         return $propertyDefinitionCollection->import($this->propertiesAndTypes());
     }
     $className = $this->calledClassName();
     if ($this->runtimeCache->has($className, __METHOD__)) {
         return $this->runtimeCache->get($className, __METHOD__);
     }
     $propertyDefinitionCollection = $this->createPropertyDefinitionCollection();
     $propertyDefinitionCollection->import($this->propertiesAndTypes());
     $this->runtimeCache->set($className, $propertyDefinitionCollection, __METHOD__);
     return $propertyDefinitionCollection;
 }
예제 #2
0
 protected function castToClass($value, $class)
 {
     if (!is_object($value) && !is_array($value)) {
         return $value;
     }
     if (!class_exists($class) || $value instanceof $class) {
         return $value;
     }
     if (!$this->runtimeCache->has($class)) {
         $this->runtimeCache->set($class, new $class());
     }
     $object = clone $this->runtimeCache->get($class);
     if (is_subclass_of($class, 'Entity\\Abstraction\\EntityInterface')) {
         $object->fromArray(is_array($value) || $value instanceof \Traversable ? $value : (array) $value);
     } else {
         foreach ($value as $key => $item) {
             $object->{$key} = $value;
         }
     }
     return $object;
 }