创建驱动实例
@param string $name
@param string $alias
@param array $args
@return mixed
543294
public static function create($option = array(), $alias = null)
	{
		if('' === static::$driverName)
		{
			static::init();
		}
		if(isset(self::$instances[static::$driverName][$alias]))
		{
			return self::$instances[static::$driverName][$alias];
		}
		else
		{
			$object = static::__createBefore($option, $alias);
			if(null === $object)
			{
				$className = static::$driverName . $option['type'];
				$ref = new ReflectionClass($className);
				$object = $ref->newInstance(isset($option['option']) ? $option['option'] : array());
			}
			static::__createAfter($option, $alias, $object);
			if(null !== $alias)
			{
				self::$instances[static::$driverName][$alias] = $object;
			}
			return $object;
		}
	}
789391
public function getAlias($name = null)
    {
        if (is_null($name)) {
            return $this->alias;
        }

        return isset($this->alias[$name]) ? $this->alias[$name] : null;
    }
171898
public function getRoute($name, array $args = [])
    {
        if (!isset($this->names[$name])) {
            return null;
        }

        $route = $this->callbacks[$this->names[$name]];

        if (strpos($route->pattern, '(') === false) {
            // If we don't have any route parameters, just return the pattern
            // straight off. No need for any regex stuff.
            return $route->pattern;
        }

        // Convert all placeholders to %o = optional and %r = required
        $from    = ['/(\([^\/]+[\)]+[\?])/', '/(\([^\/]+\))/'];
        $to      = ['%o', '%r'];
        $pattern = preg_replace($from, $to, $route->pattern);

        $frags = explode('/', trim($pattern, '/'));
        $url   = [];

        // Loop thru the pattern fragments and insert the arguments
        foreach ($frags as $frag) {
            if ($frag == '%r') {
                if (!$args) {
                    // A required parameter, but no more arguments.
                    throw new Exception('Missing route parameters');
                }
                $url[] = array_shift($args);
                continue;
            }

            if ($frag == "%o") {
                if (!$args) {
                    // No argument for the optional parameter,
                    // just continue the iteration.
                    continue;
                }
                $url[] = array_shift($args);
                continue;
            }

            $url[] = $frag;
        }

        return '/' . implode('/', $url);
    }
826249
public function alias($alias, $name) {
		if (is_array($alias)) {
			foreach ($alias as $key) {
				$this->alias($key, $name);
			}

			return;
		}

		$this->aliases[$alias] = $name;
	}
631602
public static function Factory($Alias = FALSE) {
      if (is_null(self::$_Factory)) {
         self::SetFactory(new Gdn_Factory());
         self::FactoryOverwrite(FALSE);
      }

      if ($Alias === FALSE)
         return self::$_Factory;
      
      // Get the arguments to pass to the factory.
      //$Args = array($Arg1, $Arg2, $Arg3, $Arg4, $Arg5);
      $Args = func_get_args();
      array_shift($Args);
      return self::$_Factory->Factory($Alias, $Args);
   }
1109805
public function helper($name, $args = [])
    {
        $args = func_get_args();
        $name = array_shift($args);
        if (isset($this->helpers[$name]) && is_callable($this->helpers[$name])) {
            return call_user_func_array($this->helpers[$name], $args);
        } elseif (($helper = [Helper::class, $name]) && is_callable($helper)) {
            return call_user_func_array($helper, $args);
        }

        throw new \RuntimeException(sprintf('undefined helper "%s" in %s line %d', $name, static::NAME, $this->getLineTrace()));
    }
1193696
public static function table(string $tableName, string $alias = null): QueryBuilder
    {
        $query = new QueryBuilder();
        $query = $query->table($tableName, $alias);

        return $query;
    }
819530
private function fncall($name, $argValues)
    {
        // SCSS @function
        if ($this->callScssFunction($name, $argValues, $returnValue)) {
            return $returnValue;
        }

        // native PHP functions
        if ($this->callNativeFunction($name, $argValues, $returnValue)) {
            return $returnValue;
        }

        // for CSS functions, simply flatten the arguments into a list
        $listArgs = [];

        foreach ((array) $argValues as $arg) {
            if (empty($arg[0])) {
                $listArgs[] = $this->reduce($arg[1]);
            }
        }

        return [Type::T_FUNCTION, $name, [Type::T_LIST, ',', $listArgs]];
    }
