本文整理汇总了PHP中Symfony\Component\DependencyInjection\ContainerBuilder::setAlias方法的典型用法代码示例。如果您正苦于以下问题:PHP ContainerBuilder::setAlias方法的具体用法?PHP ContainerBuilder::setAlias怎么用?PHP ContainerBuilder::setAlias使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\DependencyInjection\ContainerBuilder
的用法示例。
在下文中一共展示了ContainerBuilder::setAlias方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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('shorty.xml');
foreach ($config['providers'] as $providerName => $providerConfiguration) {
switch ($providerConfiguration['id']) {
case 'google':
$definition = new Definition($container->getParameter('rezzza.shorty.google.class'), array($providerConfiguration['key']));
$definition->addMethodCall('setHttpAdapter', array(new Definition($providerConfiguration['http_adapter'])));
$container->setDefinition($this->getShortyProviderName($providerName), $definition);
break;
case 'bitly':
$definition = new Definition($container->getParameter('rezzza.shorty.bitly.class'), array($providerConfiguration['access_token']));
$definition->addMethodCall('setHttpAdapter', array(new Definition($providerConfiguration['http_adapter'])));
$container->setDefinition($this->getShortyProviderName($providerName), $definition);
break;
case 'chain':
$definition = new Definition($container->getParameter('rezzza.shorty.chain.class'));
foreach ($providerConfiguration['providers'] as $provider) {
$definition->addMethodCall('addProvider', array(new Reference($this->getShortyProviderName($provider))));
}
$container->setDefinition($this->getShortyProviderName($providerName), $definition);
break;
default:
$container->setAlias($this->getShortyProviderName($providerName), $providerConfiguration['id']);
break;
}
}
if (isset($config['default_provider'])) {
$container->setAlias('rezzza.shorty', $this->getShortyProviderName($config['default_provider']));
}
}
示例2: process
public function process(ContainerBuilder $container)
{
$definitions = new \SplPriorityQueue();
$order = PHP_INT_MAX;
foreach ($container->getDefinitions() as $id => $definition) {
if (!($decorated = $definition->getDecoratedService())) {
continue;
}
$definitions->insert(array($id, $definition), array($decorated[2], --$order));
}
foreach ($definitions as list($id, $definition)) {
list($inner, $renamedId) = $definition->getDecoratedService();
$definition->setDecoratedService(null);
if (!$renamedId) {
$renamedId = $id . '.inner';
}
// we create a new alias/service for the service we are replacing
// to be able to reference it in the new one
if ($container->hasAlias($inner)) {
$alias = $container->getAlias($inner);
$public = $alias->isPublic();
$container->setAlias($renamedId, new Alias((string) $alias, false));
} else {
$definition = $container->getDefinition($inner);
$public = $definition->isPublic();
$definition->setPublic(false);
$container->setDefinition($renamedId, $definition);
}
$container->setAlias($inner, new Alias($id, $public));
}
}
示例3: 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'));
if (!in_array(strtolower($config['db_driver']), array('orm'))) {
throw new \InvalidArgumentException(sprintf('Invalid database driver (bait_poll.db_driver) "%s".', $config['db_driver']));
}
$loader->load(sprintf('%s.xml', $config['db_driver']));
$container->setParameter('bait_poll.model_manager_name', $config['model_manager_name']);
$container->setParameter('bait_poll.form.type', $config['form']['type']);
$container->setParameter('bait_poll.form.name', $config['form']['name']);
$container->setAlias('bait_poll.form.factory', $config['form']['factory']);
$container->setParameter('bait_poll.poll.class', $config['poll']['class']);
$container->setParameter('bait_poll.field.class', $config['field']['class']);
$container->setParameter('bait_poll.vote.class', $config['vote']['class']);
$container->setParameter('bait_poll.form.template', $config['form']['template']);
$container->setParameter('bait_poll.form.theme', $config['form']['theme']);
$container->setAlias('bait_poll.vote.manager', $config['vote']['manager']);
$container->setAlias('bait_poll.poll.manager', $config['poll']['manager']);
$loader->load('form.xml');
$container->setParameter('bait_poll.cookie.prefix', $config['cookie']['prefix']);
$container->setParameter('bait_poll.cookie.duration', $config['cookie']['duration']);
$loader->load('poll.xml');
}
示例4: process
public function process( ContainerBuilder $container )
{
if ( !$container->hasAlias( 'session.storage' ) )
{
return;
}
$sessionStorageAlias = $container->getAlias( 'session.storage' );
$sessionStorageProxyDef = $container->findDefinition( 'ezpublish_legacy.session_storage_proxy' );
$sessionStorageProxyDef->replaceArgument( 1, new Reference( (string)$sessionStorageAlias ) );
$container->setAlias( 'session.storage', 'ezpublish_legacy.session_storage_proxy' );
if ( $container->hasAlias( 'session.handler' ) )
{
$sessionHandlerAlias = $container->getAlias( 'session.handler' );
$interfaces = class_implements( $container->findDefinition( (string)$sessionHandlerAlias ) );
// Only swap session handler if it implements appropriate interface.
if ( isset( $interfaces['SessionHandlerInterface'] ) )
{
$sessionHandlerProxyDef = $container->findDefinition( 'ezpublish_legacy.session_handler_proxy' );
$sessionHandlerProxyDef->replaceArgument( 1, new Reference( (string)$sessionHandlerAlias ) );
$container->setAlias( 'session.handler', 'ezpublish_legacy.session_handler_proxy' );
}
}
}
示例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'));
foreach (array('services', 'form') as $service) {
$loader->load(sprintf('%s.xml', $service));
}
if ($config['service'] == 's3') {
$loader->load('s3.xml');
} else {
$loader->load('connector.xml');
}
switch ($config['service']) {
case 'php':
$container->setAlias('jonlil_ckfinder.connector', 'jonlil.ckfinder.connector.php');
break;
case 's3':
$container->setAlias('jonlil_ckfinder.connector', 'jonlil.ckfinder.connector.s3');
$container->setParameter('jonlil_ckfinder.amazon', array('secret' => $config['secret'], 'bucket' => $config['bucket'], 'access_key' => $config['accessKey'], 'base_url' => $config['baseUrl'], 'base_dir' => $config['baseDir'], 'thumbnails_file' => $config['thumbnailsFile'], 'thumbnails_enabled' => $config['thumbnailsEnabled'], 'direct_access' => $config['directAccess'], 'file_delete' => $config['fileDelete'], 'file_rename' => $config['fileRename'], 'file_upload' => $config['fileUpload'], 'file_view' => $config['fileView'], 'folder_delete' => $config['folderDelete'], 'folder_rename' => $config['folderRename'], 'folder_create' => $config['folderCreate'], 'folder_view' => $config['folderView']));
$container->setParameter('jonlil_ckfinder.baseDir', $config['baseDir']);
break;
}
$container->setParameter('jonlil_ckfinder.license', array('key' => $config['license']['key'], 'name' => $config['license']['name']));
$container->setParameter('jonlil_ckfinder.baseUrl', $config['baseUrl']);
$container->setParameter('twig.form.resources', array_merge($container->getParameter('twig.form.resources'), array('JonlilCKFinderBundle:Form:ckfinder_widget.html.twig')));
}
示例6: 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');
}
}
}
示例7: load
/**
* {@inheritDoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$prefix = self::PREFIX;
$container->setAlias($prefix . self::RECIPIENT_PROVIDER, $config[self::RECIPIENT_PROVIDER]);
$container->setParameter($prefix . self::RECIPIENT_CLASS, $config[self::RECIPIENT_CLASS]);
$container->setParameter($prefix . self::RECIPIENT_NEWSLETTER_FIELD, $config[self::RECIPIENT_NEWSLETTER_FIELD]);
$container->setAlias($prefix . self::TEMPLATE_PROVIDER, $config[self::TEMPLATE_PROVIDER]);
$container->setAlias($prefix . self::TEMPLATE_TWIG_SWIFT_MAILER, $config[self::TEMPLATE_TWIG_SWIFT_MAILER]);
$container->setParameter($prefix . 'no_reply', array('email' => $config[self::NO_REPLY][self::NO_REPLY_EMAIL_ADDRESS], 'name' => $config[self::NO_REPLY][self::NO_REPLY_EMAIL_NAME]));
$container->setParameter($prefix . self::TEMPLATE_IMAGE_DIR, realpath($config[self::TEMPLATE_IMAGE_DIR]));
$allowedFolders = array();
foreach ($config[self::ALLOWED_IMAGES_FOLDERS] as $folder) {
$allowedFolders[] = realpath($folder);
}
$container->setParameter($prefix . self::ALLOWED_IMAGES_FOLDERS, $allowedFolders);
$container->setAlias($prefix . self::NOTIFIER_SERVICE, $config[self::NOTIFIER_SERVICE]);
$container->setParameter($prefix . self::NEWSLETTER . "_" . self::NEWSLETTER_INTERVAL, $config[self::NEWSLETTER][self::NEWSLETTER_INTERVAL]);
$container->setParameter($prefix . self::NEWSLETTER . "_" . self::NEWSLETTER_SEND_TIME, $config[self::NEWSLETTER][self::NEWSLETTER_SEND_TIME]);
$container->setParameter($prefix . self::TEMPLATES . "_" . self::NEWSLETTER_TEMPLATE, $config[self::TEMPLATES][self::NEWSLETTER_TEMPLATE]);
$container->setParameter($prefix . self::TEMPLATES . "_" . self::NOTIFICATIONS_TEMPLATE, $config[self::TEMPLATES][self::NOTIFICATIONS_TEMPLATE]);
$container->setParameter($prefix . self::TEMPLATES . "_" . self::CONTENT_ITEM_TEMPLATE, $config[self::TEMPLATES][self::CONTENT_ITEM_TEMPLATE]);
$container->setParameter($prefix . self::CAMPAIGN_PARAM_NAME, $config[self::CAMPAIGN_PARAM_NAME]);
$container->setParameter($prefix . self::CAMPAIGN_KEYWORD_PARAM_NAME, $config[self::CAMPAIGN_KEYWORD_PARAM_NAME]);
$container->setAlias($prefix . self::WEB_VIEW_SERVICE, $config[self::WEB_VIEW_SERVICE]);
$container->setParameter($prefix . self::WEB_VIEW_RETENTION, $config[self::WEB_VIEW_RETENTION]);
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.yml');
}
示例8: load
/**
* Loads the configs for Cache and puts data into the container.
*
* @param array $configs Array of configs
* @param ContainerBuilder $container Container Object
*/
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.yml');
// Configure client services
$first = isset($config['providers']['default']) ? 'default' : null;
foreach ($config['providers'] as $name => $arguments) {
if ($first === null) {
$first = $name;
}
$factoryClass = $container->getDefinition($arguments['factory'])->getClass();
$factoryClass::validate($arguments['options'], $name);
// See if any option has a service reference
$arguments['options'] = $this->findReferences($arguments['options']);
$def = $container->register('cache.provider.' . $name, DummyAdapter::class);
$def->setFactory([new Reference($arguments['factory']), 'createAdapter'])->addArgument($arguments['options']);
$def->addTag('cache.provider');
foreach ($arguments['aliases'] as $alias) {
$container->setAlias($alias, 'cache.provider.' . $name);
}
}
if ($first !== null) {
$container->setAlias('cache', 'cache.provider.' . $first);
}
}
示例9: process
public function process(ContainerBuilder $container)
{
$viewReferenceManagers = $container->findTaggedServiceIds('view_reference.manager');
$viewReferenceRepositories = $container->findTaggedServiceIds('view_reference.repository');
$connectors = [];
$connectorType = $container->getParameter('victoire_view_reference.connector.type');
foreach ($viewReferenceManagers as $id => $tags) {
foreach ($tags as $attributes) {
$connectors[$attributes['connector']]['manager'] = $id;
}
}
foreach ($viewReferenceRepositories as $id => $tags) {
foreach ($tags as $attributes) {
$connectors[$attributes['connector']]['repository'] = $id;
}
}
if (!isset($connectorType)) {
throw new \Exception('No manager and repository found to have ' . $connectorType . ' connector.');
}
if (!isset($connectors[$connectorType]['manager'])) {
throw new \Exception('No manager found to have ' . $connectorType . ' connector.');
}
if (!isset($connectors[$connectorType]['repository'])) {
throw new \Exception('No repository found to have ' . $connectorType . ' connector.');
}
$container->setAlias('victoire_view_reference.connector.manager', $connectors[$connectorType]['manager']);
$container->setAlias('victoire_view_reference.connector.repository', $connectors[$connectorType]['repository']);
}
示例10: 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);
}
示例11: setUp
/**
* {@inheritdoc}
*/
public function setUp()
{
$this->container_builder = new ContainerBuilder();
$this->container_builder->register('foo', 'My/Class');
$this->container_builder->setAlias('bar', 'foo');
$this->dumper = new PhpArrayDumper($this->container_builder);
}
示例12: process
/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
{
$container->getDefinition('jms_serializer.json_serialization_visitor')->addArgument($container->getDefinition('json_api.metadata_factory'))->addArgument('%json_api.show_version_info%')->setClass('Mango\\Bundle\\JsonApiBundle\\Serializer\\JsonApiSerializationVisitor');
$container->setAlias('jms_serializer', 'json_api.serializer');
$container->setAlias('serializer', 'json_api.serializer');
$container->setAlias('fos_rest.serializer', 'json_api.serializer');
}
示例13: process
public function process(ContainerBuilder $container)
{
if ($container->has('fos_rest.serializer')) {
$class = $container->getParameterBag()->resolveValue($container->findDefinition('fos_rest.serializer')->getClass());
if (!is_subclass_of($class, 'FOS\\RestBundle\\Serializer\\Serializer')) {
throw new \InvalidArgumentException(sprintf('"fos_rest.serializer" must implement FOS\\RestBundle\\Serializer\\Serializer (instance of "%s" given).', $class));
}
return;
}
if (!$container->has('serializer') && !$container->has('jms_serializer.serializer')) {
throw new \InvalidArgumentException('Neither a service called "jms_serializer.serializer" nor "serializer" is available and no serializer is explicitly configured. You must either enable the JMSSerializerBundle, enable the FrameworkBundle serializer or configure a custom serializer.');
}
if ($container->has('serializer')) {
$class = $container->getParameterBag()->resolveValue($container->findDefinition('serializer')->getClass());
if (is_subclass_of($class, 'Symfony\\Component\\Serializer\\SerializerInterface')) {
$container->setAlias('fos_rest.serializer', 'fos_rest.serializer.symfony');
$container->removeDefinition('fos_rest.serializer.exception_wrapper_serialize_handler');
} elseif (is_subclass_of($class, 'JMS\\Serializer\\SerializerInterface')) {
$container->setAlias('fos_rest.serializer', 'fos_rest.serializer.jms');
} elseif (is_subclass_of($class, 'FOS\\RestBundle\\Serializer\\Serializer')) {
$container->setAlias('fos_rest.serializer', 'serializer');
} else {
throw new \InvalidArgumentException(sprintf('"fos_rest.serializer" must implement FOS\\RestBundle\\Serializer\\Serializer (instance of "%s" given).', $class));
}
return;
} else {
$container->removeDefinition('fos_rest.serializer.exception_wrapper_normalizer');
}
if ($container->has('jms_serializer.serializer')) {
$container->setAlias('fos_rest.serializer', 'fos_rest.serializer.jms');
} else {
$container->removeDefinition('fos_rest.serializer.exception_wrapper_serialize_handler');
}
}
示例14: process
public function process(ContainerBuilder $container)
{
// "query.max_query_count" is an array, it is only accessible
// through "query" node and getting the "max_query_count" array
// key with PHP.
$query = $container->getParameter('liip_functional_test.query');
if (null === $query['max_query_count']) {
$container->removeDefinition('liip_functional_test.query.count_client');
return;
}
if ($container->hasDefinition('test.client')) {
// test.client is a definition.
// Register it again as a private service to inject it as the parent
$definition = $container->getDefinition('test.client');
$definition->setPublic(false);
$container->setDefinition('liip_functional_test.query.count_client.parent', $definition);
} elseif ($container->hasAlias('test.client')) {
// test.client is an alias.
// Register a private alias for this service to inject it as the parent
$container->setAlias('liip_functional_test.query.count_client.parent', new Alias((string) $container->getAlias('test.client'), false));
} else {
throw new \Exception('The LiipFunctionalTestBundle\'s Query Counter can only be used in the test environment.' . PHP_EOL . 'See https://github.com/liip/LiipFunctionalTestBundle#only-in-test-environment');
}
$container->setAlias('test.client', 'liip_functional_test.query.count_client');
}
示例15: 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('commands.xml');
$loader->load('controllers.xml');
$loader->load('form-handlers.xml');
$loader->load('form-subscribers.xml');
$loader->load('form-types.xml');
$loader->load('forms.xml');
$loader->load('handlers.xml');
$loader->load('jobs.xml');
$loader->load('services.xml');
if (!in_array(strtolower($config['db_driver']), ['mongodb', 'orm'])) {
throw new \InvalidArgumentException(sprintf('Invalid db driver "%s".', $config['db_driver']));
}
$loader->load('db_driver/' . sprintf('%s.xml', $config['db_driver']));
$container->setAlias($this->getAlias() . '.manager.job_configuration', $config['job_configuration_manager']);
$container->setAlias($this->getAlias() . '.manager.job_report', $config['job_report_manager']);
$container->setParameter($this->getAlias() . '.model.job_configuration.class', $config['class']['model']['job_configuration']);
$container->setParameter($this->getAlias() . '.model.job_report.class', $config['class']['model']['job_report']);
$container->setParameter($this->getAlias() . '.queues', $config['queues']);
$container->setParameter($this->getAlias() . '.reset.timeout', $config['reset']['timeout']);
}