public function import($scope)
 {
     if (!$this->className) {
         throw new WrongStateException("no class defined for PrimitiveUuidIdentifierList '{$this->name}'");
     }
     if (!BasePrimitive::import($scope)) {
         return null;
     }
     if (!is_array($scope[$this->name])) {
         return false;
     }
     $list = array_unique($scope[$this->name]);
     $values = array();
     foreach ($list as $id) {
         if (!Assert::checkUUID($id)) {
             return false;
         }
         $values[] = $id;
     }
     $objectList = $this->dao()->getListByIds($values);
     if (count($objectList) == count($values) && !($this->min && count($values) < $this->min) && !($this->max && count($values) > $this->max)) {
         $this->value = $objectList;
         return true;
     }
     return false;
 }
Example #2
0
 public static function isIndexExists($array, $key, $message = null)
 {
     Assert::isArray($array);
     if (!array_key_exists($key, $array)) {
         throw new WrongArgumentException($message . ', ' . self::dumpArgument($key));
     }
 }
Example #3
0
 /**
  * @return GmpBigInteger
  **/
 public static function make($number, $base = 10)
 {
     Assert::isTrue(is_numeric($number));
     $result = new self();
     $result->resource = gmp_init($number, $base);
     return $result;
 }
Example #4
0
 public function rebind($name, $object)
 {
     Assert::isNotNull($object);
     $this->map[$name] = $object;
     $this->reverseMap[spl_object_hash($object)] = $name;
     return $this;
 }
Example #5
0
 public static function swap(DAOConnected $first, DAOConnected $second, $property = 'position')
 {
     Assert::isTrue(get_class($first) === get_class($second));
     $setMethod = 'set' . ucfirst($property);
     $getMethod = 'get' . ucfirst($property);
     Assert::isTrue(method_exists($first, $setMethod) && method_exists($first, $getMethod));
     /** @var StorableDAO $dao */
     $dao = $first->dao();
     $db = DBPool::me()->getByDao($dao);
     $oldPosition = $first->{$getMethod}();
     $newPosition = $second->{$getMethod}();
     $db->begin();
     $e = null;
     try {
         $dao->save($first->{$setMethod}(self::$nullValue));
         $dao->save($second->{$setMethod}($oldPosition));
         $dao->save($first->{$setMethod}($newPosition));
         $db->commit();
     } catch (DatabaseException $e) {
         $db->rollback();
     }
     $dao->uncacheByIds([$first->getId(), $second->getId()]);
     if ($e) {
         throw $e;
     }
 }
 public function import($scope)
 {
     if (!$this->className) {
         throw new WrongStateException("no class defined for PrimitiveIdentifierList '{$this->name}'");
     }
     if (!BasePrimitive::import($scope)) {
         return null;
     }
     if (!is_array($scope[$this->name])) {
         return false;
     }
     $list = array_unique($scope[$this->name]);
     $values = array();
     foreach ($list as $id) {
         if (!Assert::checkScalar($id)) {
             return false;
         }
         $values[] = $id;
     }
     $objectList = array();
     foreach ($values as $value) {
         $className = $this->className;
         $objectList[] = new $className($value);
     }
     if (count($objectList) == count($values)) {
         $this->value = $objectList;
         return true;
     }
     return false;
 }
Example #7
0
 public function set($name, $value)
 {
     if (!isset($this->mapping[$name])) {
         throw new WrongArgumentException("knows nothing about property '{$name}'");
     }
     $primitive = $this->mapping[$name];
     $setter = 'set' . ucfirst($primitive->getName());
     if (!method_exists($this->object, $setter)) {
         throw new WrongArgumentException("cannot find mutator for '{$name}' in class " . get_class($this->object));
     }
     if (is_object($value)) {
         if ($primitive instanceof PrimitiveAnyType && $value instanceof PrototypedEntity) {
             $value = ObjectToDTOConverter::create($value->entityProto())->make($value);
         } else {
             $value = $this->dtoValue($value, $primitive);
         }
     } elseif (is_array($value) && is_object(current($value))) {
         $dtoValue = [];
         foreach ($value as $oneValue) {
             Assert::isTrue(is_object($oneValue), 'array must contain only objects');
             $dtoValue[] = $this->dtoValue($oneValue, $primitive);
         }
         $value = $dtoValue;
     }
     return $this->object->{$setter}($value);
 }
