/** * Constructor */ public function __construct() { // load configuration $configLoader = new ConfigLoader(); $this->_conf = $configLoader->getConfig(); parent::__construct(); }
public function __construct(ConfigLoader $loader, ConfigEnvironments $configEnvironments, $defaultEnvironment = 'production') { $this->settings = $loader->fetch(); $this->environments = $configEnvironments->getSettings(); $this->configEnvironments = $configEnvironments; $this->setDefaultEnvironment($defaultEnvironment); }
/** * Reads configuration from file. * @param string file name * @return array */ public function loadFromFile($file) { $loader = new ConfigLoader(); $res = $loader->load($file); $container = $this->compiler->getContainerBuilder(); foreach ($loader->getDependencies() as $file) { $container->addDependency($file); } return $res; }
public function testGetConfig() { $config = ConfigLoader::getConfig('unit'); $this->assertEquals('unit', $config['name']); $config = ConfigLoader::getConfig('unitTest'); $this->assertEquals('unitTest', $config['name']); $this->assertEquals('unit-test', $config['attributes']['class']); $this->assertFalse(ConfigLoader::getConfig('NotKeyExists')); }
/** * Load the application config * @return Config */ protected function loadConfig() { $config = null; if (CacheManager::resourceExists(self::CONFIG_RESOURCE_NAME, CacheManager::APPLICATION_SCOPE)) { $config = CacheManager::loadResource(self::CONFIG_RESOURCE_NAME, CacheManager::APPLICATION_SCOPE); } else { $config = ConfigLoader::load(CONFIG_FILE); CacheManager::saveResource(self::CONFIG_RESOURCE_NAME, $config, CacheManager::APPLICATION_SCOPE); } PiconApplication::get()->getConfigLoadListener()->onConfigLoaded($config); return $config; }
/** * @param $path * @throws WriterException * @return Folder */ public function create($path) { try { $config = ConfigLoader::load('writer'); if (!empty($config['use_db'])) { return new FolderDB($path); } else { return new FolderNoDB($path); } } catch (WriterFolderException $e) { throw new WriterException('Folder init error: ' . $e->getMessage()); } }
/** * Initialize collection of folders */ private function initFolders() { $folderFactory = new FolderFactory(); $folders = ConfigLoader::load('folders'); try { foreach ($folders as $dirName) { $directoryPath = $this->_config['base_dir'] . DIRECTORY_SEPARATOR . $dirName; $this->_folders[] = $folderFactory->create($directoryPath); } } catch (WriterException $e) { echo $e->getMessage(); } }
/** * @throws WriterException * @return \PDO */ public static function connection() { static $_connection = null; if (empty($_connection)) { try { $dbConfig = ConfigLoader::load('db'); $_connection = new \PDO('mysql:dbname=' . $dbConfig['name'] . ';host=' . $dbConfig['host'], $dbConfig['user'], $dbConfig['pass']); } catch (\PDOException $e) { throw new WriterException("DB error \n" . $e->getTraceAsString()); } } return $_connection; }
/** * Selects a file for the ConfigLoader. When calling the getValue() function the Loader will read that file. * @param $file String; of the file WITHOUT extension. The file MUST be placed in config loader and MUST have .config extension * @throws ConfigurationException Thrown in case the file does not exists or it is empty. */ public static function selectFile($file) { $path = "config/" . trim($file) . ".config"; try { self::$currentFileLines = Files::readLines($path); } catch (FileNotFoundException $e) { throw new ConfigurationException($e->getMessage()); } self::$currentFile = $path; if (!self::$currentFileLines || self::$currentFileLines[0] == "") { throw new ConfigurationException("The config file '" . $file . "' is empty!"); } }
public static function load($file, &$config = null) { if ($config == null) { $config = new Config(); } $xml = new \DOMDocument(); $xml->load($file); libxml_use_internal_errors(true); if (!$xml->schemaValidate(PICON_DIRECTORY . '/core/config.xsd')) { throw new ConfigException("Config XML does not match schema"); } ConfigLoader::parse($xml, $config); return $config; }
protected function getConfig() { return ConfigLoader::load(__DIR__ . '/config/picon.xml'); }
<?php require './Config.php'; require './ConfigLoader.php'; $config = new Config(); // utworz ladowarki wczytujace rozne fragmenty konfiguracji $basicConfig = new ConfigLoader(); $basicConfig->setFilename('./config/basic.ini.php'); $securityConfig = new ConfigLoader(); $securityConfig->setFilename('./config/security.ini.php'); $layoutConfig = new ConfigLoader(); $layoutConfig->setFilename('./config/layout.ini.php'); $config->addLoader($basicConfig); $config->addLoader($securityConfig); $config->addLoader($layoutConfig); // zaladujmy pare opcji echo $config->get('website_name'); echo $config->get('session_time');
public function setUp() { parent::setUp(); ConfigLoader::load($this->configuration, ConfigLoader::MYSQL); }
/** * @expectedException \picon\ConfigException */ public function testMissingProfile() { ConfigLoader::load(dirname(__FILE__) . '/../../resources/missingprofile.xml'); }
<strong>jphp://jphp.demo/ConfigLoader.File/<a href="<?php echo $request->getRequestPath(), $source ? '">display demo</a>' : '?source=TRUE">show-source</a>'; ?> </strong></font> </td> </tr> <tr> <td bgcolor=#ffffff> <br> <?php if ($source) { highlight_string(implode('', file(__FILE__))); exit; } $url = 'http://' . $request->getServerName() . dirname($request->getScriptName()) . '/config.conf'; $config = new ConfigLoader($url); $config->loadFromFile(); ?> <strong>Loading properties file from :</strong> <br> <?php echo '<dd>', $url; ?> <br> <br> <strong>Properties keys :</strong> <br> <?php for ($keys = $config->keys(); $keys->hasMoreElements();) { $key = $keys->nextElement(); echo '<dd>· ', $key, '<br>';
function MultiConfigLoader($reader) { parent::ConfigLoader($reader); }
/** * Returns user rights configuration * * Avaliable options are: * force - forces to reload whole ini config * user_id - user id * * @param array $options Associative array of options * @return ConfigContainer User rights configuration * @throws Exception Throws exception when required parameters are not set */ public static function getUserRightsConfig(array $options = array()) { if (!LMSDB::checkIfInstanceExists()) { throw new Exception('Cannot load uiconfig while database connection does not exist!'); } if (!isset($options['user_id'])) { throw new Exception('Cannot load user rights config without user id!'); } $force = isset($options['force']) ? $options['force'] : false; if ($force || self::$user_rights_config === null) { $options['provider'] = UserRightsConfigProvider::NAME; $options['parser'] = UserRightsConfigParser::NAME; $config_loader = new ConfigLoader(); self::$user_rights_config = $config_loader->loadConfig($options); } return self::$user_rights_config; }
$parameters = json_decode($data, true); return $parameters; } } class JsonFileDumper implements FileDumperInterface { /** * @param string $resource * @param array $data */ public function dump($resource, $data) { $json = json_encode($data); file_put_contents($resource, $json); } } $myConfig = new MyConfig(); $jsonLoader = new JsonFileLoader(); $jsonDumper = new JsonFileDumper(); $configLoader = new ConfigLoader($myConfig, $jsonLoader); $configDumper = new ConfigDumper($myConfig, $jsonDumper); echo "Before loading config from file." . PHP_EOL; var_dump($myConfig->getParameters()); $configLoader->load(__DIR__ . '/parameters.json'); echo "After loading config from file." . PHP_EOL; var_dump($myConfig->getParameters()); $myConfig->setParameter('newKey', rand(1, 1000)); $configDumper->dump(__DIR__ . '/parameters.json'); $configLoader->load(__DIR__ . '/parameters.json'); echo "After saving update of config" . PHP_EOL; var_dump($myConfig->getParameters());
/** * Selects a file for the ConfigLoader. When calling the getValue() function the Loader will read that file. * @param $file String; of the file WITHOUT extension. The file MUST be placed in config loader and MUST have .config extension * @throws ConfigurationException Thrown in case the file does not exists or it is empty. */ public static function selectFile($file) { parent::selectFile($file); self::$lineCount = count(self::$currentFileLines); self::$currentLine = 0; }