本文整理汇总了PHP中Symfony\Component\DependencyInjection\Definition::addMethodCall方法的典型用法代码示例。如果您正苦于以下问题:PHP Definition::addMethodCall方法的具体用法?PHP Definition::addMethodCall怎么用?PHP Definition::addMethodCall使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\DependencyInjection\Definition
的用法示例。
在下文中一共展示了Definition::addMethodCall方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getConnectionReference
/**
* @param string $name
* @param array $config
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
*
* @return \Symfony\Component\DependencyInjection\Reference
*/
private function getConnectionReference($name, array $config, ContainerBuilder $container)
{
if (isset($config['connection_id'])) {
return new Reference($config['connection_id']);
}
$host = $config['host'];
$port = $config['port'];
$connClass = '%doctrine_cache.redis.connection.class%';
$connId = sprintf('doctrine_cache.services.%s_redis.connection', $name);
$connDef = new Definition($connClass);
$connParams = array($host, $port);
if (isset($config['timeout'])) {
$connParams[] = $config['timeout'];
}
$connDef->setPublic(false);
$connDef->addMethodCall('connect', $connParams);
if (isset($config['password'])) {
$password = $config['password'];
$connDef->addMethodCall('auth', array($password));
}
if (isset($config['database'])) {
$database = (int) $config['database'];
$connDef->addMethodCall('select', array($database));
}
$container->setDefinition($connId, $connDef);
return new Reference($connId);
}
示例2: 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);
}
示例3: loadQueues
protected function loadQueues()
{
$qmDefinition = null;
if ($this->container->hasDefinition($this->queueManagerService)) {
$qmDefinition = $this->container->findDefinition($this->queueManagerService);
}
foreach ($this->config['queues'] as $key => $consumer) {
if (!isset($this->config['connections'][$consumer['connection']])) {
throw new \RuntimeException("SQS queue '{$key}' can not use connection '{$consumer['connection']}' because it is not defined in the connections section");
}
$pDefinition = new Definition('%kaliop_queueing.sqs.producer.class%', array($this->config['connections'][$consumer['connection']]));
$pDefinition->addMethodCall('setQueueUrl', array($consumer['queue_options']['name']));
$name = sprintf('kaliop_queueing.sqs.%s_producer', $key);
$this->container->setDefinition($name, $pDefinition);
$cDefinition = new Definition('%kaliop_queueing.sqs.consumer.class%', array($this->config['connections'][$consumer['connection']]));
$cDefinition->addMethodCall('setQueueUrl', array($consumer['queue_options']['name']))->addMethodCall('setCallback', array(new Reference($consumer['callback'])));
if (count($consumer['queue_options']['routing_keys'])) {
$cDefinition->addMethodCall('setRoutingKey', array(reset($consumer['queue_options']['routing_keys'])));
}
if ($consumer['queue_options']['max_messages_per_request'] > 1) {
$cDefinition->addMethodCall('setRequestBatchSize', array($consumer['queue_options']['max_messages_per_request']));
}
$name = sprintf('kaliop_queueing.sqs.%s_consumer', $key);
$this->container->setDefinition($name, $cDefinition);
//if (!$consumer['auto_setup_fabric']) {
// $definition->addMethodCall('disableAutoSetupFabric');
//}
if ($qmDefinition) {
$qmDefinition->addMethodCall('registerQueue', array($key));
}
}
}
示例4: createRpcServer
protected function createRpcServer($connection)
{
$rpcServer = new Definition('%rezzza_jobflow.rabbitmq.rpc_server.class%', array($connection));
$rpcServer->addMethodCall('initServer', array('jobflow'));
$rpcServer->addMethodCall('setCallback', array(new Reference('rezzza_jobflow.rabbitmq.worker')));
return $rpcServer;
}
示例5: testLoad
/**
* Check if load adds parameters to container as expected.
*
* @param array $parameters
* @param array $expectedConnections
* @param array $expectedManagers
*
* @dataProvider getData
*/
public function testLoad($parameters, $expectedConnections, $expectedManagers)
{
$container = new ContainerBuilder();
class_exists('testClass') ?: eval('class testClass {}');
$container->setParameter('kernel.bundles', ['testBundle' => 'testClass']);
$container->setParameter('kernel.cache_dir', '');
$container->setParameter('kernel.debug', true);
$extension = new ONGRElasticsearchExtension();
$extension->load($parameters, $container);
if ($parameters['elasticsearch']['managers']['test']['debug']) {
$reflection = new \ReflectionClass($this);
$dir = dirname($reflection->getFileName()) . DIRECTORY_SEPARATOR . 'customDir';
$handler = new Definition('ONGR\\ElasticsearchBundle\\Logger\\Handler\\CollectionHandler', []);
$logger = new Definition('Monolog\\Logger', ['tracer', [$handler]]);
$collector = new Definition('ONGR\\ElasticsearchBundle\\DataCollector\\ElasticsearchDataCollector');
$collector->addMethodCall('setManagers', [new Parameter('es.managers')]);
$collector->addMethodCall('addLogger', [new Reference('es.logger.trace')]);
$collector->addTag('data_collector', ['template' => 'ONGRElasticsearchBundle:Profiler:profiler.html.twig', 'id' => 'es']);
$this->assertEquals($collector, $container->getDefinition('es.collector'));
$this->assertEquals($logger, $container->getDefinition('es.logger.trace'));
$this->assertEquals(new DirectoryResource($dir), $container->getResources()[1]);
}
$this->assertEquals($expectedConnections, $container->getParameter('es.connections'), 'Incorrect connections parameter.');
$this->assertEquals($expectedManagers, $container->getParameter('es.managers'), 'Incorrect managers parameter');
$this->assertTrue($container->hasDefinition('es.metadata_collector'), 'Container should have MetadataCollector definition set.');
}
示例6: loadConsumers
protected function loadConsumers()
{
$qmDefinition = null;
if ($this->container->hasDefinition($this->queueManagerService)) {
$qmDefinition = $this->container->findDefinition($this->queueManagerService);
}
foreach ($this->config['consumers'] as $key => $consumer) {
if (!isset($this->config['connections'][$consumer['connection']])) {
throw new \RuntimeException("Stomp consumer '{$key}' can not use connection '{$consumer['connection']}' because it is not defined in the connections section");
}
$connectionDefinition = $this->config['connections'][$consumer['connection']];
$cDefinition = new Definition('%kaliop_queueing.stomp.consumer.class%', array($connectionDefinition));
$cDefinition->addMethodCall('setSubscriptionName', array($consumer['subscription_options']['name']))->addMethodCall('setStompQueueName', array($consumer['queue_options']['name']))->addMethodCall('setCallback', array(new Reference($consumer['callback'])));
if (count($consumer['subscription_options']['routing_keys'])) {
$cDefinition->addMethodCall('setRoutingKey', array(reset($consumer['subscription_options']['routing_keys'])));
}
$name = sprintf('kaliop_queueing.stomp.%s_consumer', $key);
$this->container->setDefinition($name, $cDefinition);
//if (!$consumer['auto_setup_fabric']) {
// $definition->addMethodCall('disableAutoSetupFabric');
//}
if ($qmDefinition) {
$qmDefinition->addMethodCall('registerConsumer', array($key));
}
}
}
示例7: 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)]);
}
}
示例8: applyDefaults
/**
* Apply the default values required by the AdminInterface to the Admin service definition
*
* @param \Symfony\Component\DependencyInjection\Definition $definition
* @param array $attributes
* @return \Symfony\Component\DependencyInjection\Definition
*/
public function applyDefaults(Definition $definition, array $attributes = array())
{
$definition->setScope(ContainerInterface::SCOPE_PROTOTYPE);
$manager_type = $attributes[0]['manager_type'];
if (!$definition->hasMethodCall('setModelManager')) {
$definition->addMethodCall('setModelManager', array(new Reference(sprintf('sonata.admin.manager.%s', $manager_type))));
}
if (!$definition->hasMethodCall('setFormContractor')) {
$definition->addMethodCall('setFormContractor', array(new Reference(sprintf('sonata.admin.builder.%s_form', $manager_type))));
}
if (!$definition->hasMethodCall('setListBuilder')) {
$definition->addMethodCall('setListBuilder', array(new Reference(sprintf('sonata.admin.builder.%s_list', $manager_type))));
}
if (!$definition->hasMethodCall('setDatagridBuilder')) {
$definition->addMethodCall('setDatagridBuilder', array(new Reference(sprintf('sonata.admin.builder.%s_datagrid', $manager_type))));
}
if (!$definition->hasMethodCall('setTranslator')) {
$definition->addMethodCall('setTranslator', array(new Reference('translator')));
}
if (!$definition->hasMethodCall('setConfigurationPool')) {
$definition->addMethodCall('setConfigurationPool', array(new Reference('sonata.admin.pool')));
}
if (!$definition->hasMethodCall('setRouter')) {
$definition->addMethodCall('setRouter', array(new Reference('router')));
}
if (!$definition->hasMethodCall('setLabel')) {
$label = isset($attributes[0]['label']) ? $attributes[0]['label'] : '-';
$definition->addMethodCall('setLabel', array($label));
}
$definition->addMethodCall('configure');
return $definition;
}
示例9: registerConnection
/**
* @param string $name
* @param array $config
* @param ContainerBuilder $container
*
* @return $this
*/
protected function registerConnection(ContainerBuilder $container, $config, $name = 'default')
{
$config += ['cache' => null, 'class' => 'Phppro\\Sdk\\Connection\\DefaultConnection'];
$def = new Definition($config['class'], [$config]);
$def->addMethodCall('setEventDispatcher', [new Reference('event_dispatcher')]);
switch ($config['cache']) {
case null:
case 'none':
break;
case 'memory':
$def->addMethodCall('setCache', [new Reference('sdk.cache.memory')]);
break;
case 'session':
$def->addMethodCall('setCache', [new Reference('sdk.cache.session')]);
break;
case 'redis':
$def->addMethodCall('setCache', [new Reference('sdk.cache.redis')]);
break;
default:
throw new InvalidConfigurationException(sprintf("Unsupported SDK cache type '%s'", $config['cache']), 500);
}
$def->addTag('sdk.connection', ['connection' => $name]);
$container->setDefinition('sdk.connection.' . $name, $def);
return $this;
}
示例10: load
/**
* {@inheritDoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$immutableProperties = array_merge($config['content_immutable_properties'], array('linkedToSite', 'deleted'));
$container->setParameter('open_orchestra_model.content.immutable_properties', $immutableProperties);
foreach ($config['fixtures_interface'] as $command => $content) {
$container->setParameter('open_orchestra_model.fixtures_interface.' . $command, $content);
}
$container->setParameter('open_orchestra_model.fixtures.command', array_keys($config['fixtures_interface']));
foreach ($config['document'] as $class => $content) {
if (is_array($content)) {
$container->setParameter('open_orchestra_model.document.' . $class . '.class', $content['class']);
if (array_key_exists('repository', $content)) {
$definition = new Definition($content['repository'], array($content['class']));
$definition->setFactory(array(new Reference('doctrine.odm.mongodb.document_manager'), 'getRepository'));
$definition->addMethodCall('setAggregationQueryBuilder', array(new Reference('doctrine_mongodb.odm.default_aggregation_query')));
if (method_exists($content['repository'], 'setFilterTypeManager')) {
$definition->addMethodCall('setFilterTypeManager', array(new Reference('open_orchestra_pagination.filter_type.manager')));
}
$container->setDefinition('open_orchestra_model.repository.' . $class, $definition);
}
}
}
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('listener.yml');
$loader->load('validator.yml');
$loader->load('manager.yml');
$loader->load('saver.yml');
$loader->load('form.yml');
$loader->load('transformer.yml');
$loader->load('helper.yml');
}
示例11: process
/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
{
foreach ($container->findTaggedServiceIds('snc_redis.connection_parameters') as $id => $attr) {
$clientAlias = $attr[0]['clientAlias'];
$parameterDefinition = $container->getDefinition($id);
$parameters = $parameterDefinition->getArgument(0);
if ($parameters['logging']) {
$optionId = sprintf('snc_redis.client.%s_options', $clientAlias);
$option = $container->getDefinition($optionId);
if (1 < count($option->getArguments())) {
throw new \RuntimeException('Please check the predis option arguments.');
}
$arguments = $option->getArgument(0);
$connectionFactoryId = sprintf('snc_redis.%s_connectionfactory', $clientAlias);
$connectionFactoryDef = new Definition($container->getParameter('snc_redis.connection_factory.class'));
$connectionFactoryDef->setPublic(false);
$connectionFactoryDef->addArgument(new Reference(sprintf('snc_redis.client.%s_profile', $clientAlias)));
$connectionFactoryDef->addMethodCall('setConnectionWrapperClass', array($container->getParameter('snc_redis.connection_wrapper.class')));
$connectionFactoryDef->addMethodCall('setLogger', array(new Reference('snc_redis.logger')));
$container->setDefinition($connectionFactoryId, $connectionFactoryDef);
$arguments['connections'] = new Reference($connectionFactoryId);
$option->replaceArgument(0, $arguments);
}
}
}
示例12: addConnection
/**
* @param Definition $definition
* @param string $id
* @param array $tags
*/
protected function addConnection(Definition $definition, $id, $tags)
{
$definition->addMethodCall('setRequestFactory', [new Reference('ms.rpc.request_factory')]);
$definition->addMethodCall('setResponseFactory', [new Reference('ms.rpc.response_factory')]);
$definition->addMethodCall('setSerializer', [new Reference('serializer')]);
$definition->setLazy(true);
}
示例13: load
public function load(array $configs, ContainerBuilder $container)
{
$loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.yml');
$config = array();
foreach ($configs as $subConfig) {
$config = array_merge($config, $subConfig);
}
foreach ($config['email'] as $alias => $options) {
$optionId = sprintf('rage_notification.email.%s.message', $alias);
$optionDef = new Definition($container->getParameter('rage_notification.email_message.class'));
$optionDef->setShared(false);
$optionDef->addArgument(new Reference('mailer'));
$optionDef->addArgument(new Reference('templating'));
if (!empty($options['from'])) {
$optionDef->addMethodCall('setFrom', [$options['from']]);
}
if (!empty($options['reply_to'])) {
$optionDef->addMethodCall('setReplyTo', [$options['reply_to']]);
}
if (!empty($options['embed_images'])) {
$optionDef->addMethodCall('setEmbedImages', [$options['embed_images']['url'], $options['embed_images']['path']]);
}
if (!empty($options['template_path'])) {
$optionDef->addMethodCall('setTemplatePath', [$options['template_path']]);
}
if (!empty($options['css_file'])) {
$optionDef->addMethodCall('setCssFile', [$options['css_file']]);
}
$container->setDefinition($optionId, $optionDef);
if ($alias === 'default') {
$container->setAlias('rage_notification.email.message', $optionId);
}
}
}
示例14: buildProcessorCollection
/**
* @param array $config config
*
* @return Definition
*/
private function buildProcessorCollection(ContainerBuilder $container)
{
$collection = new Definition('Dokapi\\Processor\\Collection');
if ($container->getParameter('dokapi.swagger.processors.raw_php')) {
$collection->addMethodCall('loadDefaultProcessors');
}
$processors = $container->getParameter('dokapi.swagger.processors.customs');
if ($container->getParameter('dokapi.swagger.processors.annotation')) {
$processors[] = 'Dokapi\\DokapiRest\\Processor\\Annotation\\ApiProcessor';
$processors[] = 'Dokapi\\DokapiRest\\Processor\\Annotation\\DataTypePropertyProcessor';
$processors[] = 'Dokapi\\DokapiRest\\Processor\\Annotation\\ModelProcessor';
$processors[] = 'Dokapi\\DokapiRest\\Processor\\Annotation\\OperationProcessor';
$processors[] = 'Dokapi\\DokapiRest\\Processor\\Annotation\\ResourceProcessor';
$processors[] = 'Dokapi\\DokapiRest\\Processor\\Annotation\\ResponseProcessor';
}
if ($container->getParameter('dokapi.swagger.processors.fos_rest')) {
if ($index = array_search('Dokapi\\DokapiRest\\Processor\\Annotation\\ResourceProcessor', $processors)) {
//conflicts with annotation for fos_rest integration.
unset($processors[$index]);
}
$processors[] = '@dokapi.fos_rest.processor.route';
}
if ($container->getParameter('dokapi.swagger.processor.api_distributor.enable')) {
$processors[] = '@dokapi.processor.api_distributor';
}
foreach ($processors as $processor) {
if (strpos($processor, '@') === 0) {
$processor = new Reference(substr($processor, 1));
} else {
$processor = new Definition($processor);
}
$collection->addMethodCall('add', array($processor));
}
return $collection;
}
示例15: loadRegistrationSubscriber
private function loadRegistrationSubscriber(ContainerBuilder $container, array $config)
{
$definition = new Definition();
if (array_key_exists('class', $config)) {
$definition->setClass($config['class']);
} else {
$definition->setClass('Tahoe\\Bundle\\MultiTenancyBundle\\EventSubscriber\\RegistrationSubscriber');
}
$definition->addTag('kernel.event_subscriber');
if (array_key_exists('manager', $config)) {
$definition->addArgument(new Reference($config['manager']));
} else {
$definition->addArgument(new Reference('tahoe.multi_tenancy.registration_manager'));
}
if (array_key_exists('router', $config)) {
$definition->addMethodCall('setRouter', array(new Reference($config['router'])));
} else {
$definition->addMethodCall('setRouter', array(new Reference('tahoe.multi_tenancy.tenant_aware_router')));
}
if (array_key_exists('redirect_route', $config)) {
$container->setParameter(sprintf("%s.registration_subscriber.redirect_route", $this->getAlias()), $config['redirect_route']);
} else {
// default parameter
$container->setParameter(sprintf("%s.registration_subscriber.redirect_route", $this->getAlias()), 'dashboard');
}
// we add the definition to the container
$container->setDefinition('tahoe.multi_tenancy.registration_subscriber', $definition);
}