/**
  * Returns extension configuration.
  * @param  array default values.
  * @param  bool  perform %parameters% expansion?
  * @return array
  */
 public function getConfig(array $defaults = NULL, $expand = TRUE)
 {
     $config = $this->compiler->getConfig();
     $config = isset($config[$this->name]) ? $config[$this->name] : array();
     unset($config['services'], $config['factories']);
     $config = Helpers::merge($config, $defaults);
     return $expand ? $this->compiler->getContainerBuilder()->expand($config) : $config;
 }
 private function getSection(array $data, $key, $file)
 {
     Validators::assertField($data, $key, 'array|null', "section '%' in file '{$file}'");
     $item = $data[$key];
     if ($parent = Helpers::takeParent($item)) {
         $item = Helpers::merge($item, $this->getSection($data, $parent, $file));
     }
     return $item;
 }
 /**
  * Generates configuration in NEON format.
  * @param  array
  * @return string
  */
 public function dump(array $data)
 {
     $tmp = array();
     foreach ($data as $name => $secData) {
         if ($parent = Helpers::takeParent($secData)) {
             $name .= ' ' . self::INHERITING_SEPARATOR . ' ' . $parent;
         }
         $tmp[$name] = $secData;
     }
     return "# generated by Nette\n\n" . Neon::encode($tmp, Neon::BLOCK);
 }
Beispiel #4
0
 /**
  * Parses single service from configuration file.
  * @return void
  */
 public static function parseService(Nette\DI\ServiceDefinition $definition, $config, $shared = TRUE)
 {
     if ($config === NULL) {
         return;
     } elseif (!is_array($config)) {
         $config = array('class' => NULL, 'factory' => $config);
     }
     $known = $shared ? array('class', 'factory', 'arguments', 'setup', 'autowired', 'run', 'tags') : array('class', 'factory', 'arguments', 'setup', 'autowired', 'tags', 'internal', 'parameters');
     if ($error = array_diff(array_keys($config), $known)) {
         throw new Nette\InvalidStateException("Unknown key '" . implode("', '", $error) . "' in definition of service.");
     }
     $arguments = array();
     if (array_key_exists('arguments', $config)) {
         Validators::assertField($config, 'arguments', 'array');
         $arguments = self::filterArguments($config['arguments']);
         $definition->setArguments($arguments);
     }
     if (array_key_exists('class', $config) || array_key_exists('factory', $config)) {
         $definition->class = NULL;
         $definition->factory = NULL;
     }
     if (array_key_exists('class', $config)) {
         Validators::assertField($config, 'class', 'string|stdClass|null');
         if ($config['class'] instanceof \stdClass) {
             $definition->setClass($config['class']->value, self::filterArguments($config['class']->attributes));
         } else {
             $definition->setClass($config['class'], $arguments);
         }
     }
     if (array_key_exists('factory', $config)) {
         Validators::assertField($config, 'factory', 'callable|stdClass|null');
         if ($config['factory'] instanceof \stdClass) {
             $definition->setFactory($config['factory']->value, self::filterArguments($config['factory']->attributes));
         } else {
             $definition->setFactory($config['factory'], $arguments);
         }
     }
     if (isset($config['setup'])) {
         if (Helpers::takeParent($config['setup'])) {
             $definition->setup = array();
         }
         Validators::assertField($config, 'setup', 'list');
         foreach ($config['setup'] as $id => $setup) {
             Validators::assert($setup, 'callable|stdClass', "setup item #{$id}");
             if ($setup instanceof \stdClass) {
                 Validators::assert($setup->value, 'callable', "setup item #{$id}");
                 $definition->addSetup($setup->value, self::filterArguments($setup->attributes));
             } else {
                 $definition->addSetup($setup);
             }
         }
     }
     $definition->setShared($shared);
     if (isset($config['parameters'])) {
         Validators::assertField($config, 'parameters', 'array');
         $definition->setParameters($config['parameters']);
     }
     if (isset($config['autowired'])) {
         Validators::assertField($config, 'autowired', 'bool');
         $definition->setAutowired($config['autowired']);
     }
     if (isset($config['internal'])) {
         Validators::assertField($config, 'internal', 'bool');
         $definition->setInternal($config['internal']);
     }
     if (isset($config['run'])) {
         $config['tags']['run'] = (bool) $config['run'];
     }
     if (isset($config['tags'])) {
         Validators::assertField($config, 'tags', 'array');
         if (Helpers::takeParent($config['tags'])) {
             $definition->tags = array();
         }
         foreach ($config['tags'] as $tag => $attrs) {
             if (is_int($tag) && is_string($attrs)) {
                 $definition->addTag($attrs);
             } else {
                 $definition->addTag($tag, $attrs);
             }
         }
     }
 }
 /**
  * Build system container class.
  * @return string
  */
 protected function buildContainer(&$dependencies = NULL)
 {
     $loader = $this->createLoader();
     $config = array();
     $code = "<?php\n";
     foreach ($this->files as $tmp) {
         list($file, $section) = $tmp;
         $config = Helpers::merge($loader->load($file, $section), $config);
         $code .= "// source: {$file} {$section}\n";
     }
     $code .= "\n";
     $this->checkCompatibility($config);
     if (!isset($config['parameters'])) {
         $config['parameters'] = array();
     }
     $config['parameters'] = Helpers::merge($config['parameters'], $this->parameters);
     $compiler = $this->createCompiler();
     $this->onCompile($this, $compiler);
     $code .= $compiler->compile($config, $this->parameters['container']['class'], $config['parameters']['container']['parent']);
     $dependencies = array_merge($loader->getDependencies(), $this->isDebugMode() ? $compiler->getContainerBuilder()->getDependencies() : array());
     return $code;
 }
