Commit 3b945fe2 authored by catch's avatar catch

Issue #2366043 by dawehner: Upgrade to Symfony 2.6

parent 150cbcf6
This diff is collapsed.
......@@ -173,4 +173,30 @@ public function getRequirements() {
return $this->route->getRequirements();
}
/**
* {@inheritdoc}
*/
public function serialize() {
$data = unserialize(parent::serialize());
$data['fit'] = $this->fit;
$data['patternOutline'] = $this->patternOutline;
$data['numParts'] = $this->numParts;
return serialize($data);
}
/**
* {@inheritdoc}
*/
public function unserialize($serialized)
{
parent::unserialize($serialized);
$data = unserialize($serialized);
$this->fit = $data['fit'];
$this->patternOutline = $data['patternOutline'];
$this->numParts = $data['numParts'];
}
}
......@@ -16,7 +16,6 @@
'Symfony\\Component\\Translation\\' => array($vendorDir . '/symfony/translation'),
'Symfony\\Component\\Serializer\\' => array($vendorDir . '/symfony/serializer'),
'Symfony\\Component\\Routing\\' => array($vendorDir . '/symfony/routing'),
'Symfony\\Component\\Process\\' => array($vendorDir . '/symfony/process'),
'Symfony\\Component\\HttpKernel\\' => array($vendorDir . '/symfony/http-kernel'),
'Symfony\\Component\\HttpFoundation\\' => array($vendorDir . '/symfony/http-foundation'),
'Symfony\\Component\\EventDispatcher\\' => array($vendorDir . '/symfony/event-dispatcher'),
......
This diff is collapsed.
EmailValidator [![Build Status](https://travis-ci.org/egulias/EmailValidator.png?branch=master)](https://travis-ci.org/egulias/EmailValidator) [![Coverage Status](https://coveralls.io/repos/egulias/EmailValidator/badge.png?branch=master)](https://coveralls.io/r/egulias/EmailValidator?branch=master) [![SensioLabsInsight](https://insight.sensiolabs.com/projects/b18d473e-bd5a-4d88-a7b2-7aeaee0ebd7b/small.png)](https://insight.sensiolabs.com/projects/b18d473e-bd5a-4d88-a7b2-7aeaee0ebd7b)[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/egulias/EmailValidator/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/egulias/EmailValidator/?branch=master)
EmailValidator [![Build Status](https://travis-ci.org/egulias/EmailValidator.png?branch=master)](https://travis-ci.org/egulias/EmailValidator) [![Coverage Status](https://coveralls.io/repos/egulias/EmailValidator/badge.png?branch=master)](https://coveralls.io/r/egulias/EmailValidator?branch=master) [![SensioLabsInsight](https://insight.sensiolabs.com/projects/22ba6692-9c02-42e5-a65d-1c5696bfffc6/small.png)](https://insight.sensiolabs.com/projects/22ba6692-9c02-42e5-a65d-1c5696bfffc6)[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/egulias/EmailValidator/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/egulias/EmailValidator/?branch=master)
=============================
##Installation##
Install via composer. Add to your current compooser.json ```require``` key: ```"egulias/email-validator":"1.0.x-dev" ```
Run the command below to install via Composer
```shell
composer require egulias/email-validator
```
##Usage##
......@@ -24,7 +29,7 @@ More advanced example (returns detailed diagnostic error codes):
```php
<?php
use egulias\EmailValidator\EmailValidator;
use Egulias\EmailValidator\EmailValidator;
$validator = new EmailValidator;
$email = 'dominic@sayers.cc';
......@@ -46,6 +51,6 @@ As this is a port from another library and work, here are other people related t
* Josepf Bielawski [@stloyd](http://github.com/stloyd): For its first re-work of Dominic's lib
* Dominic Sayers [@dominicsayers](http://github.com/dominicsayers): The original isemail function
##Licence##
Released under the MIT Licence attached with this code.
##License##
Released under the MIT License attached with this code.
......@@ -10,7 +10,7 @@
],
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
"dev-master": "1.3.x-dev"
}
},
"require": {
......
......@@ -31,10 +31,13 @@ class EmailLexer extends AbstractLexer
const S_SEMICOLON = 275;
const S_OPENQBRACKET = 276;
const S_CLOSEQBRACKET = 277;
const S_SLASH = 278;
const S_EMPTY = null;
const GENERIC = 300;
const CRLF = 301;
const INVALID = 302;
const ASCII_INVALID_FROM = 127;
const ASCII_INVALID_TO = 199;
/**
* US-ASCII visible characters not valid for atext (@link http://tools.ietf.org/html/rfc5322#section-3.2.3)
......@@ -52,6 +55,7 @@ class EmailLexer extends AbstractLexer
';' => self::S_SEMICOLON,
'@' => self::S_AT,
'\\' => self::S_BACKSLASH,
'/' => self::S_SLASH,
',' => self::S_COMMA,
'.' => self::S_DOT,
'"' => self::S_DQUOTE,
......@@ -67,14 +71,31 @@ class EmailLexer extends AbstractLexer
'>' => self::S_GREATERTHAN,
'{' => self::S_OPENQBRACKET,
'}' => self::S_CLOSEQBRACKET,
'' => self::S_EMPTY
'' => self::S_EMPTY,
'\0' => self::C_NUL,
);
protected $invalidASCII = array(226 => 1,);
protected $hasInvalidTokens = false;
protected $previous;
public function reset()
{
$this->hasInvalidTokens = false;
parent::reset();
}
public function hasInvalidTokens()
{
return $this->hasInvalidTokens;
}
/**
* @param $type
* @throws \UnexpectedValueException
* @return boolean
*/
public function find($type)
{
......@@ -100,7 +121,7 @@ public function getPrevious()
/**
* moveNext
*
* @return mixed
* @return boolean
*/
public function moveNext()
{
......@@ -112,7 +133,7 @@ public function moveNext()
/**
* Lexical catchable patterns.
*
* @return array
* @return string[]
*/
protected function getCatchablePatterns()
{
......@@ -130,7 +151,7 @@ protected function getCatchablePatterns()
/**
* Lexical non-catchable patterns.
*
* @return array
* @return string[]
*/
protected function getNonCatchablePatterns()
{
......@@ -146,14 +167,48 @@ protected function getNonCatchablePatterns()
*/
protected function getType(&$value)
{
if ($this->isNullType($value)) {
return self::C_NUL;
}
if (isset($this->charValue[$value])) {
return $this->charValue[$value];
}
if (preg_match('/[\x10-\x1F]+/', $value)) {
if ($this->isInvalid($value)) {
$this->hasInvalidTokens = true;
return self::INVALID;
}
return self::GENERIC;
}
/**
* @param string $value
*/
protected function isNullType($value)
{
if ($value === "\0") {
return true;
}
return false;
}
/**
* @param string $value
*/
protected function isInvalid($value)
{
if (preg_match('/[\x10-\x1F]+/', $value)) {
return true;
}
if (isset($this->invalidASCII[ord($value)])) {
return true;
}
return false;
}
}
......@@ -28,6 +28,9 @@ public function __construct(EmailLexer $lexer)
$this->domainPartParser = new DomainPart($this->lexer);
}
/**
* @param string $str
*/
public function parse($str)
{
$this->lexer->setInput($str);
......@@ -36,6 +39,10 @@ public function parse($str)
throw new \InvalidArgumentException('ERR_NOLOCALPART');
}
if ($this->lexer->hasInvalidTokens()) {
throw new \InvalidArgumentException('ERR_INVALID_ATEXT');
}
$this->localPartParser->parse($str);
$this->domainPartParser->parse($str);
......@@ -78,6 +85,10 @@ protected function hasAtToken()
return true;
}
/**
* @param string $localPart
* @param string $parsedDomainPart
*/
protected function addLongEmailWarning($localPart, $parsedDomainPart)
{
if (strlen($localPart . '@' . $parsedDomainPart) > self::EMAIL_MAX_LENGTH) {
......
......@@ -2,8 +2,6 @@
namespace Egulias\EmailValidator;
use Egulias\EmailValidator\Parser\LocalPart;
/**
* EmailValidator
*
......@@ -97,7 +95,7 @@ public function isValid($email, $checkDNS = false, $strict = false)
return false;
}
return ($strict) ? (!$this->hasWarnings() && $dns) : true;
return !$strict || (!$this->hasWarnings() && $dns);
}
/**
......@@ -146,16 +144,9 @@ public function getThreshold()
protected function checkDNS()
{
$checked = false;
if (!function_exists('dns_get_record') && (
in_array(self::DNSWARN_NO_RECORD, $this->warnings) &&
in_array(self::DNSWARN_NO_MX_RECORD, $this->warnings)
)) {
return $checked;
}
$checked = true;
$result = checkdnsrr(trim($this->parser->getParsedDomainPart()), 'MX');
$checked = true;
if (!$result) {
$this->warnings[] = self::DNSWARN_NO_RECORD;
......
......@@ -23,6 +23,9 @@ public function parse($domainPart)
if ($this->lexer->token['type'] === EmailLexer::S_EMPTY) {
throw new \InvalidArgumentException('ERR_NODOMAIN');
}
if ($this->lexer->token['type'] === EmailLexer::S_HYPHEN) {
throw new \InvalidArgumentException('ERR_DOMAINHYPHENEND');
}
if ($this->lexer->token['type'] === EmailLexer::S_OPENPARENTHESIS) {
$this->warnings[] = EmailValidator::DEPREC_COMMENT;
......@@ -103,6 +106,10 @@ protected function doParseDomainPart()
do {
$prev = $this->lexer->getPrevious();
if ($this->lexer->token['type'] === EmailLexer::S_SLASH) {
throw new \InvalidArgumentException('ERR_DOMAIN_CHAR_NOT_ALLOWED');
}
if ($this->lexer->token['type'] === EmailLexer::S_OPENPARENTHESIS) {
$this->parseComments();
$this->lexer->moveNext();
......@@ -210,6 +217,9 @@ protected function doParseDomainLiteral()
return $addressLiteral;
}
/**
* @param string $addressLiteral
*/
protected function checkIPV4Tag($addressLiteral)
{
$matchesIP = array();
......@@ -295,5 +305,4 @@ protected function parseDomainComments()
throw new \InvalidArgumentException('ERR_EXPECTING_ATEXT');
}
}
}
\ No newline at end of file
}
......@@ -4,6 +4,7 @@
use Egulias\EmailValidator\EmailLexer;
use Egulias\EmailValidator\EmailValidator;
use \InvalidArgumentException;
class LocalPart extends Parser
......@@ -21,8 +22,7 @@ public function parse($localPart)
$closingQuote = $this->checkDQUOTE($closingQuote);
if ($closingQuote && $parseDQuote) {
$this->parseDoubleQuote();
$parseDQuote = false;
$parseDQuote = $this->parseDoubleQuote();
}
if ($this->lexer->token['type'] === EmailLexer::S_OPENPARENTHESIS) {
......@@ -56,23 +56,51 @@ public function parse($localPart)
protected function parseDoubleQuote()
{
$special = array (
$parseAgain = true;
$special = array(
EmailLexer::S_CR => true,
EmailLexer::S_HTAB => true,
EmailLexer::S_LF => true
);
$invalid = array(
EmailLexer::C_NUL => true,
EmailLexer::S_HTAB => true,
EmailLexer::S_CR => true,
EmailLexer::S_LF => true
);
$setSpecialsWarning = true;
$this->lexer->moveNext();
while ($this->lexer->token['type'] !== EmailLexer::S_DQUOTE && $this->lexer->token) {
$parseAgain = false;
if (isset($special[$this->lexer->token['type']]) && $setSpecialsWarning) {
$this->warnings[] = EmailValidator::CFWS_FWS;
$setSpecialsWarning = false;
}
$this->lexer->moveNext();
if (!$this->escaped() && isset($invalid[$this->lexer->token['type']])) {
throw new InvalidArgumentException("ERR_EXPECTED_ATEXT");
}
}
}
$prev = $this->lexer->getPrevious();
if ($prev['type'] === EmailLexer::S_BACKSLASH) {
if (!$this->checkDQUOTE(false)) {
throw new \InvalidArgumentException("ERR_UNCLOSED_DQUOTE");
}
}
if (!$this->lexer->isNextToken(EmailLexer::S_AT) && $prev['type'] !== EmailLexer::S_BACKSLASH) {
throw new \InvalidArgumentException("ERR_EXPECED_AT");
}
return $parseAgain;
}
protected function isInvalidToken($token, $closingQuote)
{
......
......@@ -124,8 +124,7 @@ protected function escaped()
if ($previous['type'] === EmailLexer::S_BACKSLASH
&&
($this->lexer->token['type'] === EmailLexer::S_SP ||
$this->lexer->token['type'] === EmailLexer::S_HTAB)
$this->lexer->token['type'] !== EmailLexer::GENERIC
) {
return true;
}
......@@ -164,6 +163,7 @@ protected function checkDQUOTE($hasClosingQuote)
if ($this->lexer->isNextToken(EmailLexer::GENERIC) && $previous['type'] === EmailLexer::GENERIC) {
throw new \InvalidArgumentException('ERR_EXPECTING_ATEXT');
}
$this->warnings[] = EmailValidator::RFC5321_QUOTEDSTRING;
try {
$this->lexer->find(EmailLexer::S_DQUOTE);
......@@ -187,4 +187,4 @@ protected function checkCRLFInFWS()
throw new \InvalidArgumentException("ERR_FWS_CRLF_END");
}
}
}
\ No newline at end of file
}
......@@ -44,6 +44,15 @@ public function testLexerSearchToken()
$this->assertTrue($lexer->find(EmailLexer::S_HTAB));
}
public function testLexerHasInvalidTokens()
{
$lexer = new EmailLexer();
$lexer->setInput(chr(226));
$lexer->moveNext();
$lexer->moveNext();
$this->assertTrue($lexer->hasInvalidTokens());
}
public function getTokens()
{
return array(
......@@ -61,6 +70,7 @@ public function getTokens()
array("\"", EmailLexer::S_DQUOTE),
array("-", EmailLexer::S_HYPHEN),
array("\\", EmailLexer::S_BACKSLASH),
array("/", EmailLexer::S_SLASH),
array("(", EmailLexer::S_OPENPARENTHESIS),
array(")", EmailLexer::S_CLOSEPARENTHESIS),
array('<', EmailLexer::S_LOWERTHAN),
......@@ -74,7 +84,9 @@ public function getTokens()
array('{', EmailLexer::S_OPENQBRACKET),
array('}', EmailLexer::S_CLOSEQBRACKET),
array('', EmailLexer::S_EMPTY),
array(chr(31), EmailLexer::INVALID)
array(chr(31), EmailLexer::INVALID),
array(chr(226), EmailLexer::INVALID),
array(chr(0), EmailLexer::C_NUL)
);
}
}
......@@ -43,6 +43,10 @@ public function getValidEmails()
array('"user,name"@example.com'),
array('"user name"@example.com'),
array('"user@name"@example.com'),
array('"\a"@iana.org'),
array('"test\ test"@iana.org'),
array('""@iana.org'),
array('"\""@iana.org'),
);
}
......@@ -57,9 +61,10 @@ public function testInvalidEmails($email)
public function getInvalidEmails()
{
return array(
array('example.@example.co.uk'),
array('example@example@example.co.uk'),