Exemple #1
0
 public function getName()
 {
     return UNC::classToName($this->className, UNC::ENTITY_MASK);
 }
Exemple #2
0
 /**
  * Get a unique query checksum
  *
  * @return integer
  */
 private function _getQueryChecksum()
 {
     return md5(serialize(["name" => $this->getName(), "entity" => UNC::classToName($this->entityReflection->getClassName(), UNC::ENTITY_MASK), "limit" => $this->limit, "offset" => $this->offset, "selection" => $this->selection, "orderBy" => $this->orderBy, "localAssociations" => array_keys($this->associations["local"]), "remoteAssociations" => array_keys($this->associations["remote"]), "conditions" => $this->filter]));
 }
Exemple #3
0
 /**
  * Create query
  *
  * @return QueryBuilder
  */
 protected function query()
 {
     $class = UNC::nameToClass($this->getEntityName(), UNC::ENTITY_MASK);
     return $class::query();
 }
Exemple #4
0
 /**
  * Validate value type
  *
  * @param mixed $value Given value
  *
  * @throws Exception\InvalidArgumentException
  * @throws \Exception
  */
 public function validateValueType($value)
 {
     if ($this->hasOption(self::OPTION_PRIMARY) && self::isPrimaryEmpty($value)) {
         throw new Exception\InvalidArgumentException("Primary value can not be empty string or null!", $value);
     }
     if ($value === null) {
         return;
     }
     // Enumeration
     if ($this->hasOption(self::OPTION_ENUM) && !$this->getOption(self::OPTION_ENUM)->isValid($value)) {
         throw new Exception\InvalidArgumentException("Value " . $value . " is not from defined entity enumeration " . "range on property " . $this->name . "!", $value);
     }
     // Scalar or array type
     if (self::isScalarType($this->type) || $this->type === self::TYPE_ARRAY) {
         if (gettype($value) === $this->type) {
             return;
         }
         throw new Exception\InvalidArgumentException("Expected " . $this->type . " but " . gettype($value) . " given on property " . $this->name . "!", $value);
     }
     // Object validation
     $givenType = gettype($value);
     if ($givenType === "object") {
         $givenType = get_class($value);
     }
     if ($this->type === self::TYPE_ENTITY) {
         // Entity
         $expectedEntityClass = UNC::nameToClass($this->typeOption, UNC::ENTITY_MASK);
         if ($value instanceof $expectedEntityClass) {
             return;
         } else {
             throw new Exception\InvalidArgumentException("Expected entity " . $this->typeOption . " but " . $givenType . " given on property " . $this->name . "!", $value);
         }
     } elseif ($this->type === self::TYPE_COLLECTION) {
         // Collection
         $entityClass = UNC::nameToClass($this->typeOption, UNC::ENTITY_MASK);
         if (!$value instanceof Entity\Collection) {
             throw new Exception\InvalidArgumentException("Expected entity collection but " . $givenType . " given on" . " property " . $this->name . "!", $value);
         } elseif ($value->getEntityClass() !== $entityClass) {
             throw new Exception\InvalidArgumentException("Expected collection of entity " . $entityClass . " but collection of entity " . $value->getEntityClass() . " given on property " . $this->name . "!", $value);
         } else {
             return;
         }
     } elseif ($this->type === self::TYPE_DATETIME) {
         // DateTime
         if ($value instanceof \DateTime) {
             return;
         } else {
             throw new Exception\InvalidArgumentException("Expected DateTime but " . $givenType . " given on" . " property " . $this->name . "!", $value);
         }
     } elseif ($this->type === self::TYPE_DATE) {
         // Date
         if ($value instanceof \DateTime) {
             return;
         } else {
             throw new Exception\InvalidArgumentException("Expected date as DateTime object but " . $givenType . " given on property " . $this->name . "!", $value);
         }
     } else {
         // Unexpected
         throw new \Exception("Unsupported type " . $this->type . "!");
     }
 }