load_routes

Function to load all of the defined routes

@param mixed $config		Configuration array (or ArrayAccess class) defining our behaviors/options
@access public
@return void
500094
public function load_routes( $config = null ) {
		// Set our config
		$this->config( $config );

		// Get our routing config
		$routing_config = $this->get_config('routing');

		// If we want to load them all automatically
		if ( $routing_config['load_all_automatically'] ) {
			// Define our routes directory
			$route_dir = $routing_config['route_directory'];

			// Get an array of all of the files in the routes directory
			$found_routes = scandir( $route_dir );

			// Loop through each found route
			foreach( $found_routes as $route ) {
				// Is the route a file?
				if ( is_file( $route_dir . $route ) && ( strpos( $route, '_' ) !== 0 ) ) {
					// Define our endpoint base
					$route_base_url = '/' . basename( $route, '.php' );
					$route_namespace_url = $route_base_url;
					$route_name = ltrim( $route_namespace_url, '/' );

					// Is this our top-level route?
					if ( $route_name == $routing_config['top_level_route'] ) {
						// Set our base url to the top level
						$route_base_url = null;
					}

					// Instanciate the route's controller... but do it as a responder so it only instanciate's what is needed for that matched response. :)
					Router::with( $route_base_url, function() use ( $route_namespace_url ) {
						Router::route( function( $request, $respond, $service ) use ( $route_namespace_url ) {
							// Instanciate the route's controller
							Router::app()->new_route_controller( $route_namespace_url );
						});
					});

					// Include our routes from namespaced, separate files
					Router::with( $route_base_url, $route_dir . $route );
				}
			}
		}
		// Or we'll do it manually (based on what we have defined in our config)
		else {
			// Grab all of our manually assigned routes
			foreach( $routing_config['routes'] as $route ) {
				// Define our endpoint base and include path
				$route_base_url = '/' . $route;
				$route_namespace_url = $route_base_url;
				$route_path = PAULUS_ROUTES_DIR . $route . '.php';

				// Is this our top-level route?
				if ( $route == $routing_config['top_level_route'] ) {
					// Set our base url to the top level
					$route_base_url = null;
				}

				// Instanciate the route's controller... but do it as a responder so it only instanciate's what is needed for that matched response. :)
				Router::with( $route_base_url, function() use ( $route_namespace_url ) {
					Router::route( function( $request, $respond, $service ) use ( $route_namespace_url ) {
						// Instanciate the route's controller
						Router::app()->new_route_controller( $route_namespace_url );
					});
				});

				// Include our routes from namespaced, separate files
				Router::with( $route_base_url, $route_path );
			}
		}
	}
1066120
private function loadConfig($config) {
        if(isset($config['moduleConf']['API_USERNAME']) && 
                isset($config['moduleConf']['API_PASSWORD']) && 
                isset($config['moduleConf']['API_SIGNATURE']) &&
                isset($config['moduleConf']['API_ENDPOINT']) &&
                isset($config['moduleConf']['version']) &&
                isset($config['moduleConf']['paypal_url']) && 
                isset($config['moduleConf']['command_url'])){
            $this->setAPI_USERNAME($config['moduleConf']['API_USERNAME']);
            $this->setAPI_PASSWORD($config['moduleConf']['API_PASSWORD']);
            $this->setAPI_SIGNATURE($config['moduleConf']['API_SIGNATURE']);
            $this->setAPI_ENDPOINT($config['moduleConf']['API_ENDPOINT']);
            $this->setVersion($config['moduleConf']['version']);
            $this->setPaypal_url($config['moduleConf']['paypal_url']);
            $this->setCommand_url($config['moduleConf']['command_url']);
        }
        else{
            throw new PaypalException('Missing values in config file.');
        }
    }
1192974
public function setConfig($config)
	{
		if (is_object($config)) {
			$config = get_object_vars($config);
		}
		foreach ($config as $index => $value) {
			$this->$index = $value;
		}
	}
21746
public function registerConfiguredHooks(string $config = '')
    {
        if (empty($config)) {
            $config = 'app.hooks';
        }

        $hooks = Collection::make($this->config[$config]);

        (new HooksRepository($this))->load($hooks->all());
    }
1118355
public function loadConfig($config = null): void
    {
        $baseClass = Base::getInstance();
        $this->errorLevel = (string)$baseClass->Database->MySQL->errorLevel;

        if (\is_null($config)) {
            $config = $baseClass->Database->MySQL->defaultConnection;
        }
        if (!($config instanceof AbstractConfig)) {
            throw new RuntimeException('$config must be an instance of MS\LightFramework\Config\AbstractConfig');
        }

        $this->databaseHost = (string)$config->databaseHost;
        $this->databaseUser = (string)$config->databaseUser;
        $this->databasePass = (string)$config->databasePass;
        $this->databaseName = (string)$config->databaseName;
        $this->connectionCharset = (string)$config->connectionCharset;
        $this->connectionCollation = (string)$config->connectionCollation;

        $this->openConnection();
        $this->selectDatabase($this->databaseName);
        $this->setConnectionCharset($this->connectionCharset);
        $this->setConnectionCollation($this->connectionCollation);
    }
