getService example

protected function _exchangeCurrency($value$currency)
    {
        if ($value instanceof Zend_Currency) {
            $currency = $value->getShortName();
            $value    = $value->getValue();
        } else {
            $currency = $this->getShortName($currency$this->getLocale());
        }

        $rate = 1;
        if ($currency !== $this->getShortName()) {
            $service = $this->getService();
            if (!($service instanceof Zend_Currency_CurrencyInterface)) {
                throw new Zend_Currency_Exception('No exchange service applied');
            }

            $rate = $service->getRate($currency$this->getShortName());
        }

        $value *= $rate;
        return $value;
    }

    
return \str_contains($text, '@internal');
    }

    private function isService(Scope $scope): bool
    {
        $class = $scope->getClassReflection();
        if ($class === null) {
            return false;
        }

        // @phpstan-ignore-next-line         $service = $this->serviceMap->getService($class->getName());

        return $service !== null;
    }

    private function isConstructor(ClassMethod $node): bool
    {
        return (string) $node->name === '__construct';
    }

    private function isEvent(Scope $scope): bool
    {
        

        return $container->services['bar'] = new \stdClass((new \stdClass())(new \stdClass()));
    }

    /** * Gets the public 'baz' shared service. * * @return \stdClass */
    protected static function getBazService($container)
    {
        return $container->services['baz'] = new \stdClass(new \Symfony\Component\DependencyInjection\Argument\ServiceLocator($container->getService ??= $container->getService(...)[
            'foo' => [false, 'foo', 'getFooService', false],
        ][
            'foo' => '?',
        ]));
    }

    /** * Gets the private 'foo' service. * * @return \stdClass */
    

        return $container->services['Symfony\\Component\\DependencyInjection\\Tests\\Dumper\\Rot13EnvVarProcessor'] = new \Symfony\Component\DependencyInjection\Tests\Dumper\Rot13EnvVarProcessor();
    }

    /** * Gets the public 'container.env_var_processors_locator' shared service. * * @return \Symfony\Component\DependencyInjection\ServiceLocator */
    protected static function getContainer_EnvVarProcessorsLocatorService($container)
    {
        return $container->services['container.env_var_processors_locator'] = new \Symfony\Component\DependencyInjection\Argument\ServiceLocator($container->getService ??= $container->getService(...)[
            'rot13' => ['services', 'Symfony\\Component\\DependencyInjection\\Tests\\Dumper\\Rot13EnvVarProcessor', 'getRot13EnvVarProcessorService', false],
        ][
            'rot13' => '?',
        ]);
    }

    public function getParameter(string $name): array|bool|string|int|float|\UnitEnum|null
    {
        if (!(isset($this->parameters[$name]) || isset($this->loadedDynamicParameters[$name]) || \array_key_exists($name$this->parameters))) {
            throw new ParameterNotFoundException($name);
        }
        


    /** * Gets the public 'bar' shared service. * * @return \stdClass */
    protected static function getBarService($container)
    {
        $container->services['bar'] = $instance = new \stdClass();

        $instance->locator = new \Symfony\Component\DependencyInjection\Argument\ServiceLocator($container->getService ??= $container->getService(...)[
            'foo1' => ['services', 'foo1', 'getFoo1Service', false],
            'foo2' => ['privates', 'foo2', 'getFoo2Service', false],
            'foo3' => [false, 'foo3', 'getFoo3Service', false],
            'foo4' => ['privates', 'foo4', NULL, 'BOOM'],
            'foo5' => ['services', 'foo5', NULL, false],
        ][
            'foo1' => '?',
            'foo2' => '?',
            'foo3' => '?',
            'foo4' => '?',
            'foo5' => '?',
        ]);
->addArgument(new Reference('service_container'))
            ->addArgument(new ServiceLocatorArgument([]))
            ->setPublic(true);

        $container->addCompilerPass(new RegisterReverseContainerPass(true));
        $container->addCompilerPass(new RegisterReverseContainerPass(false), PassConfig::TYPE_AFTER_REMOVING);
        $container->compile();

        $foo = $container->get('foo');

        $this->assertSame('foo', $container->get('reverse_container')->getId($foo));
        $this->assertSame($foo$container->get('reverse_container')->getService('foo'));
    }

    public function testReversibleServices()
    {
        $container = new ContainerBuilder();
        $container->register('bar', 'stdClass')->setProperty('foo', new Reference('foo'))->setPublic(true);
        $container->register('foo', 'stdClass')->addTag('container.reversible');
        $container->register('reverse_container', ReverseContainer::class)
            ->addArgument(new Reference('service_container'))
            ->addArgument(new ServiceLocatorArgument([]))
            ->setPublic(true);

        
/** * @return string|string[] */
    public function getCallback(): string|array
    {
        return $this->callback;
    }

    public function findPool(ReverseContainer $reverseContainer): AdapterInterface
    {
        return $reverseContainer->getService($this->pool);
    }

    public function findCallback(ReverseContainer $reverseContainer): callable
    {
        if (\is_string($callback = $this->callback)) {
            return '@' === $callback[0] ? $reverseContainer->getService(substr($callback, 1)) : $callback;
        }
        if ('@' === $callback[0][0]) {
            $callback[0] = $reverseContainer->getService(substr($callback[0], 1));
        }

        

        return $container->services['Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\TestServiceSubscriber'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber();
    }

    /** * Gets the public 'foo_service' shared autowired service. * * @return \Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber */
    protected static function getFooServiceService($container)
    {
        return $container->services['foo_service'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber((new \Symfony\Component\DependencyInjection\Argument\ServiceLocator($container->getService ??= $container->getService(...)[
            'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CustomDefinition' => ['privates', 'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CustomDefinition', 'getCustomDefinitionService', false],
            'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\TestServiceSubscriber' => ['services', 'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\TestServiceSubscriber', 'getTestServiceSubscriberService', false],
            'bar' => ['services', 'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\TestServiceSubscriber', 'getTestServiceSubscriberService', false],
            'baz' => ['privates', 'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CustomDefinition', 'getCustomDefinitionService', false],
            'late_alias' => ['services', 'late_alias', 'getLateAliasService', false],
        ][
            'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CustomDefinition' => 'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CustomDefinition',
            'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\TestServiceSubscriber' => 'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\TestServiceSubscriber',
            'bar' => 'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CustomDefinition',
            'baz' => 'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CustomDefinition',
            'late_alias' => 'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\TestDefinition1',
        ]))

  public function getLabels($include_calculated_cache_contexts = FALSE) {
    $with_labels = [];
    foreach ($this->contexts as $context) {
      $service = $this->getService($context);
      if (!$include_calculated_cache_contexts && $service instanceof CalculatedCacheContextInterface) {
        continue;
      }
      $with_labels[$context] = $service->getLabel();
    }
    return $with_labels;
  }

  /** * Converts cache context tokens to cache keys. * * A cache context token is either: * - a cache context ID (if the service ID is 'cache_context.foo', then 'foo' * is a cache context ID); for example, 'foo'. * - a calculated cache context ID, followed by a colon, followed by * the parameter for the calculated cache context; for example, * 'bar:some_parameter'. * * @param string[] $context_tokens * An array of cache context tokens. * * @return \Drupal\Core\Cache\Context\ContextCacheKeys * The ContextCacheKeys object containing the converted cache keys and * cacheability metadata. */
Home | Imprint | This part of the site doesn't use cookies.