Skip to content

Commit

Permalink
Attachment manager refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
deftomat committed Sep 14, 2015
1 parent 73f9a17 commit 7278b1c
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 52 deletions.
20 changes: 0 additions & 20 deletions Attachment/AttachmentManager.php

This file was deleted.

6 changes: 3 additions & 3 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ public function getConfigTreeBuilder()
->defaultValue(null)
->info('Instance of Support\MessageId\Generator interface.')
->end()
->arrayNode('attachment_managers')
->arrayNode('attachment_swappers')
->children()
->scalarNode('inbound')
->isRequired()
->info('Instance of Attachment\AttachmentManager interface.')
->info('Instance of Inbound\Attachment\AttachmentSwapper interface.')
->end()
->scalarNode('outbound')
->isRequired()
->info('Instance of Attachment\AttachmentManager interface.')
->info('Instance of Outbound\Attachment\AttachmentSwapper interface.')
->end()
->end()
->end()
Expand Down
4 changes: 2 additions & 2 deletions DependencyInjection/EverlutionEmailExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ private function defineServices(ContainerBuilder $container, array $processedCon
$container->setAlias('everlution.email.ext.outbound.message_event.request_processor', $processedConfig['request_processors']['outbound_message_event']);
$container->setAlias('everlution.email.ext.inbound.request_processor', $processedConfig['request_processors']['inbound']);

$container->setAlias('everlution.email.ext.outbound.attachment_manager', $processedConfig['attachment_managers']['outbound']);
$container->setAlias('everlution.email.ext.inbound.attachment_manager', $processedConfig['attachment_managers']['inbound']);
$container->setAlias('everlution.email.ext.outbound.attachment_swapper', $processedConfig['attachment_swappers']['outbound']);
$container->setAlias('everlution.email.ext.inbound.attachment_swapper', $processedConfig['attachment_swappers']['inbound']);

$this->defineMessageIdService($container, $processedConfig);
}
Expand Down
23 changes: 23 additions & 0 deletions Inbound/Attachment/AttachmentSwapper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Everlution\EmailBundle\Inbound\Attachment;

use Everlution\EmailBundle\Attachment\Attachment;
use Everlution\EmailBundle\Entity\StorableInboundMessage;

interface AttachmentSwapper
{

/**
* @param Attachment[] $attachments
* @param StorableInboundMessage $storableMessage
*/
public function saveAttachments(array $attachments, $storableMessage);

/**
* @param Attachment[] $images
* @param StorableInboundMessage $storableMessage
*/
public function saveImages(array $images, $storableMessage);

}
16 changes: 8 additions & 8 deletions Inbound/MessageProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Everlution\EmailBundle\Inbound;

use Everlution\EmailBundle\Attachment\Attachment;
use Everlution\EmailBundle\Attachment\AttachmentManager;
use Everlution\EmailBundle\Inbound\Attachment\AttachmentSwapper;
use Everlution\EmailBundle\Entity\StorableInboundMessage;
use Everlution\EmailBundle\Entity\Repository\StorableInboundMessage as StorableMessageRepository;
use Everlution\EmailBundle\Inbound\Message\InboundMessage;
Expand All @@ -18,17 +18,17 @@ class MessageProcessor
/** @var StorableMessageRepository */
protected $storableMessageRepository;

/** @var AttachmentManager */
protected $attachmentManager;
/** @var AttachmentSwapper */
protected $attachmentSwapper;

/**
* @param StorableMessageRepository $storableMessageRepository
* @param AttachmentManager $attachmentManager
* @param AttachmentSwapper $attachmentSwapper
*/
public function __construct(StorableMessageRepository $storableMessageRepository, AttachmentManager $attachmentManager)
public function __construct(StorableMessageRepository $storableMessageRepository, AttachmentSwapper $attachmentSwapper)
{
$this->storableMessageRepository = $storableMessageRepository;
$this->attachmentManager = $attachmentManager;
$this->attachmentSwapper = $attachmentSwapper;
}

/**
Expand Down Expand Up @@ -77,7 +77,7 @@ protected function storeStorableMessage(StorableInboundMessage $storableMessage)
*/
protected function storeAttachments(array $attachments, StorableInboundMessage $storableMessage)
{
$this->attachmentManager->saveAttachments($attachments, $storableMessage);
$this->attachmentSwapper->saveAttachments($attachments, $storableMessage);
}

