本文整理汇总了PHP中Symfony\Component\DependencyInjection\ContainerBuilder::hasAlias方法的典型用法代码示例。如果您正苦于以下问题:PHP ContainerBuilder::hasAlias方法的具体用法?PHP ContainerBuilder::hasAlias怎么用?PHP ContainerBuilder::hasAlias使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\DependencyInjection\ContainerBuilder
的用法示例。
在下文中一共展示了ContainerBuilder::hasAlias方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: definitionClass
/**
* @param string $id
* @return string
*/
public function definitionClass(string $id) : string
{
if ($this->builder->hasAlias($id)) {
return $this->builder->getDefinition((string) $this->builder->getAlias($id))->getClass()->getClass();
}
return $this->builder->getDefinition($id)->getClass();
}
示例2: process
/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
{
if ($container->hasParameter('default_backend')) {
$default_backend = $container->getParameter('default_backend');
// Opt out from the default backend.
if (!$default_backend) {
return;
}
} else {
try {
$default_backend = $container->get('database')->driver();
$container->set('database', NULL);
} catch (\Exception $e) {
// If Drupal is not installed or a test doesn't define database there
// is nothing to override.
return;
}
}
foreach ($container->findTaggedServiceIds('backend_overridable') as $id => $attributes) {
// If the service is already an alias it is not the original backend, so
// we don't want to fallback to other storages any longer.
if ($container->hasAlias($id)) {
continue;
}
if ($container->hasDefinition("{$default_backend}.{$id}") || $container->hasAlias("{$default_backend}.{$id}")) {
$container->setAlias($id, new Alias("{$default_backend}.{$id}"));
}
}
}
示例3: process
public function process(ContainerBuilder $container)
{
// Cache warmer does more harm than good with Drupal.
if ($container->hasDefinition('cache_warmer')) {
$container->removeDefinition('cache_warmer');
}
if ($container->hasAlias('cache_warmer')) {
$container->removeAlias('cache_warmer');
}
// When not working with symfony, we need to provide a file locator
// service of our own instead of the symfony's one
if (!$container->hasDefinition('file_locator') && !$container->hasAlias('file_locator')) {
$container->addDefinitions(['file_locator' => (new Definition())->setClass(CustomFileLocator::class)->addArgument(new Reference('kernel'))]);
} else {
// We are working with fullstack, and our users might have changed
// the global resource directory to somewhere safer than Drupal's
// sites/SITE folder, case in which we must honnor the user's
// configuration
$definition = $container->getDefinition('file_locator');
$definition->setArguments([new Reference('kernel'), $container->getParameter('kernel.root_dir') . '/Resources']);
}
// By registering the framework bundle, we also inherit from Symfony
// default URL generator, which will cause us great pain because of
// Drupal routes will not be known by the framework and throw a few
// exceptions.
if ($container->has('router.default')) {
$container->getDefinition('router.default')->setClass('MakinaCorpus\\Drupal\\Sf\\Routing\\Router');
}
// When NOT in fullstack mode, we need to provide a null implementation
// for the controller resolver service, else the container will be
// unable to spawn the http kernel service
if (!$container->has('controller_resolver')) {
$container->addDefinitions(['controller_resolver' => (new Definition())->setClass('controller_resolver')]);
}
}
示例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: testNoDefaultPheanstalk
public function testNoDefaultPheanstalk()
{
$config = ['leezy_pheanstalk' => ['pheanstalks' => ['primary' => ['server' => 'beanstalkd.domain.tld', 'port' => 11300, 'timeout' => 60]]]];
$this->extension->load($config, $this->container);
$this->container->compile();
$this->assertTrue($this->container->hasDefinition('leezy.pheanstalk.primary'));
$this->assertFalse($this->container->hasAlias('leezy.pheanstalk'));
}
示例6: process
/**
* {@inheritDoc}
*/
public function process(ContainerBuilder $container)
{
$handlers = $container->getParameter('monolog.swift_mailer.handlers');
foreach ($handlers as $id) {
$definition = $container->getDefinition($id);
if ($container->hasAlias('swiftmailer.transport.real') || $container->hasDefinition('swiftmailer.transport.real')) {
$definition->addMethodCall('setTransport', array(new Reference('swiftmailer.transport.real')));
} elseif ($container->hasAlias('swiftmailer.transport') || $container->hasDefinition('swiftmailer.transport')) {
$definition->addMethodCall('setTransport', array(new Reference('swiftmailer.transport')));
}
}
}
示例7: testCreateClients
public function testCreateClients()
{
$config = array('zeichen32_git_lab_api' => array('clients' => array('firstclient' => array('token' => '12345', 'url' => 'http://example.org/api/v3/'), 'secondclient' => array('token' => '12345', 'url' => 'http://example.com/api/v3/'))));
$this->extension->load($config, $this->container);
$this->assertTrue($this->container->hasAlias('zeichen32_gitlabapi.client.default'));
$this->assertTrue($this->container->has('gitlab_api'));
$this->assertTrue($this->container->has('zeichen32_gitlabapi.client.firstclient'));
$this->assertTrue($this->container->has('zeichen32_gitlabapi.client.secondclient'));
$this->assertInstanceOf('Gitlab\\Client', $this->container->get('zeichen32_gitlabapi.client.default'));
$this->assertInstanceOf('Gitlab\\Client', $this->container->get('zeichen32_gitlabapi.client.firstclient'));
$this->assertInstanceOf('Gitlab\\Client', $this->container->get('zeichen32_gitlabapi.client.secondclient'));
$this->assertNotSame($this->container->get('zeichen32_gitlabapi.client.firstclient'), $this->container->get('zeichen32_gitlabapi.client.secondclient'));
}
示例8: process
/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
{
if (!($container->hasDefinition($this->queueEngineService) || !$container->hasAlias($this->queueEngineService)) && !($container->hasDefinition($this->dispatcherService) || $container->hasAlias($this->dispatcherService))) {
return;
}
$dispatcher = $container->getDefinition($this->dispatcherService);
foreach ($container->findTaggedServiceIds($this->jobTag) as $id => $tags) {
foreach ($tags as $tag) {
// workaround
$dispatcher->addMethodCall('addListenerService', array($tag['type'], array($this->queueEngineService, 'process')));
}
}
}
示例9: process
public function process(ContainerBuilder $container)
{
if (!$container->hasAlias('logger') || !$container->hasAlias('translator')) {
return;
}
if ($container->hasParameter('translator.logging') && $container->getParameter('translator.logging')) {
$translatorAlias = $container->getAlias('translator');
$definition = $container->getDefinition((string) $translatorAlias);
$class = $container->getParameterBag()->resolveValue($definition->getClass());
if (is_subclass_of($class, 'Symfony\\Component\\Translation\\TranslatorInterface') && is_subclass_of($class, 'Symfony\\Component\\Translation\\TranslatorBagInterface')) {
$container->getDefinition('translator.logging')->setDecoratedService('translator');
$container->getDefinition('translation.warmer')->replaceArgument(0, new Reference('translator.logging.inner'));
}
}
}
示例10: process
public function process(ContainerBuilder $container)
{
if (!$container->hasAlias('logger') || !$container->hasAlias('translator')) {
return;
}
if ($container->getParameter('translator.logging')) {
$translatorAlias = $container->getAlias('translator');
$definition = $container->getDefinition((string) $translatorAlias);
$class = $container->getParameterBag()->resolveValue($definition->getClass());
$refClass = new \ReflectionClass($class);
if ($refClass->implementsInterface('Symfony\\Component\\Translation\\TranslatorInterface') && $refClass->implementsInterface('Symfony\\Component\\Translation\\TranslatorBagInterface')) {
$container->getDefinition('translator.logging')->setDecoratedService('translator');
}
}
}
示例11: setDefinition
/**
* @param ContainerBuilder $container
* @param $serviceName
* @param $className
* @return $this
*/
protected function setDefinition(ContainerBuilder $container, $serviceName, $className)
{
if (!$container->hasDefinition($serviceName) && !$container->hasAlias($serviceName)) {
$container->setDefinition($serviceName, new Definition($className));
}
return $this;
}
示例12: process
public function process(ContainerBuilder $container)
{
$clearSpoolsId = 'long_running.swift_mailer.clear_spools';
if (!$container->has($clearSpoolsId)) {
return;
}
if (!$container->hasAlias('swiftmailer.mailer') || $container->getParameter('swiftmailer.mailers') === []) {
return;
}
$spoolServiceReferences = [];
$realTransportServiceReferences = [];
$mailers = $container->getParameter('swiftmailer.mailers');
foreach ($mailers as $name => $mailer) {
if ($container->getParameter(sprintf('swiftmailer.mailer.%s.spool.enabled', $name))) {
$transport = sprintf('swiftmailer.mailer.%s.transport', $name);
$transportDefinition = $container->findDefinition($transport);
if (is_a($transportDefinition->getClass(), 'Swift_Transport_SpoolTransport', true)) {
$spool = sprintf('swiftmailer.mailer.%s.spool', $name);
$spoolDefinition = $container->findDefinition($spool);
if (is_a($spoolDefinition->getClass(), 'Swift_MemorySpool', true)) {
$realTransport = sprintf('swiftmailer.mailer.%s.transport.real', $name);
$spoolServiceReferences[$name] = new Reference($spool);
$realTransportServiceReferences[$name] = new Reference($realTransport);
}
}
}
}
$definition = $container->getDefinition($clearSpoolsId);
$definition->replaceArgument(0, $spoolServiceReferences);
$definition->replaceArgument(1, $realTransportServiceReferences);
}
示例13: 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');
}
示例14: process
/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
{
$tags = $container->findTaggedServiceIds($this->tagName);
foreach ($tags as $id => $tag) {
/** @var Definition $serviceLinkDef */
$serviceLinkDef = $container->getDefinition($id);
if (!isset($tag[0]['service'])) {
throw new InvalidArgumentException(sprintf('Tag "%s" for service "%s" does not have required param "service"', $this->tagName, $id));
}
$serviceId = $tag[0]['service'];
$isOptional = false;
if (strpos($serviceId, '?') === 0) {
$serviceId = substr($serviceId, 1);
$isOptional = true;
}
if ($container->hasDefinition($serviceId)) {
// the service we are referring to must be public
$serviceDef = $container->getDefinition($serviceId);
if (!$serviceDef->isPublic()) {
$serviceDef->setPublic(true);
}
} elseif ($container->hasAlias($serviceId)) {
// the service alias we are referring to must be public
$serviceAlias = $container->getAlias($serviceId);
if (!$serviceAlias->isPublic()) {
$serviceAlias->setPublic(true);
}
} elseif (!$isOptional) {
throw new InvalidArgumentException(sprintf('Target service "%s" is undefined. The service link "%s" with tag "%s" and tag-service "%s"', $serviceId, $id, $this->tagName, $serviceId));
}
$serviceLinkDef->setClass($this->decoratorClass)->setPublic(false)->setArguments([new Reference('service_container'), $serviceId, $isOptional]);
}
}
示例15: process
/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
{
$tags = $container->findTaggedServiceIds(self::TAG_NAME);
foreach ($tags as $id => $tag) {
/** @var Definition $serviceLinkDef */
$serviceLinkDef = $container->getDefinition($id);
if (!isset($tag[0]['service'])) {
throw new RuntimeException(sprintf('Tag "%s" for service "%s" does not have required param "service"', self::TAG_NAME, $id));
}
$serviceId = $tag[0]['service'];
$isOptional = false;
if (strpos($serviceId, '?') === 0) {
$serviceId = substr($serviceId, 1);
$isOptional = true;
}
if ($container->hasDefinition($serviceId)) {
// the service we are referring to must be public
$serviceDef = $container->getDefinition($serviceId);
if (!$serviceDef->isPublic()) {
$serviceDef->setPublic(true);
}
} elseif ($container->hasAlias($serviceId)) {
// the service alias we are referring to must be public
$serviceAlias = $container->getAlias($serviceId);
if (!$serviceAlias->isPublic()) {
$serviceAlias->setPublic(true);
}
} elseif (!$isOptional) {
throw new RuntimeException(sprintf('Target service "%s" is undefined. The service link "%s" with tag "%s" and tag-service "%s"', $serviceId, $id, self::TAG_NAME, $serviceId));
}
$serviceLinkDef->setClass('Oro\\Bundle\\EntityConfigBundle\\DependencyInjection\\Utils\\ServiceLink')->setPublic(false)->setArguments([new Reference('service_container'), $serviceId, $isOptional]);
}
}