2016-09-10 01:41:21 +03:00
|
|
|
<?php
|
|
|
|
|
2016-09-23 22:39:33 +03:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2016-09-10 16:13:55 +03:00
|
|
|
namespace bkrukowski\TransparentEmail;
|
2016-09-10 01:41:21 +03:00
|
|
|
|
2016-09-24 13:09:20 +03:00
|
|
|
use bkrukowski\TransparentEmail\Emails\EmailInterface;
|
2016-09-10 16:13:55 +03:00
|
|
|
use bkrukowski\TransparentEmail\Services\ServiceInterface;
|
2016-09-10 01:41:21 +03:00
|
|
|
|
2016-10-14 21:19:38 +03:00
|
|
|
class TransparentEmail implements TransparentEmailInterface
|
2016-09-10 01:41:21 +03:00
|
|
|
{
|
|
|
|
/**
|
2016-09-23 22:29:25 +03:00
|
|
|
* @var ServiceCollectorInterface|ServiceInterface[]
|
2016-09-10 01:41:21 +03:00
|
|
|
*/
|
|
|
|
private $services;
|
|
|
|
|
2016-10-14 21:19:38 +03:00
|
|
|
public function __construct(ServiceCollectorInterface $services)
|
2016-09-10 01:41:21 +03:00
|
|
|
{
|
2016-10-14 21:19:38 +03:00
|
|
|
$this->services = $services;
|
2016-09-10 01:41:21 +03:00
|
|
|
}
|
|
|
|
|
2016-09-24 13:09:20 +03:00
|
|
|
public function getPrimaryEmail(EmailInterface $email) : EmailInterface
|
2016-09-10 01:41:21 +03:00
|
|
|
{
|
2016-09-23 22:29:25 +03:00
|
|
|
foreach ($this->services as $service) {
|
2016-09-24 13:09:20 +03:00
|
|
|
if ($service->isSupported($email)) {
|
|
|
|
return $service->getPrimaryEmail($email);
|
2016-09-10 01:41:21 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-24 13:09:20 +03:00
|
|
|
return $email;
|
2016-09-10 01:41:21 +03:00
|
|
|
}
|
|
|
|
}
|