/** * @param CoreInterface $core * @throws Exception */ protected function boot(CoreInterface $core) { $config = $core->make('Surume\\Config\\ConfigInterface'); $factory = $core->make('Surume\\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); } }
/** * @param CoreInterface $core */ protected function boot(CoreInterface $core) { $runtime = $core->make('Surume\\Runtime\\RuntimeInterface'); $channel = $core->make('Surume\\Runtime\\Channel\\ChannelInterface'); $runtime->on('create', [$channel, 'start']); $runtime->on('destroy', [$channel, 'stop']); }
/** * @param CoreInterface $core * @throws Exception */ protected function boot(CoreInterface $core) { $config = $core->make('Surume\\Config\\ConfigInterface'); $factory = $core->make('Surume\\Supervisor\\SolverFactoryInterface'); $handlers = (array) $config->get('error.handlers'); 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('error.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); } }
/** * @param CoreInterface $core * @throws Exception */ protected function boot(CoreInterface $core) { $config = $core->make('Surume\\Config\\ConfigInterface'); $baseSupervisor = $core->make('Surume\\Runtime\\Supervisor\\SupervisorBaseInterface'); $remoteSupervisor = $core->make('Surume\\Runtime\\Supervisor\\SupervisorRemoteInterface'); $this->bootBaseSupervisor($baseSupervisor, $config); $this->bootRemoteSupervisor($remoteSupervisor, $config); }
/** * @param CoreInterface $core */ protected function boot(CoreInterface $core) { $runtime = $core->make('Surume\\Runtime\\RuntimeInterface'); $channel = $core->make('Surume\\Runtime\\Channel\\ChannelInterface'); $console = $core->make('Surume\\Runtime\\Channel\\ConsoleInterface'); $this->applyConsoleRouting($channel, $console); $runtime->on('create', [$console, 'start']); $runtime->on('destroy', [$console, 'stop']); }
/** * @param CoreInterface $core */ protected function boot(CoreInterface $core) { $config = $core->make('Surume\\Config\\ConfigInterface'); $runtime = $core->make('Surume\\Runtime\\RuntimeInterface'); $factory = $core->make('Surume\\Command\\CommandFactoryInterface'); $manager = $core->make('Surume\\Command\\CommandManagerInterface'); $manager->import($this->defaultCommands($config, $factory, $runtime)); $manager->import($this->appCommands($config, $factory, $runtime)); }
/** * @param CoreInterface $core */ protected function register(CoreInterface $core) { $loop = $core->make('Surume\\Loop\\LoopExtendedInterface'); $runtime = $core->make('Surume\\Runtime\\RuntimeInterface'); $error = $core->make('Surume\\Runtime\\Supervisor\\SupervisorBaseInterface'); $manager = $core->make('Surume\\Runtime\\RuntimeManagerInterface'); $model = $runtime->model(); $model->setLoop($loop); $model->setSupervisor($error); $model->setRuntimeManager($manager); }
/** * @param CoreInterface $core */ protected function boot(CoreInterface $core) { $runtime = $core->make('Surume\\Runtime\\RuntimeInterface'); $channel = $core->make('Surume\\Runtime\\Channel\\ChannelInterface'); $console = $core->make('Surume\\Runtime\\Channel\\ConsoleInterface'); if ($runtime->parent() === null) { $this->applyRootRouting($runtime, $channel, $console); } else { $this->applySimpleRouting($runtime, $channel); } $runtime->on('create', [$channel, 'start']); $runtime->on('destroy', [$channel, 'stop']); }
/** * @param CoreInterface $core */ protected function register(CoreInterface $core) { $factory = $core->make('Surume\\Channel\\ChannelFactoryInterface'); $config = $core->make('Surume\\Config\\ConfigInterface'); $console = $core->make('Surume\\Console\\Client\\ConsoleClientInterface'); $channel = $factory->create('Surume\\Channel\\ChannelBase', [$config->get('channel.channels.console.class'), array_merge($config->get('channel.channels.console.config'), ['hosts' => Runtime::RESERVED_CONSOLE_SERVER])]); $this->applyConsoleController($channel); $console->onStart(function () use($channel) { $channel->start(); }); $console->onStop(function () use($channel) { $channel->stop(); }); $core->instance('Surume\\Console\\Client\\Channel\\ConsoleInterface', $channel); }
/** * @param CoreInterface $core * @throws Exception */ protected function register(CoreInterface $core) { $config = $core->make('Surume\\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); } $core->instance('Surume\\Console\\Client\\Command\\CommandFactoryInterface', $factory); }
/** * @param CoreInterface $core */ protected function register(CoreInterface $core) { $config = $core->make('Surume\\Config\\ConfigInterface'); $model = $config->get('loop.model'); $loop = new Loop(new $model()); $core->instance('Surume\\Loop\\LoopInterface', $loop); $core->instance('Surume\\Loop\\LoopExtendedInterface', $loop); }
/** * @param CoreInterface $core */ protected function register(CoreInterface $core) { $config = $core->make('Surume\\Config\\ConfigInterface'); $factory = new LoggerFactory(); $logger = new Logger('surume', [$this->createHandler($core, $config, 'debug', Logger::DEBUG), $this->createHandler($core, $config, 'info', Logger::INFO), $this->createHandler($core, $config, 'notice', Logger::NOTICE), $this->createHandler($core, $config, 'warning', Logger::WARNING), $this->createHandler($core, $config, 'error', Logger::EMERGENCY)]); $core->instance('Surume\\Log\\LoggerFactory', $factory); $core->instance('Surume\\Log\\LoggerInterface', $logger); }
/** * @param CoreInterface $core */ protected function boot(CoreInterface $core) { $config = $core->make('Surume\\Config\\ConfigInterface'); $factory = $core->make('Surume\\Console\\Client\\Command\\CommandFactoryInterface'); $handler = $core->make('Surume\\Console\\Client\\Command\\CommandHandlerInterface'); $console = $core->make('Surume\\Console\\Client\\ConsoleClientInterface'); $cmds = (array) $factory->getDefinitions(); $commands = []; foreach ($cmds as $command => $definition) { $commands[] = $factory->create($command, [$handler]); } $this->symfony->addCommands($commands); $version = $core->version(); $console->onCommand(function () use($version) { echo "SurumePHP-v{$version}\n"; $this->symfony->run(); }); }
/** * @param CoreInterface $core */ protected function register(CoreInterface $core) { $context = $core->make('Surume\\Core\\CoreInputContextInterface'); $config = $core->make('Surume\\Config\\ConfigInterface'); $env = new Environment($context, $config); $env->setOption('error_reporting', E_ALL); $env->setOption('log_errors', '1'); $env->setOption('display_errors', '0'); $inis = (array) $config->get('core.ini'); foreach ($inis as $option => $value) { $env->setOption($option, $value); } $this->setProcessProperties($env); $env->registerErrorHandler(['Surume\\Throwable\\ErrorEnvHandler', 'handleError']); $env->registerShutdownHandler(['Surume\\Throwable\\ErrorEnvHandler', 'handleShutdown']); $env->registerExceptionHandler(['Surume\\Throwable\\ExceptionEnvHandler', 'handleException']); $core->instance('Surume\\Core\\EnvironmentInterface', $env); }
/** * @param CoreInterface $core */ protected function register(CoreInterface $core) { $config = $core->make('Surume\\Config\\ConfigInterface'); $factory = new FilesystemAdapterFactory(); $fsCloud = new FilesystemManager(); $fsDisk = new Filesystem($factory->create('Local', [['path' => $core->basePath()]])); $disks = $config->get('filesystem.cloud'); foreach ($disks as $disk => $config) { $fsCloud->mountFilesystem($disk, new Filesystem($factory->create($config['factory'], [$config['config']]))); } $core->instance('Surume\\Filesystem\\FilesystemInterface', $fsDisk); $core->instance('Surume\\Filesystem\\FilesystemManagerInterface', $fsCloud); }
/** * @param CoreInterface $core */ protected function register(CoreInterface $core) { $context = $core->make('Surume\\Core\\CoreInputContextInterface'); $global = $core->dataPath() . '/config-global/' . $this->getDir($core->unit()); $local = $core->dataPath() . '/config/' . $context->name(); $config = new Config(); $this->addConfigByPath($config, $global); $this->addConfigByPath($config, $local); $this->addConfig($config, new Config($core->config())); $vars = array_merge($config->exists('vars') ? $config->get('vars') : [], $this->getDefaultVariables($core, $context)); $records = ArraySupport::flatten($config->all()); foreach ($records as $key => $value) { $new = StringSupport::parametrize($value, $vars); if (is_string($value) && $new != $value) { $config->set($key, $new); } } $core->instance('Surume\\Config\\ConfigInterface', $config); }
/** * @param CoreInterface $core */ protected function boot(CoreInterface $core) { $console = $this->console; $loop = $core->make('Surume\\Loop\\LoopExtendedInterface'); $console->setLoop($loop); }
/** * @param CoreInterface $core */ protected function boot(CoreInterface $core) { $runtime = $core->make('Surume\\Runtime\\RuntimeInterface'); $manager = $core->make('Surume\\Command\\CommandManagerInterface'); $manager->import($this->commands($runtime)); }
/** * @param CoreInterface $core */ protected function register(CoreInterface $core) { $channel = $core->make('Surume\\Console\\Client\\Channel\\ConsoleInterface'); $manager = new CommandHandler($channel, 'ConsoleServer'); $core->instance('Surume\\Console\\Client\\Command\\CommandHandlerInterface', $manager); }
/** * @param CoreInterface $core * @param RuntimeManagerFactoryInterface $managerFactory * @param mixed[] $default * @param mixed[] $config * @return RuntimeManagerInterface */ private function createManager(CoreInterface $core, 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] = $core->make($value); } } return $managerFactory->create($managerClass, [$managerConfig]); }
/** * @param CoreInterface $core */ protected function register(CoreInterface $core) { $emitter = new EventEmitter($core->make('Surume\\Loop\\LoopInterface')); $core->instance('Surume\\Event\\EventEmitterInterface', $emitter); }