Esempio n. 1
0
 /**
  * @param ContainerInterface $container
  */
 protected function register(ContainerInterface $container)
 {
     $factory = new CommandFactory();
     $manager = new CommandManager();
     $container->instance('Kraken\\Runtime\\Command\\CommandFactoryInterface', $factory);
     $container->instance('Kraken\\Runtime\\Command\\CommandManagerInterface', $manager);
 }
Esempio n. 2
0
 /**
  * @param ContainerInterface $container
  * @throws Exception
  */
 protected function register(ContainerInterface $container)
 {
     $config = $container->make('Kraken\\Config\\ConfigInterface');
     $factory = new CommandFactory();
     $commands = (array) $config->get('command.models');
     foreach ($commands as $commandClass) {
         if (!class_exists($commandClass)) {
             throw new ResourceUndefinedException("ConsoleCommand [{$commandClass}] does not exist.");
         }
         $factory->define($commandClass, function ($handler) use($commandClass) {
             return new $commandClass($handler);
         });
     }
     $plugins = (array) $config->get('command.plugins');
     foreach ($plugins as $pluginClass) {
         if (!class_exists($pluginClass)) {
             throw new ResourceUndefinedException("FactoryPlugin [{$pluginClass}] does not exist.");
         }
         $plugin = new $pluginClass();
         if (!$plugin instanceof FactoryPluginInterface) {
             throw new InvalidArgumentException("FactoryPlugin [{$pluginClass}] does not implement FactoryPluginInterface.");
         }
         $plugin->registerPlugin($factory);
     }
     $manager = new CommandManager();
     $container->instance('Kraken\\Console\\Client\\Command\\CommandFactoryInterface', $factory);
     $container->instance('Kraken\\Console\\Client\\Command\\CommandManagerInterface', $manager);
 }
Esempio n. 3
0
 /**
  * @param ContainerInterface $container
  */
 protected function register(ContainerInterface $container)
 {
     $config = $container->make('Kraken\\Config\\ConfigInterface');
     $model = $config->get('loop.model');
     $loop = new Loop(new $model());
     $container->instance('Kraken\\Loop\\LoopInterface', $loop);
     $container->instance('Kraken\\Loop\\LoopExtendedInterface', $loop);
 }
 /**
  * @param ContainerInterface $container
  */
 protected function register(ContainerInterface $container)
 {
     $config = $container->make('Kraken\\Config\\ConfigInterface');
     $errorManager = $container->make('Kraken\\Supervision\\SupervisorInterface', [null, $config->get('supervision.base.params')]);
     $errorSupervisor = $container->make('Kraken\\Supervision\\SupervisorInterface', [null, $config->get('supervision.remote.params')]);
     $container->instance('Kraken\\Runtime\\Supervision\\SupervisorBaseInterface', $errorManager);
     $container->instance('Kraken\\Runtime\\Supervision\\SupervisorRemoteInterface', $errorSupervisor);
 }
Esempio n. 5
0
 /**
  * @param ContainerInterface $container
  */
 protected function register(ContainerInterface $container)
 {
     $loop = $container->make('Kraken\\Loop\\LoopInterface');
     $context = $container->make('Kraken\\Runtime\\RuntimeContextInterface');
     $modelFactory = new ChannelModelFactory($context->getAlias(), $loop);
     $factory = new ChannelFactory($context->getAlias(), $modelFactory, $loop);
     $container->instance('Kraken\\Channel\\ChannelModelFactoryInterface', $modelFactory);
     $container->factory('Kraken\\Channel\\ChannelModelInterface', function () use($modelFactory) {
         return $modelFactory->create('Kraken\\Channel\\Model\\Null\\NullModel');
     });
     $container->instance('Kraken\\Channel\\ChannelFactoryInterface', $factory);
     $container->factory('Kraken\\Channel\\ChannelInterface', [$factory, 'create']);
     $container->factory('Kraken\\Channel\\ChannelCompositeInterface', [$factory, 'create']);
 }
 /**
  * @param ContainerInterface $container
  */
 protected function register(ContainerInterface $container)
 {
     $core = $container->make('Kraken\\Core\\CoreInterface');
     $config = $container->make('Kraken\\Config\\ConfigInterface');
     $factory = new FilesystemAdapterFactory();
     $fsCloud = new FilesystemManager();
     $fsDisk = new Filesystem($factory->create('Local', [['path' => $core->getBasePath()]]));
     $disks = $config->get('filesystem.cloud');
     foreach ($disks as $disk => $config) {
         $fsCloud->mountFilesystem($disk, new Filesystem($factory->create($config['class'], [$config['config']])));
     }
     $container->instance('Kraken\\Filesystem\\FilesystemInterface', $fsDisk);
     $container->instance('Kraken\\Filesystem\\FilesystemFactoryInterface', new FilesystemFactory());
     $container->instance('Kraken\\Filesystem\\FilesystemManagerInterface', $fsCloud);
 }
 /**
  * @param ContainerInterface $container
  */
 protected function register(ContainerInterface $container)
 {
     $config = $container->make('Kraken\\Config\\ConfigInterface');
     $factory = $container->make('Kraken\\Channel\\ChannelFactoryInterface');
     $runtime = $container->make('Kraken\\Runtime\\RuntimeContainerInterface');
     $console = $factory->create('Kraken\\Channel\\Channel', [$runtime->getParent() === null ? $config->get('channel.channels.console.class') : 'Kraken\\Channel\\Model\\Null\\NullModel', array_merge($config->get('channel.channels.console.config'), ['host' => Runtime::RESERVED_CONSOLE_CLIENT])]);
     $container->instance('Kraken\\Runtime\\Service\\ChannelConsole', $console);
 }
