-
Notifications
You must be signed in to change notification settings - Fork 327
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
105 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the SncRedisBundle package. | ||
* | ||
* (c) Henrik Westphal <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Snc\RedisBundle\DependencyInjection\Compiler; | ||
|
||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
|
||
class SwiftMailerPass implements CompilerPassInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function process(ContainerBuilder $container) | ||
{ | ||
$serviceId = 'snc_redis.swiftmailer.spool'; | ||
if ($container->hasDefinition($serviceId)) { | ||
$handlerDefinition = $container->getDefinition($serviceId); | ||
if ('Snc\\RedisBundle\\SwiftMailer\\RedisSpool' === $handlerDefinition->getClass()) { | ||
// default class, lets check for Swift Mailer version and set correct class | ||
$class = new \ReflectionClass('\\Swift_Spool'); | ||
$parameters = $class->getMethod('queueMessage')->getParameters(); | ||
switch ($parameters[0]->getClass()->getName()) { | ||
case 'Swift_Mime_Message': | ||
// Swift Mailer 5.x | ||
$handlerDefinition->setClass($handlerDefinition->getClass().'5'); | ||
break; | ||
case 'Swift_Mime_SimpleMessage': | ||
// Swift Mailer 6.x | ||
$handlerDefinition->setClass($handlerDefinition->getClass().'6'); | ||
break; | ||
default: | ||
throw new \RuntimeException('Failed to detect the current Swift Mailer version.'); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the SncRedisBundle package. | ||
* | ||
* (c) Henrik Westphal <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Snc\RedisBundle\SwiftMailer; | ||
|
||
/** | ||
* RedisSpool5 (Swift Mailer 5.x) | ||
*/ | ||
class RedisSpool5 extends RedisSpool | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function queueMessage(\Swift_Mime_Message $message) | ||
{ | ||
$this->redis->rpush($this->key, serialize($message)); | ||
|
||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the SncRedisBundle package. | ||
* | ||
* (c) Henrik Westphal <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Snc\RedisBundle\SwiftMailer; | ||
|
||
/** | ||
* RedisSpool6 (Swift Mailer 6.x) | ||
*/ | ||
class RedisSpool6 extends RedisSpool | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function queueMessage(\Swift_Mime_SimpleMessage $message) | ||
{ | ||
$this->redis->rpush($this->key, serialize($message)); | ||
|
||
return true; | ||
} | ||
} |