示例#1
0
 /**
  * Called to validate an entity. By deafult it validates all the entity
  * properties.
  *
  * @param AnDomainEntityAbstract $entity The entity that is being validated
  *
  * @return bool
  */
 public function validateEntity($entity)
 {
     $description = $entity->getEntityDescription();
     //if entity is persisted only look at the modified
     //properties
     if ($entity->isModified()) {
         $properties = array_intersect_key($description->getProperty(), KConfig::unbox($entity->getModifiedData()));
     } else {
         $properties = $description->getProperty();
     }
     foreach ($properties as $property) {
         $value = $entity->get($property->getName());
         $entity->getValidator()->validateData($entity, $property, $value);
     }
     return $entity->getErrors()->count() === 0;
 }
示例#2
0
 /**
  * Return an array of serializable data of the entity in format of associative array.
  * 
  * The default implementation return an array of scalar attributes
  * 
  * @param AnDomainEntityAbstract $entity
  * 
  * @return array
  */
 public function toSerializableArray($entity)
 {
     $data = array_intersect_key($entity->getData(), $entity->getEntityDescription()->getAttributes());
     return $data;
 }