616307
public function load(Config $config)
    {
        $parsed = [];

        if ($this->isFile($this->getPath())) {
            $parsed = $this->parse($this->fetch($this->getPath()));
        }

        if (!is_array($parsed)) {
            $parsed = [];
        }

        $this->apply($parsed, $config);
    }
1013648
private final function loadConfig(): void
    {
        $this->config = new Config();

        $file = sprintf('%s/app/service/%s/config/config.php', APP_DIR, $this->name);
        if (file_exists($file) && is_array($data = include $file)) {
            $this->config->setData($data);
        }
    }
633481
public function load(Config $config)
    {
        $php = new Service\PhpService();

        foreach ($php->getConfig() as $k => $v) {
            $config->set('php_'.$k, $v);
        }

        $config->setDefaultItem('commands', 'loc', ['cmd' => "!bin/phploc src", 'description' => "display code size (line of code, classes, ...)"]);
    }
16141
protected function _setup($config) {
        if (!empty($config['url'])) {
            $this->_url = $config['url'];
        }
        if (!empty($config['params'])) {
            $this->_params = $config['params'];
        }
    }
752592
protected function loadConfig(array $config)
    {
        $this->config = $config;
        if (array_key_exists('namespaces', $config)) {
            $this->ns = $config['namespaces'];
        }

        $this->defaultContext = $this->getMandatoryKey('defaultContext', $config);

        foreach ($this->getMandatoryKey('data_sources', $config) as $source => $c) {
            if (!array_key_exists('type', $c)) {
                throw new \Tripod\Exceptions\ConfigException("No 'type' set for data source $source");
            }
            if (!array_key_exists('connection', $c)) {
                throw new \Tripod\Exceptions\ConfigException("No connection information set for data source $source");
            }
            $this->dataSources[$source] = $c;
        }

        $transactionConfig = $this->getMandatoryKey('transaction_log', $config);
        $this->tConfig['data_source'] = $this->getMandatoryKey('data_source', $transactionConfig, 'transaction_log');
        if (!isset($this->dataSources[$this->tConfig['data_source']])) {
            throw new \Tripod\Exceptions\ConfigException("Transaction log data source, " . $this->tConfig['data_source'] . ", was not defined");
        }
        $this->tConfig["database"] = $this->getMandatoryKey("database", $transactionConfig, 'transaction_log');
        $this->tConfig["collection"] = $this->getMandatoryKey("collection", $transactionConfig, 'transaction_log');

        // A 'pod' corresponds to a logical database
        $this->databases = $this->getMandatoryKey("stores", $config);
        $defaultDB = null;
        foreach ($this->databases as $storeName => $storeConfig) {
            $this->dbConfig[$storeName] = ["data_source" => $this->getMandatoryKey("data_source", $storeConfig)];
            if (isset($storeConfig['database']) && !empty($storeConfig['database'])) {
                $this->dbConfig[$storeName]["database"]=$storeConfig['database'];
            } else {
                $this->dbConfig[$storeName]["database"] = $storeName;
            }

            $this->cardinality[$storeName] = [];
            $this->indexes[$storeName] = [];
            $this->podConnections[$storeName] = [];
            if (isset($storeConfig["pods"])) {
                foreach ($storeConfig["pods"] as $podName => $podConfig) {
                    $dataSource = (isset($podConfig['data_source']) ? $podConfig['data_source'] : $storeConfig['data_source']);
                    $this->podConnections[$storeName][$podName] = $dataSource;

                    // Set cardinality, also checking against defined namespaces
                    if (array_key_exists('cardinality', $podConfig)) {
                        // Test that the namespace exists for each cardinality rule defined
                        $cardinality = $podConfig['cardinality'];
                        foreach ($cardinality as $qname => $cardinalityValue) {
                            $namespaces = explode(':', $qname);
                            // just grab the first element
                            $namespace  = array_shift($namespaces);

                            if (array_key_exists($namespace, $this->ns)) {
                                $this->cardinality[$storeName][$podName][] = $cardinality;
                            } else {
                                throw new \Tripod\Exceptions\ConfigException("Cardinality '{$qname}' does not have the namespace defined");
                            }
                        }
                    } else {
                        $this->cardinality[$storeName][$podName] = [];
                    }

                    $this->cardinality[$storeName][$podName] = array_key_exists("cardinality", $podConfig) ? $podConfig['cardinality'] : [];

                    // Ensure indexes are legal
                    if (array_key_exists("indexes", $podConfig)) {
                        $this->indexes[$storeName][$podName] = [];
                        foreach ($podConfig["indexes"] as $indexName => $indexFields) {
                            // check no more than 1 indexField is an array to ensure Mongo will be able to create compound indexes
                            if (count($indexFields) > 1) {
                                $fieldsThatAreArrays = 0;
                                foreach ($indexFields as $field => $fieldVal) {
                                    $cardinalityField = str_replace('.value', '', $field);
                                    if (!array_key_exists($cardinalityField, $this->cardinality[$storeName][$podName]) ||
                                        $this->cardinality[$storeName][$podName][$cardinalityField] != 1) {
                                        $fieldsThatAreArrays++;
                                    }
                                    if ($fieldsThatAreArrays > 1) {
                                        throw new \Tripod\Exceptions\ConfigException("Compound index $indexName has more than one field with cardinality > 1 - mongo will not be able to build this index");
                                    }
                                }
                            } // @codeCoverageIgnoreStart
                            // @codeCoverageIgnoreEnd

                            $this->indexes[$storeName][$podName][$indexName] = $indexFields;
                        }
                    }
                }
            }
            if (isset($storeConfig['batch_sizes'])) {
                foreach ([OP_TABLES, OP_SEARCH, OP_VIEWS] as $op) {
                    if (isset($storeConfig['batch_sizes'][$op]) && is_numeric($storeConfig['batch_sizes'][$op])) {
                        $this->batchSize[$op] = intval($storeConfig['batch_sizes'][$op]);
                    }
                }
            }
            $searchConfig = array_key_exists("search_config", $storeConfig) ? $storeConfig["search_config"] : [];
            $this->searchDocSpecs[$storeName] = [];
            if (!empty($searchConfig)) {
                $this->searchProviderClassName[$storeName] = $this->getMandatoryKey('search_provider', $searchConfig, 'search');
                // Load search doc specs if search_config is set
                $searchDocSpecs = $this->getMandatoryKey('search_specifications', $searchConfig, 'search');
                foreach ($searchDocSpecs as $spec) {
                    if (!isset($spec[_ID_KEY])) {
                        throw new \Tripod\Exceptions\ConfigException("Search document spec does not contain " . _ID_KEY);
                    }
                    if (!isset($spec['from']) || !in_array($spec['from'], $this->getPods($storeName))) {
                        throw new \Tripod\Exceptions\ConfigException("'" . $spec[_ID_KEY] . "[\"from\"]' property not set or references an undefined pod");
                    }
                    if (!isset($spec['filter'])) {
                        throw new \Tripod\Exceptions\ConfigException("'" . $spec[_ID_KEY] . "[\"filter\"]' property not set");
                    }

                    if (!isset($spec['fields']) && !isset($spec['joins'])) {
                        throw new \Tripod\Exceptions\ConfigException("'" . $spec[_ID_KEY] . "' contains no 'fields' or 'joins' properties");
                    }

                    if($this->searchProviderClassName[$storeName] == SEARCH_PROVIDER_MONGO)
                    {
                        if(isset($spec['to_data_source']))
                        {
                            if(!isset($this->dataSources[$spec['to_data_source']]))
                            {
                                throw new \Tripod\Exceptions\ConfigException("'" . $spec[_ID_KEY] . "[\"to_data_source\"]' property references an undefined data source");
                            }
                        }
                        else
                        {
                            $spec['to_data_source'] = $storeConfig['data_source'];
                        }
                    }
                    $this->searchDocSpecs[$storeName][$spec[_ID_KEY]] = $spec;
                }
            }

            // Load view specs
            $viewSpecs = (array_key_exists("view_specifications",$storeConfig)) ? $storeConfig["view_specifications"] : [];
            $this->viewSpecs[$storeName] = [];
            foreach ($viewSpecs as $spec)
            {
                if(!isset($spec[_ID_KEY]))
                {
                    throw new \Tripod\Exceptions\ConfigException("View spec does not contain " . _ID_KEY);
                }
                if(!isset($spec['from']) || !in_array($spec['from'], $this->getPods($storeName)))
                {
                    throw new \Tripod\Exceptions\ConfigException("'" . $spec[_ID_KEY] . "[\"from\"]' property not set or references an undefined pod");
                }
                if(!isset($spec['joins']))
                {
                    throw new \Tripod\Exceptions\ConfigException('Could not find any joins in view specification - usecase better served with select()');
                }
                $this->ifCountExistsWithoutTTLThrowException($spec);
                if(isset($spec['to_data_source']))
                {
                    if(!isset($this->dataSources[$spec['to_data_source']]))
                    {
                        throw new \Tripod\Exceptions\ConfigException("'" . $spec[_ID_KEY] . "[\"to_data_source\"]' property references an undefined data source");
                    }
                }
                else
                {
                    $spec['to_data_source'] = $storeConfig['data_source'];
                }
                $this->viewSpecs[$storeName][$spec[_ID_KEY]] = $spec;
            }

            // Load table specs
            $tableSpecs = (array_key_exists("table_specifications",$storeConfig)) ? $storeConfig["table_specifications"] : [];
            $this->tableSpecs[$storeName] = [];
            foreach ($tableSpecs as $spec)
            {
                $this->validateTableSpec($spec);

                if(isset($spec['to_data_source']))
                {
                    if(!isset($this->dataSources[$spec['to_data_source']]))
                    {
                        throw new \Tripod\Exceptions\ConfigException("'" . $spec[_ID_KEY] . "[\"to_data_source\"]' property references an undefined data source");
                    }
                }
                else
                {
                    $spec['to_data_source'] = $storeConfig['data_source'];
                }

                $this->tableSpecs[$storeName][$spec[_ID_KEY]] = $spec;
            }
        }

    }
