Example #1
0
 private static function instance($model = null, $extra = null)
 {
     $_instance = new self();
     if (0 < preg_match('/^\\d+$/', $extra)) {
         $_instance->id = $extra;
     } elseif (is_string($extra)) {
         $_instance->alias = '`' . $extra . '`';
     }
     if (!is_string($model)) {
         return $_instance->error('模型字符串不正确');
     } else {
         $_instance->model = $model;
     }
     return $_instance;
 }
Example #2
0
File: Neon.php Project: rezon/sugi
 /**
  * Decodes a NEON string.
  * @param  string
  * @return mixed
  */
 public static function decode($input)
 {
     if (!is_string($input)) {
         throw new \InvalidArgumentException("Argument must be a string, " . gettype($input) . " given.");
     }
     if (!self::$re) {
         self::$re = '~(' . implode(')|(', self::$patterns) . ')~Ami';
     }
     $parser = new self();
     $parser->tokenize($input);
     $res = $parser->parse(0);
     while (isset($parser->tokens[$parser->n])) {
         if ($parser->tokens[$parser->n][0] === "\n") {
             $parser->n++;
         } else {
             $parser->error();
         }
     }
     return $res;
 }
Example #3
0
	/**
	 * Decodes a NEON string.
	 * @param  string
	 * @return mixed
	 */
	public static function decode($input)
	{
		if (!is_string($input)) {
			throw new \InvalidArgumentException("Argument must be a string, " . gettype($input) . " given.");
		}
		if (!self::$tokenizer) {
			self::$tokenizer = new Tokenizer(self::$patterns, 'mi');
		}

		$input = str_replace("\r", '', $input);
		self::$tokenizer->tokenize($input);

		$parser = new self;
		$res = $parser->parse(0);

		while (isset(self::$tokenizer->tokens[$parser->n])) {
			if (self::$tokenizer->tokens[$parser->n][0] === "\n") {
				$parser->n++;
			} else {
				$parser->error();
			}
		}
		return $res;
	}