Esempio n. 8
0
 /**
  * @param ContainerInterface $container
  */
 protected function register(ContainerInterface $container)
 {
     $config = $container->make('Kraken\\Config\\ConfigInterface');
     $handlers = [];
     if ($config->exists('log.levels')) {
         $levels = (array) $config->get('log.levels');
     } else {
         $levels = [];
     }
     foreach ($levels as $level) {
         $handlers[] = $this->createHandler($config, strtolower($level), constant("\\Kraken\\Log\\Logger::{$level}"));
     }
     $factory = new LoggerFactory();
     $logger = new Logger('Kraken', $handlers);
     $container->instance('Kraken\\Log\\LoggerFactory', $factory);
     $container->instance('Kraken\\Log\\LoggerInterface', $logger);
 }
 /**
  * @param ContainerInterface $container
  */
 protected function register(ContainerInterface $container)
 {
     $runtime = $container->make('Kraken\\Runtime\\RuntimeContainerInterface');
     $factory = new SolverFactory($runtime);
     $config = [];
     $container->instance('Kraken\\Supervision\\SolverFactoryInterface', $factory);
     $container->factory('Kraken\\Supervision\\SupervisorInterface', function (SolverFactoryInterface $passedFactory = null, $passedConfig = [], $passedRules = []) use($factory, $config) {
         return new Supervisor($passedFactory !== null ? $passedFactory : $factory, array_merge($config, $passedConfig), $passedRules);
     });
 }
Esempio n. 10
0
 /**
  * @param ContainerInterface $container
  */
 protected function register(ContainerInterface $container)
 {
     $this->commander = $container->make('Kraken\\Runtime\\Command\\CommandManagerInterface');
     $config = $container->make('Kraken\\Config\\ConfigInterface');
     $runtime = $container->make('Kraken\\Runtime\\RuntimeContainerInterface');
     $factory = $container->make('Kraken\\Channel\\ChannelFactoryInterface');
     $master = $factory->create('Kraken\\Channel\\Channel', [$runtime->getParent() !== null ? $config->get('channel.channels.master.class') : 'Kraken\\Channel\\Model\\Null\\NullModel', array_merge($config->get('channel.channels.master.config'), ['host' => $runtime->getParent() !== null ? $runtime->getParent() : $runtime->getAlias()])]);
     $slave = $factory->create('Kraken\\Channel\\Channel', [$config->get('channel.channels.slave.class'), $config->get('channel.channels.slave.config')]);
     $composite = $factory->create('Kraken\\Channel\\ChannelComposite')->setBus('master', $master)->setBus('slave', $slave);
     $container->instance('Kraken\\Runtime\\Service\\ChannelInternal', $composite);
 }
Esempio n. 11
0
 /**
  * @param ContainerInterface $container
  */
 protected function register(ContainerInterface $container)
 {
     $this->commander = $container->make('Kraken\\Runtime\\Command\\CommandManagerInterface');
     $config = $container->make('Kraken\\Config\\ConfigInterface');
     $runtime = $container->make('Kraken\\Runtime\\RuntimeContainerInterface');
     $factory = $container->make('Kraken\\Channel\\ChannelFactoryInterface');
     $master = $factory->create('Kraken\\Channel\\Channel', [$config->get('channel.channels.master.class'), $config->get('channel.channels.master.config')]);
     $slave = $factory->create('Kraken\\Channel\\Channel', [$config->get('channel.channels.slave.class'), array_merge($config->get('channel.channels.slave.config'), ['name' => Runtime::RESERVED_CONSOLE_CLIENT])]);
     $composite = $factory->create('Kraken\\Channel\\ChannelComposite')->setBus('master', $master)->setBus('slave', $slave);
     $container->instance('Kraken\\Runtime\\Service\\ChannelInternal', $composite);
 }
