WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru Самая быстрая Тема-конструктор для WordPress
функция не описана

YoastSEO_Vendor\Symfony\Component\DependencyInjection

Container::get() public Yoast 1.0

Gets a service.

If a service is defined both through a set() method and with a get{$id}Service() method, the former has always precedence.

Это метод класса: Container{}

Хуков нет.

Возвращает

Объект. The associated service

Использование

$Container = new Container();
$Container->get( $id, $invalidBehavior );
$id(строка) (обязательный)
The service identifier
$invalidBehavior(число)
The behavior when the service does not exist
По умолчанию: 1

Заметки

  • Смотрите: Reference

Код Container::get() Yoast 15.1.1

<?php
public function get($id, $invalidBehavior = 1)
{
    // Attempt to retrieve the service by checking first aliases then
    // available services. Service IDs are case insensitive, however since
    // this method can be called thousands of times during a request, avoid
    // calling $this->normalizeId($id) unless necessary.
    for ($i = 2;;) {
        if (isset($this->privates[$id])) {
            @\trigger_error(\sprintf('The "%s" service is private, getting it from the container is deprecated since Symfony 3.2 and will fail in 4.0. You should either make the service public, or stop using the container directly and use dependency injection instead.', $id), \E_USER_DEPRECATED);
        }
        if (isset($this->aliases[$id])) {
            $id = $this->aliases[$id];
        }
        // Re-use shared service instance if it exists.
        if (isset($this->services[$id])) {
            return $this->services[$id];
        }
        if ('service_container' === $id) {
            return $this;
        }
        if (isset($this->loading[$id])) {
            throw new \YoastSEO_Vendor\Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException($id, \array_merge(\array_keys($this->loading), [$id]));
        }
        $this->loading[$id] = \true;
        try {
            if (isset($this->fileMap[$id])) {
                return 4 === $invalidBehavior ? null : $this->load($this->fileMap[$id]);
            } elseif (isset($this->methodMap[$id])) {
                return 4 === $invalidBehavior ? null : $this->{$this->methodMap[$id]}();
            } elseif (--$i && $id !== ($normalizedId = $this->normalizeId($id))) {
                unset($this->loading[$id]);
                $id = $normalizedId;
                continue;
            } elseif (!$this->methodMap && !$this instanceof \YoastSEO_Vendor\Symfony\Component\DependencyInjection\ContainerBuilder && __CLASS__ !== static::class && \method_exists($this, $method = 'get' . \strtr($id, $this->underscoreMap) . 'Service')) {
                // We only check the convention-based factory in a compiled container (i.e. a child class other than a ContainerBuilder,
                // and only when the dumper has not generated the method map (otherwise the method map is considered to be fully populated by the dumper)
                @\trigger_error('Generating a dumped container without populating the method map is deprecated since Symfony 3.2 and will be unsupported in 4.0. Update your dumper to generate the method map.', \E_USER_DEPRECATED);
                return 4 === $invalidBehavior ? null : $this->{$method}();
            }
            break;
        } catch (\Exception $e) {
            unset($this->services[$id]);
            throw $e;
        } finally {
            unset($this->loading[$id]);
        }
    }
    if (1 === $invalidBehavior) {
        if (!$id) {
            throw new \YoastSEO_Vendor\Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException($id);
        }
        if (isset($this->syntheticIds[$id])) {
            throw new \YoastSEO_Vendor\Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException($id, null, null, [], \sprintf('The "%s" service is synthetic, it needs to be set at boot time before it can be used.', $id));
        }
        if (isset($this->getRemovedIds()[$id])) {
            throw new \YoastSEO_Vendor\Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException($id, null, null, [], \sprintf('The "%s" service or alias has been removed or inlined when the container was compiled. You should either make it public, or stop using the container directly and use dependency injection instead.', $id));
        }
        $alternatives = [];
        foreach ($this->getServiceIds() as $knownId) {
            $lev = \levenshtein($id, $knownId);
            if ($lev <= \strlen($id) / 3 || \false !== \strpos($knownId, $id)) {
                $alternatives[] = $knownId;
            }
        }
        throw new \YoastSEO_Vendor\Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException($id, null, null, $alternatives);
    }
}