コード例 #1
0
 public function __construct($root, $path)
 {
     Assert::isString($path, 'non-string path given');
     if (is_object($root)) {
         $className = get_class($root);
     } else {
         Assert::classExists($root);
         $className = $root;
     }
     $this->root = $className;
     $this->path = $path;
     $this->fetchHelpers($className);
     $proto = self::$protos[$className];
     $path = explode('.', $path);
     for ($i = 0, $size = count($path); $i < $size; ++$i) {
         $this->properties[$i] = $property = $proto->getPropertyByName($path[$i]);
         if ($className = $property->getClassName()) {
             $this->fetchHelpers($className);
             $proto = self::$protos[$className];
         } elseif ($i < $size) {
             continue;
         } else {
             throw new WrongArgumentException('corrupted path');
         }
     }
 }
コード例 #2
0
 /**
  * @return StripTagsFilter
  **/
 public function setAllowableTags($exclude)
 {
     if (null !== $exclude) {
         Assert::isString($exclude);
     }
     $this->exclude = $exclude;
     return $this;
 }
コード例 #3
0
 /**
  * @throws WrongArgumentException
  * @return SelectQuery
  **/
 public static function makeFullTextQuery(FullTextDAO $dao, Criteria $criteria, $string)
 {
     Assert::isString($string, 'only strings accepted today');
     $array = self::prepareSearchString($string);
     if (!$array) {
         throw new ObjectNotFoundException();
     }
     if (!($field = $dao->getIndexField()) instanceof DBField) {
         $field = new DBField($dao->getIndexField(), $dao->getTable());
     }
     return $criteria->toSelectQuery()->andWhere(Expression::fullTextOr($field, $array))->prependOrderBy(Expression::fullTextRankAnd($field, $array))->desc();
 }
コード例 #4
0
ファイル: Assert.php プロジェクト: bullhorn/fast-rest
 /**
  * isFloat
  * @param mixed $value
  * @return float
  */
 public static function isFloat($value)
 {
     if (is_object($value)) {
         $value = Assert::isString($value);
     }
     if (is_float($value)) {
         return $value;
     } elseif (is_int($value)) {
         return (double) $value;
     } elseif (is_scalar($value) && (preg_match('@^-?[0-9]+(\\.[0-9]+)?$@', $value) || trim($value) == '')) {
         return (double) $value;
     } else {
         throw new \InvalidArgumentException('Must be Float: ' . print_r($value, true));
     }
 }
コード例 #5
0
 /**
  * @return OqlQueryClause
  **/
 public function parse($string = null)
 {
     if ($string === null) {
         Assert::isNotNull($this->tokenizer);
     } else {
         Assert::isString($string);
         $this->tokenizer = new OqlTokenizer($string);
     }
     $this->state = self::INITIAL_STATE;
     $this->oqlObject = $this->makeOqlObject();
     $this->parentheses = 0;
     while ($this->state != self::FINAL_STATE) {
         $this->state = $this->handleState();
     }
     $this->checkParentheses();
     return $this->oqlObject;
 }
コード例 #6
0
 public function __construct()
 {
     $args = func_get_args();
     if (count($args) == 1 && is_array($args[0])) {
         $args = $args[0];
     }
     if (count($args) == 2) {
         //aka start and end
         $this->setup($args[0], $args[1]);
     } elseif (count($args) == 1) {
         //start-end or ip/mask
         Assert::isString($args[0]);
         $this->createFromString($args[0]);
     } else {
         throw new WrongArgumentException('strange parameters received');
     }
 }
