本文整理汇总了PHP中Symfony\Component\DependencyInjection\ContainerBuilder::setDefinition方法的典型用法代码示例。如果您正苦于以下问题:PHP ContainerBuilder::setDefinition方法的具体用法?PHP ContainerBuilder::setDefinition怎么用?PHP ContainerBuilder::setDefinition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\DependencyInjection\ContainerBuilder
的用法示例。
在下文中一共展示了ContainerBuilder::setDefinition方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: load
public function load(array $configs, ContainerBuilder $container)
{
$xml = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$xml->load('services.xml');
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
foreach ($configs as $subConfig) {
$config = array_merge($config, $subConfig);
}
$definition = $container->getDefinition('goetas_webservices.xsd2php.naming_convention.' . $config['naming_strategy']);
$container->setDefinition('goetas_webservices.xsd2php.naming_convention', $definition);
$schemaReader = $container->getDefinition('goetas_webservices.xsd2php.schema_reader');
foreach ($config['known_locations'] as $namespace => $location) {
$schemaReader->addMethodCall('addKnownSchemaLocation', [$namespace, $location]);
}
foreach (['php', 'jms'] as $type) {
$definition = $container->getDefinition('goetas_webservices.xsd2php.path_generator.' . $type . '.' . $config['path_generator']);
$container->setDefinition('goetas_webservices.xsd2php.path_generator.' . $type, $definition);
$pathGenerator = $container->getDefinition('goetas_webservices.xsd2php.path_generator.' . $type);
$pathGenerator->addMethodCall('setTargets', [$config['destinations_' . $type]]);
$converter = $container->getDefinition('goetas_webservices.xsd2php.converter.' . $type);
foreach ($config['namespaces'] as $xml => $php) {
$converter->addMethodCall('addNamespace', [$xml, self::sanitizePhp($php)]);
}
foreach ($config['aliases'] as $xml => $data) {
foreach ($data as $type => $php) {
$converter->addMethodCall('addAliasMapType', [$xml, $type, self::sanitizePhp($php)]);
}
}
}
$container->setParameter('goetas_webservices.xsd2php.config', $config);
}
示例2: 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');
$container->setParameter('eo_airbrake.api_key', $config['api_key']);
$container->setParameter('eo_airbrake.async', $config['async']);
$container->setParameter('eo_airbrake.host', $config['host']);
$container->setParameter('eo_airbrake.secure', $config['secure']);
// Exception Listener
if ($config['api_key']) {
// Airbreak Configuration
$class = $container->getParameter('eo_airbrake.configuration.class');
$definition = new Definition($class, array($config['api_key'], $config['async'], $container->getParameter('kernel.environment'), $config['host'], $config['secure']));
$container->setDefinition('eo_airbrake.configuration', $definition);
// Airbreak Client
$class = $container->getParameter('eo_airbrake.client.class');
$definition = new Definition($class, array(new Reference('eo_airbrake.configuration')));
$container->setDefinition('eo_airbrake.client', $definition);
// Exception Listener
$class = $container->getParameter('eo_airbrake.exception_listener.class');
$definition = new Definition($class, array(new Reference('eo_airbrake.client'), $config['ignored_exceptions']));
$definition->addTag('kernel.event_listener', array('event' => 'kernel.exception', 'method' => 'onKernelException'));
$container->setDefinition('php_airbrake.exception_listener', $definition);
// PHP Shutdown Listener
$class = $container->getParameter('eo_airbrake.shutdown_listener.class');
$definition = new Definition($class, array(new Reference('eo_airbrake.client')));
$definition->addTag('kernel.event_listener', array('event' => 'kernel.controller', 'method' => 'register'));
$container->setDefinition('php_airbrake.shutdown_listener', $definition);
}
}
示例3: process
/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
{
$analysis = $container->getParameter('es.analysis');
$connections = $container->getParameter('es.connections');
$managers = $container->getParameter('es.managers');
$collector = $container->get('es.metadata_collector');
foreach ($managers as $managerName => $manager) {
if (!isset($connections[$manager['connection']])) {
throw new InvalidConfigurationException('There is no ES connection with the name: ' . $manager['connection']);
}
$managerName = strtolower($managerName);
$connection = $connections[$manager['connection']];
$managerDefinition = new Definition($container->getParameter('es.manager.class'), [$managerName, $connection, $analysis, $manager]);
$managerDefinition->setFactory([new Reference('es.manager_factory'), 'createManager']);
$container->setDefinition(sprintf('es.manager.%s', $managerName), $managerDefinition);
// Make es.manager.default as es.manager service.
if ($managerName === 'default') {
$container->setAlias('es.manager', 'es.manager.default');
}
$mappings = $collector->getMappings($manager['mappings']);
// Building repository services.
foreach ($mappings as $repositoryType => $repositoryDetails) {
$repositoryDefinition = new Definition($container->getParameter('es.repository.class'), [$repositoryDetails['bundle'] . ':' . $repositoryDetails['class']]);
$repositoryDefinition->setFactory([new Reference(sprintf('es.manager.%s', $managerName)), 'getRepository']);
$repositoryId = sprintf('es.manager.%s.%s', $managerName, $repositoryType);
if (strtolower(substr($repositoryType, -8)) === 'document') {
$container->setAlias(sprintf('es.manager.%s.%s', $managerName, substr($repositoryType, 0, strlen($repositoryType) - 8)), $repositoryId);
}
$container->setDefinition($repositoryId, $repositoryDefinition);
}
}
}
示例4: process
public function process(ContainerBuilder $container)
{
if (!($container->hasDefinition('fragment.listener') && $container->hasDefinition('ezpublish.decorated_fragment_renderer'))) {
return null;
}
$fragmentListenerDef = $container->findDefinition('fragment.listener');
$fragmentListenerDef->setFactoryService('ezpublish.fragment_listener.factory')->setFactoryMethod('buildFragmentListener')->addArgument('%fragment.listener.class%');
// Looping over all fragment renderers to decorate them
// This is to make sure they are siteaccess aware (siteaccess is serialized in rendered path).
foreach ($container->findTaggedServiceIds('kernel.fragment_renderer') as $id => $attributes) {
$renamedId = "{$id}.inner";
$definition = $container->getDefinition($id);
$public = $definition->isPublic();
$tags = $definition->getTags();
$definition->setPublic(false);
$container->setDefinition($renamedId, $definition);
$decoratedDef = new DefinitionDecorator('ezpublish.decorated_fragment_renderer');
$decoratedDef->setArguments(array(new Reference($renamedId)));
$decoratedDef->setPublic($public);
$decoratedDef->setTags($tags);
// Special treatment for inline fragment renderer, to fit ESI renderer constructor type hinting (forced to InlineFragmentRenderer)
if ($id === 'fragment.renderer.inline') {
$decoratedDef->setClass($container->getParameter('ezpublish.decorated_fragment_renderer.inline.class'));
}
$container->setDefinition($id, $decoratedDef);
}
}
示例5: createAndRegisterDefinitions
private function createAndRegisterDefinitions(array $config = array())
{
foreach ($config as $commandName => $commandOptions) {
$definition = $this->generateCommandDefinition($commandName, $commandOptions);
$this->container->setDefinition('phpzone.shell.' . $commandName, $definition);
}
}
示例6: loadManagers
protected function loadManagers($config, ContainerBuilder $container)
{
$baseDefinition = $container->getDefinition('kcs.api_connector.request_manager.abstract');
foreach ($config as $name => $managerConfig) {
$definition = clone $baseDefinition;
$definition->setAbstract(false);
switch ($managerConfig['transport']) {
case 'guzzle':
$definition->replaceArgument(0, new Reference('kcs.api_connector.guzzle_transport'));
break;
case 'custom':
$service_name = 'kcs.api_connector.custom_transport.' . $name;
$transport_definition = new Definition($managerConfig['transport_class']);
$container->setDefinition($service_name, $transport_definition);
$definition->replaceArgument(0, new Reference($service_name));
}
$definition->replaceArgument(2, $managerConfig['base_url']);
$auth = isset($managerConfig['authenticator']) ? $managerConfig['authenticator'] : AnonymousAuthenticator::class;
if (!class_exists($auth)) {
$auth = new Reference($auth);
}
$definition->addMethodCall('setDefaultAuthenticator', [$auth]);
$container->setDefinition('kcs.api_connector.request_manager.' . $name, $definition);
}
}
示例7: createBusDefinition
private function createBusDefinition($id, $priority)
{
$definition = new Definition('stdClass');
$definition->addTag($this->middlewareTag, array('priority' => $priority));
$this->container->setDefinition($id, $definition);
return $definition;
}
示例8: process
/**
* You can modify the container here before it is dumped to PHP code.
*
* @param ContainerBuilder $container
*/
public function process(ContainerBuilder $container)
{
// get applications configuration array
$applications = $container->getParameter(DreamCommerceShopAppstoreExtension::ALIAS . '.apps');
// create definition for application registry
$applicationsDefinition = new Definition('DreamCommerce\\ShopAppstoreBundle\\Handler\\ApplicationRegistry');
// configuration for every app
foreach ($applications as $app => $data) {
$definition = new Definition('DreamCommerce\\ShopAppstoreBundle\\Handler\\Application');
$definition->addArgument($app);
$definition->addArgument($data['app_id']);
$definition->addArgument($data['app_secret']);
$definition->addArgument($data['appstore_secret']);
// if logger is instantiated, use it
$definition->addArgument(new Reference(DreamCommerceShopAppstoreExtension::ALIAS . '.logger', ContainerInterface::NULL_ON_INVALID_REFERENCE));
// ignore SSL errors?
$definition->addArgument($container->getParameter(DreamCommerceShopAppstoreExtension::ALIAS . '.skip_ssl'));
// application version
$definition->addArgument($data['minimal_version']);
// user agent, todo: make calls consistent, eg. logger argument -> call like this
$definition->addMethodCall('setUserAgent', [$data['user_agent']]);
// defined application webhooks configuration
$definition->addMethodCall('setWebhooks', [$data['webhooks']]);
$app = DreamCommerceShopAppstoreExtension::ALIAS . '.app.' . $app;
// append definition
$container->setDefinition($app, $definition);
// add application to the registry
$applicationsDefinition->addMethodCall('register', array(new Reference($app)));
}
// append applications registry to the container
$container->setDefinition(DreamCommerceShopAppstoreExtension::ALIAS . '.apps', $applicationsDefinition);
}
示例9: load
/**
* {@inheritdoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
if ($config['cache']) {
$container->setAlias('vesax.seo.metadata_cache', 'doctrine_cache.providers.' . $config['cache']);
}
if ($config['redirects']['enabled']) {
$container->setDefinition('vesax.seo.redirect_matcher', new Definition('Vesax\\SEOBundle\\Matcher\\RedirectRuleMatcher'));
$redirectListenerDefinition = new Definition('Vesax\\SEOBundle\\EventListener\\RedirectListener', [new Reference('vesax.seo.redirect_rule_repository'), new Reference('vesax.seo.redirect_matcher'), new Reference('vesax.seo.metadata_cache', ContainerInterface::NULL_ON_INVALID_REFERENCE)]);
$redirectListenerDefinition->addTag('kernel.event_listener', ['event' => 'kernel.exception', 'method' => 'onException']);
if (!$config['redirects']['not_found_only']) {
$redirectListenerDefinition->addTag('kernel.event_listener', ['event' => 'kernel.request', 'method' => 'onRequest', 'priority' => 99]);
}
$container->setDefinition('vesax.seo.redirect_listener', $redirectListenerDefinition);
$redirectAdminDefinition = new Definition('Vesax\\SEOBundle\\Admin\\RedirectRuleAdmin', [null, "Vesax\\SEOBundle\\Entity\\RedirectRule", "SonataAdminBundle:CRUD"]);
$redirectAdminDefinition->addTag('sonata.admin', ['manager_type' => 'orm', 'group' => 'SEO', 'label' => 'Redirect Rules']);
$container->setDefinition('vesax.seo.admin.rediect_rule', $redirectAdminDefinition);
}
if ($config['robots']) {
$menuListenerDefinition = new Definition('Vesax\\SEOBundle\\EventListener\\ConfigureAdminMenuListener');
$menuListenerDefinition->addTag('kernel.event_listener', ['event' => 'sonata.admin.event.configure.menu.sidebar', 'method' => 'configureMenu']);
$container->setDefinition('vesax.seo.admin.menu_listener', $menuListenerDefinition);
}
if ($config['meta']) {
$metaAdminDefinition = new Definition('Vesax\\SEOBundle\\Admin\\RuleAdmin', [null, Rule::class, 'SonataAdminBundle:CRUD']);
$metaAdminDefinition->addTag('sonata.admin', ['manager_type' => 'orm', 'group' => 'SEO', 'label' => 'Page Rules']);
$container->setDefinition('vesax.seo.admin.rule', $metaAdminDefinition);
}
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.yml');
}
示例10: createPackageDefinition
/**
* Returns a definition for an asset package.
*
* @param ContainerBuilder $container Container
* @param array $httpUrls SSL assets_base_urls
* @param array $sslUrls assets_base_urls
* @param string $rootDir Directory where to look for reved assets
* @param string $summaryFile Grunt filerev summary file
* @param string $cacheDir Kernel cache dir
* @param bool $debug Debug mode?
* @param string $name Package name
*
* @return DefinitionDecorator
*/
private function createPackageDefinition(ContainerBuilder $container, array $httpUrls, array $sslUrls, $rootDir, $summaryFile, $cacheDir, $debug, $name = null)
{
if (!$httpUrls) {
$package = new DefinitionDecorator('grunt.filerev.templating.asset.path_package');
$package->setPublic(false)->setScope('request')->replaceArgument(1, $rootDir)->replaceArgument(2, $summaryFile)->replaceArgument(3, $cacheDir)->replaceArgument(4, $debug);
return $package;
}
if ($httpUrls == $sslUrls) {
$package = new DefinitionDecorator('grunt.filerev.templating.asset.url_package');
$package->setPublic(false)->replaceArgument(0, $sslUrls)->replaceArgument(1, $rootDir)->replaceArgument(2, $summaryFile)->replaceArgument(3, $cacheDir)->replaceArgument(4, $debug);
return $package;
}
$prefix = $name ? 'templating.asset.package.' . $name : 'templating.asset.default_package';
$httpPackage = new DefinitionDecorator('grunt.filerev.templating.asset.url_package');
$httpPackage->replaceArgument(0, $httpUrls)->replaceArgument(1, $rootDir)->replaceArgument(2, $summaryFile)->replaceArgument(3, $cacheDir)->replaceArgument(4, $debug);
$container->setDefinition($prefix . '.http', $httpPackage);
if ($sslUrls) {
$sslPackage = new DefinitionDecorator('grunt.filerev.templating.asset.url_package');
$sslPackage->replaceArgument(0, $sslUrls)->replaceArgument(1, $rootDir)->replaceArgument(2, $summaryFile)->replaceArgument(3, $cacheDir)->replaceArgument(4, $debug);
} else {
$sslPackage = new DefinitionDecorator('grunt.filerev.templating.asset.path_package');
$sslPackage->setScope('request')->replaceArgument(1, $rootDir)->replaceArgument(2, $summaryFile)->replaceArgument(3, $cacheDir)->replaceArgument(4, $debug);
}
$container->setDefinition($prefix . '.ssl', $sslPackage);
$package = new DefinitionDecorator('templating.asset.request_aware_package');
$package->setPublic(false)->setScope('request')->replaceArgument(1, $prefix . '.http')->replaceArgument(2, $prefix . '.ssl');
return $package;
}
示例11: testConfigure
public function testConfigure()
{
$prevDumper = $this->getDumpHandler();
$container = new ContainerBuilder();
$container->setDefinition('var_dumper.cloner', new Definition('Symfony\\Component\\HttpKernel\\Tests\\EventListener\\MockCloner'));
$container->setDefinition('mock_dumper', new Definition('Symfony\\Component\\HttpKernel\\Tests\\EventListener\\MockDumper'));
ob_start();
$exception = null;
$listener = new DumpListener($container, 'mock_dumper');
try {
$listener->configure();
$lazyDumper = $this->getDumpHandler();
VarDumper::dump('foo');
$loadedDumper = $this->getDumpHandler();
VarDumper::dump('bar');
$this->assertSame('+foo-+bar-', ob_get_clean());
$listenerReflector = new \ReflectionClass($listener);
$lazyReflector = new \ReflectionFunction($lazyDumper);
$loadedReflector = new \ReflectionFunction($loadedDumper);
$this->assertSame($listenerReflector->getFilename(), $lazyReflector->getFilename());
$this->assertSame($listenerReflector->getFilename(), $loadedReflector->getFilename());
$this->assertGreaterThan($lazyReflector->getStartLine(), $loadedReflector->getStartLine());
} catch (\Exception $exception) {
}
VarDumper::setHandler($prevDumper);
if (null !== $exception) {
throw $exception;
}
}
示例12: load
/**
* {@inheritDoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
foreach ($config['renderer'] as $rendererName => $rendererConfiguration) {
switch ($rendererConfiguration['type']) {
default:
// case native
$class = 'Avisota\\Renderer\\NativeMessageRenderer';
$args = array();
}
$definition = new Definition($class, $args);
$container->setDefinition('avisota.renderer.' . $rendererName, $definition);
}
foreach ($config['queue'] as $queueName => $queueConfiguration) {
switch ($queueConfiguration['type']) {
default:
// case simple
$class = 'Avisota\\Queue\\SimpleDatabaseQueue';
$args = array(new Reference('doctrine.dbal.default_connection'), $queueConfiguration['table']);
}
$definition = new Definition($class, $args);
$container->setDefinition('avisota.queue.' . $queueName, $definition);
}
foreach ($config['transport'] as $transportName => $transportConfiguration) {
switch ($transportConfiguration['type']) {
default:
// case swift
$class = 'Avisota\\Transport\\SwiftTransport';
$args = array(new Reference($transportConfiguration['id']), new Reference('avisota.renderer.' . $transportConfiguration['renderer']));
}
$definition = new Definition($class, $args);
$container->setDefinition('avisota.transport.' . $transportName, $definition);
}
}
示例13: newGuzzleClient
/**
* Creates a new Guzzle client definition
*
* @param string $name Client name
* @param array $config Client configuration
* @param ContainerBuilder $container Service container
*
* @throws \LogicException
*/
private function newGuzzleClient($name, array $config, ContainerBuilder $container)
{
$client = new Definition('Guzzle\\Service\\Description\\ServiceDescription');
$client->setFactory(['Guzzle\\Service\\Description\\ServiceDescription', 'factory']);
if (!isset($config['description']['name'])) {
$config['description']['name'] = $name;
}
$client->addArgument($config['description']);
// Add the service to the container
$serviceName = sprintf('lsw_guzzle.%s', $name);
$container->setDefinition($serviceName, $client);
$client = new Definition('Guzzle\\Service\\Client');
$client->setFactory(['Guzzle\\Service\\Client', 'factory']);
$client->addArgument($config['config']);
$client->addMethodCall('setDescription', array(new Reference($serviceName)));
$client->addMethodCall('addSubscriber', array(new Reference('lsw_guzzle.log_plugin')));
if (isset($config['config']['json_objects']) && $config['config']['json_objects']) {
$client->addMethodCall('addSubscriber', array(new Reference('lsw_guzzle.json_objects_plugin')));
}
if ($container->hasDefinition('lsw_guzzle.command_history_plugin')) {
$client->addMethodCall('addSubscriber', array(new Reference('lsw_guzzle.command_history_plugin')));
}
// Add the service to the container
$serviceName = sprintf('guzzle.%s', $name);
$container->setDefinition($serviceName, $client);
}
示例14: handleConfiguration
protected function handleConfiguration($config, ContainerBuilder $container)
{
if (!isset($config['features'])) {
return;
}
if (!$container->hasDefinition('hotflo_feature_toggle.feature_container')) {
return;
}
$featureToggleContainerDefinition = $container->findDefinition('hotflo_feature_toggle.feature_toggle_container');
foreach ($config['toggles'] as $toggle => $properties) {
if ($properties['type'] == 'service') {
$container->setAlias('hotflo_feature_toggle.toggle.' . $toggle, $properties['service']);
} else {
if (!class_exists($properties['class'])) {
throw new InvalidConfigurationException(sprintf('Class \'%s\' not found.', $properties['class']));
}
$toggleDefinition = new Definition($properties['class']);
$toggleDefinition->addArgument($properties['options']);
$container->setDefinition('hotflo_feature_toggle.toggle.' . $toggle, $toggleDefinition);
}
$featureToggleContainerDefinition->addMethodCall('addFeatureToggle', [new Reference('hotflo_feature_toggle.toggle.' . $toggle), $toggle]);
}
$featureContainerDefinition = $container->findDefinition('hotflo_feature_toggle.feature_container');
foreach ($config['features'] as $feature => $properties) {
$featureDefinition = new Definition('JoshuaEstes\\Component\\FeatureToggle\\Feature');
$featureDefinition->addArgument($properties['options']);
$featureDefinition->addMethodCall('setKey', [$feature]);
$featureDefinition->addMethodCall('setToggle', [new Reference('hotflo_feature_toggle.toggle.' . $properties['toggle'])]);
$container->setDefinition('hotflo_feature_toggle.feature.' . $feature, $featureDefinition);
$featureContainerDefinition->addMethodCall('addFeature', [new Reference('hotflo_feature_toggle.feature.' . $feature)]);
}
}
示例15: process
public function process(ContainerBuilder $container)
{
// log
$definition = $container->findDefinition('csa_guzzle.subscriber.log');
$logServiceId = $container->getParameter('csa_guzzle.subscriber.log.service');
if ($container->hasDefinition($logServiceId)) {
$definition->replaceArgument(0, new Reference($logServiceId));
}
$channel = $container->getParameter('csa_guzzle.subscriber.log.channel');
if (!empty($channel)) {
$definition->clearTag('monolog.logger');
$definition->addTag('monolog.logger', array('channel' => $channel));
}
// Cache
$cacheServiceId = $container->getParameter('csa_guzzle.subscriber.cache.service');
if ($container->hasDefinition($cacheServiceId)) {
$container->setDefinition('csa_guzzle.cache_storage', new Definition('%csa_guzzle.cache_storage.class%', array(new Reference($cacheServiceId), $container->getParameter('csa_guzzle.subscriber.cache.prefix'))));
$cacheSubscriber = new Definition('%csa_guzzle.subscriber.cache.class%', array(new Reference('csa_guzzle.cache_storage'), $container->getParameter('csa_guzzle.subscriber.cache.enable')));
$cacheSubscriber->addTag('csa_guzzle.subscriber');
$container->setDefinition('csa_guzzle.subscriber.cache', $cacheSubscriber);
}
// get all Guzzle subscribers
$subscribers = $container->findTaggedServiceIds('csa_guzzle.subscriber');
if (!count($subscribers)) {
return;
}
// Factory
$factory = $container->findDefinition('csa_guzzle.client_factory');
$arg = [];
foreach ($subscribers as $subscriber => $options) {
$arg[] = new Reference($subscriber);
}
$factory->replaceArgument(1, $arg);
}