486433
public function load(Config $config)
    {

        $phpExtraPhpunitOpts = [];
        $xdebugSoLocation    = $this->getXdebugService()->findXdebugSoPath();

        if (null !== $xdebugSoLocation) {
            $phpExtraPhpunitOpts[] = sprintf('-d zend_extension=%s', $xdebugSoLocation);
        }

        $config['phpunit_conf_dir']       = $this->getPhpunitService()->getPhpunitXmlDir([__DIR__.'/../Resources/phpunit']);
        $config['php_extra_phpunit_opts'] = join(' ', $phpExtraPhpunitOpts);

        $config->setDefaultItem('commands', '_test', "#test,execute all tests");
        $config->setDefaultItem('commands', '_test-unit', "#test-unit,execute unit tests");
        $config->setDefaultItem('commands', '_test-group', "#test-group");
        $config->setDefaultItem('commands', '_test-integ', "#test-integ");
        $config->setDefaultItem('commands', '_test-loop', "#test-loop");
        $config->setDefaultItem('commands', '_test-unit-loop', "#test-unit-loop");
        $config->setDefaultItem('commands', '_test-unit', "#test-unit");
        $config->setDefaultItem('commands', 'tu', "#test-unit");
        $config->setDefaultItem('commands', 'ti', "#test-integ");
        $config->setDefaultItem('commands', 'tg', "#test-group");
        $config->setDefaultItem('commands', 'tul', "#test-unit-loop");
    }
