Commit 34e63095 authored by alexpott's avatar alexpott
Browse files

Issue #1939660 by chx | catch: Use YAML as the primary means for service registration.

parent 31256993
services:
cache_factory:
class: Drupal\Core\Cache\CacheFactory
arguments: ['@settings']
calls:
- [setContainer, ['@service_container']]
cache.backend.database:
class: Drupal\Core\Cache\DatabaseBackendFactory
arguments: ['@database']
cache.backend.memory:
class: Drupal\Core\Cache\MemoryBackendFactory
cache.bootstrap:
class: Drupal\Core\Cache\CacheBackendInterface
tags:
- { name: cache.bin }
factory_method: get
factory_service: cache_factory
arguments: [bootstrap]
cache.config:
class: Drupal\Core\Cache\CacheBackendInterface
tags:
- { name: cache.bin }
factory_method: get
factory_service: cache_factory
arguments: [config]
cache.cache:
class: Drupal\Core\Cache\CacheBackendInterface
tags:
- { name: cache.bin }
factory_method: get
factory_service: cache_factory
arguments: [cache]
cache.menu:
class: Drupal\Core\Cache\CacheBackendInterface
tags:
- { name: cache.bin }
factory_method: get
factory_service: cache_factory
arguments: [menu]
cache.page:
class: Drupal\Core\Cache\CacheBackendInterface
tags:
- { name: cache.bin }
factory_method: get
factory_service: cache_factory
arguments: [page]
cache.path:
class: Drupal\Core\Cache\CacheBackendInterface
tags:
- { name: cache.bin }
factory_method: get
factory_service: cache_factory
arguments: [path]
config.cachedstorage.storage:
class: Drupal\Core\Config\FileStorage
factory_class: Drupal\Core\Config\FileStorageFactory
factory_method: getActive
config.storage:
class: Drupal\Core\Config\CachedStorage
arguments: ['@config.cachedstorage.storage', '@cache.config']
config.context.factory:
class: Drupal\Core\Config\Context\ConfigContextFactory
arguments: ['@event_dispatcher']
config.context:
class: Drupal\Core\Config\Context\ContextInterface
tags:
- { name: persist }
factory_method: get
factory_service: config.context.factory
config.context.free:
class: Drupal\Core\Config\Context\ContextInterface
factory_method: get
factory_service: config.context.factory
arguments: [Drupal\Core\Config\Context\FreeConfigContext]
config.factory:
class: Drupal\Core\Config\ConfigFactory
tags:
- { name: persist }
arguments: ['@config.storage', '@config.context']
config.storage.staging:
class: Drupal\Core\Config\FileStorage
factory_class: Drupal\Core\Config\FileStorageFactory
factory_method: getStaging
config.storage.snapshot:
class: Drupal\Core\Config\DatabaseStorage
arguments: ['@database', config_snapshot]
config.storage.schema:
class: Drupal\Core\Config\Schema\SchemaStorage
config.typed:
class: Drupal\Core\Config\TypedConfigManager
arguments: ['@config.storage', '@config.storage.schema']
database:
class: Drupal\Core\Database\Connection
factory_class: Drupal\Core\Database\Database
factory_method: getConnection
arguments: [default]
keyvalue:
class: Drupal\Core\KeyValueStore\KeyValueFactory
arguments: ['@service_container']
keyvalue.database:
class: Drupal\Core\KeyValueStore\KeyValueDatabaseFactory
arguments: ['@database']
keyvalue.expirable:
class: Drupal\Core\KeyValueStore\KeyValueExpirableFactory
arguments: ['@service_container']
keyvalue.expirable.database:
class: Drupal\Core\KeyValueStore\KeyValueDatabaseExpirableFactory
tags:
- { name: needs_destruction }
arguments: ['@database']
settings:
class: Drupal\Component\Utility\Settings
factory_class: Drupal\Component\Utility\Settings
factory_method: getSingleton
state:
class: Drupal\Core\KeyValueStore\KeyValueStoreInterface
factory_method: get
factory_service: keyvalue
arguments: [state]
queue:
class: Drupal\Core\Queue\QueueFactory
arguments: ['@settings']
calls:
- [setContainer, ['@service_container']]
queue.database:
class: Drupal\Core\Queue\QueueDatabaseFactory
arguments: ['@database']
path.alias_whitelist:
class: Drupal\Core\Path\AliasWhitelist
tags:
- { name: needs_destruction }
arguments: [path_alias_whitelist, cache, '@keyvalue', '@database']
path.alias_manager:
class: Drupal\Core\Path\AliasManager
arguments: ['@database', '@path.alias_whitelist', '@language_manager']
http_client_simpletest_subscriber:
class: Drupal\Core\Http\Plugin\SimpletestHttpRequestSubscriber
http_default_client:
class: Guzzle\Http\Client
arguments: [null, { curl.CURLOPT_TIMEOUT: 30, curl.CURLOPT_MAXREDIRS: 3 }]
calls:
- [addSubscriber, ['@http_client_simpletest_subscriber']]
- [setUserAgent, ['Drupal (+http://drupal.org/)']]
plugin.manager.entity:
class: Drupal\Core\Entity\EntityManager
arguments: ['%container.namespaces%']
request:
class: Symfony\Component\HttpFoundation\Request
event_dispatcher:
class: Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher
arguments: ['@service_container']
controller_resolver:
class: Drupal\Core\ControllerResolver
arguments: ['@service_container']
http_kernel:
class: Drupal\Core\HttpKernel
arguments: ['@event_dispatcher', '@service_container', '@controller_resolver']
language_manager:
class: Drupal\Core\Language\LanguageManager
database.slave:
class: Drupal\Core\Database\Connection
factory_class: Drupal\Core\Database\Database
factory_method: getConnection
arguments: [slave]
typed_data:
class: Drupal\Core\TypedData\TypedDataManager
calls:
- [setValidationConstraintManager, ['@validation.constraint']]
validation.constraint:
class: Drupal\Core\Validation\ConstraintManager
arguments: ['%container.namespaces%']
lock:
class: Drupal\Core\Lock\DatabaseLockBackend
user.tempstore:
class: Drupal\user\TempStoreFactory
arguments: ['@database', '@lock']
router.request_context:
class: Symfony\Component\Routing\RequestContext
calls:
- [fromRequest, ['@request']]
router.route_provider:
class: Drupal\Core\Routing\RouteProvider
arguments: ['@database']
router.matcher.final_matcher:
class: Drupal\Core\Routing\UrlMatcher
router.matcher:
class: Symfony\Cmf\Component\Routing\NestedMatcher\NestedMatcher
arguments: ['@router.route_provider']
calls:
- [setFinalMatcher, ['@router.matcher.final_matcher']]
router.generator:
class: Drupal\Core\Routing\UrlGenerator
arguments: ['@router.route_provider', '@path.alias_manager.cached']
router.dynamic:
class: Symfony\Cmf\Component\Routing\DynamicRouter
arguments: ['@router.request_context', '@router.matcher', '@router.generator']
legacy_generator:
class: Drupal\Core\Routing\NullGenerator
legacy_url_matcher:
class: Drupal\Core\LegacyUrlMatcher
legacy_router:
class: Symfony\Cmf\Component\Routing\DynamicRouter
arguments: ['@router.request_context', '@legacy_url_matcher', '@legacy_generator']
router:
class: Symfony\Cmf\Component\Routing\ChainRouter
calls:
- [setContext, ['@router.request_context']]
- [add, ['@router.dynamic']]
- [add, ['@legacy_router']]
entity.query:
class: Drupal\Core\Entity\Query\QueryFactory
arguments: ['@plugin.manager.entity']
calls:
- [setContainer, ['@service_container']]
entity.query.config:
class: Drupal\Core\Config\Entity\Query\QueryFactory
arguments: ['@config.storage']
router.dumper:
class: Drupal\Core\Routing\MatcherDumper
arguments: ['@database']
router.builder:
class: Drupal\Core\Routing\RouteBuilder
arguments: ['@router.dumper', '@lock', '@event_dispatcher', '@module_handler']
path.alias_manager.cached:
class: Drupal\Core\CacheDecorator\AliasManagerCacheDecorator
arguments: ['@path.alias_manager', '@cache.path']
path.crud:
class: Drupal\Core\Path\Path
arguments: ['@database', '@path.alias_manager']
# The argument to the hashing service defined in services.yml, to the
# constructor of PhpassHashedPassword is the log2 number of iterations for
# password stretching.
# @todo increase by 1 every Drupal version in order to counteract increases in
# the speed and power of computers available to crack the hashes. The current
# password hashing method was introduced in Drupal 7 with a log2 count of 15.
password:
class: Drupal\Core\Password\PhpassHashedPassword
arguments: [16]
mime_type_matcher:
class: Drupal\Core\Routing\MimeTypeMatcher
tags:
- { name: route_filter }
paramconverter_manager:
class: Drupal\Core\ParamConverter\ParamConverterManager
tags:
- { name: route_enhancer }
paramconverter.entity:
class: Drupal\Core\ParamConverter\EntityConverter
tags:
- { name: paramconverter }
arguments: ['@plugin.manager.entity']
router_processor_subscriber:
class: Drupal\Core\EventSubscriber\RouteProcessorSubscriber
tags:
- { name: event_subscriber }
arguments: ['@content_negotiation']
router_listener:
class: Symfony\Component\HttpKernel\EventListener\RouterListener
tags:
- { name: event_subscriber }
arguments: ['@router']
content_negotiation:
class: Drupal\Core\ContentNegotiation
view_subscriber:
class: Drupal\Core\EventSubscriber\ViewSubscriber
tags:
- { name: event_subscriber }
arguments: ['@content_negotiation']
legacy_access_subscriber:
class: Drupal\Core\EventSubscriber\LegacyAccessSubscriber
tags:
- { name: event_subscriber }
access_manager:
class: Drupal\Core\Access\AccessManager
calls:
- [setContainer, ['@service_container']]
access_subscriber:
class: Drupal\Core\EventSubscriber\AccessSubscriber
tags:
- { name: event_subscriber }
arguments: ['@access_manager']
access_check.default:
class: Drupal\Core\Access\DefaultAccessCheck
tags:
- { name: access_check }
maintenance_mode_subscriber:
class: Drupal\Core\EventSubscriber\MaintenanceModeSubscriber
tags:
- { name: event_subscriber }
path_subscriber:
class: Drupal\Core\EventSubscriber\PathSubscriber
tags:
- { name: event_subscriber }
arguments: ['@path.alias_manager.cached', '@path_processor_manager']
legacy_request_subscriber:
class: Drupal\Core\EventSubscriber\LegacyRequestSubscriber
tags:
- { name: event_subscriber }
legacy_controller_subscriber:
class: Drupal\Core\EventSubscriber\LegacyControllerSubscriber
tags:
- { name: event_subscriber }
finish_response_subscriber:
class: Drupal\Core\EventSubscriber\FinishResponseSubscriber
tags:
- { name: event_subscriber }
arguments: ['@language_manager']
scope: request
request_close_subscriber:
class: Drupal\Core\EventSubscriber\RequestCloseSubscriber
tags:
- { name: event_subscriber }
arguments: ['@module_handler']
config_global_override_subscriber:
class: Drupal\Core\EventSubscriber\ConfigGlobalOverrideSubscriber
tags:
- { name: event_subscriber }
language_request_subscriber:
class: Drupal\Core\EventSubscriber\LanguageRequestSubscriber
tags:
- { name: event_subscriber }
arguments: ['@language_manager']
exception_controller:
class: Drupal\Core\ExceptionController
arguments: ['@content_negotiation']
calls:
- [setContainer, ['@service_container']]
exception_listener:
class: Symfony\Component\HttpKernel\EventListener\ExceptionListener
tags:
- { name: event_subscriber }
arguments: [['@exception_controller', execute]]
path_processor_manager:
class: Drupal\Core\PathProcessor\PathProcessorManager
path_processor_decode:
class: Drupal\Core\PathProcessor\PathProcessorDecode
tags:
- { name: path_processor_inbound, priority: 1000 }
path_processor_front:
class: Drupal\Core\PathProcessor\PathProcessorFront
tags:
- { name: path_processor_inbound, priority: 200 }
arguments: ['@config.factory']
path_processor_alias:
class: Drupal\Core\PathProcessor\PathProcessorAlias
tags:
- { name: path_processor_inbound, priority: 100 }
arguments: ['@path.alias_manager']
transliteration:
class: Drupal\Core\Transliteration\PHPTransliteration
flood:
class: Drupal\Core\Flood\DatabaseBackend
arguments: ['@database']
plugin.manager.condition:
class: Drupal\Core\Condition\ConditionManager
kernel_destruct_subscriber:
class: Drupal\Core\EventSubscriber\KernelDestructionSubscriber
tags:
- { name: event_subscriber }
calls:
- [setContainer, ['@service_container']]
ajax.subscriber:
class: Drupal\Core\Ajax\AjaxSubscriber
tags:
- { name: event_subscriber }
image.toolkit.manager:
class: Drupal\system\Plugin\ImageToolkitManager
arguments: ['%container.namespaces%']
image.toolkit:
class: Drupal\system\Plugin\ImageToolkitInterface
factory_method: getDefaultToolkit
factory_service: image.toolkit.manager
......@@ -62,20 +62,4 @@ public function get($bin) {
return $this->container->get($service_name)->get($bin);
}
/**
* Helper to register a cache bin to the container.
*
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
* The container to register the cache bin on.
* @param $bin
* The cache bin to add. Do not add the cache_ prefix.
*/
public static function registerBin(ContainerBuilder $container, $bin) {
$container
->register("cache.$bin", 'Drupal\Core\Cache\CacheBackendInterface')
->setFactoryService('cache_factory')
->setFactoryMethod('get')
->addArgument($bin)
->addTag('cache.bin');
}
}
<?php
/**
* Contains \Drupal\Core\Config\FileStorageFactory.
*/
namespace Drupal\Core\Config;
/**
* Provides a factory for creating config file storage objects.
*/
class FileStorageFactory {
/**
* Returns a FileStorage object working with the active config directory.
*
* @return \Drupal\Core\Config\FileStorage FileStorage
*/
static function getActive() {
return new FileStorage(config_get_config_directory(CONFIG_ACTIVE_DIRECTORY));
}
/**
* Returns a FileStorage object working with the staging config directory.
*
* @return \Drupal\Core\Config\FileStorage FileStorage
*/
static function getStaging() {
return new FileStorage(config_get_config_directory(CONFIG_STAGING_DIRECTORY));
}
}
This diff is collapsed.
<?php
/**
* @file
* Contains \Drupal\Core\DependencyInjection\YamlFileLoader.
*/
namespace Drupal\Core\DependencyInjection;
use Symfony\Component\DependencyInjection\Alias;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\DefinitionDecorator;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\Yaml\Parser;
/**
* YamlFileLoader loads YAML files service definitions.
*
* Drupal does not use Symfony's Config component, so this is a partial copy
* of \Symfony\Component\DependencyInjection\Loader\YamlFileLoader class not
* depending on the Config component.
*/
class YamlFileLoader {
/**
* @param \Drupal\Core\DependencyInjection\ContainerBuilder $container
*/
protected $container;
public function __construct(ContainerBuilder $container) {
$this->container = $container;
}
/**
* Load a YAML file containing service definitions and kernel parameters.
*
* string $filename
* The name of the file to load.
*/
public function load($filename) {
$content = $this->loadFile($filename);
$content += array('parameters' => array(), 'services' => array());
// parameters
foreach ($content['parameters'] as $key => $value) {
$this->container->setParameter($key, $this->resolveServices($value));
}
// services
foreach ($content['services'] as $id => $service) {
$this->parseDefinition($id, $service, $filename);
}
}
/**
* Parses a definition.
*
* Copied from \Symfony\Component\DependencyInjection\Loader\YamlFileLoader::parseDefinition().
*
* @param string $id
* The id of the service.
* @param string|array $service
* Either a string starting with a @ meaning this service is an alias or
* the array defining the service.
* @param string $filename
* The name of the file, only used in error messages.
*
* @throws \InvalidArgumentException When tags are invalid
*/
protected function parseDefinition($id, $service, $filename) {
if (is_string($service) && 0 === strpos($service, '@')) {
$this->container->setAlias($id, substr($service, 1));
return;
}
elseif (isset($service['alias'])) {
$public = !array_key_exists('public', $service) || (Boolean) $service['public'];
$this->container->setAlias($id, new Alias($service['alias'], $public));
return;
}
if (isset($service['parent'])) {
$definition = new DefinitionDecorator($service['parent']);
}
else {
$definition = new Definition();
}
if (isset($service['class'])) {
$definition->setClass($service['class']);
}
if (isset($service['scope'])) {
$definition->setScope($service['scope']);
}
if (isset($service['synthetic'])) {
$definition->setSynthetic($service['synthetic']);
}
if (isset($service['public'])) {
$definition->setPublic($service['public']);
}
if (isset($service['abstract'])) {
$definition->setAbstract($service['abstract']);
}
if (isset($service['factory_class'])) {
$definition->setFactoryClass($service['factory_class']);
}
if (isset($service['factory_method'])) {
$definition->setFactoryMethod($service['factory_method']);
}
if (isset($service['factory_service'])) {
$definition->setFactoryService($service['factory_service']);
}
if (isset($service['file'])) {
$definition->setFile($service['file']);
}
if (isset($service['arguments'])) {
$definition->setArguments($this->resolveServices($service['arguments']));
}
if (isset($service['properties'])) {
$definition->setProperties($this->resolveServices($service['properties']));
}
if (isset($service['configurator'])) {
if (is_string($service['configurator'])) {
$definition->setConfigurator($service['configurator']);
}
else {
$definition->setConfigurator(array($this->resolveServices($service['configurator'][0]), $service['configurator'][1]));
}
}
if (isset($service['calls'])) {
foreach ($service['calls'] as $call) {
$args = isset($call[1]) ? $this->resolveServices($call[1]) : array();
$definition->addMethodCall($call[0], $args);
}
}
if (isset($service['tags'])) {
if (!is_array($service['tags'])) {
throw new \InvalidArgumentException(sprintf('Parameter "tags" must be an array for service "%s" in %s.', $id, $filename));
}
foreach ($service['tags'] as $tag) {
if (!isset($tag['name'])) {