예제 #1
0
 /**
  * Constructor
  */
 public function __construct()
 {
     // load configuration
     $configLoader = new ConfigLoader();
     $this->_conf = $configLoader->getConfig();
     parent::__construct();
 }
예제 #2
0
 public function __construct(ConfigLoader $loader, ConfigEnvironments $configEnvironments, $defaultEnvironment = 'production')
 {
     $this->settings = $loader->fetch();
     $this->environments = $configEnvironments->getSettings();
     $this->configEnvironments = $configEnvironments;
     $this->setDefaultEnvironment($defaultEnvironment);
 }
예제 #3
0
 /**
  * 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;
 }
예제 #6
0
 /**
  * @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());
     }
 }
예제 #7
0
 /**
  * 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();
     }
 }
예제 #8
0
 /**
  * @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;
 }
예제 #9
0
 /**
  * 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!");
     }
 }
예제 #10
0
 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;
 }
예제 #11
0
 protected function getConfig()
 {
     return ConfigLoader::load(__DIR__ . '/config/picon.xml');
 }
예제 #12
0
파일: 2.php 프로젝트: gajosew/saz
<?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');
예제 #13
0
 public function setUp()
 {
     parent::setUp();
     ConfigLoader::load($this->configuration, ConfigLoader::MYSQL);
 }
예제 #14
0
 /**
  * @expectedException \picon\ConfigException
  */
 public function testMissingProfile()
 {
     ConfigLoader::load(dirname(__FILE__) . '/../../resources/missingprofile.xml');
 }
예제 #15
0
파일: index.php 프로젝트: alexpagnoni/jphp
   <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>&middot; ', $key, '<br>';
예제 #16
0
 function MultiConfigLoader($reader)
 {
     parent::ConfigLoader($reader);
 }
예제 #17
0
파일: LMSConfig.php 프로젝트: kornelek/lms
 /**
  * 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;
 }
예제 #18
0
        $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());
예제 #19
0
 /**
  * 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;
 }