327213
protected function executeCommand(OutputInterface $output, $name, $args = [])
    {
        array_unshift($args, 'internal');

        $return = $this->getApplication()->find($name)->run(new ArrayInput($args), $output);

        if (0 !== $return) {
            throw new \RuntimeException(sprintf("An error occured when executing command '%s'", $name), 30);
        }

        return $this;
    }
846028
public function execute($name, $args)
	{
	    if (!$this->__sock) {
	        return null;
	    }
	    
	    $args = (array) $args;
	    if(in_array($name, static::$keyCommands)) {
	        if ($this->options['prefix'] && strpos($args[0], $this->options['prefix']) === false) {
	            $args[0] = $this->options['prefix'] . $args[0];
	        }
	    }
	    
	    /* Build the Redis unified protocol command */
	    array_unshift($args, strtoupper($name));
	    $command = sprintf('*%d%s%s%s', count($args), CRLF, implode(array_map(array($this, 'formatArgument'), $args), CRLF), CRLF);
	    
	    /* Open a Redis connection and execute the command */
	    for ($written = 0; $written < strlen($command); $written += $fwrite) {
	        $fwrite = fwrite($this->__sock, substr($command, $written));
	        if ($fwrite === FALSE) {
	            throw new Exception('Failed to write entire command to stream');
	        }
	    }
	    
	    /* Parse the response based on the reply identifier */
	    $reply = trim(fgets($this->__sock, 512));
	    switch (substr($reply, 0, 1)) {
	        /* Error reply */
	        case '-':
	            throw new RedisException(substr(trim($reply), 4));
	            break;
	            /* Inline reply */
	        case '+':
	            $response = substr(trim($reply), 1);
	            break;
	            /* Bulk reply */
	        case '$':
	            $response = null;
	            if ($reply == '$-1') {
	                break;
	            }
	            $read = 0;
	            $size = substr($reply, 1);
	            do {
	                $block_size = ($size - $read) > 1024 ? 1024 : ($size - $read);
	                $response .= fread($this->__sock, $block_size);
	                $read += $block_size;
	            } while ($read < $size);
	            fread($this->__sock, 2); /* discard crlf */
	            break;
	            /* Multi-bulk reply */
	        case '*':
	            $count = substr($reply, 1);
	            if ($count == '-1') {
	                return null;
	            }
	            $response = array();
	            for ($i = 0; $i < $count; $i++) {
	                $bulk_head = trim(fgets($this->__sock, 512));
	                $size = substr($bulk_head, 1);
	                if ($size == '-1') {
	                    $response[] = null;
	                }
	                else {
	                    $read = 0;
	                    $block = "";
	                    do {
	                        $block_size = ($size - $read) > 1024 ? 1024 : ($size - $read);
	                        $block .= fread($this->__sock, $block_size);
	                        $read += $block_size;
	                    } while ($read < $size);
	                    fread($this->__sock, 2); /* discard crlf */
	                    $response[] = $block;
	                }
	            }
	            break;
	            /* Integer reply */
	        case ':':
	            $response = intval(substr(trim($reply), 1));
	            break;
	        default:
	            throw new RedisException("invalid server response: {$reply}");
	            break;
	    }
	    /* Party on */
	    return $response;
	}
1205123
public static function create($name, ...$args)
    {
        $name = static::getClass($name);

        $class = static::findClass($name);

        if ($class) {
            return static::createObject($class, ...$args);
        }

        return null;
    }
