本文整理匯總了PHP中Symfony\Component\DependencyInjection\DefinitionDecorator::addMethodCall方法的典型用法代碼示例。如果您正苦於以下問題:PHP DefinitionDecorator::addMethodCall方法的具體用法?PHP DefinitionDecorator::addMethodCall怎麽用?PHP DefinitionDecorator::addMethodCall使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Symfony\Component\DependencyInjection\DefinitionDecorator
的用法示例。
在下文中一共展示了DefinitionDecorator::addMethodCall方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: load
/**
* {@inheritDoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config/services'));
if ('custom' !== $config['db_driver']) {
$loader->load(sprintf('%s.xml', $config['db_driver']));
}
$this->remapParametersNamespaces($config, $container, array('' => array('db_driver' => 'abc.file_distribution.storage', 'model_manager_name' => 'abc.file_distribution.model_manager_name')));
if (!empty($config['definition'])) {
$this->loadFilesystem($config['definition'], $container, $loader, $config['db_driver']);
}
$loader->load('service.xml');
if (isset($config['filesystems'])) {
foreach ($config['filesystems'] as $name => $filesystem) {
$definitionId = 'abc.file_distribution.definition.' . $name;
$definition = new DefinitionDecorator('abc.file_distribution.definition.prototype');
$definition->addMethodCall('setType', array($filesystem['type']));
$definition->addMethodCall('setPath', array($filesystem['path']));
$definition->addMethodCall('setProperties', array($filesystem['options']));
$container->setDefinition($definitionId, $definition);
$definition = new Definition('Abc\\Filesystem\\Filesystem', array(new Reference('abc.file_distribution.adapter_factory'), new Reference($definitionId)));
$container->setDefinition('abc.file_distribution.filesystem.' . $name, $definition);
}
}
}
示例2: load
/**
* {@inheritdoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$config = $this->processConfiguration(new Configuration(), $configs);
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.xml');
$container->setAlias('kassko_class_resolver', new Alias('kassko_class_resolver.chain', true));
$containerAdapterDef = $container->getDefinition('kassko_class_resolver.container');
$containerAdapterDef->setClass($config['container_adapter_class']);
$container->addAliases($config['resolvers_aliases']);
if (isset($config['resolvers'])) {
foreach ($config['resolvers']['chain'] as $resolverConfig) {
$resolverDef = new DefinitionDecorator('kassko_class_resolver.chain');
foreach ($resolverConfig['nested_resolvers'] as $nestedResolverService) {
$resolverDef->addMethodCall('add', [new Reference($nestedResolverService)]);
}
if (null !== $resolverConfig['service']) {
$resolverDef->addMethodCall('setDefault', [new Reference($resolverConfig['service'])]);
} else {
$defaultResolverDef = new Definition($container->getParameter('kassko_class_resolver.default.class'), ['action' => $resolverConfig['on_not_found_class']['action']]);
$resolverDef->addMethodCall('setDefault', [$defaultResolverDef]);
}
$this->addAliasesByService($container, $config['resolver_aliases'], $resolverConfig['resolver_service']);
}
foreach ($config['resolvers']['container'] as $resolverConfig) {
$container->setDefinition($resolverConfig['resolver_service'], new DefinitionDecorator('kassko_class_resolver.container_aware'));
$this->addAliasesByService($container, $resolverConfig['resolver_aliases'], $resolverConfig['resolver_service']);
}
foreach ($config['resolvers']['map'] as $resolverConfig) {
foreach ($resolverConfig['items'] as $item) {
if ('@' !== substr($item['service'], 0, 1)) {
$item['service'] = new Reference($item['service']);
}
}
$resolverDef = new Definition($container->getParameter('kassko_class_resolver.map.class'), [$resolverConfig['items']]);
$container->setDefinition($resolverConfig['resolver_service'], $resolverDef);
$this->addAliasesByService($container, $resolverConfig['resolver_aliases'], $resolverConfig['resolver_service']);
}
foreach ($config['resolvers']['factory_adapter'] as $index => $resolverConfig) {
$resolverDef = new Definition($container->getParameter('kassko_class_resolver.factory_adapter.class'), [new Reference($resolverConfig['adapted_factory']), $resolverConfig['support_method'], $resolverConfig['resolve_method']]);
$container->setDefinition($resolverConfig['resolver_service'], $resolverDef);
$this->addAliasesByService($container, $resolverConfig['resolver_aliases'], $resolverConfig['resolver_service']);
}
foreach ($config['resolvers']['static_factory_adapter'] as $index => $resolverConfig) {
$resolverDef = new Definition($container->getParameter('kassko_class_resolver.static_factory_adapter.class'), [$resolverConfig['adapted_factory'], $resolverConfig['support_method'], $resolverConfig['resolve_method']]);
$container->setDefinition($resolverConfig['resolver_service'], $resolverDef);
$this->addAliasesByService($container, $resolverConfig['resolver_aliases'], $resolverConfig['resolver_service']);
}
}
}
示例3: createConverter
private function createConverter($name, array $config, ContainerBuilder $container)
{
$environment = new DefinitionDecorator($config['environment']);
$environment->setPublic(false);
$environment->setClass($container->getDefinition($config['environment'])->getClass());
$environment->addMethodCall('mergeConfig', [$config['config']]);
$environment->addTag('webuni_commonmark.environment.extensions', $config['extensions']);
// $environment->addTag('webuni_commonmark.environment', ['parent' => $config['environment'], 'extensions' => [$config['extensions']]);
$environmentName = 'webuni_commonmark.' . $name . '_environment' . $config['environment'];
$container->setDefinition($environmentName, $environment);
$parser = new DefinitionDecorator($config['parser']);
$parser->setPublic(false);
$parser->setClass($container->getDefinition($config['parser'])->getClass());
$parser->replaceArgument(0, new Reference($environmentName));
$renderer = new DefinitionDecorator($config['renderer']);
$renderer->setPublic(false);
$renderer->setClass($container->getDefinition($config['renderer'])->getClass());
$renderer->replaceArgument(0, new Reference($environmentName));
$converter = new DefinitionDecorator($config['converter']);
$converter->setPublic(true);
$converter->setClass($container->getDefinition($config['converter'])->getClass());
$converter->replaceArgument(0, $parser);
$converter->replaceArgument(1, $renderer);
$converterName = 'webuni_commonmark.' . $name . '_converter';
$container->setDefinition($converterName, $converter);
return $converterName;
}
示例4: registerMiddleware
/**
* Sets up handlers and registers middleware for each tagged client.
*
* @param ContainerBuilder $container
* @param array $middlewareBag
*/
private function registerMiddleware(ContainerBuilder $container, array $middlewareBag)
{
$clients = $container->findTaggedServiceIds(self::CLIENT_TAG);
foreach ($clients as $clientId => $tags) {
if (count($tags) > 1) {
throw new \LogicException('Clients should use a single \'csa_guzzle.client\' tag');
}
$clientMiddleware = $middlewareBag;
if (isset($tags[0]['middleware'])) {
$whitelist = explode(' ', $tags[0]['middleware']);
$clientMiddleware = array_filter($clientMiddleware, function ($value) use($whitelist) {
return in_array($value['alias'], $whitelist, true);
});
}
$handlerStack = new DefinitionDecorator('csa_guzzle.handler_stack');
$handlerStack->setPublic(false);
foreach ($clientMiddleware as $middleware) {
$handlerStack->addMethodCall('push', [new Reference($middleware['id']), $middleware['alias']]);
}
$clientHandlerStackId = sprintf('csa_guzzle.handler_stack.%s', $clientId);
$container->setDefinition($clientHandlerStackId, $handlerStack);
$clientDefinition = $container->findDefinition($clientId);
$arguments = $clientDefinition->getArguments();
$options = [];
if (!empty($arguments)) {
$options = array_shift($arguments);
}
$options['handler'] = new Reference($clientHandlerStackId);
array_unshift($arguments, $options);
$clientDefinition->setArguments($arguments);
}
}
示例5: load
/**
* {@inheritDoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.xml');
if (array_key_exists('servers', $config)) {
foreach ($config['servers'] as $id => $server) {
$container->setParameter('json_rpc.serializer.class', $server['serializer']);
$container->setParameter('json_rpc.reflection.class', $server['reflection']);
$definition = new DefinitionDecorator('json_rpc.server');
$definition->addTag('json_rpc.servers', array('resource' => $id));
foreach ($server['services'] as $service) {
$definition->addMethodCall('addService', array($service['namespace'], $service['class']));
}
$container->setDefinition(sprintf('json_rpc.server.%s', $id), $definition);
$definition = new DefinitionDecorator('json_rpc.transport.internal');
$definition->addTag('json_rpc.transports');
$definition->replaceArgument(0, new Reference(sprintf('json_rpc.server.%s', $id)));
$container->setDefinition(sprintf('json_rpc.transport.internal.%s', $id), $definition);
$definition = new DefinitionDecorator('json_rpc.client.internal');
$definition->addTag('json_rpc.clients.internal');
$definition->replaceArgument(0, new Reference(sprintf('json_rpc.transport.internal.%s', $id)));
$container->setDefinition(sprintf('json_rpc.client.internal.%s', $id), $definition);
}
}
}
示例6: configureConnectionClient
private function configureConnectionClient(ContainerBuilder $builder, $connectionName, array $connectionConfig, $profiling)
{
$connectionDef = new DefinitionDecorator('kassko_cassandra.connection.prototype');
$connectionDef->addTag('kassko_cassandra.connection');
//logger Cql creation.
$loggerCqlServiceName = $this->computeLoggerCqlServiceName($connectionName);
$loggerCqlServiceDef = new DefinitionDecorator('kassko_cassandra.logger_cql.prototype');
if (isset($connectionConfig['logger_service'])) {
$loggerCqlServiceDef->replaceArgument(0, new Reference($connectionConfig['logger_service']));
}
$builder->setDefinition($loggerCqlServiceName, $loggerCqlServiceDef);
//loggerChain creation.
$loggerChainServiceName = $this->computeLoggerChainServiceName($connectionName);
$loggerChainDef = new DefinitionDecorator('kassko_cassandra.logger_chain.prototype');
$builder->setDefinition($loggerChainServiceName, $loggerChainDef);
$loggerChainDef->addMethodCall('addLogger', [new Reference($loggerCqlServiceName)]);
if ($profiling) {
$loggerProfilerServiceName = $this->computeLoggerProfilerServiceName($connectionName);
$builder->setDefinition($loggerProfilerServiceName, new DefinitionDecorator('kassko_cassandra.logger_profiler.prototype'));
$loggerChainDef->addMethodCall('addLogger', [new Reference($loggerProfilerServiceName)]);
$queryStatsManagerDef = $builder->getDefinition('kassko_cassandra.query_stats.manager');
$queryStatsManagerDef->addMethodCall('addLogger', [$connectionName, new Reference($loggerProfilerServiceName)]);
}
if (isset($connectionConfig['event_dispatcher_service'])) {
$connectionDef->addMethodCall('setEventDispatcher', [new Reference($connectionConfig['event_dispatcher_service'])]);
}
$connectionDef->addMethodCall('setLogger', [new Reference($loggerChainServiceName)]);
$connectionDef->addMethodCall('useKeyspace', [$connectionConfig['keyspace']]);
list($dsn, $username, $password) = $this->resolveConnectionParam($connectionConfig);
if (null === $username xor null === $password) {
throw new \LogicException(sprintf('username and password should be provided both or neither for keyspace "%s".', $connectionConfig['keyspace']));
}
if (null !== $username) {
$connectionDef->setArguments([$dsn, $username, $password]);
} else {
$connectionDef->setArguments([$dsn]);
}
$serviceName = $this->computeServiceName($connectionName);
$builder->setDefinition($serviceName, $connectionDef);
if (isset($connectionConfig['alias'])) {
$builder->setAlias($connectionConfig['alias'], $serviceName);
}
}
示例7: load
/** {@inheritdoc} */
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('error-handler-services.xml');
$container->setParameter('error_handler.stage', $config['stage']);
$container->setParameter('error_handler.root_dir', $config['root_dir']);
$shutdownSeverity = strtoupper($config['shutdown_severity']);
$container->setParameter('error_handler.shutdown_severity', $shutdownSeverity);
$baseErrorHandler = $container->getDefinition('base_error_handler');
$baseErrorHandler->replaceArgument(0, Severity::$SEVERITIES[$shutdownSeverity]);
$errorHandler = $container->getDefinition('error_handler');
foreach ($config['categories'] as $categoryName => $categoryConfiguration) {
if (empty($categoryConfiguration['handlers'])) {
continue;
}
foreach ($categoryConfiguration['handlers'] as $handlerName => $handlerConfiguration) {
$handlerClass = $container->getParameter(sprintf('error_handler.handler_%s.class', $handlerName));
$handlerId = sprintf('error_handler.handler.%s.%s', $categoryName, $handlerName);
$handlerDefinition = new DefinitionDecorator('error_handler.abstract.handler');
$handlerDefinition->setClass($handlerClass);
$handlerDefinition->setPublic(false);
$handlerDefinition->setLazy(true);
switch ($handlerName) {
case 'bugsnag':
$handlerDefinition->addArgument($handlerConfiguration['apiKey']);
if (isset($handlerConfiguration['endpoint'])) {
$handlerDefinition->addMethodCall('setEndpoint', array($handlerConfiguration['endpoint']));
}
if (isset($handlerConfiguration['useSSL'])) {
$handlerDefinition->addMethodCall('setUseSSL', array($handlerConfiguration['useSSL']));
}
break;
case 'raven':
$handlerDefinition->addArgument($handlerConfiguration['endpoint']);
break;
}
$container->setDefinition($handlerId, $handlerDefinition);
$errorHandler->addMethodCall('addHandler', array(new Reference($handlerId), array($categoryName)));
}
}
}
示例8: addApis
/**
* {@inheritDoc}
*/
protected function addApis(Definition $paymentDefinition, ContainerBuilder $container, $contextName, array $config)
{
$apiDefinition = new DefinitionDecorator('payum.authorize_net_aim.api.prototype');
$apiDefinition->replaceArgument(0, $config['login_id']);
$apiDefinition->replaceArgument(1, $config['transaction_key']);
$apiDefinition->addMethodCall('setSandbox', array($config['sandbox']));
$apiId = 'payum.context.' . $contextName . '.api';
$container->setDefinition($apiId, $apiDefinition);
$paymentDefinition->addMethodCall('addApi', array(new Reference($apiId)));
}
示例9: loadAmqpTransport
private function loadAmqpTransport(array $config, ContainerBuilder $container)
{
$this->loader->load('transport/amqp/amqp.xml');
$this->loader->load(sprintf('transport/amqp/%s.xml', $config['driver']));
if (class_exists('JMS\\AopBundle\\JMSAopBundle')) {
$this->loader->load('transport/amqp/tracer.xml');
}
$camelizeKey = function (array $config) {
$camelized = [];
foreach ($config as $key => $value) {
$camelized[lcfirst(ContainerBuilder::camelize($key))] = $value;
}
return $camelized;
};
$definitions = [];
foreach ($config['connections'] as $name => $connectionConfig) {
$exchanges = $connectionConfig['exchanges'];
unset($connectionConfig['exchanges']);
$queues = $connectionConfig['queues'];
unset($connectionConfig['queues']);
$amqp = new DefinitionDecorator('event_band.transport.amqp.definition');
$amqp->addMethodCall('connection', [$camelizeKey($connectionConfig)]);
foreach ($exchanges as $exchange => $exchangeConfig) {
$exchangeType = $exchangeConfig['type'];
unset($exchangeConfig['type']);
$amqp->addMethodCall($exchangeType . 'Exchange', [$exchange, $camelizeKey($exchangeConfig)]);
}
foreach ($queues as $queue => $queueConfig) {
$amqp->addMethodCall('queue', [$queue, $camelizeKey($queueConfig)]);
}
$definitionId = self::getTransportDefinitionId('amqp', $name);
$container->setDefinition($definitionId, $amqp);
$definitions[$name] = $definitionId;
$connection = new DefinitionDecorator('event_band.transport.amqp.connection_definition');
$connection->setFactoryService($definitionId);
$connectionId = self::getAmqpConnectionDefinitionId($name);
$container->setDefinition($connectionId, $connection);
$factory = new DefinitionDecorator(sprintf('event_band.transport.amqp.connection_factory.%s', $config['driver']));
$factory->addMethodCall('setDefinition', [new Reference($connectionId)]);
$container->setDefinition(self::getAmqpLibConnectionFactoryId($name), $factory);
$driver = new DefinitionDecorator('event_band.transport.amqp.driver.' . $config['driver']);
$driver->replaceArgument(0, new Reference($this->getAmqpLibConnectionFactoryId($name)));
$container->setDefinition($this->getAmqpDriverId($name), $driver);
$configurator = new DefinitionDecorator('event_band.transport.amqp.configurator');
$configurator->replaceArgument(0, new Reference($this->getAmqpDriverId($name)));
$container->setDefinition(self::getTypedTransportConfiguratorId('amqp', $name), $configurator);
$container->getDefinition(self::getTransportConfiguratorId())->addMethodCall('registerConfigurator', ['amqp.' . $name, new Reference(self::getTypedTransportConfiguratorId('amqp', $name))]);
}
$container->setParameter('event_band.transport_definitions', array_merge($container->getParameter('event_band.transport_definitions'), ['amqp' => $definitions]));
foreach ($config['converters'] as $name => $converterConfig) {
$definition = new DefinitionDecorator('event_band.transport.amqp.converter.serialize');
$definition->replaceArgument(0, new Reference(self::getSerializerId($converterConfig['parameters']['serializer'])));
$container->setDefinition(self::getAmqpConverterId($name), $definition);
}
}
示例10: generate
/**
* @throws \LogicException
*/
public function generate()
{
$definition = new DefinitionDecorator('phpmentors_pageflower.reflection_conversational_controller');
$definition->setArguments(array($this->controllerClass->getName()));
foreach ($this->controllerClass->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) {
/* @var $method \ReflectionMethod */
if ($method->getDeclaringClass()->getName() == $this->controllerClass->getName()) {
foreach ($this->reader->getMethodAnnotations($method) as $annotation) {
if ($annotation instanceof Init) {
$definition->addMethodCall('addInitMethod', array($method->getName()));
} elseif ($annotation instanceof Accept) {
if ($annotation->value === null || is_string($annotation->value) && strlen($annotation->value) == 0) {
throw new \LogicException(sprintf('The value for annotation "%s" cannot be empty.', get_class($annotation)));
}
foreach ((array) $annotation->value as $accept) {
if ($accept === null || strlen($accept) == 0) {
throw new \LogicException(sprintf('The value for annotation "%s" cannot be empty.', get_class($annotation)));
}
if (!in_array($accept, $this->states)) {
throw new \LogicException(sprintf('The value for annotation "%s" must be a one of [ %s ], "%s" is specified.', 'PHPMentors\\PageflowerBundle\\Annotation\\Accept', implode(', ', $this->states), $accept));
}
$definition->addMethodCall('addAcceptableState', array($method->getName(), $accept));
}
}
}
}
}
foreach ($this->controllerClass->getProperties() as $property) {
/* @var $property \ReflectionProperty */
if ($property->getDeclaringClass()->getName() == $this->controllerClass->getName() && !$property->isStatic()) {
foreach ($this->reader->getPropertyAnnotations($property) as $annotation) {
$definition->addMethodCall('addStatefulProperty', array($property->getName()));
}
}
}
$reflectionConversationalControllerServiceId = 'phpmentors_pageflower.reflection_conversational_controller.' . $this->controllerServiceId;
$this->container->setDefinition($reflectionConversationalControllerServiceId, $definition);
$this->container->getDefinition('phpmentors_pageflower.reflection_conversational_controller_repository')->addMethodCall('add', array(new Reference($reflectionConversationalControllerServiceId)));
}
開發者ID:iteman,項目名稱:pageflower-bundle,代碼行數:42,代碼來源:ReflectionConversationalControllerDefinitionGenerator.php
示例11: buildPrivateKeyProvider
protected function buildPrivateKeyProvider(array $config, ContainerBuilder $container)
{
if (@$config['private_key']['id']) {
$id = $config['private_key']['id'];
} else {
if (@$config['private_key']['file']) {
$fileProvider = new DefinitionDecorator('appsco_market_api.private_key_provider.file.abstract');
$fileProvider->addMethodCall('setFilename', array($config['private_key']['file']));
$id = 'appsco_market_api.private_key_provider.file';
$container->setDefinition($id, $fileProvider);
} else {
$id = 'appsco_market_api.private_key_provider.null';
}
}
$clientService = $container->getDefinition('appsco_market_api.client');
$clientService->replaceArgument(1, new Reference($id));
}
示例12: loadIndexListener
protected function loadIndexListener(array $indexConfig, ContainerBuilder $container, $objectPersisterId, $typeDef, $indexId)
{
if (isset($indexConfig['listener']['service'])) {
return $indexConfig['listener']['service'];
}
$abstractListenerId = sprintf('acts.sphinx_realtime.listener.abstract.%s', $indexConfig['driver']);
$listenerId = sprintf('acts.sphinx_realtime.listener.%s', $indexId);
$listenerDef = new DefinitionDecorator($abstractListenerId);
$listenerDef->replaceArgument(0, new Reference($objectPersisterId));
$listenerDef->replaceArgument(1, $indexConfig['model']);
$listenerDef->replaceArgument(3, $indexConfig['identifier']);
$listenerDef->replaceArgument(2, $this->getDoctrineEvents($indexConfig));
switch ($indexConfig['driver']) {
case 'orm':
$listenerDef->addTag('doctrine.event_subscriber');
break;
}
if (isset($indexConfig['listener']['is_indexable_callback'])) {
$callback = $indexConfig['listener']['is_indexable_callback'];
if (is_array($callback)) {
list($class) = $callback + array(null);
if (is_string($class) && !class_exists($class)) {
$callback[0] = new Reference($class);
}
}
$listenerDef->addMethodCall('setIsIndexableCallback', array($callback));
}
$container->setDefinition($listenerId, $listenerDef);
return $listenerId;
}
示例13: createRelyingPartyComposite
protected function createRelyingPartyComposite(ContainerBuilder $container, $id)
{
$service = new DefinitionDecorator('aerial_ship_saml_sp.relying_party.composite');
$service->addMethodCall('append', array(new Reference('aerial_ship_saml_sp.relying_party.discovery.' . $id)));
$service->addMethodCall('append', array(new Reference('aerial_ship_saml_sp.relying_party.federation_metadata.' . $id)));
$service->addMethodCall('append', array(new Reference('aerial_ship_saml_sp.relying_party.authenticate.' . $id)));
$service->addMethodCall('append', array(new Reference('aerial_ship_saml_sp.relying_party.assertion_consumer.' . $id)));
$service->addMethodCall('append', array(new Reference('aerial_ship_saml_sp.relying_party.logout.' . $id)));
// sso session check must be the last one since it can handle every request
$service->addMethodCall('append', array(new Reference('aerial_ship_saml_sp.relying_party.sso_session_check.' . $id)));
$container->setDefinition('aerial_ship_saml_sp.relying_party.composite.' . $id, $service);
}
示例14: loadView
private function loadView(array $config, XmlFileLoader $loader, ContainerBuilder $container)
{
if (!empty($config['view']['exception_wrapper_handler'])) {
$container->setAlias('fos_rest.view.exception_wrapper_handler', $config['view']['exception_wrapper_handler']);
}
if (!empty($config['view']['jsonp_handler'])) {
$handler = new DefinitionDecorator($config['service']['view_handler']);
$handler->setPublic(true);
$jsonpHandler = new Reference('fos_rest.view_handler.jsonp');
$handler->addMethodCall('registerHandler', array('jsonp', array($jsonpHandler, 'createResponse')));
$container->setDefinition('fos_rest.view_handler', $handler);
$container->setParameter('fos_rest.view_handler.jsonp.callback_param', $config['view']['jsonp_handler']['callback_param']);
if (empty($config['view']['mime_types']['jsonp'])) {
$config['view']['mime_types']['jsonp'] = $config['view']['jsonp_handler']['mime_type'];
}
}
if ($config['view']['mime_types']['enabled']) {
$loader->load('mime_type_listener.xml');
if (!empty($config['mime_type_listener']['service'])) {
$service = $container->getDefinition('fos_rest.mime_type_listener');
$service->clearTag('kernel.event_listener');
}
$container->setParameter('fos_rest.mime_types', $config['view']['mime_types']);
} else {
$container->setParameter('fos_rest.mime_types', array());
}
if ($config['view']['view_response_listener']['enabled']) {
$loader->load('view_response_listener.xml');
if (!empty($config['view_response_listener']['service'])) {
$service = $container->getDefinition('fos_rest.view_response_listener');
$service->clearTag('kernel.event_listener');
}
$container->setParameter('fos_rest.view_response_listener.force_view', $config['view']['view_response_listener']['force']);
}
$formats = array();
foreach ($config['view']['formats'] as $format => $enabled) {
if ($enabled) {
$formats[$format] = false;
}
}
foreach ($config['view']['templating_formats'] as $format => $enabled) {
if ($enabled) {
$formats[$format] = true;
}
}
$container->setParameter('fos_rest.formats', $formats);
foreach ($config['view']['force_redirects'] as $format => $code) {
if (true === $code) {
$config['view']['force_redirects'][$format] = Codes::HTTP_FOUND;
}
}
$container->setParameter('fos_rest.force_redirects', $config['view']['force_redirects']);
if (!is_numeric($config['view']['failed_validation'])) {
$config['view']['failed_validation'] = constant('\\FOS\\RestBundle\\Util\\Codes::' . $config['view']['failed_validation']);
}
$container->setParameter('fos_rest.failed_validation', $config['view']['failed_validation']);
if (!is_numeric($config['view']['empty_content'])) {
$config['view']['empty_content'] = constant('\\FOS\\RestBundle\\Util\\Codes::' . $config['view']['empty_content']);
}
$container->setParameter('fos_rest.empty_content', $config['view']['empty_content']);
$container->setParameter('fos_rest.serialize_null', $config['view']['serialize_null']);
$container->setParameter('fos_rest.default_engine', $config['view']['default_engine']);
}
示例15: loadDbalConnection
/**
* Loads a configured DBAL connection.
*
* @param string $name The name of the connection
* @param array $connection A dbal connection configuration.
* @param ContainerBuilder $container A ContainerBuilder instance
*/
protected function loadDbalConnection($name, array $connection, ContainerBuilder $container)
{
// configuration
$configuration = $container->setDefinition(sprintf('doctrine.dbal.%s_connection.configuration', $name), new DefinitionDecorator('doctrine.dbal.connection.configuration'));
$logger = null;
if ($connection['logging']) {
$logger = new Reference('doctrine.dbal.logger');
}
unset($connection['logging']);
if ($connection['profiling']) {
$profilingLoggerId = 'doctrine.dbal.logger.profiling.' . $name;
$container->setDefinition($profilingLoggerId, new DefinitionDecorator('doctrine.dbal.logger.profiling'));
$logger = new Reference($profilingLoggerId);
$container->getDefinition('data_collector.doctrine')->addMethodCall('addLogger', array($name, $logger));
if (null !== $logger) {
$chainLogger = new DefinitionDecorator('doctrine.dbal.logger.chain');
$chainLogger->addMethodCall('addLogger', array($logger));
$loggerId = 'doctrine.dbal.logger.chain.' . $name;
$container->setDefinition($loggerId, $chainLogger);
$logger = new Reference($loggerId);
}
}
unset($connection['profiling']);
if ($logger) {
$configuration->addMethodCall('setSQLLogger', array($logger));
}
// event manager
$def = $container->setDefinition(sprintf('doctrine.dbal.%s_connection.event_manager', $name), new DefinitionDecorator('doctrine.dbal.connection.event_manager'));
// connection
if (isset($connection['charset'])) {
if (isset($connection['driver']) && stripos($connection['driver'], 'mysql') !== false || isset($connection['driver_class']) && stripos($connection['driver_class'], 'mysql') !== false) {
$mysqlSessionInit = new Definition('%doctrine.dbal.events.mysql_session_init.class%');
$mysqlSessionInit->setArguments(array($connection['charset']));
$mysqlSessionInit->setPublic(false);
$mysqlSessionInit->addTag('doctrine.event_subscriber', array('connection' => $name));
$container->setDefinition(sprintf('doctrine.dbal.%s_connection.events.mysqlsessioninit', $name), $mysqlSessionInit);
unset($connection['charset']);
}
}
$options = $this->getConnectionOptions($connection);
$container->setDefinition(sprintf('doctrine.dbal.%s_connection', $name), new DefinitionDecorator('doctrine.dbal.connection'))->setArguments(array($options, new Reference(sprintf('doctrine.dbal.%s_connection.configuration', $name)), new Reference(sprintf('doctrine.dbal.%s_connection.event_manager', $name)), $connection['mapping_types']));
}