Esempio n. 12
0
 /**
  * @param ContainerInterface $container
  */
 protected function register(ContainerInterface $container)
 {
     $config = $container->make('Kraken\\Config\\ConfigInterface');
     $runtime = $container->make('Kraken\\Runtime\\RuntimeContainerInterface');
     $channel = $container->make('Kraken\\Runtime\\Service\\ChannelInternal');
     $system = $container->make('Kraken\\Util\\System\\SystemInterface');
     $fs = $container->make('Kraken\\Filesystem\\FilesystemInterface');
     $manager = new ProjectManager($runtime, $channel, $system, $fs);
     $manager->setProjectRoot($config->get('project.config.main.alias'));
     $manager->setProjectName($config->get('project.config.main.name'));
     $container->instance('Kraken\\Console\\Server\\Manager\\ProjectManagerInterface', $manager);
 }
Esempio n. 13
0
 /**
  * @param ContainerInterface $container
  */
 protected function register(ContainerInterface $container)
 {
     $core = $container->make('Kraken\\Core\\CoreInterface');
     $context = $container->make('Kraken\\Runtime\\RuntimeContextInterface');
     $env = new Environment($context, $core->getDataPath() . '/environment/.env');
     $env->setOption('error_reporting', E_ALL);
     $env->setOption('log_errors', '1');
     $env->setOption('display_errors', '0');
     $env->registerErrorHandler(['Kraken\\Throwable\\ErrorHandler', 'handleError']);
     $env->registerShutdownHandler(function () use($context) {
         ErrorHandler::handleShutdown($context->getType() === Runtime::UNIT_PROCESS);
     });
     $env->registerExceptionHandler(['Kraken\\Throwable\\ExceptionHandler', 'handleException']);
     $container->instance('Kraken\\Environment\\EnvironmentInterface', $env);
 }
Esempio n. 14
0
 /**
  * @param ContainerInterface $container
  */
 protected function register(ContainerInterface $container)
 {
     $factory = $container->make('Kraken\\Channel\\ChannelFactoryInterface');
     $config = $container->make('Kraken\\Config\\ConfigInterface');
     $console = $container->make('Kraken\\Console\\Client\\ClientInterface');
     $channel = $factory->create('Kraken\\Channel\\Channel', [$config->get('channel.channels.console.class'), array_merge($config->get('channel.channels.console.config'), ['host' => Runtime::RESERVED_CONSOLE_SERVER])]);
     $this->applyConsoleController($channel);
     $console->on('start', function () use($channel) {
         $channel->start();
     });
     $console->on('stop', function () use($channel) {
         $channel->stop();
     });
     $container->instance('Kraken\\Console\\Client\\Service\\ChannelConsole', $channel);
 }
Esempio n. 15
0
 /**
  * @param ContainerInterface $container
  */
 protected function register(ContainerInterface $container)
 {
     $isolate = $container->getType() === Runtime::UNIT_PROCESS ? new Isolate() : null;
     $system = new SystemUnix($isolate);
     $container->instance('Kraken\\Util\\System\\SystemInterface', $system);
 }
Esempio n. 16
0
 /**
  * @param ContainerInterface $container
  */
 public function register(ContainerInterface $container)
 {
     $container->instance(Resource::class, new Resource(['a' => 'A', 'b' => 'B', 'booted' => false]));
 }
Esempio n. 17
0
 /**
  * @param ContainerInterface $container
  */
 protected function register(ContainerInterface $container)
 {
     $emitter = new EventEmitter($container->make('Kraken\\Loop\\LoopInterface'));
     $container->instance('Kraken\\Event\\EventEmitterInterface', $emitter);
 }
Esempio n. 18
0
 /**
  * @param ContainerInterface $container
  */
 protected function register(ContainerInterface $container)
 {
     $container->instance('Kraken\\Container\\ContainerInterface', $container);
 }
Esempio n. 19
0
 /**
  * @param ContainerInterface $container
  */
 protected function register(ContainerInterface $container)
 {
     $console = $container->make('Kraken\\Console\\Client\\Client');
     $container->instance('Kraken\\Runtime\\RuntimeContextInterface', $console);
     $container->instance('Kraken\\Console\\Client\\ClientInterface', $console);
 }
Esempio n. 20
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);
 }
Esempio n. 21
0
 /**
  * @param ContainerInterface $container
  */
 protected function register(ContainerInterface $container)
 {
     $runtime = $container->make('Kraken\\Runtime\\RuntimeContainer');
     $container->instance('Kraken\\Runtime\\RuntimeContextInterface', $runtime);
     $container->instance('Kraken\\Runtime\\RuntimeContainerInterface', $runtime);
 }