mirror of
https://github.com/retailcrm/transparent-email.git
synced 2025-02-16 14:53:15 +03:00
Add Yandex.ru service support
This commit is contained in:
parent
df33d7edbc
commit
dc65847371
@ -25,6 +25,14 @@ class EditableEmail implements EmailInterface
|
|||||||
return $copy;
|
return $copy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function replaceInLocalPart(string $toReplace, string $replacement) : EditableEmail
|
||||||
|
{
|
||||||
|
$copy = clone $this;
|
||||||
|
$copy->localPart = str_replace($toReplace, $replacement, $this->localPart);
|
||||||
|
|
||||||
|
return $copy;
|
||||||
|
}
|
||||||
|
|
||||||
public function removeSuffixAlias(string $delimiter) : EditableEmail
|
public function removeSuffixAlias(string $delimiter) : EditableEmail
|
||||||
{
|
{
|
||||||
$copy = clone $this;
|
$copy = clone $this;
|
||||||
|
41
src/Services/YandexRu.php
Normal file
41
src/Services/YandexRu.php
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace bkrukowski\TransparentEmail\Services;
|
||||||
|
|
||||||
|
use bkrukowski\TransparentEmail\Emails\EditableEmail;
|
||||||
|
use bkrukowski\TransparentEmail\Emails\EmailInterface;
|
||||||
|
|
||||||
|
class YandexRu implements ServiceInterface
|
||||||
|
{
|
||||||
|
public function getPrimaryEmail(EmailInterface $email) : EmailInterface
|
||||||
|
{
|
||||||
|
return (new EditableEmail($email))
|
||||||
|
->removeSuffixAlias('+')
|
||||||
|
->replaceInLocalPart('.', '-')
|
||||||
|
->lowerCaseLocalPartIf(true)
|
||||||
|
->setDomain($this->mapDomain($email->getDomain()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isSupported(EmailInterface $email) : bool
|
||||||
|
{
|
||||||
|
return in_array($email->getDomain(), ['ya.ru', 'yandex.com', 'yandex.ru', 'yandex.by', 'yandex.kz', 'yandex.ua']);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getDomainMapping() : array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'ya.ru' => 'yandex.ru',
|
||||||
|
'yandex.com' => 'yandex.ru',
|
||||||
|
'yandex.by' => 'yandex.ru',
|
||||||
|
'yandex.kz' => 'yandex.ru',
|
||||||
|
'yandex.ua' => 'yandex.ru'
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
private function mapDomain(string $domain) : string
|
||||||
|
{
|
||||||
|
return $this->getDomainMapping()[$domain] ?? $domain;
|
||||||
|
}
|
||||||
|
}
|
@ -11,6 +11,7 @@ use bkrukowski\TransparentEmail\Services\OutlookCom;
|
|||||||
use bkrukowski\TransparentEmail\Services\TlenPl;
|
use bkrukowski\TransparentEmail\Services\TlenPl;
|
||||||
use bkrukowski\TransparentEmail\Services\Www33MailCom;
|
use bkrukowski\TransparentEmail\Services\Www33MailCom;
|
||||||
use bkrukowski\TransparentEmail\Services\YahooCom;
|
use bkrukowski\TransparentEmail\Services\YahooCom;
|
||||||
|
use bkrukowski\TransparentEmail\Services\YandexRu;
|
||||||
|
|
||||||
class TransparentEmailFactory
|
class TransparentEmailFactory
|
||||||
{
|
{
|
||||||
@ -39,7 +40,8 @@ class TransparentEmailFactory
|
|||||||
Www33MailCom::class,
|
Www33MailCom::class,
|
||||||
TlenPl::class,
|
TlenPl::class,
|
||||||
AppsGoogleCom::class,
|
AppsGoogleCom::class,
|
||||||
MailRu::class
|
MailRu::class,
|
||||||
|
YandexRu::class
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
63
tests/Services/YandexRuTest.php
Normal file
63
tests/Services/YandexRuTest.php
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace bkrukowski\TransparentEmail\Tests\Services;
|
||||||
|
|
||||||
|
use bkrukowski\TransparentEmail\Emails\Email;
|
||||||
|
use bkrukowski\TransparentEmail\Services\YandexRu;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
class YandexRuTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @dataProvider providerGetPrimaryEmail
|
||||||
|
*
|
||||||
|
* @param string $inputEmail
|
||||||
|
* @param string $outputEmail
|
||||||
|
*/
|
||||||
|
public function testGetPrimaryEmail(string $inputEmail, string $outputEmail)
|
||||||
|
{
|
||||||
|
$this->assertEquals($outputEmail, (new YandexRu())->getPrimaryEmail(new Email($inputEmail)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function providerGetPrimaryEmail() : array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
['foobar@YANDEX.RU', 'foobar@yandex.ru'],
|
||||||
|
['fOObar@YAndEX.ru', 'foobar@yandex.ru'],
|
||||||
|
['foobar+alias@yandex.ru', 'foobar@yandex.ru'],
|
||||||
|
['JaneDoe@ya.ru', 'janedoe@yandex.ru'],
|
||||||
|
['Jane.Doe@ya.ru', 'jane-doe@yandex.ru'],
|
||||||
|
['foobar@yandex.com', 'foobar@yandex.ru'],
|
||||||
|
['foobar@yandex.by', 'foobar@yandex.ru'],
|
||||||
|
['foobar@yandex.kz', 'foobar@yandex.ru'],
|
||||||
|
['foobar@yandex.ua', 'foobar@yandex.ru'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider providerIsSupported
|
||||||
|
*
|
||||||
|
* @param string $domain
|
||||||
|
* @param bool $result
|
||||||
|
*/
|
||||||
|
public function testIsSupported(string $domain, bool $result)
|
||||||
|
{
|
||||||
|
$this->assertSame($result, (new YandexRu())->isSupported(new Email('Jane.Doe@' . $domain)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function providerIsSupported() : array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
['yandex.ru', true],
|
||||||
|
['yandex.com', true],
|
||||||
|
['yandex.by', true],
|
||||||
|
['yandex.kz', true],
|
||||||
|
['yandex.ua', true],
|
||||||
|
['yandex.RU', true],
|
||||||
|
['yan.dex.ru', false],
|
||||||
|
['YANDEX.RU', true],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user