public function build(ServiceDefinitionInterface $service_definition, SettingsInterface $provisioner_settings) { $logger_manager = AgaviContext::getInstance()->getLoggerManager(); $logger = $logger_manager->getLogger()->getPsr3Logger(); $service = $service_definition->getClass(); $this->di_container->share($logger)->alias(LoggerInterface::CLASS, $service); }
public function build(ServiceDefinitionInterface $service_definition, SettingsInterface $provisioner_settings) { $service = $service_definition->getClass(); $state = [':config' => $service_definition->getConfig()]; if ($provisioner_settings->has('logger')) { $logger_name = $provisioner_settings->get('logger', 'default'); $logger = AgaviContext::getInstance()->getLoggerManager()->getLogger($logger_name)->getPsr3Logger(); $state[':logger'] = $logger; } if ($provisioner_settings->has('connector')) { $connector_name = $provisioner_settings->get('connector', 'default'); $connector_service = $this->di_container->make(ConnectorServiceInterface::CLASS); $state[':connector'] = $connector_service->getConnector($connector_name); } $this->di_container->define($service, $state); // there will only be one instance of the service when the "share" setting is true if ($provisioner_settings->get('share', true) === true) { $this->di_container->share($service); } if ($provisioner_settings->has('alias')) { $alias = $provisioner_settings->get('alias'); if (!is_string($alias) && !class_exists($alias)) { throw new ConfigError('Alias given must be an existing class or interface name (fully qualified).'); } $this->di_container->alias($alias, $service); } }
public function build(ServiceDefinitionInterface $service_definition, SettingsInterface $provisioner_settings) { $view_templates_config = $this->loadViewTemplatesConfig(); $service = $service_definition->getClass(); $state = [':config' => $service_definition->getConfig(), ':view_templates_container_map' => $this->createViewTemplatesContainerMap($view_templates_config)]; $this->di_container->define($service, $state)->share($service)->alias(ViewTemplateServiceInterface::CLASS, $service); }
public function build(ServiceDefinitionInterface $service_definition, SettingsInterface $provisioner_settings) { $navigations_config = $this->loadNavigationsConfig(); $default_navigation_name = $navigations_config['default_navigation']; $service = $service_definition->getClass(); $state = [':navigations_config' => new ArrayConfig($navigations_config['navigations']), ':default_navigation' => $default_navigation_name]; $this->di_container->define($service, $state)->share($service)->alias(NavigationServiceInterface::CLASS, $service); }
public function build(ServiceDefinitionInterface $service_definition, SettingsInterface $provisioner_settings) { $view_config = $this->loadViewConfig(); $service = $service_definition->getClass(); $state = [':config' => $service_definition->getConfig(), ':view_config' => new ArrayConfig($view_config)]; $this->di_container->alias(NameResolverInterface::CLASS, SubjectNameResolver::CLASS); $this->di_container->define($service, $state)->share($service)->alias(ViewConfigServiceInterface::CLASS, $service); }
public function build(ServiceDefinitionInterface $service_definition, SettingsInterface $provisioner_settings) { $service = $service_definition->getClass(); $agavi_context = AgaviContext::getInstance(); $logger_name = $provisioner_settings->get('logger_name', 'translation'); $state = [':config' => $service_definition->getConfig(), ':tm' => $agavi_context->getTranslationManager(), ':logger' => $agavi_context->getLoggerManager()->getLogger($logger_name)->getPsr3Logger()]; $this->di_container->define($service, $state)->share($service); $this->di_container->alias(TranslatorInterface::CLASS, $service); }
public function build(ServiceDefinitionInterface $service_definition, SettingsInterface $provisioner_settings) { $factory_delegate = function (EnvironmentInterface $environment, WorkflowActivityService $workflow_activity_service, AggregateRootTypeMap $aggregate_root_type_map, UrlGeneratorInterface $url_generator) use($service_definition) { $activity_container_map = $this->buildActivityContainerMap(); $service_class = $service_definition->getClass(); return new $service_class($environment, $workflow_activity_service, $activity_container_map, $aggregate_root_type_map, $url_generator); }; $service = $service_definition->getClass(); $this->di_container->delegate($service, $factory_delegate)->share($service)->alias(ActivityServiceInterface::CLASS, $service); }
public function build(ServiceDefinitionInterface $service_definition, SettingsInterface $provisioner_settings) { $factory_delegate = function (ServiceLocatorInterface $service_locator) use($service_definition) { $activity_container_map = $this->buildActivityContainerMap(); $service_class = $service_definition->getClass(); return new $service_class($service_locator, $activity_container_map); }; $service = $service_definition->getClass(); $this->di_container->delegate($service, $factory_delegate)->share($service); }
public function build(ServiceDefinitionInterface $service_definition, SettingsInterface $provisioner_settings) { $this->di_container->share(ConnectorMap::CLASS)->prepare(ConnectorMap::CLASS, function (ConnectorMap $connector_map, DiContainer $di_container) { $connections_config = $this->loadConnectionsConfig(); $this->registerConnectors($connector_map, $connections_config); }); $service = $service_definition->getClass(); $state = ['connector_map' => ConnectorMap::CLASS]; $this->di_container->define($service, $state)->share($service)->alias(ConnectorServiceInterface::CLASS, $service); }
public function build(ServiceDefinitionInterface $service_definition, SettingsInterface $provisioner_settings) { $factory_delegate = function (ServiceLocatorInterface $service_locator) use($service_definition) { $state_machine_definitions = $this->buildStateMachineDefinitions(); $service_class = $service_definition->getClass(); return new $service_class($state_machine_definitions, $service_locator); }; $service = $service_definition->getClass(); $this->di_container->delegate($service, $factory_delegate)->share($service)->alias(StateMachineBuilderInterface::CLASS, $service); }
public function build(ServiceDefinitionInterface $service_definition, SettingsInterface $provisioner_settings) { $data_access_config = $this->loadDbalConfig(); $this->provisionStorageWriterMap($data_access_config['storage_writers']); $this->provisionStorageReaderMap($data_access_config['storage_readers']); $this->provisionFinderMap($data_access_config['finders']); $this->provisionQueryServiceMap($data_access_config['query_services']); $this->provisionUnitOfWorkMap($data_access_config['units_of_work']); $service = $service_definition->getClass(); $this->di_container->share($service)->alias(DataAccessServiceInterface::CLASS, $service); }
public function build(ServiceDefinitionInterface $service_definition, SettingsInterface $provisioner_settings) { $factory_delegate = function (AggregateRootTypeMap $aggregate_root_type_map) use($service_definition) { $fixture_config = $this->loadFixtureConfig(); $fixture_target_map = $this->buildFixtureTargetMap($fixture_config['targets']); $service_config = $service_definition->getConfig(); $service_class = $service_definition->getClass(); return new $service_class($service_config, $fixture_target_map, $aggregate_root_type_map); }; $service = $service_definition->getClass(); $this->di_container->delegate($service, $factory_delegate)->share($service)->alias(FixtureServiceInterface::CLASS, $service); }
public function build(ServiceDefinitionInterface $service_definition, SettingsInterface $provisioner_settings) { $command_bus_config = (include AgaviConfigCache::checkConfig(AgaviConfig::get('core.config_dir') . DIRECTORY_SEPARATOR . self::COMMAND_BUS_CONFIG_FILE, AgaviContext::getInstance()->getName())); $callback = function (CommandBusInterface $command_bus, DiContainer $di_container) use($command_bus_config) { if (!$this->prepare_executed) { $this->prepareCommandBus($command_bus, $command_bus_config); $this->prepare_executed = true; } }; $service = $service_definition->getClass(); $this->di_container->prepare($service, $callback)->share($service)->alias(CommandBusInterface::CLASS, $service); }
public function build(ServiceDefinitionInterface $service_definition, SettingsInterface $provisioner_settings) { $jobs_config = (include AgaviConfigCache::checkConfig(AgaviConfig::get('core.config_dir') . DIRECTORY_SEPARATOR . self::JOBS_CONFIG_FILE, AgaviContext::getInstance()->getName())); $service = $service_definition->getClass(); $factory_delegate = function (ConnectorServiceInterface $connector_service, ServiceLocatorInterface $service_locator, EventBusInterface $event_bus, LoggerInterface $logger) use($service_definition, $provisioner_settings, $jobs_config) { $connector = $connector_service->getConnector($provisioner_settings->get('connection')); $config = $service_definition->getConfig(); $service_class = $service_definition->getClass(); return new $service_class($connector, $service_locator, $event_bus, new JobMap($jobs_config), $config, $logger); }; $this->di_container->delegate($service, $factory_delegate)->share($service)->alias(JobServiceInterface::CLASS, $service); }
public function build(ServiceDefinitionInterface $service_definition, SettingsInterface $provisioner_settings) { $config = $this->loadConfig(); $output_format_map = new OutputFormatMap(); foreach ($config as $name => $output_format) { $output_format['media_type_info'] = new MediaTypeInfo($output_format['media_type_info']); $output_format_map->setItem($name, new OutputFormat($output_format)); } $service = $service_definition->getClass(); $state = [':output_format_map' => $output_format_map]; $this->di_container->define($service, $state)->share($service)->alias(OutputFormatServiceInterface::CLASS, $service); }
public function build(ServiceDefinitionInterface $service_definition, SettingsInterface $provisioner_settings) { $factory_delegate = function () use($service_definition) { $migration_config = $this->loadMigrationConfig(); $migration_target_map = $this->buildMigrationTargetMap($migration_config['targets']); $service_config = $service_definition->getConfig(); $service_class = $service_definition->getClass(); return new $service_class($service_config, $migration_target_map); }; $service = $service_definition->getClass(); $this->di_container->delegate($service, $factory_delegate)->share($service)->alias(MigrationServiceInterface::CLASS, $service); }
public function build(ServiceDefinitionInterface $service_definition, SettingsInterface $provisioner_settings) { $service = $service_definition->getClass(); $factory_delegate = function (DiContainer $di_container) use($service_definition, $provisioner_settings) { $service = $service_definition->getClass(); $command_enricher = new $service(); foreach ($provisioner_settings->get('enrichers') as $enricher_class) { $command_enricher->addItem($di_container->make($enricher_class)); } return $command_enricher; }; $this->di_container->delegate($service, $factory_delegate)->share($service)->alias(CommandEnricherInterface::CLASS, $service); }
public function build(ServiceDefinitionInterface $service_definition, SettingsInterface $provisioner_settings) { $factory_delegate = function (DiContainer $di_container) use($service_definition, $provisioner_settings) { $config = $service_definition->getConfig(); $logger_name = $provisioner_settings->get('logger', 'default'); $logger = AgaviContext::getInstance()->getLoggerManager()->getLogger($logger_name)->getPsr3Logger(); $builder_impl = $provisioner_settings->get('state_machine_builder', StateMachineBuilder::CLASS); $state_machine_builder = $di_container->make($builder_impl); $service_class = $service_definition->getClass(); return new $service_class($config, $state_machine_builder, $logger); }; $service = $service_definition->getClass(); $this->di_container->delegate($service, $factory_delegate)->share($service)->alias(WorkflowServiceInterface::CLASS, $service); }
public function build(ServiceDefinitionInterface $service_definition, SettingsInterface $provisioner_settings) { $service = $service_definition->getClass(); $config = $this->loadConfig(); if (!isset($config[MailServiceInterface::DEFAULT_MAILER_NAME])) { throw new ConfigError(sprintf('The "%s" config file needs to specify a default mailer config under the key "%s".', self::CONFIG_FILE_NAME, MailServiceInterface::DEFAULT_MAILER_NAME)); } $connector_name = $provisioner_settings->get('connection', 'Default.Mailer'); $swift_mailer = $this->connector_service->getConnection($connector_name); if (!$swift_mailer instanceof Swift_Mailer) { throw new ConfigError(sprintf('MailService connector "%s" must be an instance of: %s', $connector_name, Swift_Mailer::CLASS)); } $state = [':mailer_configs' => new ArrayConfig($config), ':mailer' => $swift_mailer]; $this->di_container->define($service, $state)->share($service)->alias(MailServiceInterface::CLASS, $service); }
public function build(ServiceDefinitionInterface $service_definition, SettingsInterface $provisioner_settings) { $service = $service_definition->getClass(); $state = [':config' => $service_definition->getConfig(), ':query_translation' => $this->buildQueryTranslation($provisioner_settings)]; $this->di_container->define($service, $state); // there will only be one instance of the service when the "share" setting is true if ($provisioner_settings->get('share', true) === true) { $this->di_container->share($service); } if ($provisioner_settings->has('alias')) { $alias = $provisioner_settings->get('alias'); if (!is_string($alias) && !class_exists($alias)) { throw new ConfigError('Alias given must be an existing class or interface name (fully qualified).'); } $this->di_container->alias($alias, $service); } }
public function build(ServiceDefinitionInterface $service_definition, SettingsInterface $provisioner_settings) { $process_map_config = (include AgaviConfigCache::checkConfig(AgaviConfig::get('core.config_dir') . DIRECTORY_SEPARATOR . self::PROCESS_CONFIG_FILE, AgaviContext::getInstance()->getName())); $process_map_class = $service_definition->getClass(); $this->di_container->share($process_map_class)->delegate($process_map_class, function (DiContainer $di_container) use($process_map_class, $process_map_config) { $process_map = new $process_map_class(); foreach ($process_map_config as $process_name => $process_config) { $builder_settings = $process_config['builder']['settings']; if (!isset($builder_settings['name'])) { $builder_settings['name'] = $process_name; } $state_machine_builder = $di_container->make($process_config['builder']['class'], [':options' => $builder_settings]); $process_implementor = isset($process_config['class']) ? $process_config['class'] : Process::CLASS; $process_map->setItem($process_name, $di_container->make($process_implementor, [':name' => $process_name, ':state_machine' => $state_machine_builder->build()])); } return $process_map; }); }
public function build(ServiceDefinitionInterface $service_definition, SettingsInterface $provisioner_settings) { $service = $service_definition->getClass(); $config = $this->loadFilesystemsConfig(); $factory_delegate = function (AggregateRootTypeMap $art_map, ConnectorServiceInterface $connector_service) use($service, $config) { $filesystems = []; $connectors = []; $schemes = []; // check all configured filesystem connectors (they wrap a Filesystem instance with a specific adapter) foreach ($config as $scheme => $connector_name) { $connectors[$scheme] = $connector_service->getConnector($connector_name); $schemes[$scheme] = $connector_name; } if (!array_key_exists(FilesystemServiceInterface::SCHEME_FILES, $schemes)) { throw new ConfigError(sprintf('There is no filesystem connector registered for scheme "%s". Please check the config: %s', FilesystemServiceInterface::SCHEME_FILES, self::FILESYSTEMS_CONFIG_NAME)); } if (!array_key_exists(FilesystemServiceInterface::SCHEME_TEMPFILES, $schemes)) { throw new ConfigError(sprintf('There is no filesystem connector registered for scheme "%s". Please check the config: %s', FilesystemServiceInterface::SCHEME_TEMPFILES, self::FILESYSTEMS_CONFIG_NAME)); } // reuse configured schemes for aggregate root specific file schemes foreach ($art_map->getKeys() as $art_prefix) { $files_scheme = $art_prefix . '.' . FilesystemServiceInterface::SCHEME_FILES; $tempfiles_scheme = $art_prefix . '.' . FilesystemServiceInterface::SCHEME_TEMPFILES; if (!array_key_exists($files_scheme, $schemes)) { $schemes[$files_scheme] = $connectors[FilesystemServiceInterface::SCHEME_FILES]->getName(); } if (!array_key_exists($tempfiles_scheme, $schemes)) { $schemes[$tempfiles_scheme] = $connectors[FilesystemServiceInterface::SCHEME_TEMPFILES]->getName(); } } // get actual Filesystem instances for each scheme (they are configured and ready to use after this) foreach ($schemes as $scheme => $connector_name) { $filesystem = $connector_service->getConnection($connector_name); if (!$filesystem instanceof FilesystemInterface) { throw new ConfigError(sprintf('Filesystem connector for scheme "%s" must be an instance of: %s', $scheme, FilesystemInterface::CLASS)); } $filesystems[$scheme] = $filesystem; } $mount_manager = new MountManager($filesystems); return new $service($mount_manager, $schemes); }; $this->di_container->delegate($service, $factory_delegate)->share($service)->alias(FilesystemServiceInterface::CLASS, $service); }
public function build(ServiceDefinitionInterface $service_definition, SettingsInterface $provisioner_settings = null) { $event_bus_config = (include AgaviConfigCache::checkConfig(AgaviConfig::get('core.config_dir') . DIRECTORY_SEPARATOR . self::EVENT_BUS_CONFIG_FILE, AgaviContext::getInstance()->getName())); $channel_map = new ChannelMap(); foreach ($event_bus_config['channels'] as $channel_name => $channel_config) { $channel_map->setItem($channel_name, new Channel($channel_name)); } $required_channels = array_diff($channel_map::getDefaultChannels(), $channel_map->getKeys()); foreach ($required_channels as $default_channel) { $channel_map->setItem($default_channel, new Channel($default_channel)); } $callback = function (EventBusInterface $event_bus, DiContainer $di_container) use($event_bus_config) { if (!$this->prepare_executed) { $this->prepareEventBus($event_bus, $event_bus_config); $this->prepare_executed = true; } }; $service = $service_definition->getClass(); $state = [':channel_map' => $channel_map]; $this->di_container->define($service, $state)->prepare($service, $callback)->share($service)->alias(EventBusInterface::CLASS, $service); }
public function build(ServiceDefinitionInterface $service_definition, SettingsInterface $provisioner_settings) { $service = $service_definition->getClass(); $state = [':config' => $service_definition->getConfig(), ':routing' => AgaviContext::getInstance()->getRouting()]; $this->di_container->define($service, $state)->share($service)->alias(UrlGeneratorInterface::CLASS, $service); }
public function build(ServiceDefinitionInterface $service_definition, SettingsInterface $provisioner_settings) { $service = $service_definition->getClass(); $state = [':expression_language' => new ExpressionLanguage()]; $this->di_container->define($service, $state)->share($service)->alias(ExpressionServiceInterface::CLASS, $service); }
public function build(ServiceDefinitionInterface $service_definition, SettingsInterface $provisioner_settings) { $service = $service_definition->getClass(); $this->di_container->share($service); }
public function build(ServiceDefinitionInterface $service_definition, SettingsInterface $provisioner_settings) { $service = $service_definition->getClass(); $state = [':config' => $service_definition->getConfig()]; $this->di_container->define($service, $state)->share($service); }
public function build(ServiceDefinitionInterface $service_definition, SettingsInterface $provisioner_settings) { $service = $service_definition->getClass(); $state = [':twig' => $this->createTwigRenderer($this->getTwigTemplateRendererSettings($provisioner_settings))]; $this->di_container->define($service, $state)->share($service)->alias(TemplateRendererInterface::CLASS, $service); }
public function build(ServiceDefinitionInterface $service_definition, SettingsInterface $provisioner_settings) { $service = $service_definition->getClass(); $state = [':access_config' => $this->loadAclConfig()]; $this->di_container->define($service, $state)->share($service)->alias(PermissionServiceInterface::CLASS, $service); }
protected function runServiceProvisioner(ServiceDefinitionInterface $service_definition, array $settings) { $provisioner_config = $service_definition->getProvisioner(); if (!$provisioner_config) { throw new RuntimeError('Missing provisioner meta-data (at least "class" plus optional a "method" and some "settings").'); } if (!class_exists($provisioner_config['class'])) { throw new RuntimeError('Unable to load provisioner class: ' . $provisioner_config['class']); } $provisioner = $this->di_container->make($provisioner_config['class']); $provisioner_method = $provisioner_config['method']; $provisioner_callable = [$provisioner, $provisioner_method]; if (isset($provisioner_config['settings']) && is_array($provisioner_config['settings'])) { $settings = array_merge($provisioner_config['settings'], $settings); } $provisioner_settings = new Settings($settings); if (!empty($provisioner_method) && is_callable($provisioner_callable)) { $provisioner->{$provisioner_method}($service_definition, $provisioner_settings); } elseif ($provisioner instanceof ProvisionerInterface) { $provisioner->build($service_definition, $provisioner_settings); } else { throw new RuntimeError(sprintf("Provisioner needs <method> configuration or must implement %s", ProvisionerInterface::CLASS)); } }