Example #8
0
 /**
  * @throws WrongArgumentException
  * @return PrimitiveIdentifier
  **/
 public function of($class)
 {
     $className = $this->guessClassName($class);
     Assert::isTrue(class_exists($className, true) || interface_exists($className, true), "knows nothing about '{$className}' class/interface");
     $this->ofClassName = $className;
     return $this;
 }
 /**
  * @return DoctypeDeclaration
  **/
 public function setPublic($isPublic)
 {
     Assert::isBoolean($isPublic);
     $this->public = $isPublic;
     $this->inline = false;
     return $this;
 }
Example #10
0
 /**
  * @return StripTagsFilter
  **/
 public function setAllowableTags($exclude)
 {
     if (null !== $exclude) {
         Assert::isString($exclude);
     }
     $this->exclude = $exclude;
     return $this;
 }
Example #11
0
 /**
  * @throws WrongArgumentException
  * @return DBSchema
  **/
 public function addTable(DBTable $table)
 {
     $name = $table->getName();
     Assert::isFalse(isset($this->tables[$name]), "table '{$name}' already exist");
     $this->tables[$table->getName()] = $table;
     $this->order[] = $name;
     return $this;
 }
Example #12
0
 public function getRequestGetter()
 {
     Assert::isNotNull($this->requestType);
     if (!$this->requestGetter) {
         $this->requestGetter = self::$requestGetterMap[$this->requestType->getId()];
     }
     return $this->requestGetter;
 }
Example #13
0
 /**
  * @return PrimitiveMultiList
  **/
 public function setDefault($default)
 {
     Assert::isArray($default);
     foreach ($default as $index) {
         Assert::isTrue(array_key_exists($index, $this->list));
     }
     return parent::setDefault($default);
 }
Example #14
0
 /**
  * @throws WrongArgumentException
  * @return LogicalChain
  **/
 public static function getOpenPoint($left, $right, $point)
 {
     Assert::isFalse($point === null, 'how can i build logic from emptyness?');
     $point = new DBValue($point);
     $chain = new LogicalChain();
     $chain->expOr(Expression::orBlock(Expression::andBlock(Expression::notNull($left), Expression::notNull($right), Expression::between($point, $left, $right)), Expression::andBlock(Expression::isNull($left), Expression::ltEq($point, $right)), Expression::andBlock(Expression::isNull($right), Expression::ltEq($left, $point)), Expression::andBlock(Expression::isNull($left), Expression::isNull($right))));
     return $chain;
 }
 protected function prepareResponseFormat()
 {
     if ($this->request->hasAttachedVar('format')) {
         Assert::isNotFalse(array_search($this->request->getAttachedVar('format'), $this->allowedFormatList));
     } else {
         $this->request->setAttachedVar('format', self::DEFAULT_FORMAT);
     }
 }
Example #16
0
 public function __construct($left, $right, $logic)
 {
     Assert::isTrue($right instanceof Query || $right instanceof Criteria || $right instanceof MappableObject || is_array($right));
     Assert::isTrue($logic == self::IN || $logic == self::NOT_IN);
     $this->left = $left;
     $this->right = $right;
     $this->logic = $logic;
 }
Example #17
0
 /**
  * @throws WrongArgumentException
  * @return DBTable
  **/
 public function addColumn(DBColumn $column)
 {
     $name = $column->getName();
     Assert::isFalse(isset($this->columns[$name]), "column '{$name}' already exist");
     $this->order[] = $this->columns[$name] = $column;
     $column->setTable($this);
     return $this;
 }
