连接数据库方法
@access public
@param array         $config 连接参数
@param integer       $linkNum 连接序号
@return Manager
@throws InvalidArgumentException
@throws RuntimeException
17189
public function connect(array $config = [], $linkNum = 0)
    {
        if (!isset($this->links[$linkNum])) {
            if (empty($config)) {
                $config = $this->config;
            } else {
                $config = array_merge($this->config, $config);
            }

            $this->dbName  = $config['database'];
            $this->typeMap = $config['type_map'];

            if ($config['pk_convert_id'] && '_id' == $config['pk']) {
                $this->config['pk'] = 'id';
            }

            $host = 'mongodb://' . ($config['username'] ? "{$config['username']}" : '') . ($config['password'] ? ":{$config['password']}@" : '') . $config['hostname'] . ($config['hostport'] ? ":{$config['hostport']}" : '') . '/' . ($config['database'] ? "{$config['database']}" : '');

            if ($config['debug']) {
                $startTime = microtime(true);
            }

            $this->links[$linkNum] = new Manager($host, $this->config['params']);

            if ($config['debug']) {
                // 记录数据库连接信息
                $this->logger('[ MongoDb ] CONNECT :[ UseTime:' . number_format(microtime(true) - $startTime, 6) . 's ] ' . $config['dsn']);
            }
        }

        return $this->links[$linkNum];
    }
1185142
public function command($config = array())
    {
        if (JFactory::getApplication()->isSite())
        {
            $config = new KObjectConfigJson($config);
            $config->append(array(
                'command' => NULL
            ));

            $command = $config->command;

            $command->attribs->class->append(array('btn'));

            if ($command->id === 'new' || $command->id === 'apply') {
                $command->attribs->class->append(array('btn-success'));
            }
        }

        return parent::command($config);
    }
181017
public function connect(array $config = [], $linkNum = 0, $autoConnection = false)
    {
        if (isset($this->links[$linkNum])) {
            return $this->links[$linkNum];
        }

        if (!$config) {
            $config = $this->config;
        } else {
            $config = array_merge($this->config, $config);
        }

        // 连接参数
        if (isset($config['params']) && is_array($config['params'])) {
            $params = $config['params'] + $this->params;
        } else {
            $params = $this->params;
        }

        // 记录当前字段属性大小写设置
        $this->attrCase = $params[PDO::ATTR_CASE];

        try {
            if (empty($config['dsn'])) {
                $config['dsn'] = $this->parseDsn($config);
            }

            if ($config['debug']) {
                $startTime = microtime(true);
            }

            $this->links[$linkNum] = new PDO($config['dsn'], $config['username'], $config['password'], $params);

            if ($config['debug']) {
                // 记录数据库连接信息
                $this->log('[ DB ] CONNECT:[ UseTime:' . number_format(microtime(true) - $startTime, 6) . 's ] ' . $config['dsn']);
            }

            return $this->links[$linkNum];
        } catch (\PDOException $e) {
            if ($autoConnection) {
                $this->log('[ ERR ] ' . $e->getMessage());
                return $this->connect($autoConnection, $linkNum);
            } else {
                throw $e;
            }
        }
    }
718396
public static function configure(array $config)
    {
        foreach ($config as $key => $value) {
            // 子类处理
            if (is_array($value)) {
                if (array_values($value) === $value) {
                    // 非关联数组
                    foreach ($value as $subNumberKey => $subValue) {
                        if (isset($subValue['ref'])) {
                            $config[$key][$subNumberKey] = self::configure($subValue);
                        }
                    }
                } else {
                    // 引用依赖
                    if (isset($value['ref'])) {
                        $config[$key] = self::configure($value);
                    }
                    //组件
                    if (isset($value['component'])) {
                        $name         = $value['component'];
                        $config[$key] = self::$app->$name;
                    }
                }
            } elseif ($key === 'ref') {
                // 实例化
                return \Mix\Core\Bean::newInstance($config['ref']);
            }
        }
        return $config;
    }
