示例#1
0
 /**
  * @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);
     }
 }
示例#2
0
文件: Php.php 项目: appcia/webwork
 /**
  * {@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;
 }
示例#3
0
 /**
  * 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];
 }
示例#4
0
文件: Php.php 项目: appcia/webwork
 /**
  * @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;
 }
示例#5
0
文件: App.php 项目: appcia/webwork
 /**
  * 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;
 }
示例#6
0
 /**
  * @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()));
     }
 }
示例#7
0
文件: Router.php 项目: appcia/webwork
 /**
  * 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;
 }
示例#8
0
 /**
  * @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;
 }
示例#9
0
文件: Config.php 项目: appcia/webwork
 /**
  * Merge with another config
  *
  * @param Config $config
  *
  * @return $this
  */
 public function extend(Config $config)
 {
     $this->data = $this->merge($this->data, $config->getData());
     return $this;
 }
示例#10
0
 /**
  * Constructor
  *
  * @param string $entity
  * @param array  $data
  */
 public function __construct($data = array(), $entity = null)
 {
     parent::__construct($data);
     $this->entity = $entity;
 }