Example #18
0
 /**
  * @return FileInputStream
  **/
 private function getStream()
 {
     if (!$this->stream) {
         Assert::isNotNull($this->queue->getFileName());
         $this->stream = FileInputStream::create($this->queue->getFileName())->seek($this->queue->getOffset());
     }
     return $this->stream;
 }
Example #19
0
 private function getStream()
 {
     if (!$this->stream) {
         Assert::isNotNull($this->queue->getFileName());
         $this->stream = FileOutputStream::create($this->queue->getFileName(), true);
     }
     return $this->stream;
 }
 public function importValue($value)
 {
     if ($value) {
         Assert::isEqual(get_class($value), $this->className);
     } else {
         return parent::importValue(null);
     }
     return $this->import([$this->getName() => $value->getId()]);
 }
Example #21
0
 /**
  * @throws WrongArgumentException
  * @return Range
  **/
 public function setMax($max = null)
 {
     if ($max !== null) {
         Assert::isInteger($max);
     } else {
         return $this;
     }
     return parent::setMax($max);
 }
Example #22
0
 protected function cacheListByQuery(SelectQuery $query, $array)
 {
     if ($array !== Cache::NOT_FOUND) {
         Assert::isArray($array);
         Assert::isTrue(current($array) instanceof Identifiable);
     }
     Cache::me()->mark($this->className)->add($this->makeQueryKey($query, self::SUFFIX_LIST), $array, Cache::EXPIRES_FOREVER);
     return $array;
 }
Example #23
0
 public static final function create(StorageEngineType $type = null, $linkId = null)
 {
     if (!$type) {
         return new self($linkId);
     }
     $className = $type->toString();
     Assert::classExists($className);
     return new $className($linkId);
 }
 public function getBitmask($config)
 {
     Assert::isInstance($config, AMQPQueueConfig::class);
     $bitmask = parent::getBitmask($config);
     if ($config->getExclusive()) {
         $bitmask = $bitmask | AMQP_EXCLUSIVE;
     }
     return $bitmask;
 }
Example #25
0
 /**
  * @return ArgumentParser
  **/
 public function validate()
 {
     Assert::isNotNull($this->result);
     $this->form->import($this->result);
     if ($errors = $this->form->getErrors()) {
         throw new WrongArgumentException("\nArguments wrong:\n" . print_r($errors, true));
     }
     return $this;
 }
 public function addPeer($label, CachePeer $peer, $mountPoint)
 {
     Assert::isLesserOrEqual($mountPoint, $this->summaryWeight);
     Assert::isGreaterOrEqual($mountPoint, 0);
     $this->doAddPeer($label, $peer);
     $this->peers[$label]['mountPoint'] = $mountPoint;
     $this->sorted = false;
     return $this;
 }
Example #27
0
 public function getBytes($numberOfBytes)
 {
     Assert::isPositiveInteger($numberOfBytes);
     $bytes = null;
     for ($i = 0; $i < $numberOfBytes; $i += 4) {
         $bytes .= pack('L', mt_rand());
     }
     return substr($bytes, 0, $numberOfBytes);
 }
Example #28
0
 public function __construct($class)
 {
     Assert::isTrue(ClassUtils::isInstanceOf($class, Prototyped::class));
     if (is_object($class)) {
         $this->className = get_class($class);
     } else {
         $this->className = $class;
     }
 }
 public function getBitmask($config)
 {
     Assert::isInstance($config, AMQPExchangeConfig::class);
     $bitmask = parent::getBitmask($config);
     if ($config->getInternal()) {
         $bitmask = $bitmask | AMQP_INTERNAL;
     }
     return $bitmask;
 }
Example #30
0
 /**
  * @return ProjectionChain
  **/
 public function add(ObjectProjection $projection, $name = null)
 {
     if ($name) {
         Assert::isFalse(isset($this->list[$name]));
         $this->list[$name] = $projection;
     } else {
         $this->list[] = $projection;
     }
     return $this;
 }