Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot Use Mandrill mailer as a dependency because it is abstract #106

Closed
NadjibBELLOUNDJA opened this issue Mar 3, 2018 · 1 comment
Closed

Comments

@NadjibBELLOUNDJA
Copy link

NadjibBELLOUNDJA commented Mar 3, 2018

Hello everyone.

I am trying to implement the bundle to use Mandrill, but I am getting the following error

The definition "my_project.mailer.mailer" has a reference to an abstract definition "hb_stampie.mailer.mandrill". Abstract definitions cannot be the target of references.

I have a mailers.yml where I define my services:

parameters:
    my_project.mailer.sender_name: My Project
    my_project.mailer.deploy_instance: my_project
services:
    my_project.mailer.buzz.client:
        class: Buzz\Client\Curl
    my_project.mailer.buzz.factory:
        class: Buzz\Message\Factory\Factory
    buzz:
        class: Buzz\Browser
        arguments:
            - '@my_project.mailer.buzz.client'
            - '@my_project.mailer.buzz.factory'
    my_project.mailer.mailer:
        class: MyProject\MailerBundle\Mailer\Mailer
        arguments:
            - '@hb_stampie.mailer.mandrill'
            - '@templating'
            - %my_project.mailer.sender_name%
            - %my_project.mailer.deploy_instance%

My config.yml goes like this:

hb_stampie:
    adapter: buzz
    mailer: mandrill
    server_token: '%mandrill_api_key%'
    extra:
        delivery_address: '%mailer_delivery_address%'

And my service MyProject\MailerBundle\Mailer\Mailer goes like this (I put only the constructor function)

namespace MyProject\MailerBundle\Mailer;

use MyProject\WebBundle\Entity\Member;
use Stampie\Identity;
use Stampie\MailerInterface as StampieMailerInterface;

class Mailer implements MailerInterface
{
    private $mailer;
    private $twig;
    private $defaultSenderName;
    private $deployInstance;

    /**
     * @param StampieMailerInterface $mailer
     * @param \Twig_Environment        $twig
     * @param string                             $defaultSenderName
     * @param string                             $deployInstance
     */
    public function __construct(StampieMailerInterface $mailer, \Twig_Environment $twig, $defaultSenderName, $deployInstance)
    {
        $this->mailer = $mailer;
        $this->twig = $twig;
        $this->defaultSenderName = $defaultSenderName;
        $this->deployInstance = $deployInstance;
    }
}

My MailerInterface (implemented by MyProject\MailerBundle\Mailer\Mailer) is simply the following:

namespace MyProject\MailerBundle\Mailer;

interface MailerInterface
{
    /**
     * Sends a mail to the recipient(s) using the template.
     *
     * The template must define 3 blocks: subject, body_text and body_html.
     *
     * @param Message $message
     */
    public function send(Message $message);
}

Now if I look in the config.xml of the henrikbjorn bundle, I do have
<service id="hb_stampie.mailer.mandrill" class="%hb_stampie.mailer.mandrill.class%" abstract="true" />
which means that the hb_stampie.mailer.mandrill is an abstract class.

What am I missing in the configuration here? What should I do to be able to use Mandrill to send my mails?

@stof
Copy link
Member

stof commented Aug 4, 2018

the service you should inject is hb_stampie.mailer, which is the mailer configured in the bundle.
hb_stampie.mailer.mandrill is an internal abstract service, not something meant to be used (and it will even probably disappear in the next version of the bundle).

Btw, this issue is related to the bundle, not to Stampie itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants