/**
  *
  */
 public function testApiInvoke_MergesConfiguration()
 {
     $overwrite = $this->createOverwriteHandler();
     $old = $this->getRawData();
     $new = ['b' => ['b' => 'new_Option'], 'h' => 'test', 'a' => 5];
     $data = $overwrite($old, $new);
     $this->assertSame(ArraySupport::replace([$new, $old]), $data);
 }
Пример #2
0
 /**
  * @param ContainerInterface $container
  */
 protected function register(ContainerInterface $container)
 {
     $core = $container->make('Kraken\\Core\\CoreInterface');
     $context = $container->make('Kraken\\Runtime\\RuntimeContextInterface');
     $env = $container->make('Kraken\\Environment\\EnvironmentInterface');
     $this->core = $core;
     $this->context = $context;
     $dir = $this->getDir($context->getName(), $context->getType());
     $name = $context->getName();
     $prefix = $core->getDataPath() . '/config';
     $paths = [$prefix . '/' . $dir . '/' . $name, $prefix . '/Runtime/' . $name, $prefix . '/' . $dir, $prefix . '/Runtime'];
     $path = '';
     $pathFound = false;
     foreach ($paths as $path) {
         if (is_dir($path)) {
             $path .= '/config\\.([a-zA-Z]*?)$';
             $pathFound = true;
             break;
         }
     }
     if (!$pathFound) {
         throw new ReadException('There is no valid configuration file.');
     }
     $data = $core->config();
     $data['imports'] = [];
     $data['imports'][] = ['resource' => $path, 'mode' => 'merge'];
     $config = new Config($data);
     $config->setOverwriteHandler(new OverwriteReverseMerger());
     $this->configure($config);
     $config->setOverwriteHandler(new OverwriteMerger());
     $vars = array_merge($config->exists('vars') ? $config->get('vars') : [], $this->getDefaultVariables());
     $records = ArraySupport::flatten($config->getAll());
     foreach ($records as $key => $value) {
         $new = $value;
         $new = preg_replace_callback('#%env(\\.([a-zA-Z0-9_-]*?))+%#si', function ($matches) use($env) {
             $key = strtoupper(str_replace(['%', 'env.'], ['', ''], $matches[0]));
             return $env->getEnv($key);
         }, $new);
         $new = preg_replace_callback('#%func\\.([a-zA-Z0-9_-]*?)%#si', function ($matches) use($context) {
             return call_user_func([$context, $matches[1]]);
         }, $new);
         $new = StringSupport::parametrize($new, $vars);
         if (is_string($value) && $new != $value) {
             if (ctype_digit($new)) {
                 $new = (int) $new;
             }
             $config->set($key, $new);
         }
     }
     $container->instance('Kraken\\Config\\ConfigInterface', $config);
 }
 /**
  * @param ContainerInterface $container
  */
 protected function register(ContainerInterface $container)
 {
     $system = $container->make('Kraken\\Util\\System\\SystemInterface');
     $core = $container->make('Kraken\\Core\\CoreInterface');
     $config = $container->make('Kraken\\Config\\ConfigInterface');
     $fs = $container->make('Kraken\\Filesystem\\FilesystemInterface');
     $runtime = $container->make('Kraken\\Runtime\\RuntimeContainerInterface');
     $channel = $container->make('Kraken\\Runtime\\Service\\ChannelInternal');
     $this->registerRuntimeSupervision($runtime, $channel, $config);
     $context = $config->exists('context') ? ArraySupport::flatten($config->get('context')) : [];
     $defaultConfig = ['runtime' => $runtime, 'channel' => $channel, 'context' => $context, 'system' => $system, 'filesystem' => $fs, 'receiver' => $runtime->getParent()];
     $factoryProcess = new ProcessManagerFactory();
     $factoryThread = new ThreadManagerFactory();
     if ($core->getType() === Runtime::UNIT_THREAD) {
         $factoryProcess->remove('Kraken\\Runtime\\Container\\Manager\\ProcessManagerBase');
     }
     $managerProcess = $this->createManager($container, $factoryProcess, $defaultConfig, $config->get('runtime.manager.process'));
     $managerThread = $this->createManager($container, $factoryThread, $defaultConfig, $config->get('runtime.manager.thread'));
     $managerRuntime = new RuntimeManager($channel, $managerProcess, $managerThread);
     $container->instance('Kraken\\Runtime\\Container\\ProcessManagerInterface', $managerProcess);
     $container->instance('Kraken\\Runtime\\Container\\ThreadManagerInterface', $managerThread);
     $container->instance('Kraken\\Runtime\\RuntimeManagerInterface', $managerRuntime);
 }
Пример #4
0
 /**
  * @param array $old
  * @param array $new
  * @return array
  */
 public function __invoke($old, $new)
 {
     return ArraySupport::merge([$old, $new]);
 }
Пример #5
0
 /**
  * @return array
  */
 public function getExpanded()
 {
     return ArraySupport::expand($this->getRaw());
 }
Пример #6
0
 /**
  * @override
  * @inheritDoc
  */
 public function remove($key)
 {
     return ArraySupport::remove($this->config, $key);
 }
 /**
  * @param array $old
  * @param array $new
  * @return array
  */
 public function __invoke($old, $new)
 {
     return ArraySupport::replace([$new, $old]);
 }