コード例 #7
0
 public function __construct($input)
 {
     if (Assert::checkInteger($input)) {
         $time = $input;
     } else {
         Assert::isString($input);
         $time = explode(':', $input);
     }
     $lenght = strlen($input);
     if (count($time) === 2) {
         $this->setHour($time[0])->setMinute($time[1]);
     } elseif (count($time) === 3) {
         $this->setHour($time[0])->setMinute($time[1])->setSecond($time[2]);
     } else {
         switch ($lenght) {
             case 1:
             case 2:
                 $this->setHour(substr($input, 0, 2));
                 break;
             case 3:
                 $assumedHour = substr($input, 0, 2);
                 if ($assumedHour > 23) {
                     $this->setHour(substr($input, 0, 1))->setMinute(substr($input, 1, 2));
                 } else {
                     $this->setHour($assumedHour)->setMinute(substr($input, 2, 1) . '0');
                 }
                 break;
             case 4:
             case 5:
             case 6:
                 $this->setHour(substr($input, 0, 2))->setMinute(substr($input, 2, 2))->setSecond(substr($input, 4, 2));
                 break;
             default:
                 throw new WrongArgumentException('unknown format');
         }
     }
 }
コード例 #8
0
 /**
  * @throws WrongArgumentException
  * @return PrimitiveFile
  **/
 public function addAllowedMimeType($mime)
 {
     Assert::isString($mime);
     $this->allowedMimeTypes[] = $mime;
     return $this;
 }
コード例 #9
0
 /**
  * @param $value
  * @return SimpleStringableObject
  */
 public function setString($value)
 {
     Assert::isString($value);
     $this->string = $value;
     return $this;
 }
コード例 #10
0
 /**
  * @return RouterRegexpRule
  **/
 public function setReverse($reverse)
 {
     Assert::isString($reverse);
     $this->reverse = $reverse;
     return $this;
 }
コード例 #11
0
 /**
  * @throws WrongArgumentException
  * @return Form
  **/
 public function addRule($name, LogicalObject $rule)
 {
     Assert::isString($name);
     $this->rules[$name] = $rule;
     return $this;
 }
コード例 #12
0
 public function __construct($string)
 {
     Assert::isString($string);
     $this->string = $string;
     $this->length = strlen($string);
 }
コード例 #13
0
 /**
  * @return LogRecord
  **/
 public function setMessage($message)
 {
     Assert::isString($message);
     $this->message = $message;
     return $this;
 }
コード例 #14
0
 protected static function check($string)
 {
     Assert::isString($string);
     Assert::isTrue(preg_match('/^[a-z0-9]+$/iu', $string) !== 0, 'Wrong pattern matching');
 }
コード例 #15
0
 public function setDomain($domain)
 {
     Assert::isString($domain);
     $this->domain = $domain;
     return $this;
 }
コード例 #16
0
 /**
  * @return OqlTokenizer
  **/
 private function tokenize($string)
 {
     Assert::isString($string);
     $maxMultibyteDelta = strlen($string) - mb_strlen($string);
     $isMultibyte = $maxMultibyteDelta > 0;
     $pattern = '/(' . implode(')|(', self::$masks) . ')/is';
     if ($isMultibyte) {
         $pattern .= 'u';
     }
     preg_match_all($pattern, $string, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE);
     $line = 1;
     $lineStart = 0;
     $multibyteDelta = 0;
     foreach ($matches as $match) {
         $type = count($match) - 1;
         $offset = $match[0][1] - $multibyteDelta;
         if ($type == OqlToken::NEW_LINE) {
             $line++;
             $lineStart = $offset + 1;
             continue;
         }
         $value = $match[0][0];
         $position = $offset - $lineStart;
         $this->tokens[] = OqlToken::make($this->importTokenValue($value, $type), $value, $type, $line, $position);
         if ($type == OqlToken::KEYWORD && ($pos = strpos($value, "\n")) !== false) {
             $line++;
             $lineStart = $offset + $pos + 1;
         }
         if ($isMultibyte && $type == OqlToken::STRING) {
             $multibyteDelta += strlen($value) - mb_strlen($value);
             if ($multibyteDelta >= $maxMultibyteDelta) {
                 $isMultibyte = false;
             }
         }
     }
     $this->tokensCount = count($this->tokens);
     return $this;
 }
コード例 #17
0
 /**
  * @throws WrongArgumentException
  * @return StringType
  **/
 public function setDefault($default)
 {
     Assert::isString($default, "strange default value given - '{$default}'");
     $this->default = $default;
     return $this;
 }