Skip to content
This repository was archived by the owner on Feb 6, 2022. It is now read-only.

fix OutOfBoundsException when using mail or sendmail transport #42

Closed
wants to merge 3 commits into from
Closed

Conversation

csanquer
Copy link
Contributor

Hi,

Since the #34 had been merged, an exception occured when using mail or sendmail transport :

[Symfony\Component\DependencyInjection\Exception\OutOfBoundsException]  
  The index "1" is not in the range [0, 0]. 

This patch fix it.

@stof
Copy link
Member

stof commented Jul 20, 2013

Can you add a test covering this issue to avoid regressions ?

@csanquer
Copy link
Contributor Author

I don't know how to test this, the exception occured when we call the replaceArgument on the DefinitionDecorator class but it is the Definition::replaceArgument method which is really called

@stof
Copy link
Member

stof commented Jul 20, 2013

does your test fail if you undo your patch ? This is the good way to see if the test is accurate: failing without the patch and passing with it

@csanquer
Copy link
Contributor Author

I can't reproduce the bug inside the bundle with phpunit and the bundles vendors, but without this patch it failed every time on my symfony 2.3 project

@csanquer
Copy link
Contributor Author

I think in a real symfony project the definition decorator doesn't respect fully the service configuration set in swiftmailer.xml :

<service id="swiftmailer.transport.sendmail.abstract" class="%swiftmailer.transport.sendmail.class%" abstract="true" public="false">
    <argument type="service" id="swiftmailer.transport.buffer" />
</service>

<service id="swiftmailer.transport.mail.abstract" class="%swiftmailer.transport.mail.class%" abstract="true" public="false">
    <argument type="service" id="swiftmailer.transport.mailinvoker" />
</service>

compared to :

} elseif (in_array($transport, array('mail', 'sendmail'))) {
            $definitionDecorator = new DefinitionDecorator(sprintf('swiftmailer.transport.%s.abstract', $transport));
            $container
                ->setDefinition(sprintf('swiftmailer.mailer.%s.transport.%s', $name, $transport), $definitionDecorator)
                ->addArgument(new Reference(sprintf('swiftmailer.mailer.%s.transport.eventdispatcher', $name)))
            ;
            $container->setAlias(sprintf('swiftmailer.mailer.%s.transport', $name), sprintf('swiftmailer.mailer.%s.transport.%s', $name, $transport));
        }

@csanquer
Copy link
Contributor Author

Maybe an explicit definition arguments settings will be clearer :

} elseif ('sendmail' === $transport) {
            $definitionDecorator = new DefinitionDecorator(sprintf('swiftmailer.transport.%s.abstract', $transport));
            $container
                ->setDefinition(sprintf('swiftmailer.mailer.%s.transport.%s', $name, $transport), $definitionDecorator)
                ->setArguments(array(
                    new Reference('swiftmailer.transport.buffer'),
                    new Reference(sprintf('swiftmailer.mailer.%s.transport.eventdispatcher', $name)),
                ))
            ;
            $container->setAlias(sprintf('swiftmailer.mailer.%s.transport', $name), sprintf('swiftmailer.mailer.%s.transport.%s', $name, $transport));
        } elseif ('mail' === $transport) {
            $definitionDecorator = new DefinitionDecorator(sprintf('swiftmailer.transport.%s.abstract', $transport));
            $container
                ->setDefinition(sprintf('swiftmailer.mailer.%s.transport.%s', $name, $transport), $definitionDecorator)
                ->setArguments(array(
                    new Reference('swiftmailer.transport.mailinvoker'),
                    new Reference(sprintf('swiftmailer.mailer.%s.transport.eventdispatcher', $name)),
                ))
            ;
            $container->setAlias(sprintf('swiftmailer.mailer.%s.transport', $name), sprintf('swiftmailer.mailer.%s.transport.%s', $name, $transport));
        }

@bamarni
Copy link

bamarni commented Jul 23, 2013

👍 I'm facing the same bug (since #34 has been merged) and I can confirm this patch fixes it.

@fabpot fabpot closed this in 56483a6 Jul 23, 2013
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants