-
Notifications
You must be signed in to change notification settings - Fork 3
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
1 parent
50581da
commit 7cab04f
Showing
21 changed files
with
634 additions
and
18 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
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,31 @@ | ||
<?php | ||
|
||
namespace Outstack\Enveloper\Mail\Attachments; | ||
|
||
class Attachment | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private $data; | ||
/** | ||
* @var string | ||
*/ | ||
private $filename; | ||
|
||
public function __construct(string $data, string $filename) | ||
{ | ||
$this->data = $data; | ||
$this->filename = $filename; | ||
} | ||
|
||
public function getData(): string | ||
{ | ||
return $this->data; | ||
} | ||
|
||
public function getFilename(): string | ||
{ | ||
return $this->filename; | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/Outstack/Enveloper/Mail/Attachments/AttachmentList.php
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,31 @@ | ||
<?php | ||
|
||
namespace Outstack\Enveloper\Mail\Attachments; | ||
|
||
class AttachmentList implements \IteratorAggregate | ||
{ | ||
/** | ||
* @var Attachment[] | ||
*/ | ||
private $attachments = []; | ||
|
||
public function __construct(array $attachments) | ||
{ | ||
foreach ($attachments as $attachment) { | ||
$this->addAttachment($attachment); | ||
} | ||
} | ||
|
||
private function addAttachment(Attachment $attachment) | ||
{ | ||
$this->attachments[] = $attachment; | ||
} | ||
|
||
/** | ||
* @return \ArrayIterator|Attachment[] | ||
*/ | ||
public function getIterator(): \ArrayIterator | ||
{ | ||
return new \ArrayIterator($this->attachments); | ||
} | ||
} |
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
52 changes: 52 additions & 0 deletions
52
src/Outstack/Enveloper/Resolution/AttachmentListResolver.php
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,52 @@ | ||
<?php | ||
|
||
namespace Outstack\Enveloper\Resolution; | ||
|
||
use Outstack\Enveloper\Mail\Attachments\AttachmentList; | ||
use Outstack\Enveloper\Templates\AttachmentListTemplate; | ||
use Outstack\Enveloper\Templates\AttachmentTemplate; | ||
|
||
class AttachmentListResolver | ||
{ | ||
/** | ||
* @var AttachmentResolver | ||
*/ | ||
private $attachmentResolver; | ||
|
||
public function __construct(AttachmentResolver $attachmentResolver) | ||
{ | ||
$this->attachmentResolver = $attachmentResolver; | ||
} | ||
|
||
public function resolveAttachmentList(AttachmentListTemplate $attachmentListTemplate, array $params): AttachmentList | ||
{ | ||
$resolved = []; | ||
foreach ($attachmentListTemplate->getAttachmentTemplates() as $template) { | ||
foreach ($this->resolveTemplate($template, $params) as $attachment) { | ||
$resolved[] = $attachment; | ||
} | ||
} | ||
|
||
return new AttachmentList($resolved); | ||
} | ||
|
||
private function resolveTemplate(AttachmentTemplate $template, array $params) | ||
{ | ||
if ($template->getIterateOver()) { | ||
foreach ($this->resolveIteratively($template, $params) as $template) { | ||
yield $template; | ||
} | ||
|
||
return; | ||
} | ||
|
||
yield $this->attachmentResolver->resolve($template, $params); | ||
} | ||
|
||
private function resolveIteratively(AttachmentTemplate $template, array $params) | ||
{ | ||
foreach ($params[$template->getIterateOver()] as $item) { | ||
yield $this->attachmentResolver->resolve($template, ['item' => $item]); | ||
} | ||
} | ||
} |
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,33 @@ | ||
<?php | ||
|
||
namespace Outstack\Enveloper\Resolution; | ||
|
||
use Outstack\Enveloper\Mail\Attachments\Attachment; | ||
use Outstack\Enveloper\Templates\AttachmentTemplate; | ||
|
||
class AttachmentResolver | ||
{ | ||
/** | ||
* @var TemplateLanguage | ||
*/ | ||
private $language; | ||
|
||
public function __construct(TemplateLanguage $language) | ||
{ | ||
$this->language = $language; | ||
} | ||
|
||
public function resolve(AttachmentTemplate $template, array $parameters) | ||
{ | ||
return new Attachment( | ||
$this->language->render( | ||
$template->getContents(), | ||
$parameters | ||
), | ||
$this->language->render( | ||
$template->getFilename(), | ||
$parameters | ||
) | ||
); | ||
} | ||
} |
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
31 changes: 31 additions & 0 deletions
31
src/Outstack/Enveloper/Templates/AttachmentListTemplate.php
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,31 @@ | ||
<?php | ||
|
||
namespace Outstack\Enveloper\Templates; | ||
|
||
class AttachmentListTemplate | ||
{ | ||
/** | ||
* @var AttachmentTemplate[] | ||
*/ | ||
private $templates = []; | ||
|
||
public function __construct(array $attachmentTemplates) | ||
{ | ||
foreach ($attachmentTemplates as $template) { | ||
$this->addTemplate($template); | ||
} | ||
} | ||
|
||
private function addTemplate(AttachmentTemplate $template) | ||
{ | ||
$this->templates[] = $template; | ||
} | ||
|
||
/** | ||
* @return AttachmentTemplate[] | ||
*/ | ||
public function getAttachmentTemplates(): array | ||
{ | ||
return $this->templates; | ||
} | ||
} |
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,41 @@ | ||
<?php | ||
|
||
namespace Outstack\Enveloper\Templates; | ||
|
||
class AttachmentTemplate | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private $contents; | ||
/** | ||
* @var string | ||
*/ | ||
private $filename; | ||
/** | ||
* @var null|string | ||
*/ | ||
private $iterateOver; | ||
|
||
public function __construct(string $contents, string $filename, ?string $iterateOver = null) | ||
{ | ||
$this->contents = $contents; | ||
$this->filename = $filename; | ||
$this->iterateOver = $iterateOver; | ||
} | ||
|
||
public function getContents(): string | ||
{ | ||
return $this->contents; | ||
} | ||
|
||
public function getFilename(): string | ||
{ | ||
return $this->filename; | ||
} | ||
|
||
public function getIterateOver(): ?string | ||
{ | ||
return $this->iterateOver; | ||
} | ||
} |
Oops, something went wrong.