/** * @throws LogicException * @throws InvalidArgumentException */ public function main() { $config = new Config(); $config->load($this->file); $data = $config->flatten(); foreach ($data as $name => $value) { $this->project->setUserProperty($name, $value); } }
/** * {@inheritdoc} */ public function write(Config $config, $target) { $file = new File($target); if ($file->exists()) { throw new \LogicException(sprintf("Config target file already exists '%s'", $target)); } $data = sprintf("<?php\n\n// \nreturn %s;\n", var_export($config->getData(), true)); $file->write($data); return $this; }
/** * Get a parameter or a service * * @param string $key Key * * @return mixed * @throws \OutOfBoundsException */ public function raw($key) { if (!$this->values->has($key)) { throw new \OutOfBoundsException(sprintf("Container service or parameter '%s' does not exist.", $key)); } return $this->values[$key]; }
/** * @param string $source * * @throws \LogicException * @throws \ErrorException * * @return Config */ public function read($source) { $file = new File($source); if (!$file->exists()) { throw new \LogicException(sprintf("Config source file '%s' does not exist.", $source)); } // Possible syntax errors, do not handle them / expensive! $path = $file->getPath(); $data = (include $path); if (!is_array($data)) { throw new \ErrorException("Config source file should return array: '%s'", $source); } $config = new Config(); $config->setData($data); return $config; }
/** * Load all modules basing on configuration * * @return $this * @throws \InvalidArgumentException */ protected function loadModules() { $modules = $this->config->get('app.module'); if (empty($modules)) { throw new \InvalidArgumentException("Configuration for modules is empty." . " Check whether key 'app.module' has at least one module specified."); } foreach ($modules as $name => $config) { $this->loadModule($name, $config); } return $this; }
/** * @throws LogicException * @throws InvalidArgumentException */ public function main() { $config = new Config(); $properties = $this->filterProperties(); try { foreach ($properties as $name => $value) { $config->set($name, $value); } } catch (\Exception $e) { throw new BuildException(sprintf("Cannot export properties to '%s'. %s", $this->file, $e->getMessage())); } try { $writer = Writer::objectify($this->file); $options = $this->processOptions(); $options->inject($writer); $writer->write($config, $this->file); } catch (\Exception $e) { throw new BuildException(sprintf("Cannot export properties to '%s'. %s", $this->file, $e->getMessage())); } }
/** * Add route group * * @param array $data Data * * @return $this * @throws \InvalidArgumentException */ public function addGroup(array $data) { if (!isset($data['routes'])) { throw new \InvalidArgumentException('Route group has no routes specified.'); } $group = new Group(); $config = new Config($data); $config->inject($group); $routes = $group->getRoutes(); $this->addRoutes($routes); return $this; }
/** * @param Config $config * * @return \Doctrine\Common\Cache\CacheProvider * @throws \OutOfBoundsException */ public function getCache($config) { $type = $config->get('type'); switch ($type) { case 'memcache': $memcache = new \Memcache(); $memcache->connect($config->get('config.host'), $config->get('config.port')); $cache = new \Doctrine\Common\Cache\MemcacheCache(); $cache->setMemcache($memcache); break; case 'xcache': $cache = new \Doctrine\Common\Cache\XCacheCache(); break; case 'apc': $cache = new \Doctrine\Common\Cache\ApcCache(); break; case 'array': $cache = new \Doctrine\Common\Cache\ArrayCache(); break; default: throw new \OutOfBoundsException(sprintf("Unsupported cache type: '%s'", $type)); break; } return $cache; }
/** * Merge with another config * * @param Config $config * * @return $this */ public function extend(Config $config) { $this->data = $this->merge($this->data, $config->getData()); return $this; }
/** * Constructor * * @param string $entity * @param array $data */ public function __construct($data = array(), $entity = null) { parent::__construct($data); $this->entity = $entity; }