Beispiel #6
0
 /**
  * Generates configuration in INI format.
  * @return string
  */
 public function dump(array $data)
 {
     $output = array();
     foreach ($data as $name => $secData) {
         if (!is_array($secData)) {
             $output = array();
             self::build($data, $output, '');
             break;
         }
         if ($parent = Helpers::takeParent($secData)) {
             $output[] = "[{$name} " . self::INHERITING_SEPARATOR . " {$parent}]";
         } else {
             $output[] = "[{$name}]";
         }
         self::build($secData, $output, '');
         $output[] = '';
     }
     return "; generated by Nette\n\n" . implode(PHP_EOL, $output);
 }
Beispiel #7
0
 protected function loadNativeSessionHandler(array $session)
 {
     $builder = $this->getContainerBuilder();
     $params = array_intersect_key($session, array_flip(array('weight', 'timeout', 'database', 'prefix', 'auth', 'persistent')));
     if (substr($session['host'], 0, 1) === '/') {
         $savePath = $session['host'];
     } else {
         $savePath = sprintf('tcp://%s:%d', $session['host'], $session['port']);
     }
     if (!$params['persistent']) {
         unset($params['persistent']);
     }
     if (!$params['auth']) {
         unset($params['auth']);
     }
     $options = array('saveHandler' => 'redis', 'savePath' => $savePath . ($params ? '?' . http_build_query($params, '', '&') : ''));
     foreach ($builder->getDefinition('session')->setup as $statement) {
         if ($statement->entity === 'setOptions') {
             $statement->arguments[0] = Nette\Config\Helpers::merge($options, $statement->arguments[0]);
             unset($options);
             break;
         }
     }
     if (isset($options)) {
         $builder->getDefinition('session')->addSetup('setOptions', array($options));
     }
 }
Beispiel #8
0
Nette\Utils\NeonEntity){$val=(object)array('value'=>$val->value,'attributes'=>$this->process($val->attributes));}$res[$key]=$val;}return$res;}function
dump(array$data){$tmp=array();foreach($data
as$name=>$secData){if($parent=Helpers::takeParent($secData)){$name.=' '.self::INHERITING_SEPARATOR.' '.$parent;}$tmp[$name]=$secData;}return"# generated by Nette\n\n".Neon::encode($tmp,Neon::BLOCK);}}class