Ejemplo n.º 1
0
 /**
  * @param ContainerInterface $container
  * @throws Exception
  */
 protected function boot(ContainerInterface $container)
 {
     $config = $container->make('Kraken\\Config\\ConfigInterface');
     $factory = $container->make('Kraken\\Runtime\\Command\\CommandFactoryInterface');
     $commands = (array) $config->get('command.models');
     foreach ($commands as $commandClass) {
         if (!class_exists($commandClass)) {
             throw new ResourceUndefinedException("Command [{$commandClass}] does not exist.");
         }
         $factory->define($commandClass, function ($runtime, $context = []) use($commandClass) {
             return new $commandClass($runtime, $context);
         });
     }
     $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);
     }
 }
Ejemplo n.º 2
0
 /**
  * @param ContainerInterface $container
  * @throws Exception
  */
 protected function boot(ContainerInterface $container)
 {
     $config = $container->make('Kraken\\Config\\ConfigInterface');
     $factory = $container->make('Kraken\\Supervision\\SolverFactoryInterface');
     $handlers = (array) $config->get('supervision.solvers');
     foreach ($handlers as $handlerClass) {
         if (!class_exists($handlerClass)) {
             throw new ResourceUndefinedException("Solver [{$handlerClass}] does not exist.");
         }
         $factory->define($handlerClass, function ($runtime, $context = []) use($handlerClass) {
             return new $handlerClass($runtime, $context);
         });
     }
     $plugins = (array) $config->get('supervision.plugins');
     foreach ($plugins as $pluginClass) {
         if (!class_exists($pluginClass)) {
             throw new ResourceUndefinedException("SupervisorPlugin [{$pluginClass}] does not exist.");
         }
         $plugin = new $pluginClass();
         if (!$plugin instanceof FactoryPluginInterface) {
             throw new InvalidArgumentException("SupervisorPlugin [{$pluginClass}] does not implement SupervisorPluginInterface.");
         }
         $plugin->registerPlugin($factory);
     }
 }
Ejemplo n.º 3
0
 /**
  * @param ContainerInterface $container
  * @throws Exception
  */
 protected function boot(ContainerInterface $container)
 {
     $config = $container->make('Kraken\\Config\\ConfigInterface');
     $factory = $container->make('Kraken\\Channel\\ChannelModelFactoryInterface');
     $models = (array) $config->get('channel.models');
     foreach ($models as $modelClass) {
         if (!class_exists($modelClass)) {
             throw new ResourceUndefinedException("ChannelModel [{$modelClass}] does not exist.");
         }
         $factory->define($modelClass, function ($config) use($modelClass) {
             return new $modelClass($config);
         });
     }
     $plugins = (array) $config->get('channel.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);
     }
 }
Ejemplo n.º 4
0
 /**
  * @param ContainerInterface $container
  * @throws Exception
  */
 protected function boot(ContainerInterface $container)
 {
     $config = $container->make('Kraken\\Config\\ConfigInterface');
     $baseSupervisor = $container->make('Kraken\\Runtime\\Supervision\\SupervisorBaseInterface');
     $remoteSupervisor = $container->make('Kraken\\Runtime\\Supervision\\SupervisorRemoteInterface');
     $this->bootBaseSupervision($baseSupervisor, $config);
     $this->bootRemoteSupervision($remoteSupervisor, $config);
 }
Ejemplo n.º 5
0
 /**
  * @param ContainerInterface $core
  */
 protected function boot(ContainerInterface $core)
 {
     $config = $core->make('Kraken\\Config\\ConfigInterface');
     $runtime = $core->make('Kraken\\Runtime\\RuntimeContainerInterface');
     $factory = $core->make('Kraken\\Runtime\\Command\\CommandFactoryInterface');
     $manager = $core->make('Kraken\\Runtime\\Command\\CommandManagerInterface');
     $manager->import($this->getDefaultCommands($runtime));
     $manager->import($this->getAppCommands($config, $factory, $runtime));
 }
