public function validate(AbstractEntity $entity) { $entityTypes = $entity->getDataTypes(); foreach ($entityTypes as $key => $type) { // echo $key . '->' . gettype($entity->$key) . '==' . $type['type'] . '<br />'; $type['nullable'] = isset($type['nullable']) ? $type['nullable'] : true; if (!$type['nullable'] && !isset($entity->{$key})) { return false; } if ($type['nullable'] && empty($entity->{$key})) { continue; } switch ($type['type']) { case "date": if (!preg_match('/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/', $entity->{$key})) { return false; } break; case "datetime": // if(!preg_match('/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1]) (20|21|22|23|[0-1]?\d{1}):([0-5]?\d{1}):([0-5]?\d{1})$/',$entity->$key)){ if (!preg_match('/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1]) (20|21|22|23|[0-1]?\\d{1}):([0-5]?\\d{1})$/', $entity->{$key})) { return false; } break; case "time": if (!preg_match('/^(20|21|22|23|[0-1]?\\d{1}):([0-5]?\\d{1})$/', $entity->{$key})) { return false; } break; case "string": if (gettype($entity->{$key}) != $type['type']) { return false; } break; case "int": if (!preg_match('/\\d+$/', $entity->{$key})) { return false; } break; case "decimal": // if(!preg_match('^[0-9]+[\\.\\,]{1}[0-9]+$',$entity->$key)){ if (!preg_match('/^(\\d*[.])?\\d+$/', $entity->{$key})) { return false; } break; } if ($type['size']) { if (strlen($entity->{$key}) > $type['size']) { return false; } } } return true; }
/** * Instancja konstruktora * * @param array $data */ public function __construct(array $data = array()) { parent::__construct($data); }
/** * Instancja konstruktora * * @param array $data */ public function __construct(array $data = array()) { $this->webshots = new \Doctrine\Common\Collections\ArrayCollection(); parent::__construct($data); }