/**
Expand All @@ -86,7 +86,7 @@ protected function storeAttachments(array $attachments, StorableInboundMessage $
*/
protected function storeImages(array $images, StorableInboundMessage $storableMessage)
{
$this->attachmentManager->saveImages($images, $storableMessage);
$this->attachmentSwapper->saveImages($images, $storableMessage);
}

}
23 changes: 23 additions & 0 deletions Outbound/Attachment/AttachmentSwapper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Everlution\EmailBundle\Outbound\Attachment;

use Everlution\EmailBundle\Attachment\Attachment;
use Everlution\EmailBundle\Entity\StorableOutboundMessage;

interface AttachmentSwapper
{

/**
* @param Attachment[] $attachments
* @param StorableOutboundMessage $storableMessage
*/
public function saveAttachments(array $attachments, $storableMessage);

/**
* @param Attachment[] $images
* @param StorableOutboundMessage $storableMessage
*/
public function saveImages(array $images, $storableMessage);

}
8 changes: 4 additions & 4 deletions Outbound/Mailer/AsynchronousMailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use DateTime;
use Doctrine\ORM\EntityManagerInterface;
use Everlution\EmailBundle\Attachment\AttachmentManager;
use Everlution\EmailBundle\Outbound\Attachment\AttachmentSwapper;
use Everlution\EmailBundle\Outbound\Message\OutboundMessage;
use Everlution\EmailBundle\Outbound\Message\ProcessedOutboundMessage as ProcessedMessage;
use Everlution\EmailBundle\Outbound\MailSystem\MailSystem;
Expand All @@ -25,11 +25,11 @@ class AsynchronousMailer extends StorableMessagesMailer
* @param MessageIdGenerator $messageIdGenerator
* @param MailSystem $mailSystem
* @param EntityManagerInterface $entityManager
* @param AttachmentManager $attachmentManager
* @param AttachmentSwapper $attachmentSwapper
*/
public function __construct(Stream $asyncHandlingLauncher, MessageIdGenerator $messageIdGenerator, MailSystem $mailSystem, EntityManagerInterface $entityManager, AttachmentManager $attachmentManager)
public function __construct(Stream $asyncHandlingLauncher, MessageIdGenerator $messageIdGenerator, MailSystem $mailSystem, EntityManagerInterface $entityManager, AttachmentSwapper $attachmentSwapper)
{
parent::__construct($messageIdGenerator, $mailSystem, $entityManager, $attachmentManager);
parent::__construct($messageIdGenerator, $mailSystem, $entityManager, $attachmentSwapper);
$this->registerStreamListener($asyncHandlingLauncher);
}

Expand Down
16 changes: 8 additions & 8 deletions Outbound/Mailer/StorableMessagesMailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Everlution\EmailBundle\Outbound\Mailer;

use Doctrine\ORM\EntityManagerInterface;
use Everlution\EmailBundle\Attachment\AttachmentManager;
use Everlution\EmailBundle\Outbound\Attachment\AttachmentSwapper;
use Everlution\EmailBundle\Entity\StorableOutboundMessageStatus;
use Everlution\EmailBundle\Outbound\MailSystem\MailSystemResult;
use Everlution\EmailBundle\Support\MessageId\Generator as MessageIdGenerator;
Expand All @@ -13,8 +13,8 @@
abstract class StorableMessagesMailer extends Mailer
{

/** @var AttachmentManager */
protected $attachmentManager;
/** @var AttachmentSwapper */
protected $attachmentSwapper;

/** @var EntityManagerInterface */
protected $entityManager;
Expand All @@ -23,12 +23,12 @@ abstract class StorableMessagesMailer extends Mailer
* @param MessageIdGenerator $messageIdGenerator
* @param MailSystem $mailSystem
* @param EntityManagerInterface $entityManager
* @param AttachmentManager $attachmentManager
* @param AttachmentSwapper $attachmentSwapper
*/
public function __construct(MessageIdGenerator $messageIdGenerator, MailSystem $mailSystem, EntityManagerInterface $entityManager, AttachmentManager $attachmentManager)
public function __construct(MessageIdGenerator $messageIdGenerator, MailSystem $mailSystem, EntityManagerInterface $entityManager, AttachmentSwapper $attachmentSwapper)
{
parent::__construct($messageIdGenerator, $mailSystem);
$this->attachmentManager = $attachmentManager;
$this->attachmentSwapper = $attachmentSwapper;
$this->entityManager = $entityManager;
}

Expand All @@ -52,7 +52,7 @@ protected function storeAttachments(ProcessedOutboundMessage $processedMessage)
$attachments = $processedMessage->getUniqueOutboundMessage()->getMessage()->getAttachments();
$storableMessage = $processedMessage->getStorableMessage();

$this->attachmentManager->saveAttachments($attachments, $storableMessage);
$this->attachmentSwapper->saveAttachments($attachments, $storableMessage);
}