Ejemplo n.º 6
0
 /**
  * @param ContainerInterface $container
  */
 protected function register(ContainerInterface $container)
 {
     $loop = $container->make('Kraken\\Loop\\LoopExtendedInterface');
     $runtime = $container->make('Kraken\\Runtime\\RuntimeContainerInterface');
     $error = $container->make('Kraken\\Runtime\\Supervision\\SupervisorBaseInterface');
     $manager = $container->make('Kraken\\Runtime\\RuntimeManagerInterface');
     $model = $runtime->getModel();
     $model->setLoop($loop);
     $model->setSupervisor($error);
     $model->setRuntimeManager($manager);
 }
Ejemplo n.º 7
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);
 }
Ejemplo n.º 8
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);
 }
Ejemplo n.º 9
0
 /**
  * @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);
 }
Ejemplo n.º 10
0
 /**
  * @param ContainerInterface $container
  */
 protected function boot(ContainerInterface $container)
 {
     $runtime = $container->make('Kraken\\Runtime\\RuntimeContainerInterface');
     $channel = $container->make('Kraken\\Runtime\\Service\\ChannelInternal');
     $loop = $container->make('Kraken\\Loop\\LoopInterface');
     $this->applyConsoleRouting($runtime, $channel);
     $runtime->on('create', function () use($channel) {
         $channel->start();
     });
     $runtime->on('destroy', function () use($loop, $channel) {
         $loop->onTick(function () use($channel) {
             $channel->stop();
         });
     });
 }
Ejemplo n.º 11
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);
 }
Ejemplo n.º 12
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);
 }
Ejemplo n.º 13
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);
 }
Ejemplo n.º 14
0
 /**
  * @param ContainerInterface $container
  */
 protected function boot(ContainerInterface $container)
 {
     $core = $container->make('Kraken\\Core\\CoreInterface');
     $factory = $container->make('Kraken\\Console\\Client\\Command\\CommandFactoryInterface');
     $manager = $container->make('Kraken\\Console\\Client\\Command\\CommandManagerInterface');
     $channel = $container->make('Kraken\\Console\\Client\\Service\\ChannelConsole');
     $console = $container->make('Kraken\\Console\\Client\\ClientInterface');
     $cmds = (array) $factory->getDefinitions();
     $commands = [];
     foreach ($cmds as $command => $definition) {
         $commands[] = $factory->create($command, [$channel, 'Server']);
     }
     $manager->setAutoExit(false);
     $manager->setVersion($core->getVersion());
     $manager->addCommands($commands);
     $console->onCommand(function () use($manager) {
         $manager->run();
     });
 }
Ejemplo n.º 15
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);
 }
Ejemplo n.º 16
0
 /**
  * @param ContainerInterface $container
  */
 public function boot(ContainerInterface $container)
 {
     $res = $container->make(Resource::class);
     $res->data['booted'] = true;
 }
Ejemplo 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);
 }
Ejemplo n.º 18
0
 /**
  * @param ContainerInterface $container
  * @param RuntimeManagerFactoryInterface $managerFactory
  * @param mixed[] $default
  * @param mixed[] $config
  * @return RuntimeManagerInterface
  */
 private function createManager(ContainerInterface $container, RuntimeManagerFactoryInterface $managerFactory, $default, $config)
 {
     $managerClass = $config['class'];
     $managerConfig = array_merge($default, $config['config']);
     foreach ($managerConfig as $key => $value) {
         if (is_string($value) && class_exists($value)) {
             $managerConfig[$key] = $container->make($value);
         }
     }
     return $managerFactory->create($managerClass, [$managerConfig]);
 }
Ejemplo n.º 19
0
 /**
  * @param ContainerInterface $container
  */
 protected function boot(ContainerInterface $container)
 {
     $console = $container->make('Kraken\\Console\\Client\\ClientInterface');
     $loop = $container->make('Kraken\\Loop\\LoopExtendedInterface');
     $console->setLoop($loop);
 }
Ejemplo n.º 20
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);
 }