E
E
Evgeny2017-09-24 13:08:18
symfony
Evgeny, 2017-09-24 13:08:18

How are services loaded in symfony?

Trying to figure out symfony3.3
in a cached container

%project_root%/var/cache/dev/appDevDebugProjectContainer.php

In the service creation method, I see the following code:
/**
     * Gets the public 'assets.context' shared service.
     *
     * @return \Symfony\Component\Asset\Context\RequestStackContext
     */
    protected function getAssets_ContextService()
    {
        return $this->services['assets.context'] = new \Symfony\Component\Asset\Context\RequestStackContext(${($_ = isset($this->services['request_stack']) ? $this->services['request_stack'] : $this->get('request_stack')) && false ?: '_'});
    }

confuses this part:
${($_ = isset($this->services['request_stack']) ? $this->services['request_stack'] : $this->get('request_stack')) && false ?: '_'}

it is not entirely clear how it works and why it is needed here, because in previous versions of symfony there was no such strange construction and instead it was just a question: why is this strange construction needed? Why can't you just write:$this->get('request_stack')
isset($this->services['request_stack']) ? $this->services['request_stack'] : $this->get('request_stack')

instead of
${($_ = isset($this->services['request_stack']) ? $this->services['request_stack'] : $this->get('request_stack')) && false ?: '_'}

?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
voronkovich, 2017-09-24
@jennik

A small correction - it's better to say "compiled" instead of "cached" container. The latter captures the essence better.
About the question. As far as I understand, for some reason, class names may contain the $ symbol when compiled, so the class name cannot be deduced in the usual way. See here: https://github.com/symfony/symfony/pull/19681/file...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question