740750
public function get($alias, array $args = [])
    {
        $alias    = $this->inflectClassName($alias);
        $instance = NULL;

        // If we already have a shared instance, return it now
        if ( array_key_exists($alias, $this->sharedInstances) ) {
            return $this->sharedInstances[ $alias ];
        }

        // If we have an alias for this class get that
        if ( array_key_exists($alias, $this->aliases) ) {
            $instance = $this->get($this->aliases[ $alias ], $args);
        }

        // If the class is a callable
        if ( array_key_exists($alias, $this->callables) ) {
            $instance = $this->call($alias, $args);
        }


        // If we don't have an instance, create it now
        if ( !$instance ) {
            $instance = parent::get($alias, $args);
        }

        // If we should store a copy of this instance, do it now
        if ( in_array($alias, $this->toShare) ) {
            $this->sharedInstances[ $alias ] = $instance;
        }

        return $instance;
    }
714085
public function __callResolver(string $name, array $args)
    {
        //get the handler
        $handler = $this->getResolverHandler();

        //can it be resolved?
        if ($handler->canResolve($name)) {
            //is it shared ?
            if ($handler->isShared($name)) {
                //resolve the shared
                return $this->resolveShared($name, ...$args);
            }

            //resolve it the regular way
            return $this->resolve($name, ...$args);
        }

        //oops ?
        throw ResolverException::forMethodNotFound(get_class($this), $name);
    }
676024
public function runMacro($name, $args)
    {
        if (isset($this->macros[$name])) {
            if (is_callable($this->macros[$name])) {
                return call_user_func_array($this->macros[$name], array_merge([$this], $args));
            }
        }
    }
460688
public function command(
        string $name,
        string $desc = '',
        string $alias = '',
        bool $allowUnknown = false,
        bool $default = false
    ): Command {
        $command = new Command($name, $desc, $allowUnknown, $this);

        $this->add($command, $alias, $default);

        return $command;
    }