551847
public function shareObject($config = array())
    {
        $config = new AnConfig($config);

        if (!$config->object) {
            throw new InvalidArgumentException('Not object specified to share');
        }

        $config->append(array(
             'sharer' => get_viewer(),
        ));

        if ($config->object->isOwnable()) {
            $config->append(array(
                'target' => $config->object->owner,
            ));
        }

        $request = new ComSharesSharerRequest($config);
        $sharers = new ArrayObject();
        dispatch_plugin('connect.onGetShareAdapters', array('adapters' => $sharers, 'request' => $request));

        if ($config->sharers) {
            $sharers = array_filter((array) $sharers, function ($sharer) use ($config) {
               return in_array($sharer->getIdentifier()->name, $config['sharers']);
            });
        }

        foreach ($sharers as $sharer) {
            $sharer->shareRequest($request);
        }
    }
1313659
public function setConfig(array $config)
    {
        try {
            $this->config = $this
                ->getConfigResolver()
                ->resolve($config);
        } catch (ExceptionInterface $e) {
            throw new InvalidArgumentException($e->getMessage(), $e->getCode(), $e);
        }
    }
233700
public static function init($config = null)
    {
        self::registerDevelopmentErrorHandler();
        self::registerExceptionHandler();

        if ($config === null) {
            $config = static::loadAppConfig();
        }

        static::addCoreModule($config);

        $serviceConfig = isset($config['service_manager']) ? $config['service_manager'] : array();
        $listeners = isset($config['listeners'])? $config['listeners'] : array();
        $serviceManager = new ServiceManager(new ServiceConfig($serviceConfig));

        $serviceManager->setService('ApplicationConfig', $config);
        $serviceManager->get('ModuleManager')->loadModules();

        return $serviceManager->get('Application')->bootstrap($listeners);
    }
616821
public function initialize(Config $config) {
        $di = $this->getDi();

        $di->setShared(
            Connections::DI_NAME,
            function() {
                return new Connections();
            }
        );


        $this->getDi()->setShared(
            'modelsManager',
            function() {
                return new ModelsManager();
            }
        );

        $this->addApiConfig();
    }
364971
public function init( $config = [ ] )
    {
        if ( isset( $_SERVER[ 'HTTP_USER_AGENT' ] ) )
        {
            $this->userAgent = $_SERVER[ 'HTTP_USER_AGENT' ];
        }
        if ( isset( $_SERVER[ 'SERVER_NAME' ] ) )
        {
            $this->server = $_SERVER[ 'SERVER_NAME' ];
        }
        if ( isset( $_SERVER[ 'SERVER_PORT' ] ) )
        {
            $this->port = $_SERVER[ 'SERVER_PORT' ];
        }
        if ( isset( $_SERVER[ 'REQUEST_METHOD' ] ) )
        {
            $this->method = $_SERVER[ 'REQUEST_METHOD' ];
        }
        if ( isset( $_SERVER[ 'QUERY_STRING' ] ) )
        {
            $this->query = $_SERVER[ 'QUERY_STRING' ];
        }
        if ( isset( $_SERVER[ 'SCRIPT_NAME' ] ) )
        {
            $this->script = $_SERVER[ 'SCRIPT_NAME' ];
        }
        if ( isset( $_SERVER[ 'REQUEST_URI' ] ) )
        {
            $this->requestUri = $_SERVER[ 'REQUEST_URI' ];
        }
        if ( isset( $_SERVER[ 'REQUEST_SCHEME' ] ) )
        {
            $this->scheme = $_SERVER[ 'REQUEST_SCHEME' ];
        }

        $request = str_replace( $_SERVER[ 'SCRIPT_NAME' ], '', $this->requestUri );

        $elements = explode( '/', $request );

        if ( '' === $elements[ 0 ] )
        {
            array_shift( $elements );
        }

        if ( 2 <= count( $elements ) )
        {
            $this->route = $elements[ 0 ] . '/' . $elements[ 1 ];

            array_shift( $elements );
            array_shift( $elements );

            if ( 0 < count( $elements ) )
            {
                $this->params = $elements;
            }
        }
        else if ( 1 === count( $elements ) )
        {
            $this->route = $elements[ 0 ];

            array_shift( $elements );
        }
    }
