本文整理匯總了PHP中Symfony\Component\DependencyInjection\DefinitionDecorator類的典型用法代碼示例。如果您正苦於以下問題:PHP DefinitionDecorator類的具體用法?PHP DefinitionDecorator怎麽用?PHP DefinitionDecorator使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了DefinitionDecorator類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testGetArgumentShouldCheckBounds
/**
* @expectedException \OutOfBoundsException
*/
public function testGetArgumentShouldCheckBounds()
{
$def = new DefinitionDecorator('foo');
$def->setArguments(array(0 => 'foo'));
$def->replaceArgument(0, 'foo');
$def->getArgument(1);
}
示例2: process
/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
{
if ($container->hasDefinition('doctrine')) {
$definition = new DefinitionDecorator('dag.form.type.object_to_identifier');
$definition->addArgument(new Reference('doctrine'));
$definition->addArgument('dag_entity_to_identifier');
$definition->addTag('form.type', array('alias' => 'dag_entity_to_identifier'));
$container->setDefinition('dag_entity_to_identifier', $definition);
}
if ($container->hasDefinition('doctrine_mongodb')) {
$definition = new DefinitionDecorator('dag.form.type.object_to_identifier');
$definition->addArgument(new Reference('doctrine_mongodb'));
$definition->addArgument('dag_document_to_identifier');
$definition->addTag('form.type', array('alias' => 'dag_document_to_identifier'));
$container->setDefinition('dag_document_to_identifier', $definition);
if (!$container->hasDefinition('dag_entity_to_identifier')) {
$container->setAlias('dag_entity_to_identifier', 'dag_document_to_identifier');
}
}
if ($container->hasDefinition('doctrine_phpcr')) {
$definition = new DefinitionDecorator('dag.form.type.object_to_identifier');
$definition->addArgument(new Reference('doctrine_phpcr'));
$definition->addArgument('dag_phpcr_document_to_identifier');
$definition->addTag('form.type', array('alias' => 'dag_phpcr_document_to_identifier'));
$container->setDefinition('dag_phpcr_document_to_identifier', $definition);
if (!$container->hasDefinition('dag_entity_to_identifier')) {
$container->setAlias('dag_entity_to_identifier', 'dag_phpcr_document_to_identifier');
}
}
}
示例3: process
/**
* {@inheritDoc}
*/
public function process(ContainerBuilder $container)
{
foreach ($container->findTaggedServiceIds('payum.storage_extension') as $id => $tagAttributes) {
foreach ($tagAttributes as $attributes) {
$paymentIds = array();
if (isset($attributes['all']) && $attributes['all']) {
$paymentIds = array_merge($paymentIds, $this->findAllPaymentIds($container));
}
if (isset($attributes['factory']) && $attributes['factory']) {
$paymentIds = array_merge($paymentIds, $this->findPaymentIdsByFactory($container, $attributes['factory']));
}
if (isset($attributes['context']) && $attributes['context']) {
$paymentIds = array_merge($paymentIds, $this->findPaymentIdsByContext($container, $attributes['context']));
}
$paymentIds = array_filter(array_unique($paymentIds));
foreach ($paymentIds as $paymentId) {
$storageExtension = new DefinitionDecorator('payum.extension.storage.prototype');
$storageExtension->replaceArgument(0, new Reference($id));
$storageExtension->setPublic(false);
if (false !== strpos($id, '.storage.')) {
$storageExtensionId = str_replace('.storage.', '.extension.storage.', $id);
} else {
throw new LogicException(sprintf('In order to add storage to extension the storage %id has to contains ".storage." inside.', $id));
}
$container->setDefinition($storageExtensionId, $storageExtension);
$payment = $container->getDefinition($paymentId);
$payment->addMethodCall('addExtension', array(new Reference($storageExtensionId), isset($attributes['prepend']) && $attributes['prepend']));
}
}
}
}
示例4: testSetArgument
public function testSetArgument()
{
$def = new DefinitionDecorator('foo');
$this->assertEquals(array(), $def->getArguments());
$this->assertSame($def, $def->setArgument(0, 'foo'));
$this->assertEquals(array('index_0' => 'foo'), $def->getArguments());
}
示例5: 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);
}
}
示例6: 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);
}
}
}
示例7: process
/**
* @inheritdoc
*/
public function process(ContainerBuilder $container)
{
$definitions = array();
$servicesIds = $container->findTaggedServiceIds('pmd_state_machine.token_configurable');
foreach ($servicesIds as $serviceId => $tag) {
$group = isset($tag[0]['group']) ? $tag[0]['group'] : null;
$type = isset($tag[0]['type']) ? $tag[0]['type'] : null;
if (!isset($group) || !isset($type)) {
throw new \InvalidArgumentException(sprintf('Services tagged %s must have group and type defined', 'pmd_state_machine.token_configurable'));
}
$serviceDefinition = $container->getDefinition($serviceId);
$optionsId = sprintf('pmd_state_machine.behavior.%s_%s_options', $group, $type);
$optionsReference = new Reference($optionsId, ContainerInterface::NULL_ON_INVALID_REFERENCE);
// Configure options resolver
$resolverId = sprintf('pmd_state_machine.behavior.%s_%s_resolver', $group, $type);
$resolverReference = new Reference($resolverId);
$resolverDefinition = new DefinitionDecorator('pmd_state_machine.behavior_resolver.token_options_resolver');
$resolverDefinition->replaceArgument(0, $optionsReference);
// Configure configurable decorator
$configId = sprintf('pmd_state_machine.behavior.%s_%s_configurator', $group, $type);
$configDefinition = new DefinitionDecorator('pmd_state_machine.behavior.token_configurable_configurator');
$configDefinition->replaceArgument(0, $resolverReference);
$serviceDefinition->setConfigurator(array(new Reference($configId, ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, false), 'configure'));
$definitions[$resolverId] = $resolverDefinition;
$definitions[$configId] = $configDefinition;
}
$container->addDefinitions($definitions);
}
示例8: 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;
}
示例9: 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);
}
}
}
示例10: process
/**
* @param ContainerBuilder $container
*
* @throws \InvalidArgumentException
*/
public function process(ContainerBuilder $container)
{
$config = $container->getExtensionConfig('elastica')[0];
$jsonLdFrameLoader = $container->get('nemrod.elastica.jsonld.frame.loader.filesystem');
$confManager = $container->getDefinition('nemrod.elastica.config_manager');
$filiationBuilder = $container->get('nemrod.filiation.builder');
$jsonLdFrameLoader->setFiliationBuilder($filiationBuilder);
foreach ($config['indexes'] as $name => $index) {
$indexName = isset($index['index_name']) ? $index['index_name'] : $name;
foreach ($index['types'] as $typeName => $settings) {
$jsonLdFrameLoader->setEsIndex($name);
$frame = $jsonLdFrameLoader->load($settings['frame'], null, true, true, true);
$type = !empty($frame['@type']) ? $frame['@type'] : $settings['type'];
if (empty($type)) {
throw \Exception("You must provide a RDF Type.");
}
//type
$typeId = 'nemrod.elastica.type.' . $name . '.' . $typeName;
$indexId = 'nemrod.elastica.index.' . $name;
$typeDef = new DefinitionDecorator('nemrod.elastica.type.abstract');
$typeDef->replaceArgument(0, $type);
$typeDef->setFactory(array(new Reference($indexId), 'getType'));
$typeDef->addTag('nemrod.elastica.type', array('index' => $name, 'name' => $typeName, 'type' => $type));
$container->setDefinition($typeId, $typeDef);
//registering config to configManager
$confManager->addMethodCall('setTypeConfigurationArray', array($name, $typeName, $type, $frame));
}
}
}
示例11: load
/**
* {@inheritDoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config/'));
$loader->load('services.xml');
$processor = new Processor();
$config = $processor->processConfiguration(new Configuration(), $configs);
$collection = 'in_memory';
switch (true) {
case 'redis' === $config['persistence']:
$loader->load('redis.xml');
$collection = 'predis';
$container->setParameter('qandidate.toggle.redis.namespace', $config['redis_namespace']);
$container->setAlias('qandidate.toggle.redis.client', $config['redis_client']);
break;
case 'factory' === $config['persistence']:
$collection = 'factory';
$definition = new DefinitionDecorator('qandidate.toggle.collection.in_memory');
$definition->setFactory(array(new Reference($config['collection_factory']['service_id']), $config['collection_factory']['method']));
$container->setDefinition('qandidate.toggle.collection.factory', $definition);
break;
}
$container->setAlias('qandidate.toggle.collection', 'qandidate.toggle.collection.' . $collection);
$contextFactoryService = 'qandidate.toggle.user_context_factory';
if (null !== $config['context_factory']) {
$contextFactoryService = $config['context_factory'];
}
$container->setAlias('qandidate.toggle.context_factory', $contextFactoryService);
}
示例12: createAuthProvider
/**
* Subclasses must return the id of a service which implements the
* AuthenticationProviderInterface.
*
* @param ContainerBuilder $container
* @param string $id The unique id of the firewall
* @param array $config The options array for this listener
* @param string $userProviderId The id of the user provider
*
* @return string never null, the id of the authentication provider
*/
protected function createAuthProvider(ContainerBuilder $container, $id, $config, $userProviderId)
{
$providerId = 'security.authentication.provider.appsco.' . $id;
$provider = new DefinitionDecorator('security.authentication.provider.appsco');
$provider->replaceArgument(0, new Reference($userProviderId));
$container->setDefinition($providerId, $provider);
return $providerId;
}
示例13: createAssetVersionStrategy
private function createAssetVersionStrategy($packageName, $versionStrategy)
{
$version = new DefinitionDecorator($this->namespaceService('asset.version_strategy'));
$version->addArgument($versionStrategy);
$versionId = $this->namespaceService("_package.{$packageName}.version_strategy_asset");
$this->container->setDefinition($versionId, $version);
return new Reference($versionId);
}
示例14: testMenu
public function testMenu()
{
$definition = new DefinitionDecorator('lug.ui.menu.builder');
$definition->setClass($class = $this->createMenuBuilderClassMock());
$this->container->setDefinition($menuName = 'lug.ui.menu.test', $definition);
$this->compileContainer();
$this->assertInstanceOf($class, $this->container->get($menuName));
}
示例15: registerPayloadResolver
private function registerPayloadResolver(ContainerBuilder $container)
{
$definition = new Definition(PayloadResolver::class);
$definition->setAbstract(true);
$container->setDefinition('request_object.payload_resolver', $definition);
$implDefinition = new DefinitionDecorator('request_object.payload_resolver');
$implDefinition->setClass(HttpPayloadResolver::class);
$container->setDefinition('request_object.payload_resolver.http', $implDefinition);
}