1222865
protected function _parseFunction($name, $args)
    {
        $res = '';
        switch ($name) {
            case 'if':
                $res = 'if('.$this->_parseFinal($args, $this->_allowedInExpr).'):';
                array_push($this->_blockStack, 'if');
                break;

            case 'else':
                if (substr(end($this->_blockStack), 0, 2) != 'if') {
                    $this->doError1('errors.tpl.tag.block.end.missing', end($this->_blockStack));
                } else {
                    $res = 'else:';
                }
                break;

            case 'elseif':
                if (end($this->_blockStack) != 'if') {
                    $this->doError1('errors.tpl.tag.block.end.missing', end($this->_blockStack));
                } else {
                    $res = 'elseif('.$this->_parseFinal($args, $this->_allowedInExpr).'):';
                }
                break;

            case 'foreach':
                if ($this->trusted) {
                    $notallowed = array(';','!');
                } else {
                    $notallowed = array(';','!','(');
                }

                if (preg_match("/^\s*\((.*)\)\s*$/", $args, $m)) {
                    $args = $m[1];
                }

                $res = 'foreach('.$this->_parseFinal($args, $this->_allowedInForeach, $notallowed).'):';
                array_push($this->_blockStack, 'foreach');
                break;

            case 'while':
                $res = 'while('.$this->_parseFinal($args, $this->_allowedInExpr).'):';
                array_push($this->_blockStack, 'while');
                break;

            case 'for':
                if ($this->trusted) {
                    $notallowed = array();
                } else {
                    $notallowed = array('(');
                }
                if (preg_match("/^\s*\((.*)\)\s*$/", $args, $m)) {
                    $args = $m[1];
                }
                $res = 'for('.$this->_parseFinal($args, $this->_allowedInExpr, $notallowed).'):';
                array_push($this->_blockStack, 'for');
                break;

            case '/foreach':
            case '/for':
            case '/if':
            case '/while':
                $short = substr($name, 1);
                if (end($this->_blockStack) != $short) {
                    $this->doError1('errors.tpl.tag.block.end.missing', end($this->_blockStack));
                } else {
                    array_pop($this->_blockStack);
                    $res = 'end'.$short.';';
                }
                break;

            case 'assign':
            case 'eval':
                $res = $this->_parseFinal($args, $this->_allowedAssign).';';
                break;

            case 'literal':
                if (count($this->_literals)) {
                    $res = '?>'.array_shift($this->_literals).'<?php ';
                } else {
                    $this->doError1('errors.tpl.tag.block.end.missing', 'literal');
                }
                break;

            case '/literal':
                $this->doError1('errors.tpl.tag.block.begin.missing', 'literal');
                break;

            case 'meta':
                $this->_parseMeta($args);
                break;

            case 'meta_if':
                $metaIfArgs = $this->_parseFinal($args, $this->_allowedInExpr);
                $this->_metaBody .= 'if('.$metaIfArgs.'):'."\n";
                array_push($this->_blockStack, 'meta_if');
                break;

            case 'meta_else':
                if (substr(end($this->_blockStack), 0, 7) != 'meta_if') {
                    $this->doError1('errors.tpl.tag.block.end.missing', end($this->_blockStack));
                } else {
                    $this->_metaBody .= "else:\n";
                }
                break;

            case 'meta_elseif':
                if (end($this->_blockStack) != 'meta_if') {
                    $this->doError1('errors.tpl.tag.block.end.missing', end($this->_blockStack));
                } else {
                    $elseIfArgs = $this->_parseFinal($args, $this->_allowedInExpr);
                    $this->_metaBody .= 'elseif('.$elseIfArgs."):\n";
                }
                break;

            case '/meta_if':
                $short = substr($name, 1);
                if (end($this->_blockStack) != $short) {
                    $this->doError1('errors.tpl.tag.block.end.missing', end($this->_blockStack));
                } else {
                    array_pop($this->_blockStack);
                    $this->_metaBody .= "endif;\n";
                }
                break;

            default:
                if (preg_match('!^/(\w+)$!', $name, $m)) {
                    if (end($this->_blockStack) != $m[1]) {
                        $this->doError1('errors.tpl.tag.block.end.missing', end($this->_blockStack));
                    } else {
                        array_pop($this->_blockStack);
                        if (function_exists($fct = 'jtpl_block_'.$this->outputType.'_'.$m[1])) {
                            $res = $fct($this, false, null);
                        } elseif (function_exists($fct = 'jtpl_block_common_'.$m[1])) {
                            $res = $fct($this, false, null);
                        } else {
                            $this->doError1('errors.tpl.tag.block.begin.missing', $m[1]);
                        }
                    }
                } elseif (preg_match('/^meta_(\w+)$/', $name, $m)) {
                    if ($path = $this->_getPlugin('meta', $m[1])) {
                        $this->_parseMeta($args, $path[1]);
                        $this->_pluginPath[$path[0]] = true;
                    } else {
                        $this->doError1('errors.tpl.tag.meta.unknown', $m[1]);
                    }
                    $res = '';
                } elseif ($path = $this->_getPlugin('block', $name)) {
                    require_once $path[0];
                    $argfct = $this->_parseFinal($args, $this->_allowedAssign, array(';'), true);
                    $fct = $path[1];
                    $res = $fct($this, true, $argfct);
                    array_push($this->_blockStack, $name);
                } elseif ($path = $this->_getPlugin('cfunction', $name)) {
                    require_once $path[0];
                    $argfct = $this->_parseFinal($args, $this->_allowedAssign, array(';'), true);
                    $fct = $path[1];
                    $res = $fct($this, $argfct);
                } elseif ($path = $this->_getPlugin('function', $name)) {
                    $argfct = $this->_parseFinal($args, $this->_allowedAssign);
                    $res = $path[1].'( $t'.(trim($argfct) != '' ? ','.$argfct : '').');';
                    $this->_pluginPath[$path[0]] = true;
                } elseif (isset($this->_userFunctions[$name])) {
                    $argfct = $this->_parseFinal($args, $this->_allowedAssign);
                    $res = $this->_userFunctions[$name].'( $t'.(trim($argfct) != '' ? ','.$argfct : '').');';
                } else {
                    $this->doError1('errors.tpl.tag.function.unknown', $name);
                }
        }

        return $res;
    }
155495
public function invoke($name, array $args)
    {
        $signature = $name . ':' . serialize($args);

        if (!isset($this->cache[$signature])) {
            $this->cache[$signature] = call_user_func_array(array($this->repository, $name), $args);
        }

        return $this->cache[$signature];
    }