671390
public static function createFromConfig(array $config)
    {
        $manager = static::createEmptyFromConfig($config);

        $manager->addCollection(new CssCollection)
                ->addCollection(new JavascriptCollection);

        return $manager;
       
    }
1368858
public function createCommand($config = [])
    {
        $this->open();
        $config['db'] = $this;
        $command = new Command($config);

        return $command;
    }
476232
private function _hasMany(array $config): ResultSet
    {
        //配置信息
        $tableClass = $config['table'];
        $primaryKey = $config['primaryKey'];
        $foreignKey = $config['foreignKey'];

        //取主键的值
        $primaryValue = $this->$primaryKey;

        /**
         * 子对象表
         * @var $tableInstance Table
         */
        $tableInstance = $tableClass::instance();

        //在子对象表中查询关联记录
        return ResultSet::instance($tableInstance->select('*', [$foreignKey => $primaryValue]))
            ->_setType('hasMany', $config);
    }
775852
public static function createServiceManager(array $config = [])
    {
        $serviceManager = new ServiceManager(new Config($config));

        $serviceManager->addInitializer(
            function ($instance, ServiceLocatorInterface $serviceLocator) {
                if ($instance instanceof ModelManagerAwareInterface) {
                    $instance->setModelManager($serviceLocator->get('modelmanager'));
                }
            }
        );

        $serviceManager->addInitializer(
            function ($instance, ServiceLocatorInterface $serviceLocator) {
                if ($instance instanceof ServiceLocatorAwareInterface) {
                    $instance->setServiceLocator($serviceLocator);
                }
            }
        );

        return $serviceManager;
    }
729438
protected function _connect($config)
    {
        # Connect Settings
        $host      = $config['host'];
        $port      = $config['port'];
        $user      = $config['user'];
        $password  = $config['password'];
        $methods   = $config['methods'];
        $callbacks = $config['callbacks'];
        
        if(  ! empty($methods) && ! empty($callbacks))
        {
            $this->connect = ssh2_connect($host, $port, $methods, $callbacks);
        }
        elseif( ! empty($methods) )
        {
            $this->connect = ssh2_connect($host, $port, $methods);
        }
        else
        {
            $this->connect = ssh2_connect($host, $port);
        }

        if( empty($this->connect) )
        {
            throw new InvalidArgumentException(NULL, '$this->connect');
        }

        if( ! empty($user) )
        {
            $this->login = ssh2_auth_password($this->connect, $user, $password);
        }

        if( empty($this->login) )
        {
            throw new InvalidArgumentException(NULL, '$this->login');
        }

        return $this;
    }
698713
public function createConnection($config)
    {
        $driver = $this->driver_manager->driver(array_get($config, 'driver', ''));

        if (!($driver instanceof \Doctrine\DBAL\Driver)) {
            $driver = $this->driver_manager->driver();
        }

        $params = $config;
        $params['host'] = array_get($params, 'host', array_get($config, 'server'));
        $params['user'] = array_get($params, 'user', array_get($config, 'username'));
        if (!isset($params['driverOptions'])) {
            $params['driverOptions'] = [];
        }
        if (defined('PDO::MYSQL_ATTR_MULTI_STATEMENTS')) {
            $params['driverOptions'][\PDO::MYSQL_ATTR_MULTI_STATEMENTS] = false;
        }
        $params['wrapperClass'] = array_get($config, 'wrapperClass', '\Concrete\Core\Database\Connection\Connection');
        unset($params['driver']);

        $wrapperClass = 'Doctrine\DBAL\Connection';
        if (isset($params['wrapperClass'])) {
            if (is_subclass_of($params['wrapperClass'], $wrapperClass)) {
                $wrapperClass = $params['wrapperClass'];
            } else {
                throw DBALException::invalidWrapperClass($params['wrapperClass']);
            }
        }

        $connection =  new $wrapperClass($params, $driver);
        $connection->getDatabasePlatform()->registerDoctrineTypeMapping('json', 'json_array');
        return $connection;
    }
