public function importValue($value)
 {
     if ($value instanceof UnifiedContainer) {
         if ($value->isLazy()) {
             return $this->import(array($this->name => $value->getList()));
         } elseif ($value->getParentObject()->getId() && ($list = $value->getList())) {
             return $this->import(array($this->name => ArrayUtils::getIdsArray($list)));
         } else {
             return parent::importValue(null);
         }
     }
     if (is_array($value)) {
         try {
             if ($this->scalar) {
                 Assert::isScalar(current($value));
             } else {
                 Assert::isInteger(current($value));
             }
             return $this->import(array($this->name => $value));
         } catch (WrongArgumentException $e) {
             return $this->import(array($this->name => ArrayUtils::getIdsArray($value)));
         }
     }
     return parent::importValue($value);
 }
 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;
 }
 protected function checkNumber($number)
 {
     if ($this->scalar) {
         Assert::isScalar($number);
     } else {
         Assert::isInteger($number);
     }
 }
 /**
  * @throws WrongArgumentException
  * @return Range
  **/
 public function setMax($max = null)
 {
     if ($max !== null) {
         Assert::isInteger($max);
     } else {
         return $this;
     }
     return parent::setMax($max);
 }
 /**
  * @throws WrongArgumentException
  * @return QueryCombination
  **/
 public function limit($limit = null, $offset = null)
 {
     if ($limit !== null) {
         Assert::isPositiveInteger($limit, 'invalid limit specified');
     }
     if ($offset !== null) {
         Assert::isInteger($offset, 'invalid offset specified');
     }
     $this->limit = $limit;
     $this->offset = $offset;
     return $this;
 }
Esempio n. 6
0
 /**
  * Returns timeZone offset in
  *
  * @param unknown $timeZone
  * @param unknown $when
  * @return void
  * @access public
  */
 static function offset($timeZone, $when = 'now')
 {
     try {
         $DateTimeZone = new DateTimeZone($timeZone);
         $DateTime = new DateTime($when, $DateTimeZone);
         $offset = (int) $DateTimeZone->getOffset($DateTime);
     } catch (Exception $Exception) {
         throw new AppException($Exception->getMessage());
     }
     Assert::isInteger($offset);
     return $offset;
 }
 /**
  * @param integer $id
  * @throws WrongArgumentException
  * @return AMQPChannelInterface
  **/
 public function createChannel($id)
 {
     Assert::isInteger($id);
     if (isset($this->channels[$id])) {
         throw new WrongArgumentException("AMQP channel with id '{$id}' already registered");
     }
     if (!$this->isConnected()) {
         $this->connect();
     }
     $this->channels[$id] = $this->spawnChannel($id, $this)->open();
     return $this->channels[$id];
 }
 public function importValue($value)
 {
     if (is_array($value)) {
         try {
             Assert::isInteger(current($value));
             return $this->import(array($this->name => $value));
         } catch (WrongArgumentException $e) {
             return $this->import(array($this->name => ArrayUtils::getIdsArray($value)));
         }
     }
     return parent::importValue($value);
 }
 public function __construct(IpAddress $ip, $mask)
 {
     Assert::isInteger($mask);
     if ($mask == 0 || self::MASK_MAX_SIZE < $mask) {
         throw new WrongArgumentException('wrong mask given');
     }
     $this->longMask = (int) (pow(2, 32 - $mask) * (pow(2, $mask) - 1));
     if (($ip->getLongIp() & $this->longMask) != $ip->getLongIp()) {
         throw new WrongArgumentException('wrong ip network given');
     }
     $this->ip = $ip;
     $this->mask = $mask;
 }
 protected function checkNumber($number)
 {
     Assert::isInteger($number);
 }
 public static function sendContentLength($length)
 {
     Assert::isInteger($length);
     header("Content-Length: {$length}");
     self::$headerSent = true;
 }
 /**
  * @param integer $id
  * @throws WrongArgumentException
  * @return AMQPChannelInterface
  **/
 public function createChannel($id)
 {
     Assert::isInteger($id);
     if (isset($this->channels[$id])) {
         throw new WrongArgumentException("AMQP channel with id '{$id}' already registered");
     }
     if (!$this->current) {
         $this->setCurrent($this->getAlive());
     }
     if (!$this->isConnected()) {
         $this->connect();
     }
     $this->channels[$id] = new self::$proxy($this->getCurrentItem()->spawnChannel($id, $this));
     $this->channels[$id]->open();
     return $this->channels[$id];
 }
 public function setDataSetIndex($index)
 {
     Assert::isInteger($index);
     $this->dataSetIndex = $index;
     return $this;
 }
 /**
  * Set's custom error mark for primitive.
  * 
  * @return Form
  **/
 public function markCustom($primitiveName, $customMark, $label = null)
 {
     Assert::isInteger($customMark);
     $this->errors[$this->get($primitiveName)->getName()] = $customMark;
     if ($label !== null) {
         $this->addCustomLabel($primitiveName, $customMark, $label);
     }
     return $this;
 }
Esempio n. 15
0
 /**
  * Set's custom error mark for primitive.
  * 
  * @return Form
  **/
 public function markCustom($primitiveName, $customMark)
 {
     Assert::isInteger($customMark);
     $this->errors[$this->get($primitiveName)->getName()] = $customMark;
     return $this;
 }
 /**
  * Message priority from 0 to 9.
  *
  * @return AMQPBaseMessage
  **/
 public function setPriority($int)
 {
     Assert::isInteger($int, __METHOD__);
     Assert::isTrue($int >= self::PRIORITY_MIN && $int <= self::PRIORITY_MAX, __METHOD__);
     $this->properties[self::PRIORITY] = $int;
     return $this;
 }
 public function setMaxAge($expire)
 {
     Assert::isInteger($expire);
     $this->expire = $expire;
     return $this;
 }
 /**
  * @throws WrongArgumentException
  * @return IntegerType
  **/
 public function setDefault($default)
 {
     Assert::isInteger($default, "strange default value given - '{$default}'");
     $this->default = $default;
     return $this;
 }
 /**
  * @throws WrongArgumentException
  * @return DataType
  **/
 public function setScale($scale)
 {
     Assert::isInteger($scale);
     Assert::isTrue(($this->id & self::HAVE_SCALE) > 0);
     $this->scale = $scale;
     return $this;
 }
 /**
  * @throws WrongArgumentException
  * @return MetaClassProperty
  **/
 public function setSize($size)
 {
     if ($this->type instanceof NumericType) {
         if (strpos($size, ',') !== false) {
             list($size, $precision) = explode(',', $size, 2);
             $this->type->setPrecision($precision);
         }
     }
     Assert::isInteger($size, 'only integers allowed in size parameter');
     if ($this->type->isMeasurable()) {
         $this->size = $size;
     } else {
         throw new WrongArgumentException("size not allowed for '" . $this->getName() . '::' . get_class($this->type) . "' type");
     }
     return $this;
 }
Esempio n. 21
0
 public function test_should_support_integer_assertion()
 {
     $this->assertTrue(Assert::isInteger(3));
 }