645982
private function doApplicationConfigExtend(Config $config)
    {
        $config_directories = ConfigDirectory::getDirectories(
            null,
            $this->baseRepository,
            $this->context,
            $this->environment
        );

        foreach ($config_directories as $directory) {
            if (is_dir($directory)) {
                $config->extend($directory, $this->overrideConfig);
            }
        }
    }
89835
public static function init(&$config) {
		$controllers = CacheManager::getControllers ();
		foreach ( $controllers as $controller ) {
			CacheManager::$cache->remove( self::getControllerCacheKey ( $controller ));
			$parser = new DiControllerParser ();
			$parser->parse ( $controller, $config );
			$injections = $parser->getInjections ();
			if (sizeof ( $injections ) > 0) {
				self::store ( $controller, $parser->__toString () );
			}
		}
	}
251753
public function merge(array $newConfig, array &$config)
    {
        foreach ($newConfig as $routeName => $routeInfo) {
            if (!isset($config[$routeName])) {
                $config[$routeName] = $this->newRoute($routeName, $routeInfo);
            }

            if (isset($routeInfo['child_routes'])) {
                if (!isset($config[$routeName]['child_routes'])) {
                    $config[$routeName]['child_routes'] = array();
                }

                $this->merge($routeInfo['child_routes'], $config[$routeName]['child_routes']);
            }
        }
    }
658319
protected function appendRoute(array $config)
    {
    	$options = [
    		'namespace' => 'Flipbox\ImageController',
    		'prefix' => $config['prefix']
    	];

    	Route::group($options, function(){
    		Route::get('/{file}.{ext?}', 'ImageController@image')->where('file', '[A-Za-z0-9\/]+');
    		Route::get('/{file}', 'ImageController@image')->where('file', '[A-Za-z0-9\/]+');
    	});
    }
1274262
protected function loadRoutes($routes)
    {
        if ($routes instanceof Closure) {
            $routes($this);
        } else {
            (new RouteFileRegistrar($this))->register($routes);
        }
    }
1263868
public function setConfig($config)
    {
        $this->config = $config;

        $this->routes = $config['routes'];
        $this->templates = $config['templates'];
        $this->options = $config['options'];
        $this->layoutView = $config['layout'];

        return $this;
    }