예제 #1
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;
 }
 /**
  * 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;
 }
예제 #3
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;
 }
예제 #4
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());
     }
 }
예제 #5
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();
     }
 }
예제 #6
0
 protected function getConfig()
 {
     return ConfigLoader::load(__DIR__ . '/config/picon.xml');
 }
예제 #7
0
 public function setUp()
 {
     parent::setUp();
     ConfigLoader::load($this->configuration, ConfigLoader::MYSQL);
 }
예제 #8
0
 /**
  * @expectedException \picon\ConfigException
  */
 public function testMissingProfile()
 {
     ConfigLoader::load(dirname(__FILE__) . '/../../resources/missingprofile.xml');
 }
예제 #9
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());