Ejemplo n.º 1
0
 /**
  * Return an array of validations for a property.
  *
  * @param AnDomainPropertyAbstract|string $property Property
  *
  * @return KConfig
  */
 public function getValidations($property)
 {
     if (is_string($property)) {
         $property = $this->_description->getProperty($property);
     }
     $name = $property->getName();
     if (!$this->_validations->{$name}) {
         $this->_validations->{$name} = new KConfig();
     }
     return $this->_validations->{$name};
 }
Ejemplo n.º 2
0
 /**
  * Set a property value for a key.If value is null and the $property is required then
  * set the default value
  *
  * @param string $property Property name
  * @param mixed  $value    Property value
  * 
  * @return void
  */
 protected function _setPropertyValue($property, $value)
 {
     //if a value is null and it's requires set it to the default
     //value
     $property = $this->_description->getProperty($property);
     $name = $property->getName();
     if ($property->isAttribute()) {
         $default = $property->getDefaultValue();
         if ($value === null && $default) {
             $value = $default;
         }
     }
     $this->_property[$name] = $value;
     $this->_materialized[$name] = $name;
 }
Ejemplo n.º 3
0
 /**
  * Find an existing entity with the passed properties. If not found it returns null.
  * If the record is not found then try to fetch the entity from the storage.
  *
  * @param scalar|array $needle The needle to look for
  * @param bool         $fetch  Boolean flag to whether to fetch entity or not if not found
  *
  * @return AnDomainEntityAbstract|null
  */
 public function find($needle, $fetch = true)
 {
     if (empty($needle)) {
         throw new InvalidArgumentException('No condition pased to the repository::find');
     }
     if (!is_array($needle)) {
         $needle = array($this->_description->getIdentityProperty()->getName() => $needle);
     }
     $found = null;
     //there's a key in the needle then it must be a unique entity
     if (count(array_intersect_key($this->_description->getIdentifyingProperties(), $needle)) > 0) {
         $found = $this->_space->findEntity($this->_description, $needle);
     } else {
         $entities = $this->getEntities();
         $found = $entities->find($needle);
     }
     if (!$found && $fetch) {
         $this->getCommandChain()->disable();
         $query = $this->getQuery()->where($needle);
         $found = $this->fetch($query);
         $this->getCommandChain()->enable();
     }
     return $found;
 }
Ejemplo n.º 4
0
 /**
  * Checks to see if an entity of a class with passed in keys exists
  * in the map. If it exist it will return the entity if not it will return
  * null
  * 
  * @param AnDomainDescriptionAbstract $description The entity description
  * @param array                       $identifiers The keys that uniquely identifies the entity
  * 
  * @return AnDomainEntityAbstract
  */
 public function findEntity($description, $identifiers)
 {
     $classes = $description->getUniqueIdentifiers();
     foreach ($classes as $class) {
         foreach ($identifiers as $key => $value) {
             $property = $description->getProperty($key);
             $value = $property->serialize($value);
             $value = implode('', $value);
             //use the identifier application as the unique context
             $key = $description->getEntityIdentifier()->application . $key . $value;
             if (isset($this->_identity_map[$class][$key])) {
                 //found an entity
                 $entity = $this->_identity_map[$class][$key];
                 //only return an entity if it's still within the space
                 if (!$this->_entities->contains($entity)) {
                     return null;
                 }
                 //if the description we are using is the parent of the found entity
                 //if not then we must have found a different entity with the common parent
                 //as the caller repository
                 if (!is_a($entity, $description->getEntityIdentifier()->classname)) {
                     return null;
                 }
                 return $entity;
             }
         }
     }
     return null;
 }