-
Notifications
You must be signed in to change notification settings - Fork 0
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
315b7f5
commit eb93bdb
Showing
13 changed files
with
190 additions
and
36 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
namespace Knp\UniMail\Cid; | ||
|
||
use Swift_Mime_Attachment; | ||
|
||
class Collection implements \IteratorAggregate | ||
{ | ||
/** | ||
* @var Swift_Mime_Attachment[] | ||
*/ | ||
private $cids; | ||
|
||
/** | ||
* @param Swift_Mime_Attachment[] $cids | ||
*/ | ||
public function __construct($cids = []) | ||
{ | ||
$this->cids = $cids; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getIterator() | ||
{ | ||
return new \ArrayIterator($this->cids); | ||
} | ||
|
||
/** | ||
* @return Swift_Mime_Attachment[] | ||
*/ | ||
public function all() | ||
{ | ||
return $this->cids; | ||
} | ||
|
||
/** | ||
* @param Swift_Mime_Attachment $cid | ||
* | ||
* @return Collection | ||
*/ | ||
public function add(Swift_Mime_Attachment $cid) | ||
{ | ||
$this->cids[$cid->getId()] = $cid; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @return Collection | ||
*/ | ||
public function clear() | ||
{ | ||
$this->cids = []; | ||
|
||
return $this; | ||
} | ||
} |
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,13 @@ | ||
<?php | ||
|
||
namespace Knp\UniMail\Cid; | ||
|
||
interface Resolver | ||
{ | ||
/** | ||
* @param string $string | ||
* | ||
* @return Swift_EmbeddedFile|null | ||
*/ | ||
public function createFromString($string); | ||
} |
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,36 @@ | ||
<?php | ||
|
||
namespace Knp\UniMail\Cid\Resolver; | ||
|
||
use Knp\UniMail\Cid\Resolver; | ||
use Swift_EmbeddedFile; | ||
|
||
class LocalFile implements Resolver | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private $directory; | ||
|
||
/** | ||
* @param string $directory | ||
*/ | ||
public function __construct($directory) | ||
{ | ||
$this->directory = $directory; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function createFromString($string) | ||
{ | ||
$string = str_replace('/', DIRECTORY_SEPARATOR, $string); | ||
|
||
if (false === file_exists($string)) { | ||
return; | ||
} | ||
|
||
return Swift_EmbeddedFile::fromPath(sprintf('%s%s%s', $this->directory, DIRECTORY_SEPARATOR, $string)); | ||
} | ||
} |
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,27 @@ | ||
<?php | ||
|
||
namespace Knp\UniMail\Cid\Resolver; | ||
|
||
use Knp\UniMail\Cid\Resolver; | ||
use Swift_EmbeddedFile; | ||
|
||
class RemoteFile implements Resolver | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function createFromString($string) | ||
{ | ||
$headers = @get_headers($string); | ||
|
||
if (false === $headers) { | ||
return; | ||
} | ||
|
||
if (false !== strpos($headers[0], '404')) { | ||
return; | ||
} | ||
|
||
return Swift_EmbeddedFile::fromPath($string); | ||
} | ||
} |
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
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
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