user2143356
user2143356

Reputation: 5607

Working out how to configure specific services.yml values - Symfony2

I'm trying to extend this class:

Symfony\Component\Security\Http\RememberMe\AbstractRememberMeServices

...and I need to also pass in some additional variables. This means I need to call the _construct of the above AbstractRememberMeServices class (parent:_construct from the new class), but I can't see where I can get all the variables from.

This is the __construct:

public function __construct(array $userProviders, $key, $providerKey, array $options = array(), LoggerInterface $logger = null)
{
    if (empty($key)) {
        throw new \InvalidArgumentException('$key must not be empty.');
    }
    if (empty($providerKey)) {
        throw new \InvalidArgumentException('$providerKey must not be empty.');
    }
    if (0 === count($userProviders)) {
        throw new \InvalidArgumentException('You must provide at least one user provider.');
    }

    $this->userProviders = $userProviders;
    $this->key = $key;
    $this->providerKey = $providerKey;
    $this->options = $options;
    $this->logger = $logger;
}

I can work out one of them, but where do I get the rest? As these are normally automatically set then surely I can just use those rather than set them again manually.

services.yml:

arguments:
  - 
  -
  -
  -
  - @logger

Upvotes: 2

Views: 1507

Answers (1)

Nicolai Fröhlich
Nicolai Fröhlich

Reputation: 52493

You can define a parent service for your extending service and you don't have to worry about the original arguments of the constructor as they will be inherited.

parameters:
    newsletter_manager.class: NewsletterManager

services:
    newsletter_manager:
        class:     "%newsletter_manager.class%"
        parent: mail_manager
        calls:
            - [setMailer, ["@my_alternative_mailer"]]

Then extend with setter injection as i mentioned over here.

Now you just have to find out the service name of AbstractRememberMeServices by doing a in-file text search in your vendor folder which will point you to an xml containing the service definition and the service name ;)

EDIT:

Okay i'll give you a hint ... vendor\symfony\symfony\src\Symfony\Bundle\SecurityBundle\Resources\config\security_rememberme.xml

Here's the service definition:

<services>
    <service id="security.authentication.listener.rememberme" class="%security.authentication.listener.rememberme.class%" public="false" abstract="true">
        <tag name="monolog.logger" channel="security" />
        <argument type="service" id="security.context" />
        <argument type="service" id="security.authentication.rememberme" />
        <argument type="service" id="security.authentication.manager" />
        <argument type="service" id="logger" on-invalid="null" />
        <argument type="service" id="event_dispatcher" on-invalid="null"/>
    </service>

    <service id="security.authentication.rememberme.services.persistent"
             class="%security.authentication.rememberme.services.persistent.class%"
             parent="security.authentication.rememberme.services.abstract"
             abstract="true">
        <argument type="service" id="security.secure_random" />
    </service>

Upvotes: 2

Related Questions