Beispiel #1
0
 /**
  * Validate property key & value
  *
  * Throws an exception if something is incorrect
  *
  * @PrePersist
  * @PreUpdate
  */
 public function validate()
 {
     if (!Definition\PropertyDefinition::exists($this->key)) {
         throw new \Exception('Invalid property: \'' . $this->key . '\'');
     }
     $this->cast();
     // TODO not safe
     if (!$this->getDefinition()->validateValue($this->value)) {
         throw new \Exception('Invalid property value: \'' . $this->value . '\'');
     }
 }
 /**
  * Update/set/delete properties of entities
  */
 protected function setProperties(Model\Entity $entity, $parameters)
 {
     foreach ($parameters as $key => $value) {
         if (in_array($key, array('operation', 'type', 'debug'))) {
             continue;
             // skip generic parameters
         } else {
             if (!Definition\PropertyDefinition::exists($key)) {
                 throw new \Exception('Unknown property: \'' . $key . '\'');
             }
         }
         if ($value == '') {
             // dont use empty() because it also matches 0
             $entity->deleteProperty($key);
         } else {
             $entity->setProperty($key, $value);
         }
     }
     $entity->checkProperties();
 }