transparent-email/src/TransparentEmail.php

32 lines
761 B
PHP
Raw Normal View History

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-09-10 16:13:55 +03:00
class TransparentEmail
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-09-24 13:09:20 +03:00
public function __construct(ServiceCollectorInterface $services = null)
2016-09-10 01:41:21 +03:00
{
2016-09-23 22:29:25 +03:00
$this->services = $services ?: new DefaultServiceCollector();
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
}
}