457213
protected function run(Config $config): ResultInterface
    {
        $newerCores = WP_CLI::runcommand(
            'core check-update --fields=version,update_type --format=json',
            [
                'return' => true,
                'parse' => 'json',
                'launch' => true,
                'exit_error' => false,
            ]
        );

        $messages = [];
        if (is_array($newerCores)) {
            $messages = array_map(function (array $core): string {
                return "${core['version']} (${core['update_type']})";
            }, $newerCores);
        }

        return (empty($messages))
            ? ResultFactory::makeSuccess($this)
            : ResultFactory::makeFailure(
                $this,
                array_merge(['WP core update available:'], $messages)
            );
    }
785659
public function getPage( $config = [] ) {

		$modelClass	= static::$modelClass;
		$modelTable	= $this->getModelTable();

		$groupTable	= Yii::$app->factory->get( 'groupService' )->getModelTable();
		$userTable	= $this->userService->getModelTable();
		$roleTable	= $this->roleService->getModelTable();

	    $sort = new Sort([
	        'attributes' => [
	            'id' => [
	                'asc' => [ "$modelTable.id" => SORT_ASC ],
	                'desc' => [ "$modelTable.id" => SORT_DESC ],
	                'default' => SORT_DESC,
	                'label' => 'Id'
	            ],
	            'group' => [
	                'asc' => [ "$groupTable.name" => SORT_ASC ],
	                'desc' => [ "$groupTable.name" => SORT_DESC ],
	                'default' => SORT_DESC,
	                'label' => 'Group'
	            ],
				'user' => [
					'asc' => [ "$userTable.name" => SORT_ASC ],
					'desc' => [ "$userTable.name" => SORT_DESC ],
					'default' => SORT_DESC,
					'label' => 'User',
				],
				'role' => [
					'asc' => [ "$roleTable.name" => SORT_ASC ],
					'desc' => [ "$roleTable.name" => SORT_DESC ],
					'default' => SORT_DESC,
					'label' => 'Role',
				],
				'status' => [
					'asc' => [ "$modelTable.status" => SORT_ASC ],
					'desc' => [ "$modelTable.status" => SORT_DESC ],
					'default' => SORT_DESC,
					'label' => 'Status',
				],
	            'cdate' => [
	                'asc' => [ "$modelTable.createdAt" => SORT_ASC ],
	                'desc' => [ "$modelTable.createdAt" => SORT_DESC ],
	                'default' => SORT_DESC,
	                'label' => 'Created At'
	            ],
	            'udate' => [
	                'asc' => [ "$modelTable.modifiedAt" => SORT_ASC ],
	                'desc' => [ "$modelTable.modifiedAt" => SORT_DESC ],
	                'default' => SORT_DESC,
	                'label' => 'Update At'
	            ],
	            'sdate' => [
	                'asc' => [ "$modelTable.syncedAt" => SORT_ASC ],
	                'desc' => [ "$modelTable.syncedAt" => SORT_DESC ],
	                'default' => SORT_DESC,
	                'label' => 'Synced At'
	            ]
	        ],
	        'defaultOrder' => [
	        	'cdate' => SORT_DESC
	        ]
	    ]);

		if( !isset( $config[ 'sort' ] ) ) {

			$config[ 'sort' ] = $sort;
		}

		// Query ------------

		if( !isset( $config[ 'query' ] ) ) {

			$config[ 'hasOne' ] = true;
		}

		// Filters ----------

		// Filter - Status
		$status	= Yii::$app->request->getQueryParam( 'status' );

		if( isset( $status ) && isset( $modelClass::$urlRevStatusMap[ $status ] ) ) {

			$config[ 'conditions' ][ "$modelTable.status" ]	= $modelClass::$urlRevStatusMap[ $status ];
		}

		// Searching --------

		$searchCol	= Yii::$app->request->getQueryParam( 'search' );

		if( isset( $searchCol ) ) {

			$search = [
				'user' => "$userTable.name",
				'email' => "$userTable.email"
			];

			$config[ 'search-col' ] = $search[ $searchCol ];
		}

		// Reporting --------

		$config[ 'report-col' ]	= [
			'user' => "$userTable.name",
			'email' => "$userTable.email",
			'status' => "$modelTable.status"
		];

		// Result -----------

		return parent::getPage( $config );
	}