public function add($field, $value) { if (is_object($value)) { $value = \System\Std\Object::getPropertyValue($value, $field); } $validationStatck = new ValidationStack($value); $this->fields[$field] = $validationStatck; return $validationStatck; }
public function __construct($name, $value = '', array $attributes = array()) { parent::__construct($name, $value); if (is_object($value)) { $value = \System\Std\Object::getPropertyValue($value, $name); } $attributes['value'] = $value; $attributes['name'] = !array_key_exists('name', $attributes) ? $name : $attributes['name']; $attributes['id'] = !array_key_exists('id', $attributes) ? $name : $attributes['id']; $this->attributes = array_merge($this->attributes, $attributes); }
public function saveChanges() { $log = array(); foreach ($this->dbSets as $set) { $meta = $set->getMeta(); $entities = $set->getEntities(); foreach ($entities as $entityContext) { $entity = $entityContext->getEntity(); $properties = Object::getProperties($entity); foreach ($properties as $property => $value) { if (is_object($value)) { $parentEntityHash = spl_object_hash($value); if ($this->persistedEntities->hasKey($parentEntityHash)) { $parentEntityContext = $this->persistedEntities->get($parentEntityHash); $parentMeta = $this->dbSets[$parentEntityContext->getName()]->getMeta(); $properties[$property] = Object::getPropertyValue($value, $parentMeta->getKey()->getKeyName()); } } if ($value instanceof \System\Std\Date) { $properties[$property] = $value->toString('yyyy-MM-dd HH:mm:ss'); } $columnAttributes = $meta->getColumnAttributes($property); foreach ($columnAttributes as $attribute) { if ($attribute instanceof \System\Data\Entity\Attributes\ConstraintAttribute) { $attribute->setColumnName($property); $attribute->setValue($value); if (!$attribute->isValid()) { throw new Attributes\ConstraintAttributeException($attribute->getErrorMessage()); } } if ($attribute instanceof \System\Data\Entity\Attributes\DefaultValue) { if (is_null($value)) { $properties[$property] = $attribute->getDefaultValue(); Object::setPropertyValue($entity, $property, $attribute->getDefaultValue()); } } } } switch ($entityContext->getState()) { case EntityContext::PERSIST: $result = $this->conn->insert($meta->getTable()->getTableName(), $properties); $log[] = $result; if ($result) { Object::setPropertyValue($entity, $meta->getKey()->getKeyName(), $this->conn->getInsertId($meta->getKey()->getKeyName())); $entityContext->setState(EntityContext::PERSISTED); $this->persistedEntities->add($entityContext->getHashCode(), $entityContext); } break; case EntityContext::PERSISTED: $updateParams = array($meta->getKey()->getKeyName() => $properties[$meta->getKey()->getKeyName()]); $log[] = $this->conn->update($meta->getTable()->getTableName(), $properties, $updateParams); break; case EntityContext::DELETE: $updateParams = array($meta->getKey()->getKeyName() => $properties[$meta->getKey()->getKeyName()]); $log[] = $this->conn->delete($meta->getTable()->getTableName(), $properties, $updateParams); $this->persistedEntities->removeAt($entityContext->getHashCode()); $set->detach($entity); break; } } } return array_sum($log); }