/**
  * @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;
 }
 /**
  * @param OrmClass $ormClass object that represents a class to be generated
  * @param OrmProperty $ormProperty property that implements a ContainerPropertyType
  */
 function __construct(OrmClass $ormClass, OrmProperty $ormProperty)
 {
     $this->ormProperty = $ormProperty;
     $this->propertyType = $ormProperty->getType();
     Assert::isTrue($this->propertyType instanceof ContainerPropertyType);
     parent::__construct($ormClass);
 }
 /**
  * @throws WrongArgumentException
  * @return IdentifiablePrimitive
  **/
 public function setValue($value)
 {
     $className = $this->className;
     Assert::isNotNull($this->className);
     Assert::isTrue($value instanceof $className);
     return parent::setValue($value);
 }
 function setDefaultValue($value)
 {
     Assert::isScalar($value, 'default value shall be scalar');
     Assert::isTrue(in_array($value, $this->getAvailableValues()), 'trying to set a default value that is out of options range');
     $this->defaultValue = $value;
     return $this;
 }
 function move($filepath)
 {
     Assert::isScalar($filepath);
     Assert::isTrue(is_dir(dirname($filepath)));
     Assert::isTrue(is_writable(dirname($filepath)));
     return move_uploaded_file($this->getImportedFilepath(), $filepath);
 }
 public function __construct()
 {
     require ONPHP_META_AUTO_DIR . 'schema.php';
     Assert::isTrue(isset($schema));
     $this->schema = $schema;
     // in case of unclean shutdown of previous tests
     foreach (DBTestPool::me()->getPool() as $name => $db) {
         foreach ($this->schema->getTableNames() as $name) {
             try {
                 $db->queryRaw(OSQL::dropTable($name, true)->toDialectString($db->getDialect()));
             } catch (DatabaseException $e) {
                 // ok
             }
             if ($db->hasSequences()) {
                 foreach ($this->schema->getTableByName($name)->getColumns() as $columnName => $column) {
                     try {
                         if ($column->isAutoincrement()) {
                             $db->queryRaw("DROP SEQUENCE {$name}_id;");
                         }
                     } catch (DatabaseException $e) {
                         // ok
                     }
                 }
             }
         }
     }
 }
 private function makeSelectQuery(SqlSelectiveFieldSet $fields, $source, IDalExpression $condition = null, SqlOrderChain $orderBy = null, $limit = 0, $offset = 0)
 {
     Assert::isInteger($limit);
     Assert::isInteger($offset);
     $dialect = $this->getDB()->getDialect();
     $query = array();
     $query[] = 'SELECT ' . $fields->toDialectString($dialect);
     if (is_scalar($source)) {
         $source = $dialect->quoteIdentifier($source);
     } else {
         Assert::isTrue(is_array($source));
         $tables = array();
         foreach ($source as $table) {
             $tables[] = $dialect->quoteIdentifier($table);
         }
         $source = join(", ", $tables);
     }
     $query[] = 'FROM ' . $source;
     if ($condition) {
         $query[] = 'WHERE ' . $condition->toDialectString($dialect);
     }
     if ($orderBy) {
         $query[] = $orderBy->toDialectString($dialect);
     }
     if ($limit) {
         $query[] = 'LIMIT ' . (int) $limit;
     }
     if ($offset) {
         $query[] = 'OFFSET ' . (int) $offset;
     }
     $query = join("\r\n", $query);
     return $query;
 }
Esempio n. 8
0
 /**
  * Sets the cookie value. It cannot be longer than Cookie::RFC_MAX_SIZE.
  * @param string $value
  * @return Cookie
  */
 function setValue($value)
 {
     Assert::isScalar($value);
     Assert::isTrue(strlen($value) < self::RFC_MAX_SIZE);
     $this->value = $value;
     return $this;
 }
 /**
  * @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;
 }
 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));
     $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(array($first->getId(), $second->getId()));
     if ($e) {
         throw $e;
     }
 }
 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 = array();
         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);
 }
 /**
  * @return PrototypedBuilder
  **/
 public function cloneBuilder(EntityProto $proto)
 {
     Assert::isTrue($this->proto->isInstanceOf($proto) || $proto->isInstanceOf($this->proto), Assert::dumpArgument($proto));
     $result = new $this($proto);
     $result->limitedPropertiesList = $this->limitedPropertiesList;
     return $result;
 }
Esempio n. 13
0
 function __construct(DBConnector $db)
 {
     Assert::isTrue(isset(self::$drivers[$db->getDriver()->getId()]), "unknown driver is specified: {$db->getDriver()}");
     $className = self::$drivers[$db->getDriver()->getId()];
     $driver = new ReflectionClass($className);
     Assert::isTrue($driver->isSubclassOf(new ReflectionClass('DBBackup')), "{$className} should implement DBBackup");
     $this->driver = $driver->newInstance($db);
 }
 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;
 }
 /**
  * @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);
 }
Esempio n. 16
0
 /**
  * @return string
  */
 private function getActualClassName($class)
 {
     if (!is_scalar($class)) {
         Assert::isTrue(is_object($class));
         $class = get_class($class);
     }
     return $class;
 }