/**
Expand All @@ -63,7 +63,7 @@ protected function storeImages(ProcessedOutboundMessage $processedMessage)
$attachments = $processedMessage->getUniqueOutboundMessage()->getMessage()->getImages();
$storableMessage = $processedMessage->getStorableMessage();

$this->attachmentManager->saveImages($attachments, $storableMessage);
$this->attachmentSwapper->saveImages($attachments, $storableMessage);
}

/**
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ everlution_email:
domain_name: APP_DOMAIN
mail_system: Implementation of Outbound\MailSystem\MailSystem
async_stream: Implementation of Support\Stream\Stream
attachment_managers:
inbound: Implementation of Attachment\AttachmentManager
outbound: Implementation of Attachment\AttachmentManager
attachment_swappers:
inbound: Implementation of Inbound\Attachment\AttachmentSwapper
outbound: Implementation of Outbound\Attachment\AttachmentSwapper
request_processors:
inbound: Implementation of Inbound\RequestProcessor
outbound_message_event: Implementation of Outbound\MessageEvent\RequestProcessor
Expand All @@ -56,7 +56,7 @@ everlution_email:
**async_stream** - Bundle allows to send email messages asynchronously. Email messages is stored in memory unil some value is added into this Stream. Good example is a Stream of Symfony's [kernel.terminate](http://symfony.com/doc/current/components/http_kernel/introduction.html#the-kernel-terminate-event) events.
**attachment_managers** - After sending or receiving a message, bundle try to save the message's attachments by using this *attachment managers*. This managers can save attachments in various ways.
**attachment_swappers** - After sending or receiving a message, bundle try to save the message's attachments by using this *attachment swappers*. This swappers can save attachments in various ways.
**request_processors** - Bundle provide common mechanism to handle *inbound messages* and *outbound message events*. This events may occur for example when external *mail system* try to send scheduled messages. However, different *mail systems* sending data in different format. Request processors transform this data into format, which is known for this bundle.
Expand Down
6 changes: 3 additions & 3 deletions Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ services:
- @everlution.email.ext.message_id_generator
- @everlution.email.ext.mail_system
- @doctrine.orm.entity_manager
- @everlution.email.ext.outbound.attachment_manager
- @everlution.email.ext.outbound.attachment_swapper

everlution.email.outbound.asynchronous_mailer:
class: Everlution\EmailBundle\Outbound\Mailer\AsynchronousMailer
Expand All @@ -21,7 +21,7 @@ services:
- @everlution.email.ext.message_id_generator
- @everlution.email.ext.mail_system
- @doctrine.orm.entity_manager
- @everlution.email.ext.outbound.attachment_manager
- @everlution.email.ext.outbound.attachment_swapper

everlution.email.outbound.message_event.controller:
class: Everlution\EmailBundle\Controller\MessageEventController
Expand Down Expand Up @@ -66,7 +66,7 @@ services:
class: Everlution\EmailBundle\Inbound\MessageProcessor
arguments:
- @everlution.email.inbound.message_repository
- @everlution.email.ext.inbound.attachment_manager
- @everlution.email.ext.inbound.attachment_swapper

everlution.email.inbound.message_repository:
class: Everlution\EmailBundle\Entity\Repository\StorableInboundMessage
Expand Down

0 comments on commit 7278b1c

Please sign in to comment.