本文整理匯總了PHP中Symfony\Component\DependencyInjection\DefinitionDecorator::setFactoryService方法的典型用法代碼示例。如果您正苦於以下問題:PHP DefinitionDecorator::setFactoryService方法的具體用法?PHP DefinitionDecorator::setFactoryService怎麽用?PHP DefinitionDecorator::setFactoryService使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Symfony\Component\DependencyInjection\DefinitionDecorator
的用法示例。
在下文中一共展示了DefinitionDecorator::setFactoryService方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: 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);
}
}
示例2: loadTypes
/**
* Loads the configured types.
*
* @param array $types
* @param ContainerBuilder $container
* @param array $indexConfig
*/
private function loadTypes(array $types, ContainerBuilder $container, array $indexConfig)
{
$indexableCallbacks = array();
foreach ($types as $name => $type) {
$indexName = $indexConfig['name'];
$typeId = sprintf('%s.%s', $indexConfig['reference'], $name);
$typeDef = new DefinitionDecorator('fos_elastica.type_prototype');
$typeDef->replaceArgument(0, $name);
$typeDef->setFactoryService($indexConfig['reference']);
$container->setDefinition($typeId, $typeDef);
$typeConfig = array('name' => $name, 'mapping' => array(), 'config' => array());
foreach (array('dynamic_templates', 'index_analyzer', 'properties', 'search_analyzer', '_all', '_boost', '_id', '_parent', '_routing', '_source', '_timestamp', '_ttl') as $field) {
if (isset($type[$field])) {
$typeConfig['mapping'][$field] = $type[$field];
}
}
foreach (array('persistence', 'serializer') as $field) {
$typeConfig['config'][$field] = array_key_exists($field, $type) ? $type[$field] : null;
}
$this->indexConfigs[$indexName]['types'][$name] = $typeConfig;
if (isset($type['persistence'])) {
$this->loadTypePersistenceIntegration($type['persistence'], $container, new Reference($typeId), $indexName, $name);
$typeConfig['persistence'] = $type['persistence'];
}
if (isset($type['indexable_callback'])) {
$indexableCallbacks[sprintf('%s/%s', $indexName, $name)] = $type['indexable_callback'];
}
if ($container->hasDefinition('fos_elastica.serializer_callback_prototype')) {
$typeSerializerId = sprintf('%s.serializer.callback', $typeId);
$typeSerializerDef = new DefinitionDecorator('fos_elastica.serializer_callback_prototype');
if (isset($type['serializer']['groups'])) {
$typeSerializerDef->addMethodCall('setGroups', array($type['serializer']['groups']));
}
if (isset($type['serializer']['version'])) {
$typeSerializerDef->addMethodCall('setVersion', array($type['serializer']['version']));
}
$typeDef->addMethodCall('setSerializer', array(array(new Reference($typeSerializerId), 'serialize')));
$container->setDefinition($typeSerializerId, $typeSerializerDef);
}
}
$indexable = $container->getDefinition('fos_elastica.indexable');
$indexable->replaceArgument(0, $indexableCallbacks);
}
示例3: generate
/**
* @throws \LogicException
*/
public function generate()
{
$pageflowAnnotation = $this->reader->getClassAnnotation($this->controllerClass, 'PHPMentors\\PageflowerBundle\\Annotation\\Pageflow');
if ($pageflowAnnotation === null) {
throw new \LogicException(sprintf('Annotation "%s" is not found in class "%s".', 'PHPMentors\\PageflowerBundle\\Annotation\\Pageflow', $this->controllerClass->getName()));
}
$pageflowBuilderDefinition = new DefinitionDecorator('phpmentors_pageflower.pageflow_builder');
$pageflowBuilderDefinition->setArguments(array($this->controllerServiceId));
$statesFound = false;
$transitionsFound = false;
foreach ($pageflowAnnotation->value as $annotation) {
if ($annotation instanceof States) {
if ($statesFound) {
throw new \LogicException(sprintf('Annotation "%s" must be specified only once.', get_class($annotation)));
}
$statesFound = true;
foreach ($annotation->value as $state) {
if ($state instanceof AnnotationInterface) {
if ($state->value === null || strlen($state->value) == 0) {
throw new \LogicException(sprintf('The value for annotation "%s" cannot be empty.', get_class($state)));
}
if ($state instanceof Start) {
$pageflowBuilderDefinition->addMethodCall('addState', array($state->value));
$pageflowBuilderDefinition->addMethodCall('setStartState', array($state->value));
$this->states[] = $state->value;
} elseif ($state instanceof End) {
$pageflowBuilderDefinition->addMethodCall('addState', array($state->value));
$pageflowBuilderDefinition->addMethodCall('setEndState', array($state->value, StateInterface::STATE_FINAL));
$this->states[] = $state->value;
} else {
throw new \LogicException(sprintf('State "%s" must be encapsulated with one of [ %s ], "%s" is specified.', $state->value, implode(', ', array('PHPMentors\\PageflowerBundle\\Annotation\\Start', 'PHPMentors\\PageflowerBundle\\Annotation\\End')), get_class($state)));
}
} else {
if ($state === null || strlen($state) == 0) {
throw new \LogicException(sprintf('The value for annotation "%s" cannot be empty.', get_class($annotation)));
}
$pageflowBuilderDefinition->addMethodCall('addState', array($state));
$this->states[] = $state;
}
}
} elseif ($annotation instanceof Transitions) {
if ($transitionsFound) {
throw new \LogicException(sprintf('Annotation "%s" must be specified only once.', get_class($annotation)));
}
$transitionsFound = true;
foreach ($annotation->value as $transition) {
if (is_array($transition) && count($transition) == 2 && is_string($transition[0]) && is_string($transition[1])) {
foreach (array($transition[0], $transition[1]) as $state) {
if ($state === null || strlen($state) == 0) {
throw new \LogicException(sprintf('The value for annotation "%s" cannot be empty.', get_class($annotation)));
}
if (!in_array($state, $this->states)) {
throw new \LogicException(sprintf('The value for annotation "%s" must be one of [ %s ], "%s" is specified.', get_class($annotation), implode(', ', $this->states), $state));
}
}
$pageflowBuilderDefinition->addMethodCall('addTransition', array($transition[0], $transition[1], $transition[1]));
} else {
throw new \LogicException(sprintf('The value for annotation "%s" must be string array, "%s" is specified.', get_class($annotation), var_export($transition, true)));
}
}
} else {
throw new \LogicException(sprintf('The value for annotation "%s" must be one of [ %s ], "%s" is specified.', get_class($pageflowAnnotation), implode(', ', array('"PHPMentors\\PageflowerBundle\\Annotation\\States"', '"PHPMentors\\PageflowerBundle\\Annotation\\Transitions"')), is_object($annotation) ? get_class($annotation) : $annotation));
}
}
$pageflowBuilderServiceId = 'phpmentors_pageflower.pageflow_builder.' . $this->controllerServiceId;
$this->container->setDefinition($pageflowBuilderServiceId, $pageflowBuilderDefinition);
$pageflowDefinition = new DefinitionDecorator('phpmentors_pageflower.pageflow');
$pageflowDefinition->setFactoryService($pageflowBuilderServiceId);
$pageflowServiceId = 'phpmentors_pageflower.pageflow.' . $this->controllerServiceId;
$this->container->setDefinition($pageflowServiceId, $pageflowDefinition);
$this->container->getDefinition('phpmentors_pageflower.pageflow_repository')->addMethodCall('add', array(new Reference($pageflowServiceId)));
$this->container->addClassResource($this->controllerClass);
}
示例4: registerExecutorConfiguration
/**
* @param array $config
* @param ContainerBuilder $container
* @param LoaderInterface $loader
*/
private function registerExecutorConfiguration(array $config, ContainerBuilder $container, LoaderInterface $loader)
{
$loader->load('executor.xml');
$defaultExecutor = isset($config['default']) ? $config['default'] : null;
foreach ($config['executorList'] as $name => $executorConf) {
$def = new DefinitionDecorator($executorConf['parent_service']);
$def->replaceArgument(0, $executorConf['server'])->replaceArgument(1, $executorConf['request_handler'])->replaceArgument(2, new Reference($executorConf['exception_handler_service']))->addTag(AddExecutorPass::TAG_NAME, array('default' => $name == $defaultExecutor, 'alias' => $name));
if (!empty($executorConf['use_factory'])) {
$def->setFactoryService(new Reference('syrma.web_container.executor.factory'));
$def->setFactoryMethod('create');
}
$container->setDefinition(sprintf('syrma.web_container.executor.dynamic.%s', $name), $def);
}
}
示例5: getProcessDefinition
/**
* @param string $builderName
* @param string $definitionName
* @return Definition
*/
protected function getProcessDefinition($builderName, $definitionName)
{
$process = new DefinitionDecorator('pmd_state_machine.process.definition');
$process->setFactoryService($builderName)->setFactoryMethod('getDefinition')->addTag('pmd_state_machine.definition', array('alias' => $definitionName));
return $process;
}