Esempio n. 17
0
 /**
  * Determines whether class is the child class of the parent class
  *
  * @param string|object $child
  * @param string|object $parent
  * @return boolean
  */
 static function isChild($child, $parent)
 {
     $child = self::resolveName($child);
     $parent = self::resolveName($parent);
     Assert::isTrue(self::isExists($child), 'unknown type %s', $child);
     Assert::isTrue(self::isExists($parent), 'unknown type %s', $parent);
     return in_array($parent, class_implements($child)) || in_array($parent, class_parents($child));
 }
 function setDefaultValue($value)
 {
     if (!is_array($value)) {
         $value = $value ? array($value) : array();
     }
     Assert::isTrue(sizeof($value) == array_intersect($this->getAvailableValues(), $value), 'trying to set the default value that is out of options range');
     parent::setDefaultValue($value);
 }
 /**
  * @param string $path
  * @return DBTestCreator
  */
 public function setSchemaPath($path)
 {
     require $path;
     Assert::isTrue(isset($schema));
     Assert::isInstance($schema, 'DBSchema');
     $this->schema = $schema;
     return $this;
 }
 public function __construct($class)
 {
     Assert::isTrue(ClassUtils::isInstanceOf($class, 'Prototyped'));
     if (is_object($class)) {
         $this->className = get_class($class);
     } else {
         $this->className = $class;
     }
 }
 private function fetchHelpers($className)
 {
     if (isset(self::$protos[$className], self::$daos[$className])) {
         return;
     }
     self::$protos[$className] = call_user_func(array($className, 'proto'));
     self::$daos[$className] = ClassUtils::isInstanceOf($className, 'DAOConnected') ? call_user_func(array($className, 'dao')) : null;
     Assert::isTrue(self::$protos[$className] instanceof AbstractProtoClass && (self::$daos[$className] instanceof ProtoDAO || self::$daos[$className] === null));
 }
 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;
 }
 /**
  * @return IndexedList
  **/
 public function offsetSet($offset, $value)
 {
     Assert::isTrue($value instanceof Identifiable);
     $offset = $value->getId();
     if ($this->offsetExists($offset)) {
         throw new WrongArgumentException("object with id == '{$offset}' already exists");
     }
     $this->list[$offset] = $value;
     return $this;
 }
 /**
  * @return SQLChain
  **/
 public function toMapped(ProtoDAO $dao, JoinCapableQuery $query)
 {
     $size = count($this->chain);
     Assert::isTrue($size > 0, 'empty chain');
     $chain = new $this();
     for ($i = 0; $i < $size; ++$i) {
         $chain->exp($dao->guessAtom($this->chain[$i], $query), $this->logic[$i]);
     }
     return $chain;
 }
 public function set($name, $value)
 {
     if (!isset($this->mapping[$name])) {
         throw new WrongArgumentException("knows nothing about property '{$name}'");
     }
     Assert::isTrue(!is_object($value), 'cannot put objects into scope');
     $primitive = $this->mapping[$name];
     $this->object[$primitive->getName()] = $value;
     return $this;
 }
Esempio n. 26
0
 /**
  * @return Date
  * @see http://www.faqs.org/rfcs/rfc3339.html
  * @see http://www.cl.cam.ac.uk/~mgk25/iso-time.html
  **/
 public static function makeFromWeek($weekNumber, $year = null)
 {
     if (!$year) {
         $year = date('Y');
     }
     Assert::isTrue($weekNumber > 0 && $weekNumber <= self::getWeekCountInYear($year));
     $date = new self(date(self::getFormat(), mktime(0, 0, 0, 1, 1, $year)));
     $days = ($weekNumber - 1 + (self::getWeekCountInYear($year - 1) == 53 ? 1 : 0)) * 7 + 1 - $date->getWeekDay();
     return $date->modify("+{$days} day");
 }
 /**
  * @return PrimitiveIdentifier
  **/
 public function setMethodName($methodName)
 {
     if (strpos($methodName, '::') === false) {
         $dao = $this->dao();
         Assert::isTrue(method_exists($dao, $methodName), "knows nothing about '" . get_class($dao) . "::{$methodName}' method");
     } else {
         ClassUtils::checkStaticMethod($methodName);
     }
     $this->methodName = $methodName;
     return $this;
 }
 public function toBoolean(Form $form)
 {
     Assert::isTrue($this->brackets, 'brackets must be enabled');
     $subject = $form->toFormValue($this->subject);
     switch ($this->logic) {
         case self::NOT:
             return false === $subject;
         default:
             throw new UnsupportedMethodException("'{$this->logic}' doesn't supported yet");
     }
 }
Esempio n. 29
0
 /**
  * @param string $filepath path to the file that should be presented in response
  * @param string $filename optional name of the file to be specified in the response
  * @param string $contentType optional content type of the file to be specified in the response
  * @param boolean $unlinkOnFinish whether to remove the file when response is finished
  */
 function __construct($filepath, $filename = null, $contentType = null, $unlinkOnFinish = false)
 {
     Assert::isTrue(is_file($filepath));
     Assert::isScalarOrNull($filename);
     Assert::isScalarOrNull($contentType);
     Assert::isBoolean($unlinkOnFinish);
     $this->filepath = $filepath;
     $this->filename = $filename ? $filename : basename($filepath);
     $this->contentType = $contentType;
     $this->unlinkOnFileFlush = $unlinkOnFinish;
 }
Esempio n. 30
0
 private function handleError(RouteData $routeData, WebRequest $request)
 {
     if (!isset($routeData['defaultController'])) {
         throw new DispatchControllerException($routeData, $request);
     }
     $controllerName = $routeData['defaultController'];
     $controllerClassName = $this->getControllerClassName($controllerName, $routeData);
     Assert::isTrue(class_exists($controllerClassName, true), 'missing %s as defaultController', $controllerClassName);
     $controllerObject = $this->getControllerInstance($controllerClassName, $routeData);
     $controllerObject->handle($routeData, $request);
 }