Le 15/06/2011 11:54, Oleg Stepura a écrit :
Hi!
There are some services marked as /synthetic /and some marked with
some "scope" (request service for example).
Here is the request service definition:
<!--
If you want to change the Request class, modify the code in
your front controller (app.php) so that it passes an
instance of
YourRequestClass to the Kernel.
This service definition only defines the scope of the request.
It is used to check references scope.
-->
<service id="request" scope="request" synthetic="true" />
When I try to use a "request" service from my own service which has
got a Service Container inside I receive an Exception:
You cannot create a service ("request") of an inactive scope
("request").
Ok, I digged into Service container source code and found some methods
for entering scope. But after I do
$this->container->enterScope('request');
$request = $this->container->get('request');
I get another exception:
You have requested a synthetic service ("request"). The DIC does not
know how to construct this service.
What are those service types and how to use it? Is there any
documentation anywhere for this?
The request service is defined and then compiled differently than the
usual service. Why is that?
For my use case - how can I receive a request object inside a service
but not inside a controller?
I do not need to redefine Request class, just need to receive a
request object.
Thanks in advance!
A synthetic service is a service that is injected in the container
instead of being created by the container. For instance, the request is
injected by the HttpKernel in the /handle/ method when entering the
request scope.
If you need to inject the request in your service, you need to define
the scope of your service to /request/ (a new instance is created for
sub-requests) or /prototype/ (a new instance is created each time you
get it). If you use the /container /scope (which is the default
behavior) the same instance is used each time you get the service. A
service cannot have a dependency of a narrower scope as the dependency
would need to be changed.
--
Christophe | Stof
--
If you want to report a vulnerability issue on symfony, please send it to
security at symfony-project.com
You received this message because you are subscribed to the Google
Groups "symfony developers" group.
To post to this group, send email to symfony-devs@googlegroups.com
To unsubscribe from this group, send email to
symfony-devs+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/symfony-devs?hl=en