mirror of https://github.com/1099438829/apeblog
parent
ffdb3c7228
commit
f490f83c61
|
|
@ -166,7 +166,6 @@
|
||||||
$(function () {
|
$(function () {
|
||||||
$('#tag').select2();
|
$('#tag').select2();
|
||||||
});
|
});
|
||||||
|
|
||||||
$(document).ready(function(){
|
$(document).ready(function(){
|
||||||
var E = window.wangEditor
|
var E = window.wangEditor
|
||||||
// 切换语言
|
// 切换语言
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
<!--标签插件-->
|
<!--标签插件-->
|
||||||
<link rel="stylesheet" href="/static/admin/js/jquery-tags-input/jquery.tagsinput.min.css">
|
<link rel="stylesheet" href="/static/admin/js/jquery-tags-input/jquery.tagsinput.min.css">
|
||||||
<!--富文本输入框-->
|
<!--富文本输入框-->
|
||||||
<link rel="stylesheet" href="/static/admin/js/summernote/summernote.min.css">
|
<link href="https://cdn.staticfile.org/wangeditor5/5.1.23/css/style.min.css" rel="stylesheet">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
|
@ -90,9 +90,13 @@
|
||||||
<input class="form-control js-tags-input" type="text" name="tags" data-height="38px"
|
<input class="form-control js-tags-input" type="text" name="tags" data-height="38px"
|
||||||
placeholder="请输入标签">
|
placeholder="请输入标签">
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group col-md-12">
|
<div class="form-group col-md-12">
|
||||||
<label for="content">页面内容</label>
|
<label for="editor-text-area">页面内容</label>
|
||||||
<textarea id="content" name="content" data-provide="summernote" data-toolbar="full"></textarea>
|
<div style="border: 1px solid #ccc;">
|
||||||
|
<div id="editor-toolbar" style="border-bottom: 1px solid #ccc;"></div>
|
||||||
|
<div id="editor-text-area" style="height: 500px"></div>
|
||||||
|
</div>
|
||||||
|
<textarea id="content" name="content" style="display: none;"></textarea>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group col-md-12">
|
<div class="form-group col-md-12">
|
||||||
<button type="submit" class="btn btn-primary ajax-post" target-form="add-form">立即提交
|
<button type="submit" class="btn btn-primary ajax-post" target-form="add-form">立即提交
|
||||||
|
|
@ -107,8 +111,7 @@
|
||||||
<!--select2-->
|
<!--select2-->
|
||||||
<script type="text/javascript" src="/static/admin/js/select2.min.js"></script>
|
<script type="text/javascript" src="/static/admin/js/select2.min.js"></script>
|
||||||
<!--富文本输入框-->
|
<!--富文本输入框-->
|
||||||
<script type="text/javascript" src="/static/admin/js/summernote/summernote.min.js"></script>
|
<script src="https://cdn.staticfile.org/wangeditor5/5.1.23/index.js"></script>
|
||||||
<script type="text/javascript" src="/static/admin/js/summernote/lang/summernote-zh-CN.min.js"></script>
|
|
||||||
<!--标签-->
|
<!--标签-->
|
||||||
<script src="/static/admin/js/jquery-tags-input/jquery.tagsinput.min.js"></script>
|
<script src="/static/admin/js/jquery-tags-input/jquery.tagsinput.min.js"></script>
|
||||||
<script>
|
<script>
|
||||||
|
|
@ -116,51 +119,36 @@
|
||||||
$('#tag').select2();
|
$('#tag').select2();
|
||||||
});
|
});
|
||||||
$(document).ready(function(){
|
$(document).ready(function(){
|
||||||
$('[data-provide="summernote"]').each(function() {
|
var E = window.wangEditor
|
||||||
var options = {
|
// 切换语言
|
||||||
dialogsInBody: true,
|
var LANG = location.href.indexOf('lang=en') > 0 ? 'en' : 'zh-CN'
|
||||||
lang: 'zh-CN',
|
E.i18nChangeLanguage(LANG)
|
||||||
dialogsFade: true,
|
window.editor = E.createEditor({
|
||||||
height:400
|
selector: '#editor-text-area',
|
||||||
};
|
html: '<p><br></p>',
|
||||||
var config = {};
|
config: {
|
||||||
$.each( $(this).data(), function(key, value){
|
placeholder: '请输入...',
|
||||||
key = key.replace(/-([a-z])/g, function(x){return x[1].toUpperCase();});
|
MENU_CONF: {
|
||||||
if ( key == 'provide' ) {
|
uploadImage: {
|
||||||
return;
|
fieldName: 'your-fileName',
|
||||||
|
base64LimitSize: 10 * 1024 * 1024 // 10M 以下插入 base64
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onChange(editor) {
|
||||||
|
let content = editor.getHtml()
|
||||||
|
console.log('editor content', content)
|
||||||
|
// 也可以同步到 <textarea>
|
||||||
|
$("#content").val(content)
|
||||||
}
|
}
|
||||||
config[key] = value;
|
}
|
||||||
});
|
})
|
||||||
|
|
||||||
options = $.extend(options, config);
|
window.toolbar = E.createToolbar({
|
||||||
options.toolbar = [
|
editor,
|
||||||
// [groupName, [list of button]]
|
selector: '#editor-toolbar',
|
||||||
['para_style', ['style']],
|
config: {}
|
||||||
['style', ['bold', 'italic', 'underline', 'clear']],
|
})
|
||||||
['font', ['strikethrough', 'superscript', 'subscript']],
|
|
||||||
['fontsize', ['fontname', 'fontsize', 'height']],
|
|
||||||
['color', ['color']],
|
|
||||||
['para', ['ul', 'ol', 'paragraph', 'hr']],
|
|
||||||
['table', ['table']],
|
|
||||||
['insert', ['link', 'picture', 'video']],
|
|
||||||
['do', ['undo', 'redo']],
|
|
||||||
['misc', ['fullscreen', 'codeview', 'help']]
|
|
||||||
];
|
|
||||||
$(this).summernote(options);
|
|
||||||
});
|
|
||||||
|
|
||||||
$(document).on('click', '[data-summernote-edit]', function(){
|
|
||||||
var target = $(this).data('summernote-edit');
|
|
||||||
$(target).summernote({focus: true});
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
$(document).on('click', '[data-summernote-save]', function(){
|
|
||||||
var target = $(this).data('summernote-save');
|
|
||||||
var markup = $(target).summernote('code');
|
|
||||||
$(target).summernote('destroy');
|
|
||||||
alert('修改完成');
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
<!--标签插件-->
|
<!--标签插件-->
|
||||||
<link rel="stylesheet" href="/static/admin/js/jquery-tags-input/jquery.tagsinput.min.css">
|
<link rel="stylesheet" href="/static/admin/js/jquery-tags-input/jquery.tagsinput.min.css">
|
||||||
<!--富文本输入框-->
|
<!--富文本输入框-->
|
||||||
<link rel="stylesheet" href="/static/admin/js/summernote/summernote.min.css">
|
<link href="https://cdn.staticfile.org/wangeditor5/5.1.23/css/style.min.css" rel="stylesheet">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
|
@ -106,9 +106,13 @@
|
||||||
<label for="abstract">标签</label>
|
<label for="abstract">标签</label>
|
||||||
<input class="form-control js-tags-input" type="text" name="tags" data-height="38px" value="{$info.tags}" placeholder="请输入标签">
|
<input class="form-control js-tags-input" type="text" name="tags" data-height="38px" value="{$info.tags}" placeholder="请输入标签">
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group col-md-12">
|
<div class="form-group col-md-12">
|
||||||
<label for="content">页面内容</label>
|
<label for="editor-text-area">页面内容</label>
|
||||||
<textarea id="content" name="content" data-provide="summernote" data-toolbar="full">{$info.content}</textarea>
|
<div style="border: 1px solid #ccc;">
|
||||||
|
<div id="editor-toolbar" style="border-bottom: 1px solid #ccc;"></div>
|
||||||
|
<div id="editor-text-area" style="height: 500px"></div>
|
||||||
|
</div>
|
||||||
|
<textarea id="content" name="content" style="display: none;">{$info.content}</textarea>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group col-md-12">
|
<div class="form-group col-md-12">
|
||||||
<button type="submit" class="btn btn-primary ajax-post" target-form="add-form">立即提交
|
<button type="submit" class="btn btn-primary ajax-post" target-form="add-form">立即提交
|
||||||
|
|
@ -123,8 +127,7 @@
|
||||||
<!--select2-->
|
<!--select2-->
|
||||||
<script type="text/javascript" src="/static/admin/js/select2.min.js"></script>
|
<script type="text/javascript" src="/static/admin/js/select2.min.js"></script>
|
||||||
<!--富文本输入框-->
|
<!--富文本输入框-->
|
||||||
<script type="text/javascript" src="/static/admin/js/summernote/summernote.min.js"></script>
|
<script src="https://cdn.staticfile.org/wangeditor5/5.1.23/index.js"></script>
|
||||||
<script type="text/javascript" src="/static/admin/js/summernote/lang/summernote-zh-CN.min.js"></script>
|
|
||||||
<!--标签-->
|
<!--标签-->
|
||||||
<script src="/static/admin/js/jquery-tags-input/jquery.tagsinput.min.js"></script>
|
<script src="/static/admin/js/jquery-tags-input/jquery.tagsinput.min.js"></script>
|
||||||
<script>
|
<script>
|
||||||
|
|
@ -132,51 +135,37 @@
|
||||||
$('#tag').select2();
|
$('#tag').select2();
|
||||||
});
|
});
|
||||||
$(document).ready(function(){
|
$(document).ready(function(){
|
||||||
$('[data-provide="summernote"]').each(function() {
|
var E = window.wangEditor
|
||||||
var options = {
|
// 切换语言
|
||||||
dialogsInBody: true,
|
var LANG = location.href.indexOf('lang=en') > 0 ? 'en' : 'zh-CN'
|
||||||
lang: 'zh-CN',
|
E.i18nChangeLanguage(LANG)
|
||||||
dialogsFade: true,
|
//需要判断是否含有html标签
|
||||||
height:400
|
window.editor = E.createEditor({
|
||||||
};
|
selector: '#editor-text-area',
|
||||||
var config = {};
|
html: $('#content').val(), // 从 editor.getHtml() 获取的 html 内容
|
||||||
$.each( $(this).data(), function(key, value){
|
config: {
|
||||||
key = key.replace(/-([a-z])/g, function(x){return x[1].toUpperCase();});
|
placeholder: '请输入...',
|
||||||
if ( key == 'provide' ) {
|
MENU_CONF: {
|
||||||
return;
|
uploadImage: {
|
||||||
|
fieldName: 'your-fileName',
|
||||||
|
base64LimitSize: 10 * 1024 * 1024 // 10M 以下插入 base64
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onChange(editor) {
|
||||||
|
let content = editor.getHtml()
|
||||||
|
console.log('editor content', content)
|
||||||
|
// 也可以同步到 <textarea>
|
||||||
|
$("#content").val(content)
|
||||||
}
|
}
|
||||||
config[key] = value;
|
}
|
||||||
});
|
})
|
||||||
|
|
||||||
options = $.extend(options, config);
|
window.toolbar = E.createToolbar({
|
||||||
options.toolbar = [
|
editor,
|
||||||
// [groupName, [list of button]]
|
selector: '#editor-toolbar',
|
||||||
['para_style', ['style']],
|
config: {}
|
||||||
['style', ['bold', 'italic', 'underline', 'clear']],
|
})
|
||||||
['font', ['strikethrough', 'superscript', 'subscript']],
|
|
||||||
['fontsize', ['fontname', 'fontsize', 'height']],
|
|
||||||
['color', ['color']],
|
|
||||||
['para', ['ul', 'ol', 'paragraph', 'hr']],
|
|
||||||
['table', ['table']],
|
|
||||||
['insert', ['link', 'picture', 'video']],
|
|
||||||
['do', ['undo', 'redo']],
|
|
||||||
['misc', ['fullscreen', 'codeview', 'help']]
|
|
||||||
];
|
|
||||||
$(this).summernote(options);
|
|
||||||
});
|
|
||||||
|
|
||||||
$(document).on('click', '[data-summernote-edit]', function(){
|
|
||||||
var target = $(this).data('summernote-edit');
|
|
||||||
$(target).summernote({focus: true});
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
$(document).on('click', '[data-summernote-save]', function(){
|
|
||||||
var target = $(this).data('summernote-save');
|
|
||||||
var markup = $(target).summernote('code');
|
|
||||||
$(target).summernote('destroy');
|
|
||||||
alert('修改完成');
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -45,35 +45,34 @@ class ClassLoader
|
||||||
/** @var \Closure(string):void */
|
/** @var \Closure(string):void */
|
||||||
private static $includeFile;
|
private static $includeFile;
|
||||||
|
|
||||||
/** @var ?string */
|
/** @var string|null */
|
||||||
private $vendorDir;
|
private $vendorDir;
|
||||||
|
|
||||||
// PSR-4
|
// PSR-4
|
||||||
/**
|
/**
|
||||||
* @var array[]
|
* @var array<string, array<string, int>>
|
||||||
* @psalm-var array<string, array<string, int>>
|
|
||||||
*/
|
*/
|
||||||
private $prefixLengthsPsr4 = array();
|
private $prefixLengthsPsr4 = array();
|
||||||
/**
|
/**
|
||||||
* @var array[]
|
* @var array<string, list<string>>
|
||||||
* @psalm-var array<string, array<int, string>>
|
|
||||||
*/
|
*/
|
||||||
private $prefixDirsPsr4 = array();
|
private $prefixDirsPsr4 = array();
|
||||||
/**
|
/**
|
||||||
* @var array[]
|
* @var list<string>
|
||||||
* @psalm-var array<string, string>
|
|
||||||
*/
|
*/
|
||||||
private $fallbackDirsPsr4 = array();
|
private $fallbackDirsPsr4 = array();
|
||||||
|
|
||||||
// PSR-0
|
// PSR-0
|
||||||
/**
|
/**
|
||||||
* @var array[]
|
* List of PSR-0 prefixes
|
||||||
* @psalm-var array<string, array<string, string[]>>
|
*
|
||||||
|
* Structured as array('F (first letter)' => array('Foo\Bar (full prefix)' => array('path', 'path2')))
|
||||||
|
*
|
||||||
|
* @var array<string, array<string, list<string>>>
|
||||||
*/
|
*/
|
||||||
private $prefixesPsr0 = array();
|
private $prefixesPsr0 = array();
|
||||||
/**
|
/**
|
||||||
* @var array[]
|
* @var list<string>
|
||||||
* @psalm-var array<string, string>
|
|
||||||
*/
|
*/
|
||||||
private $fallbackDirsPsr0 = array();
|
private $fallbackDirsPsr0 = array();
|
||||||
|
|
||||||
|
|
@ -81,8 +80,7 @@ class ClassLoader
|
||||||
private $useIncludePath = false;
|
private $useIncludePath = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string[]
|
* @var array<string, string>
|
||||||
* @psalm-var array<string, string>
|
|
||||||
*/
|
*/
|
||||||
private $classMap = array();
|
private $classMap = array();
|
||||||
|
|
||||||
|
|
@ -90,21 +88,20 @@ class ClassLoader
|
||||||
private $classMapAuthoritative = false;
|
private $classMapAuthoritative = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var bool[]
|
* @var array<string, bool>
|
||||||
* @psalm-var array<string, bool>
|
|
||||||
*/
|
*/
|
||||||
private $missingClasses = array();
|
private $missingClasses = array();
|
||||||
|
|
||||||
/** @var ?string */
|
/** @var string|null */
|
||||||
private $apcuPrefix;
|
private $apcuPrefix;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var self[]
|
* @var array<string, self>
|
||||||
*/
|
*/
|
||||||
private static $registeredLoaders = array();
|
private static $registeredLoaders = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ?string $vendorDir
|
* @param string|null $vendorDir
|
||||||
*/
|
*/
|
||||||
public function __construct($vendorDir = null)
|
public function __construct($vendorDir = null)
|
||||||
{
|
{
|
||||||
|
|
@ -113,7 +110,7 @@ class ClassLoader
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string[]
|
* @return array<string, list<string>>
|
||||||
*/
|
*/
|
||||||
public function getPrefixes()
|
public function getPrefixes()
|
||||||
{
|
{
|
||||||
|
|
@ -125,8 +122,7 @@ class ClassLoader
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array[]
|
* @return array<string, list<string>>
|
||||||
* @psalm-return array<string, array<int, string>>
|
|
||||||
*/
|
*/
|
||||||
public function getPrefixesPsr4()
|
public function getPrefixesPsr4()
|
||||||
{
|
{
|
||||||
|
|
@ -134,8 +130,7 @@ class ClassLoader
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array[]
|
* @return list<string>
|
||||||
* @psalm-return array<string, string>
|
|
||||||
*/
|
*/
|
||||||
public function getFallbackDirs()
|
public function getFallbackDirs()
|
||||||
{
|
{
|
||||||
|
|
@ -143,8 +138,7 @@ class ClassLoader
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array[]
|
* @return list<string>
|
||||||
* @psalm-return array<string, string>
|
|
||||||
*/
|
*/
|
||||||
public function getFallbackDirsPsr4()
|
public function getFallbackDirsPsr4()
|
||||||
{
|
{
|
||||||
|
|
@ -152,8 +146,7 @@ class ClassLoader
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string[] Array of classname => path
|
* @return array<string, string> Array of classname => path
|
||||||
* @psalm-return array<string, string>
|
|
||||||
*/
|
*/
|
||||||
public function getClassMap()
|
public function getClassMap()
|
||||||
{
|
{
|
||||||
|
|
@ -161,8 +154,7 @@ class ClassLoader
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string[] $classMap Class to filename map
|
* @param array<string, string> $classMap Class to filename map
|
||||||
* @psalm-param array<string, string> $classMap
|
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
|
|
@ -179,24 +171,25 @@ class ClassLoader
|
||||||
* Registers a set of PSR-0 directories for a given prefix, either
|
* Registers a set of PSR-0 directories for a given prefix, either
|
||||||
* appending or prepending to the ones previously set for this prefix.
|
* appending or prepending to the ones previously set for this prefix.
|
||||||
*
|
*
|
||||||
* @param string $prefix The prefix
|
* @param string $prefix The prefix
|
||||||
* @param string[]|string $paths The PSR-0 root directories
|
* @param list<string>|string $paths The PSR-0 root directories
|
||||||
* @param bool $prepend Whether to prepend the directories
|
* @param bool $prepend Whether to prepend the directories
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function add($prefix, $paths, $prepend = false)
|
public function add($prefix, $paths, $prepend = false)
|
||||||
{
|
{
|
||||||
|
$paths = (array) $paths;
|
||||||
if (!$prefix) {
|
if (!$prefix) {
|
||||||
if ($prepend) {
|
if ($prepend) {
|
||||||
$this->fallbackDirsPsr0 = array_merge(
|
$this->fallbackDirsPsr0 = array_merge(
|
||||||
(array) $paths,
|
$paths,
|
||||||
$this->fallbackDirsPsr0
|
$this->fallbackDirsPsr0
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
$this->fallbackDirsPsr0 = array_merge(
|
$this->fallbackDirsPsr0 = array_merge(
|
||||||
$this->fallbackDirsPsr0,
|
$this->fallbackDirsPsr0,
|
||||||
(array) $paths
|
$paths
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -205,19 +198,19 @@ class ClassLoader
|
||||||
|
|
||||||
$first = $prefix[0];
|
$first = $prefix[0];
|
||||||
if (!isset($this->prefixesPsr0[$first][$prefix])) {
|
if (!isset($this->prefixesPsr0[$first][$prefix])) {
|
||||||
$this->prefixesPsr0[$first][$prefix] = (array) $paths;
|
$this->prefixesPsr0[$first][$prefix] = $paths;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ($prepend) {
|
if ($prepend) {
|
||||||
$this->prefixesPsr0[$first][$prefix] = array_merge(
|
$this->prefixesPsr0[$first][$prefix] = array_merge(
|
||||||
(array) $paths,
|
$paths,
|
||||||
$this->prefixesPsr0[$first][$prefix]
|
$this->prefixesPsr0[$first][$prefix]
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
$this->prefixesPsr0[$first][$prefix] = array_merge(
|
$this->prefixesPsr0[$first][$prefix] = array_merge(
|
||||||
$this->prefixesPsr0[$first][$prefix],
|
$this->prefixesPsr0[$first][$prefix],
|
||||||
(array) $paths
|
$paths
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -226,9 +219,9 @@ class ClassLoader
|
||||||
* Registers a set of PSR-4 directories for a given namespace, either
|
* Registers a set of PSR-4 directories for a given namespace, either
|
||||||
* appending or prepending to the ones previously set for this namespace.
|
* appending or prepending to the ones previously set for this namespace.
|
||||||
*
|
*
|
||||||
* @param string $prefix The prefix/namespace, with trailing '\\'
|
* @param string $prefix The prefix/namespace, with trailing '\\'
|
||||||
* @param string[]|string $paths The PSR-4 base directories
|
* @param list<string>|string $paths The PSR-4 base directories
|
||||||
* @param bool $prepend Whether to prepend the directories
|
* @param bool $prepend Whether to prepend the directories
|
||||||
*
|
*
|
||||||
* @throws \InvalidArgumentException
|
* @throws \InvalidArgumentException
|
||||||
*
|
*
|
||||||
|
|
@ -236,17 +229,18 @@ class ClassLoader
|
||||||
*/
|
*/
|
||||||
public function addPsr4($prefix, $paths, $prepend = false)
|
public function addPsr4($prefix, $paths, $prepend = false)
|
||||||
{
|
{
|
||||||
|
$paths = (array) $paths;
|
||||||
if (!$prefix) {
|
if (!$prefix) {
|
||||||
// Register directories for the root namespace.
|
// Register directories for the root namespace.
|
||||||
if ($prepend) {
|
if ($prepend) {
|
||||||
$this->fallbackDirsPsr4 = array_merge(
|
$this->fallbackDirsPsr4 = array_merge(
|
||||||
(array) $paths,
|
$paths,
|
||||||
$this->fallbackDirsPsr4
|
$this->fallbackDirsPsr4
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
$this->fallbackDirsPsr4 = array_merge(
|
$this->fallbackDirsPsr4 = array_merge(
|
||||||
$this->fallbackDirsPsr4,
|
$this->fallbackDirsPsr4,
|
||||||
(array) $paths
|
$paths
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} elseif (!isset($this->prefixDirsPsr4[$prefix])) {
|
} elseif (!isset($this->prefixDirsPsr4[$prefix])) {
|
||||||
|
|
@ -256,18 +250,18 @@ class ClassLoader
|
||||||
throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
|
throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
|
||||||
}
|
}
|
||||||
$this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
|
$this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
|
||||||
$this->prefixDirsPsr4[$prefix] = (array) $paths;
|
$this->prefixDirsPsr4[$prefix] = $paths;
|
||||||
} elseif ($prepend) {
|
} elseif ($prepend) {
|
||||||
// Prepend directories for an already registered namespace.
|
// Prepend directories for an already registered namespace.
|
||||||
$this->prefixDirsPsr4[$prefix] = array_merge(
|
$this->prefixDirsPsr4[$prefix] = array_merge(
|
||||||
(array) $paths,
|
$paths,
|
||||||
$this->prefixDirsPsr4[$prefix]
|
$this->prefixDirsPsr4[$prefix]
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
// Append directories for an already registered namespace.
|
// Append directories for an already registered namespace.
|
||||||
$this->prefixDirsPsr4[$prefix] = array_merge(
|
$this->prefixDirsPsr4[$prefix] = array_merge(
|
||||||
$this->prefixDirsPsr4[$prefix],
|
$this->prefixDirsPsr4[$prefix],
|
||||||
(array) $paths
|
$paths
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -276,8 +270,8 @@ class ClassLoader
|
||||||
* Registers a set of PSR-0 directories for a given prefix,
|
* Registers a set of PSR-0 directories for a given prefix,
|
||||||
* replacing any others previously set for this prefix.
|
* replacing any others previously set for this prefix.
|
||||||
*
|
*
|
||||||
* @param string $prefix The prefix
|
* @param string $prefix The prefix
|
||||||
* @param string[]|string $paths The PSR-0 base directories
|
* @param list<string>|string $paths The PSR-0 base directories
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
|
|
@ -294,8 +288,8 @@ class ClassLoader
|
||||||
* Registers a set of PSR-4 directories for a given namespace,
|
* Registers a set of PSR-4 directories for a given namespace,
|
||||||
* replacing any others previously set for this namespace.
|
* replacing any others previously set for this namespace.
|
||||||
*
|
*
|
||||||
* @param string $prefix The prefix/namespace, with trailing '\\'
|
* @param string $prefix The prefix/namespace, with trailing '\\'
|
||||||
* @param string[]|string $paths The PSR-4 base directories
|
* @param list<string>|string $paths The PSR-4 base directories
|
||||||
*
|
*
|
||||||
* @throws \InvalidArgumentException
|
* @throws \InvalidArgumentException
|
||||||
*
|
*
|
||||||
|
|
@ -481,9 +475,9 @@ class ClassLoader
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the currently registered loaders indexed by their corresponding vendor directories.
|
* Returns the currently registered loaders keyed by their corresponding vendor directories.
|
||||||
*
|
*
|
||||||
* @return self[]
|
* @return array<string, self>
|
||||||
*/
|
*/
|
||||||
public static function getRegisteredLoaders()
|
public static function getRegisteredLoaders()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -98,7 +98,7 @@ class InstalledVersions
|
||||||
{
|
{
|
||||||
foreach (self::getInstalled() as $installed) {
|
foreach (self::getInstalled() as $installed) {
|
||||||
if (isset($installed['versions'][$packageName])) {
|
if (isset($installed['versions'][$packageName])) {
|
||||||
return $includeDevRequirements || empty($installed['versions'][$packageName]['dev_requirement']);
|
return $includeDevRequirements || !isset($installed['versions'][$packageName]['dev_requirement']) || $installed['versions'][$packageName]['dev_requirement'] === false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -119,7 +119,7 @@ class InstalledVersions
|
||||||
*/
|
*/
|
||||||
public static function satisfies(VersionParser $parser, $packageName, $constraint)
|
public static function satisfies(VersionParser $parser, $packageName, $constraint)
|
||||||
{
|
{
|
||||||
$constraint = $parser->parseConstraints($constraint);
|
$constraint = $parser->parseConstraints((string) $constraint);
|
||||||
$provided = $parser->parseConstraints(self::getVersionRanges($packageName));
|
$provided = $parser->parseConstraints(self::getVersionRanges($packageName));
|
||||||
|
|
||||||
return $provided->matches($constraint);
|
return $provided->matches($constraint);
|
||||||
|
|
@ -328,7 +328,9 @@ class InstalledVersions
|
||||||
if (isset(self::$installedByVendor[$vendorDir])) {
|
if (isset(self::$installedByVendor[$vendorDir])) {
|
||||||
$installed[] = self::$installedByVendor[$vendorDir];
|
$installed[] = self::$installedByVendor[$vendorDir];
|
||||||
} elseif (is_file($vendorDir.'/composer/installed.php')) {
|
} elseif (is_file($vendorDir.'/composer/installed.php')) {
|
||||||
$installed[] = self::$installedByVendor[$vendorDir] = require $vendorDir.'/composer/installed.php';
|
/** @var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $required */
|
||||||
|
$required = require $vendorDir.'/composer/installed.php';
|
||||||
|
$installed[] = self::$installedByVendor[$vendorDir] = $required;
|
||||||
if (null === self::$installed && strtr($vendorDir.'/composer', '\\', '/') === strtr(__DIR__, '\\', '/')) {
|
if (null === self::$installed && strtr($vendorDir.'/composer', '\\', '/') === strtr(__DIR__, '\\', '/')) {
|
||||||
self::$installed = $installed[count($installed) - 1];
|
self::$installed = $installed[count($installed) - 1];
|
||||||
}
|
}
|
||||||
|
|
@ -340,12 +342,17 @@ class InstalledVersions
|
||||||
// only require the installed.php file if this file is loaded from its dumped location,
|
// only require the installed.php file if this file is loaded from its dumped location,
|
||||||
// and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937
|
// and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937
|
||||||
if (substr(__DIR__, -8, 1) !== 'C') {
|
if (substr(__DIR__, -8, 1) !== 'C') {
|
||||||
self::$installed = require __DIR__ . '/installed.php';
|
/** @var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $required */
|
||||||
|
$required = require __DIR__ . '/installed.php';
|
||||||
|
self::$installed = $required;
|
||||||
} else {
|
} else {
|
||||||
self::$installed = array();
|
self::$installed = array();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$installed[] = self::$installed;
|
|
||||||
|
if (self::$installed !== array()) {
|
||||||
|
$installed[] = self::$installed;
|
||||||
|
}
|
||||||
|
|
||||||
return $installed;
|
return $installed;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@ $baseDir = dirname($vendorDir);
|
||||||
return array(
|
return array(
|
||||||
'Attribute' => $vendorDir . '/symfony/polyfill-php80/Resources/stubs/Attribute.php',
|
'Attribute' => $vendorDir . '/symfony/polyfill-php80/Resources/stubs/Attribute.php',
|
||||||
'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php',
|
'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php',
|
||||||
'Normalizer' => $vendorDir . '/symfony/polyfill-intl-normalizer/Resources/stubs/Normalizer.php',
|
|
||||||
'PhpToken' => $vendorDir . '/symfony/polyfill-php80/Resources/stubs/PhpToken.php',
|
'PhpToken' => $vendorDir . '/symfony/polyfill-php80/Resources/stubs/PhpToken.php',
|
||||||
'Stringable' => $vendorDir . '/symfony/polyfill-php80/Resources/stubs/Stringable.php',
|
'Stringable' => $vendorDir . '/symfony/polyfill-php80/Resources/stubs/Stringable.php',
|
||||||
'UnhandledMatchError' => $vendorDir . '/symfony/polyfill-php80/Resources/stubs/UnhandledMatchError.php',
|
'UnhandledMatchError' => $vendorDir . '/symfony/polyfill-php80/Resources/stubs/UnhandledMatchError.php',
|
||||||
|
|
|
||||||
|
|
@ -6,14 +6,13 @@ $vendorDir = dirname(__DIR__);
|
||||||
$baseDir = dirname($vendorDir);
|
$baseDir = dirname($vendorDir);
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'6e3fae29631ef280660b3cdad06f25a8' => $vendorDir . '/symfony/deprecation-contracts/function.php',
|
|
||||||
'a4a119a56e50fbb293281d9a48007e0e' => $vendorDir . '/symfony/polyfill-php80/bootstrap.php',
|
|
||||||
'9b552a3cc426e3287cc811caefa3cf53' => $vendorDir . '/topthink/think-helper/src/helper.php',
|
'9b552a3cc426e3287cc811caefa3cf53' => $vendorDir . '/topthink/think-helper/src/helper.php',
|
||||||
'25072dd6e2470089de65ae7bf11d3109' => $vendorDir . '/symfony/polyfill-php72/bootstrap.php',
|
|
||||||
'e69f7f6ee287b969198c3c9d6777bd38' => $vendorDir . '/symfony/polyfill-intl-normalizer/bootstrap.php',
|
|
||||||
'f598d06aa772fa33d905e87be6398fb1' => $vendorDir . '/symfony/polyfill-intl-idn/bootstrap.php',
|
|
||||||
'0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => $vendorDir . '/symfony/polyfill-mbstring/bootstrap.php',
|
|
||||||
'35fab96057f1bf5e7aba31a8a6d5fdde' => $vendorDir . '/topthink/think-orm/stubs/load_stubs.php',
|
'35fab96057f1bf5e7aba31a8a6d5fdde' => $vendorDir . '/topthink/think-orm/stubs/load_stubs.php',
|
||||||
|
'0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => $vendorDir . '/symfony/polyfill-mbstring/bootstrap.php',
|
||||||
|
'a4a119a56e50fbb293281d9a48007e0e' => $vendorDir . '/symfony/polyfill-php80/bootstrap.php',
|
||||||
|
'6e3fae29631ef280660b3cdad06f25a8' => $vendorDir . '/symfony/deprecation-contracts/function.php',
|
||||||
|
'2c102faa651ef8ea5874edb585946bce' => $vendorDir . '/swiftmailer/swiftmailer/lib/swift_required.php',
|
||||||
|
'25072dd6e2470089de65ae7bf11d3109' => $vendorDir . '/symfony/polyfill-php72/bootstrap.php',
|
||||||
'667aeda72477189d0494fecd327c3641' => $vendorDir . '/symfony/var-dumper/Resources/functions/dump.php',
|
'667aeda72477189d0494fecd327c3641' => $vendorDir . '/symfony/var-dumper/Resources/functions/dump.php',
|
||||||
'1cfd2761b63b0a29ed23657ea394cb2d' => $vendorDir . '/topthink/think-captcha/src/helper.php',
|
'1cfd2761b63b0a29ed23657ea394cb2d' => $vendorDir . '/topthink/think-captcha/src/helper.php',
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -18,27 +18,18 @@ return array(
|
||||||
'Symfony\\Polyfill\\Php80\\' => array($vendorDir . '/symfony/polyfill-php80'),
|
'Symfony\\Polyfill\\Php80\\' => array($vendorDir . '/symfony/polyfill-php80'),
|
||||||
'Symfony\\Polyfill\\Php72\\' => array($vendorDir . '/symfony/polyfill-php72'),
|
'Symfony\\Polyfill\\Php72\\' => array($vendorDir . '/symfony/polyfill-php72'),
|
||||||
'Symfony\\Polyfill\\Mbstring\\' => array($vendorDir . '/symfony/polyfill-mbstring'),
|
'Symfony\\Polyfill\\Mbstring\\' => array($vendorDir . '/symfony/polyfill-mbstring'),
|
||||||
'Symfony\\Polyfill\\Intl\\Normalizer\\' => array($vendorDir . '/symfony/polyfill-intl-normalizer'),
|
|
||||||
'Symfony\\Polyfill\\Intl\\Idn\\' => array($vendorDir . '/symfony/polyfill-intl-idn'),
|
|
||||||
'Symfony\\Contracts\\Service\\' => array($vendorDir . '/symfony/service-contracts'),
|
|
||||||
'Symfony\\Contracts\\EventDispatcher\\' => array($vendorDir . '/symfony/event-dispatcher-contracts'),
|
|
||||||
'Symfony\\Component\\VarDumper\\' => array($vendorDir . '/symfony/var-dumper'),
|
'Symfony\\Component\\VarDumper\\' => array($vendorDir . '/symfony/var-dumper'),
|
||||||
'Symfony\\Component\\Mime\\' => array($vendorDir . '/symfony/mime'),
|
|
||||||
'Symfony\\Component\\Mailer\\' => array($vendorDir . '/symfony/mailer'),
|
|
||||||
'Symfony\\Component\\HttpFoundation\\' => array($vendorDir . '/symfony/http-foundation'),
|
'Symfony\\Component\\HttpFoundation\\' => array($vendorDir . '/symfony/http-foundation'),
|
||||||
'Symfony\\Component\\EventDispatcher\\' => array($vendorDir . '/symfony/event-dispatcher'),
|
|
||||||
'Spatie\\Macroable\\' => array($vendorDir . '/spatie/macroable/src'),
|
'Spatie\\Macroable\\' => array($vendorDir . '/spatie/macroable/src'),
|
||||||
'Psr\\SimpleCache\\' => array($vendorDir . '/psr/simple-cache/src'),
|
'Psr\\SimpleCache\\' => array($vendorDir . '/psr/simple-cache/src'),
|
||||||
'Psr\\Log\\' => array($vendorDir . '/psr/log/Psr/Log'),
|
'Psr\\Log\\' => array($vendorDir . '/psr/log/Psr/Log'),
|
||||||
'Psr\\Http\\Message\\' => array($vendorDir . '/psr/http-message/src'),
|
'Psr\\Http\\Message\\' => array($vendorDir . '/psr/http-message/src'),
|
||||||
'Psr\\EventDispatcher\\' => array($vendorDir . '/psr/event-dispatcher/src'),
|
|
||||||
'Psr\\Container\\' => array($vendorDir . '/psr/container/src'),
|
'Psr\\Container\\' => array($vendorDir . '/psr/container/src'),
|
||||||
'Psr\\Cache\\' => array($vendorDir . '/psr/cache/src'),
|
'Psr\\Cache\\' => array($vendorDir . '/psr/cache/src'),
|
||||||
'PHPMailer\\PHPMailer\\' => array($vendorDir . '/phpmailer/phpmailer/src'),
|
'PHPMailer\\PHPMailer\\' => array($vendorDir . '/phpmailer/phpmailer/src'),
|
||||||
'League\\MimeTypeDetection\\' => array($vendorDir . '/league/mime-type-detection/src'),
|
'League\\MimeTypeDetection\\' => array($vendorDir . '/league/mime-type-detection/src'),
|
||||||
'League\\Flysystem\\' => array($vendorDir . '/league/flysystem/src'),
|
'League\\Flysystem\\' => array($vendorDir . '/league/flysystem/src'),
|
||||||
'FormBuilder\\' => array($vendorDir . '/xaboy/form-builder/src'),
|
'FormBuilder\\' => array($vendorDir . '/xaboy/form-builder/src'),
|
||||||
'Egulias\\EmailValidator\\' => array($vendorDir . '/egulias/email-validator/src'),
|
|
||||||
'Doctrine\\Deprecations\\' => array($vendorDir . '/doctrine/deprecations/lib/Doctrine/Deprecations'),
|
'Doctrine\\Deprecations\\' => array($vendorDir . '/doctrine/deprecations/lib/Doctrine/Deprecations'),
|
||||||
'Doctrine\\Common\\Lexer\\' => array($vendorDir . '/doctrine/lexer/src'),
|
'Doctrine\\Common\\Lexer\\' => array($vendorDir . '/doctrine/lexer/src'),
|
||||||
'Doctrine\\Common\\Annotations\\' => array($vendorDir . '/doctrine/annotations/lib/Doctrine/Common/Annotations'),
|
'Doctrine\\Common\\Annotations\\' => array($vendorDir . '/doctrine/annotations/lib/Doctrine/Common/Annotations'),
|
||||||
|
|
|
||||||
|
|
@ -7,14 +7,13 @@ namespace Composer\Autoload;
|
||||||
class ComposerStaticInit4b57298e8d0e895486f3307a354a7e1a
|
class ComposerStaticInit4b57298e8d0e895486f3307a354a7e1a
|
||||||
{
|
{
|
||||||
public static $files = array (
|
public static $files = array (
|
||||||
'6e3fae29631ef280660b3cdad06f25a8' => __DIR__ . '/..' . '/symfony/deprecation-contracts/function.php',
|
|
||||||
'a4a119a56e50fbb293281d9a48007e0e' => __DIR__ . '/..' . '/symfony/polyfill-php80/bootstrap.php',
|
|
||||||
'9b552a3cc426e3287cc811caefa3cf53' => __DIR__ . '/..' . '/topthink/think-helper/src/helper.php',
|
'9b552a3cc426e3287cc811caefa3cf53' => __DIR__ . '/..' . '/topthink/think-helper/src/helper.php',
|
||||||
'25072dd6e2470089de65ae7bf11d3109' => __DIR__ . '/..' . '/symfony/polyfill-php72/bootstrap.php',
|
|
||||||
'e69f7f6ee287b969198c3c9d6777bd38' => __DIR__ . '/..' . '/symfony/polyfill-intl-normalizer/bootstrap.php',
|
|
||||||
'f598d06aa772fa33d905e87be6398fb1' => __DIR__ . '/..' . '/symfony/polyfill-intl-idn/bootstrap.php',
|
|
||||||
'0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => __DIR__ . '/..' . '/symfony/polyfill-mbstring/bootstrap.php',
|
|
||||||
'35fab96057f1bf5e7aba31a8a6d5fdde' => __DIR__ . '/..' . '/topthink/think-orm/stubs/load_stubs.php',
|
'35fab96057f1bf5e7aba31a8a6d5fdde' => __DIR__ . '/..' . '/topthink/think-orm/stubs/load_stubs.php',
|
||||||
|
'0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => __DIR__ . '/..' . '/symfony/polyfill-mbstring/bootstrap.php',
|
||||||
|
'a4a119a56e50fbb293281d9a48007e0e' => __DIR__ . '/..' . '/symfony/polyfill-php80/bootstrap.php',
|
||||||
|
'6e3fae29631ef280660b3cdad06f25a8' => __DIR__ . '/..' . '/symfony/deprecation-contracts/function.php',
|
||||||
|
'2c102faa651ef8ea5874edb585946bce' => __DIR__ . '/..' . '/swiftmailer/swiftmailer/lib/swift_required.php',
|
||||||
|
'25072dd6e2470089de65ae7bf11d3109' => __DIR__ . '/..' . '/symfony/polyfill-php72/bootstrap.php',
|
||||||
'667aeda72477189d0494fecd327c3641' => __DIR__ . '/..' . '/symfony/var-dumper/Resources/functions/dump.php',
|
'667aeda72477189d0494fecd327c3641' => __DIR__ . '/..' . '/symfony/var-dumper/Resources/functions/dump.php',
|
||||||
'1cfd2761b63b0a29ed23657ea394cb2d' => __DIR__ . '/..' . '/topthink/think-captcha/src/helper.php',
|
'1cfd2761b63b0a29ed23657ea394cb2d' => __DIR__ . '/..' . '/topthink/think-captcha/src/helper.php',
|
||||||
);
|
);
|
||||||
|
|
@ -46,15 +45,8 @@ class ComposerStaticInit4b57298e8d0e895486f3307a354a7e1a
|
||||||
'Symfony\\Polyfill\\Php80\\' => 23,
|
'Symfony\\Polyfill\\Php80\\' => 23,
|
||||||
'Symfony\\Polyfill\\Php72\\' => 23,
|
'Symfony\\Polyfill\\Php72\\' => 23,
|
||||||
'Symfony\\Polyfill\\Mbstring\\' => 26,
|
'Symfony\\Polyfill\\Mbstring\\' => 26,
|
||||||
'Symfony\\Polyfill\\Intl\\Normalizer\\' => 33,
|
|
||||||
'Symfony\\Polyfill\\Intl\\Idn\\' => 26,
|
|
||||||
'Symfony\\Contracts\\Service\\' => 26,
|
|
||||||
'Symfony\\Contracts\\EventDispatcher\\' => 34,
|
|
||||||
'Symfony\\Component\\VarDumper\\' => 28,
|
'Symfony\\Component\\VarDumper\\' => 28,
|
||||||
'Symfony\\Component\\Mime\\' => 23,
|
|
||||||
'Symfony\\Component\\Mailer\\' => 25,
|
|
||||||
'Symfony\\Component\\HttpFoundation\\' => 33,
|
'Symfony\\Component\\HttpFoundation\\' => 33,
|
||||||
'Symfony\\Component\\EventDispatcher\\' => 34,
|
|
||||||
'Spatie\\Macroable\\' => 17,
|
'Spatie\\Macroable\\' => 17,
|
||||||
),
|
),
|
||||||
'P' =>
|
'P' =>
|
||||||
|
|
@ -62,7 +54,6 @@ class ComposerStaticInit4b57298e8d0e895486f3307a354a7e1a
|
||||||
'Psr\\SimpleCache\\' => 16,
|
'Psr\\SimpleCache\\' => 16,
|
||||||
'Psr\\Log\\' => 8,
|
'Psr\\Log\\' => 8,
|
||||||
'Psr\\Http\\Message\\' => 17,
|
'Psr\\Http\\Message\\' => 17,
|
||||||
'Psr\\EventDispatcher\\' => 20,
|
|
||||||
'Psr\\Container\\' => 14,
|
'Psr\\Container\\' => 14,
|
||||||
'Psr\\Cache\\' => 10,
|
'Psr\\Cache\\' => 10,
|
||||||
'PHPMailer\\PHPMailer\\' => 20,
|
'PHPMailer\\PHPMailer\\' => 20,
|
||||||
|
|
@ -76,10 +67,6 @@ class ComposerStaticInit4b57298e8d0e895486f3307a354a7e1a
|
||||||
array (
|
array (
|
||||||
'FormBuilder\\' => 12,
|
'FormBuilder\\' => 12,
|
||||||
),
|
),
|
||||||
'E' =>
|
|
||||||
array (
|
|
||||||
'Egulias\\EmailValidator\\' => 23,
|
|
||||||
),
|
|
||||||
'D' =>
|
'D' =>
|
||||||
array (
|
array (
|
||||||
'Doctrine\\Deprecations\\' => 22,
|
'Doctrine\\Deprecations\\' => 22,
|
||||||
|
|
@ -141,42 +128,14 @@ class ComposerStaticInit4b57298e8d0e895486f3307a354a7e1a
|
||||||
array (
|
array (
|
||||||
0 => __DIR__ . '/..' . '/symfony/polyfill-mbstring',
|
0 => __DIR__ . '/..' . '/symfony/polyfill-mbstring',
|
||||||
),
|
),
|
||||||
'Symfony\\Polyfill\\Intl\\Normalizer\\' =>
|
|
||||||
array (
|
|
||||||
0 => __DIR__ . '/..' . '/symfony/polyfill-intl-normalizer',
|
|
||||||
),
|
|
||||||
'Symfony\\Polyfill\\Intl\\Idn\\' =>
|
|
||||||
array (
|
|
||||||
0 => __DIR__ . '/..' . '/symfony/polyfill-intl-idn',
|
|
||||||
),
|
|
||||||
'Symfony\\Contracts\\Service\\' =>
|
|
||||||
array (
|
|
||||||
0 => __DIR__ . '/..' . '/symfony/service-contracts',
|
|
||||||
),
|
|
||||||
'Symfony\\Contracts\\EventDispatcher\\' =>
|
|
||||||
array (
|
|
||||||
0 => __DIR__ . '/..' . '/symfony/event-dispatcher-contracts',
|
|
||||||
),
|
|
||||||
'Symfony\\Component\\VarDumper\\' =>
|
'Symfony\\Component\\VarDumper\\' =>
|
||||||
array (
|
array (
|
||||||
0 => __DIR__ . '/..' . '/symfony/var-dumper',
|
0 => __DIR__ . '/..' . '/symfony/var-dumper',
|
||||||
),
|
),
|
||||||
'Symfony\\Component\\Mime\\' =>
|
|
||||||
array (
|
|
||||||
0 => __DIR__ . '/..' . '/symfony/mime',
|
|
||||||
),
|
|
||||||
'Symfony\\Component\\Mailer\\' =>
|
|
||||||
array (
|
|
||||||
0 => __DIR__ . '/..' . '/symfony/mailer',
|
|
||||||
),
|
|
||||||
'Symfony\\Component\\HttpFoundation\\' =>
|
'Symfony\\Component\\HttpFoundation\\' =>
|
||||||
array (
|
array (
|
||||||
0 => __DIR__ . '/..' . '/symfony/http-foundation',
|
0 => __DIR__ . '/..' . '/symfony/http-foundation',
|
||||||
),
|
),
|
||||||
'Symfony\\Component\\EventDispatcher\\' =>
|
|
||||||
array (
|
|
||||||
0 => __DIR__ . '/..' . '/symfony/event-dispatcher',
|
|
||||||
),
|
|
||||||
'Spatie\\Macroable\\' =>
|
'Spatie\\Macroable\\' =>
|
||||||
array (
|
array (
|
||||||
0 => __DIR__ . '/..' . '/spatie/macroable/src',
|
0 => __DIR__ . '/..' . '/spatie/macroable/src',
|
||||||
|
|
@ -193,10 +152,6 @@ class ComposerStaticInit4b57298e8d0e895486f3307a354a7e1a
|
||||||
array (
|
array (
|
||||||
0 => __DIR__ . '/..' . '/psr/http-message/src',
|
0 => __DIR__ . '/..' . '/psr/http-message/src',
|
||||||
),
|
),
|
||||||
'Psr\\EventDispatcher\\' =>
|
|
||||||
array (
|
|
||||||
0 => __DIR__ . '/..' . '/psr/event-dispatcher/src',
|
|
||||||
),
|
|
||||||
'Psr\\Container\\' =>
|
'Psr\\Container\\' =>
|
||||||
array (
|
array (
|
||||||
0 => __DIR__ . '/..' . '/psr/container/src',
|
0 => __DIR__ . '/..' . '/psr/container/src',
|
||||||
|
|
@ -221,10 +176,6 @@ class ComposerStaticInit4b57298e8d0e895486f3307a354a7e1a
|
||||||
array (
|
array (
|
||||||
0 => __DIR__ . '/..' . '/xaboy/form-builder/src',
|
0 => __DIR__ . '/..' . '/xaboy/form-builder/src',
|
||||||
),
|
),
|
||||||
'Egulias\\EmailValidator\\' =>
|
|
||||||
array (
|
|
||||||
0 => __DIR__ . '/..' . '/egulias/email-validator/src',
|
|
||||||
),
|
|
||||||
'Doctrine\\Deprecations\\' =>
|
'Doctrine\\Deprecations\\' =>
|
||||||
array (
|
array (
|
||||||
0 => __DIR__ . '/..' . '/doctrine/deprecations/lib/Doctrine/Deprecations',
|
0 => __DIR__ . '/..' . '/doctrine/deprecations/lib/Doctrine/Deprecations',
|
||||||
|
|
@ -246,7 +197,6 @@ class ComposerStaticInit4b57298e8d0e895486f3307a354a7e1a
|
||||||
public static $classMap = array (
|
public static $classMap = array (
|
||||||
'Attribute' => __DIR__ . '/..' . '/symfony/polyfill-php80/Resources/stubs/Attribute.php',
|
'Attribute' => __DIR__ . '/..' . '/symfony/polyfill-php80/Resources/stubs/Attribute.php',
|
||||||
'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php',
|
'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php',
|
||||||
'Normalizer' => __DIR__ . '/..' . '/symfony/polyfill-intl-normalizer/Resources/stubs/Normalizer.php',
|
|
||||||
'PhpToken' => __DIR__ . '/..' . '/symfony/polyfill-php80/Resources/stubs/PhpToken.php',
|
'PhpToken' => __DIR__ . '/..' . '/symfony/polyfill-php80/Resources/stubs/PhpToken.php',
|
||||||
'Stringable' => __DIR__ . '/..' . '/symfony/polyfill-php80/Resources/stubs/Stringable.php',
|
'Stringable' => __DIR__ . '/..' . '/symfony/polyfill-php80/Resources/stubs/Stringable.php',
|
||||||
'UnhandledMatchError' => __DIR__ . '/..' . '/symfony/polyfill-php80/Resources/stubs/UnhandledMatchError.php',
|
'UnhandledMatchError' => __DIR__ . '/..' . '/symfony/polyfill-php80/Resources/stubs/UnhandledMatchError.php',
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -1,9 +1,9 @@
|
||||||
<?php return array(
|
<?php return array(
|
||||||
'root' => array(
|
'root' => array(
|
||||||
'name' => 'topthink/think',
|
'name' => 'topthink/think',
|
||||||
'pretty_version' => 'dev-master',
|
'pretty_version' => '1.0.0+no-version-set',
|
||||||
'version' => 'dev-master',
|
'version' => '1.0.0.0',
|
||||||
'reference' => '54934945ccbf08dd2fad2c11a2c073fc9d65cb77',
|
'reference' => NULL,
|
||||||
'type' => 'project',
|
'type' => 'project',
|
||||||
'install_path' => __DIR__ . '/../../',
|
'install_path' => __DIR__ . '/../../',
|
||||||
'aliases' => array(),
|
'aliases' => array(),
|
||||||
|
|
@ -20,9 +20,9 @@
|
||||||
'dev_requirement' => false,
|
'dev_requirement' => false,
|
||||||
),
|
),
|
||||||
'doctrine/deprecations' => array(
|
'doctrine/deprecations' => array(
|
||||||
'pretty_version' => 'v1.1.1',
|
'pretty_version' => '1.1.2',
|
||||||
'version' => '1.1.1.0',
|
'version' => '1.1.2.0',
|
||||||
'reference' => '612a3ee5ab0d5dd97b7cf3874a6efe24325efac3',
|
'reference' => '4f2d4f2836e7ec4e7a8625e75c6aa916004db931',
|
||||||
'type' => 'library',
|
'type' => 'library',
|
||||||
'install_path' => __DIR__ . '/../doctrine/deprecations',
|
'install_path' => __DIR__ . '/../doctrine/deprecations',
|
||||||
'aliases' => array(),
|
'aliases' => array(),
|
||||||
|
|
@ -37,15 +37,6 @@
|
||||||
'aliases' => array(),
|
'aliases' => array(),
|
||||||
'dev_requirement' => false,
|
'dev_requirement' => false,
|
||||||
),
|
),
|
||||||
'egulias/email-validator' => array(
|
|
||||||
'pretty_version' => '3.2.6',
|
|
||||||
'version' => '3.2.6.0',
|
|
||||||
'reference' => 'e5997fa97e8790cdae03a9cbd5e78e45e3c7bda7',
|
|
||||||
'type' => 'library',
|
|
||||||
'install_path' => __DIR__ . '/../egulias/email-validator',
|
|
||||||
'aliases' => array(),
|
|
||||||
'dev_requirement' => false,
|
|
||||||
),
|
|
||||||
'league/flysystem' => array(
|
'league/flysystem' => array(
|
||||||
'pretty_version' => '2.5.0',
|
'pretty_version' => '2.5.0',
|
||||||
'version' => '2.5.0.0',
|
'version' => '2.5.0.0',
|
||||||
|
|
@ -56,9 +47,9 @@
|
||||||
'dev_requirement' => false,
|
'dev_requirement' => false,
|
||||||
),
|
),
|
||||||
'league/mime-type-detection' => array(
|
'league/mime-type-detection' => array(
|
||||||
'pretty_version' => '1.13.0',
|
'pretty_version' => '1.12.0',
|
||||||
'version' => '1.13.0.0',
|
'version' => '1.12.0.0',
|
||||||
'reference' => 'a6dfb1194a2946fcdc1f38219445234f65b35c96',
|
'reference' => 'c7f2872fb273bf493811473dafc88d60ae829f48',
|
||||||
'type' => 'library',
|
'type' => 'library',
|
||||||
'install_path' => __DIR__ . '/../league/mime-type-detection',
|
'install_path' => __DIR__ . '/../league/mime-type-detection',
|
||||||
'aliases' => array(),
|
'aliases' => array(),
|
||||||
|
|
@ -101,29 +92,14 @@
|
||||||
'dev_requirement' => false,
|
'dev_requirement' => false,
|
||||||
),
|
),
|
||||||
'psr/container' => array(
|
'psr/container' => array(
|
||||||
'pretty_version' => '1.1.2',
|
'pretty_version' => '1.1.1',
|
||||||
'version' => '1.1.2.0',
|
'version' => '1.1.1.0',
|
||||||
'reference' => '513e0666f7216c7459170d56df27dfcefe1689ea',
|
'reference' => '8622567409010282b7aeebe4bb841fe98b58dcaf',
|
||||||
'type' => 'library',
|
'type' => 'library',
|
||||||
'install_path' => __DIR__ . '/../psr/container',
|
'install_path' => __DIR__ . '/../psr/container',
|
||||||
'aliases' => array(),
|
'aliases' => array(),
|
||||||
'dev_requirement' => false,
|
'dev_requirement' => false,
|
||||||
),
|
),
|
||||||
'psr/event-dispatcher' => array(
|
|
||||||
'pretty_version' => '1.0.0',
|
|
||||||
'version' => '1.0.0.0',
|
|
||||||
'reference' => 'dbefd12671e8a14ec7f180cab83036ed26714bb0',
|
|
||||||
'type' => 'library',
|
|
||||||
'install_path' => __DIR__ . '/../psr/event-dispatcher',
|
|
||||||
'aliases' => array(),
|
|
||||||
'dev_requirement' => false,
|
|
||||||
),
|
|
||||||
'psr/event-dispatcher-implementation' => array(
|
|
||||||
'dev_requirement' => false,
|
|
||||||
'provided' => array(
|
|
||||||
0 => '1.0',
|
|
||||||
),
|
|
||||||
),
|
|
||||||
'psr/http-message' => array(
|
'psr/http-message' => array(
|
||||||
'pretty_version' => '1.1',
|
'pretty_version' => '1.1',
|
||||||
'version' => '1.1.0.0',
|
'version' => '1.1.0.0',
|
||||||
|
|
@ -160,6 +136,15 @@
|
||||||
'aliases' => array(),
|
'aliases' => array(),
|
||||||
'dev_requirement' => false,
|
'dev_requirement' => false,
|
||||||
),
|
),
|
||||||
|
'swiftmailer/swiftmailer' => array(
|
||||||
|
'pretty_version' => 'v5.4.12',
|
||||||
|
'version' => '5.4.12.0',
|
||||||
|
'reference' => '181b89f18a90f8925ef805f950d47a7190e9b950',
|
||||||
|
'type' => 'library',
|
||||||
|
'install_path' => __DIR__ . '/../swiftmailer/swiftmailer',
|
||||||
|
'aliases' => array(),
|
||||||
|
'dev_requirement' => false,
|
||||||
|
),
|
||||||
'symfony/deprecation-contracts' => array(
|
'symfony/deprecation-contracts' => array(
|
||||||
'pretty_version' => 'v2.5.2',
|
'pretty_version' => 'v2.5.2',
|
||||||
'version' => '2.5.2.0',
|
'version' => '2.5.2.0',
|
||||||
|
|
@ -169,75 +154,15 @@
|
||||||
'aliases' => array(),
|
'aliases' => array(),
|
||||||
'dev_requirement' => false,
|
'dev_requirement' => false,
|
||||||
),
|
),
|
||||||
'symfony/event-dispatcher' => array(
|
|
||||||
'pretty_version' => 'v5.4.26',
|
|
||||||
'version' => '5.4.26.0',
|
|
||||||
'reference' => '5dcc00e03413f05c1e7900090927bb7247cb0aac',
|
|
||||||
'type' => 'library',
|
|
||||||
'install_path' => __DIR__ . '/../symfony/event-dispatcher',
|
|
||||||
'aliases' => array(),
|
|
||||||
'dev_requirement' => false,
|
|
||||||
),
|
|
||||||
'symfony/event-dispatcher-contracts' => array(
|
|
||||||
'pretty_version' => 'v2.5.2',
|
|
||||||
'version' => '2.5.2.0',
|
|
||||||
'reference' => 'f98b54df6ad059855739db6fcbc2d36995283fe1',
|
|
||||||
'type' => 'library',
|
|
||||||
'install_path' => __DIR__ . '/../symfony/event-dispatcher-contracts',
|
|
||||||
'aliases' => array(),
|
|
||||||
'dev_requirement' => false,
|
|
||||||
),
|
|
||||||
'symfony/event-dispatcher-implementation' => array(
|
|
||||||
'dev_requirement' => false,
|
|
||||||
'provided' => array(
|
|
||||||
0 => '2.0',
|
|
||||||
),
|
|
||||||
),
|
|
||||||
'symfony/http-foundation' => array(
|
'symfony/http-foundation' => array(
|
||||||
'pretty_version' => 'v5.4.32',
|
'pretty_version' => 'v5.4.35',
|
||||||
'version' => '5.4.32.0',
|
'version' => '5.4.35.0',
|
||||||
'reference' => 'cbcd80a4c36f59772d62860fdb0cb6a38da63fd2',
|
'reference' => 'f2ab692a22aef1cd54beb893aa0068bdfb093928',
|
||||||
'type' => 'library',
|
'type' => 'library',
|
||||||
'install_path' => __DIR__ . '/../symfony/http-foundation',
|
'install_path' => __DIR__ . '/../symfony/http-foundation',
|
||||||
'aliases' => array(),
|
'aliases' => array(),
|
||||||
'dev_requirement' => false,
|
'dev_requirement' => false,
|
||||||
),
|
),
|
||||||
'symfony/mailer' => array(
|
|
||||||
'pretty_version' => 'v5.4.31',
|
|
||||||
'version' => '5.4.31.0',
|
|
||||||
'reference' => '5ca8a7628a5ee69767047dd0f4cf4c9521c999b8',
|
|
||||||
'type' => 'library',
|
|
||||||
'install_path' => __DIR__ . '/../symfony/mailer',
|
|
||||||
'aliases' => array(),
|
|
||||||
'dev_requirement' => false,
|
|
||||||
),
|
|
||||||
'symfony/mime' => array(
|
|
||||||
'pretty_version' => 'v5.4.26',
|
|
||||||
'version' => '5.4.26.0',
|
|
||||||
'reference' => '2ea06dfeee20000a319d8407cea1d47533d5a9d2',
|
|
||||||
'type' => 'library',
|
|
||||||
'install_path' => __DIR__ . '/../symfony/mime',
|
|
||||||
'aliases' => array(),
|
|
||||||
'dev_requirement' => false,
|
|
||||||
),
|
|
||||||
'symfony/polyfill-intl-idn' => array(
|
|
||||||
'pretty_version' => 'v1.28.0',
|
|
||||||
'version' => '1.28.0.0',
|
|
||||||
'reference' => 'ecaafce9f77234a6a449d29e49267ba10499116d',
|
|
||||||
'type' => 'library',
|
|
||||||
'install_path' => __DIR__ . '/../symfony/polyfill-intl-idn',
|
|
||||||
'aliases' => array(),
|
|
||||||
'dev_requirement' => false,
|
|
||||||
),
|
|
||||||
'symfony/polyfill-intl-normalizer' => array(
|
|
||||||
'pretty_version' => 'v1.28.0',
|
|
||||||
'version' => '1.28.0.0',
|
|
||||||
'reference' => '8c4ad05dd0120b6a53c1ca374dca2ad0a1c4ed92',
|
|
||||||
'type' => 'library',
|
|
||||||
'install_path' => __DIR__ . '/../symfony/polyfill-intl-normalizer',
|
|
||||||
'aliases' => array(),
|
|
||||||
'dev_requirement' => false,
|
|
||||||
),
|
|
||||||
'symfony/polyfill-mbstring' => array(
|
'symfony/polyfill-mbstring' => array(
|
||||||
'pretty_version' => 'v1.28.0',
|
'pretty_version' => 'v1.28.0',
|
||||||
'version' => '1.28.0.0',
|
'version' => '1.28.0.0',
|
||||||
|
|
@ -254,7 +179,7 @@
|
||||||
'type' => 'library',
|
'type' => 'library',
|
||||||
'install_path' => __DIR__ . '/../symfony/polyfill-php72',
|
'install_path' => __DIR__ . '/../symfony/polyfill-php72',
|
||||||
'aliases' => array(),
|
'aliases' => array(),
|
||||||
'dev_requirement' => false,
|
'dev_requirement' => true,
|
||||||
),
|
),
|
||||||
'symfony/polyfill-php80' => array(
|
'symfony/polyfill-php80' => array(
|
||||||
'pretty_version' => 'v1.28.0',
|
'pretty_version' => 'v1.28.0',
|
||||||
|
|
@ -265,15 +190,6 @@
|
||||||
'aliases' => array(),
|
'aliases' => array(),
|
||||||
'dev_requirement' => false,
|
'dev_requirement' => false,
|
||||||
),
|
),
|
||||||
'symfony/service-contracts' => array(
|
|
||||||
'pretty_version' => 'v2.5.2',
|
|
||||||
'version' => '2.5.2.0',
|
|
||||||
'reference' => '4b426aac47d6427cc1a1d0f7e2ac724627f5966c',
|
|
||||||
'type' => 'library',
|
|
||||||
'install_path' => __DIR__ . '/../symfony/service-contracts',
|
|
||||||
'aliases' => array(),
|
|
||||||
'dev_requirement' => false,
|
|
||||||
),
|
|
||||||
'symfony/var-dumper' => array(
|
'symfony/var-dumper' => array(
|
||||||
'pretty_version' => 'v4.4.47',
|
'pretty_version' => 'v4.4.47',
|
||||||
'version' => '4.4.47.0',
|
'version' => '4.4.47.0',
|
||||||
|
|
@ -293,9 +209,9 @@
|
||||||
'dev_requirement' => false,
|
'dev_requirement' => false,
|
||||||
),
|
),
|
||||||
'topthink/think' => array(
|
'topthink/think' => array(
|
||||||
'pretty_version' => 'dev-master',
|
'pretty_version' => '1.0.0+no-version-set',
|
||||||
'version' => 'dev-master',
|
'version' => '1.0.0.0',
|
||||||
'reference' => '54934945ccbf08dd2fad2c11a2c073fc9d65cb77',
|
'reference' => NULL,
|
||||||
'type' => 'project',
|
'type' => 'project',
|
||||||
'install_path' => __DIR__ . '/../../',
|
'install_path' => __DIR__ . '/../../',
|
||||||
'aliases' => array(),
|
'aliases' => array(),
|
||||||
|
|
@ -383,9 +299,9 @@
|
||||||
'dev_requirement' => false,
|
'dev_requirement' => false,
|
||||||
),
|
),
|
||||||
'yzh52521/think-mail' => array(
|
'yzh52521/think-mail' => array(
|
||||||
'pretty_version' => 'v3.0.2',
|
'pretty_version' => 'v3.0.0',
|
||||||
'version' => '3.0.2.0',
|
'version' => '3.0.0.0',
|
||||||
'reference' => '51535665a75d8324c1301e5a11f116411ea73355',
|
'reference' => '91bf462a59a5cb4c65dd7149db3a86af432c50e2',
|
||||||
'type' => 'library',
|
'type' => 'library',
|
||||||
'install_path' => __DIR__ . '/../yzh52521/think-mail',
|
'install_path' => __DIR__ . '/../yzh52521/think-mail',
|
||||||
'aliases' => array(),
|
'aliases' => array(),
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,8 @@
|
||||||
|
|
||||||
$issues = array();
|
$issues = array();
|
||||||
|
|
||||||
if (!(PHP_VERSION_ID >= 70400)) {
|
if (!(PHP_VERSION_ID >= 70205)) {
|
||||||
$issues[] = 'Your Composer dependencies require a PHP version ">= 7.4.0". You are running ' . PHP_VERSION . '.';
|
$issues[] = 'Your Composer dependencies require a PHP version ">= 7.2.5". You are running ' . PHP_VERSION . '.';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($issues) {
|
if ($issues) {
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ use function array_reduce;
|
||||||
use function assert;
|
use function assert;
|
||||||
use function debug_backtrace;
|
use function debug_backtrace;
|
||||||
use function sprintf;
|
use function sprintf;
|
||||||
|
use function str_replace;
|
||||||
use function strpos;
|
use function strpos;
|
||||||
use function strrpos;
|
use function strrpos;
|
||||||
use function substr;
|
use function substr;
|
||||||
|
|
@ -138,7 +139,7 @@ class Deprecation
|
||||||
|
|
||||||
// first check that the caller is not from a tests folder, in which case we always let deprecations pass
|
// first check that the caller is not from a tests folder, in which case we always let deprecations pass
|
||||||
if (isset($backtrace[1]['file'], $backtrace[0]['file']) && strpos($backtrace[1]['file'], DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR) === false) {
|
if (isset($backtrace[1]['file'], $backtrace[0]['file']) && strpos($backtrace[1]['file'], DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR) === false) {
|
||||||
$path = DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . $package . DIRECTORY_SEPARATOR;
|
$path = DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . str_replace('/', DIRECTORY_SEPARATOR, $package) . DIRECTORY_SEPARATOR;
|
||||||
|
|
||||||
if (strpos($backtrace[0]['file'], $path) === false) {
|
if (strpos($backtrace[0]['file'], $path) === false) {
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -1,22 +0,0 @@
|
||||||
<?xml version="1.0"?>
|
|
||||||
<ruleset>
|
|
||||||
<arg name="basepath" value="."/>
|
|
||||||
<arg name="extensions" value="php"/>
|
|
||||||
<arg name="parallel" value="80"/>
|
|
||||||
<arg name="cache" value=".phpcs-cache"/>
|
|
||||||
<arg name="colors"/>
|
|
||||||
|
|
||||||
<!-- Ignore warnings, show progress of the run and show sniff names -->
|
|
||||||
<arg value="nps"/>
|
|
||||||
|
|
||||||
<config name="php_version" value="70100"/>
|
|
||||||
|
|
||||||
<!-- Directories to be checked -->
|
|
||||||
<file>lib</file>
|
|
||||||
<file>tests</file>
|
|
||||||
|
|
||||||
<!-- Include full Doctrine Coding Standard -->
|
|
||||||
<rule ref="Doctrine">
|
|
||||||
<exclude name="SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint" />
|
|
||||||
</rule>
|
|
||||||
</ruleset>
|
|
||||||
|
|
@ -1,9 +0,0 @@
|
||||||
parameters:
|
|
||||||
level: 6
|
|
||||||
paths:
|
|
||||||
- lib
|
|
||||||
- tests
|
|
||||||
|
|
||||||
includes:
|
|
||||||
- vendor/phpstan/phpstan-phpunit/extension.neon
|
|
||||||
- vendor/phpstan/phpstan-phpunit/rules.neon
|
|
||||||
|
|
@ -1,30 +0,0 @@
|
||||||
<?xml version="1.0"?>
|
|
||||||
<psalm
|
|
||||||
errorLevel="1"
|
|
||||||
resolveFromConfigFile="true"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xmlns="https://getpsalm.org/schema/config"
|
|
||||||
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
|
|
||||||
findUnusedBaselineEntry="true"
|
|
||||||
findUnusedCode="false"
|
|
||||||
>
|
|
||||||
<projectFiles>
|
|
||||||
<directory name="lib/Doctrine/Deprecations" />
|
|
||||||
<directory name="tests/Doctrine/Deprecations" />
|
|
||||||
<ignoreFiles>
|
|
||||||
<directory name="vendor" />
|
|
||||||
</ignoreFiles>
|
|
||||||
</projectFiles>
|
|
||||||
<plugins>
|
|
||||||
<pluginClass class="Psalm\PhpUnitPlugin\Plugin"/>
|
|
||||||
</plugins>
|
|
||||||
<issueHandlers>
|
|
||||||
<DeprecatedMethod>
|
|
||||||
<errorLevel type="suppress">
|
|
||||||
<!-- Remove when dropping support for PHPUnit 9.6 -->
|
|
||||||
<referencedMethod name="PHPUnit\Framework\TestCase::expectDeprecation"/>
|
|
||||||
<referencedMethod name="PHPUnit\Framework\TestCase::expectDeprecationMessage"/>
|
|
||||||
</errorLevel>
|
|
||||||
</DeprecatedMethod>
|
|
||||||
</issueHandlers>
|
|
||||||
</psalm>
|
|
||||||
|
|
@ -1,33 +0,0 @@
|
||||||
# EmailValidator v3 Changelog
|
|
||||||
|
|
||||||
## New Features
|
|
||||||
|
|
||||||
* Access to local part and domain part from EmailParser
|
|
||||||
* Validations outside of the scope of the RFC will be considered "extra" validations, thus opening the door for adding new; will live in their own folder "extra" (as requested in #248, #195, #183).
|
|
||||||
|
|
||||||
## Breaking changes
|
|
||||||
|
|
||||||
* PHP version upgraded to match Symfony's (as of 12/2020).
|
|
||||||
* DNSCheckValidation now fails for missing MX records. While the RFC argues that the existence of only A records to be valid, starting in v3 they will be considered invalid.
|
|
||||||
* Emails domain part are now intenteded to be RFC 1035 compliant, rendering previous valid emails (e.g example@examp&) invalid.
|
|
||||||
|
|
||||||
## PHP versions upgrade policy
|
|
||||||
PHP version upgrade requirement will happen via MINOR (3.x) version upgrades of the library, following the adoption level by major frameworks.
|
|
||||||
|
|
||||||
## Changes
|
|
||||||
* #235
|
|
||||||
* #215
|
|
||||||
* #130
|
|
||||||
* #258
|
|
||||||
* #188
|
|
||||||
* #181
|
|
||||||
* #217
|
|
||||||
* #214
|
|
||||||
* #249
|
|
||||||
* #236
|
|
||||||
* #257
|
|
||||||
* #210
|
|
||||||
|
|
||||||
## Thanks
|
|
||||||
To contributors, be it with PRs, reporting issues or supporting otherwise.
|
|
||||||
|
|
||||||
|
|
@ -1,153 +0,0 @@
|
||||||
# Contributing
|
|
||||||
|
|
||||||
When contributing to this repository make sure to follow the Pull request process below.
|
|
||||||
Reduce to the minimum 3rd party dependencies.
|
|
||||||
|
|
||||||
Please note we have a [code of conduct](#Code of Conduct), please follow it in all your interactions with the project.
|
|
||||||
|
|
||||||
## Pull Request Process
|
|
||||||
|
|
||||||
When doing a PR to v2 remember that you also have to do the PR port to v3, or tests confirming the bug is not reproducible.
|
|
||||||
|
|
||||||
1. Supported version is v3. If you are fixing a bug in v2, please port to v3
|
|
||||||
2. Use the title as a brief description of the changes
|
|
||||||
3. Describe the changes you are proposing
|
|
||||||
1. If adding an extra validation state the benefits of adding it and the problem is solving
|
|
||||||
2. Document in the readme, by adding it to the list
|
|
||||||
4. Provide appropriate tests for the code you are submitting: aim to keep the existing coverage percentage.
|
|
||||||
5. Add your Twitter handle (if you have) so we can thank you there.
|
|
||||||
|
|
||||||
## License
|
|
||||||
By contributing, you agree that your contributions will be licensed under its MIT License.
|
|
||||||
|
|
||||||
## Code of Conduct
|
|
||||||
|
|
||||||
### Our Pledge
|
|
||||||
|
|
||||||
We as members, contributors, and leaders pledge to make participation in our
|
|
||||||
community a harassment-free experience for everyone, regardless of age, body
|
|
||||||
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
|
||||||
identity and expression, level of experience, education, socio-economic status,
|
|
||||||
nationality, personal appearance, race, religion, or sexual identity
|
|
||||||
and orientation.
|
|
||||||
|
|
||||||
We pledge to act and interact in ways that contribute to an open, welcoming,
|
|
||||||
diverse, inclusive, and healthy community.
|
|
||||||
|
|
||||||
### Our Standards
|
|
||||||
|
|
||||||
Examples of behavior that contributes to a positive environment for our
|
|
||||||
community include:
|
|
||||||
|
|
||||||
* Demonstrating empathy and kindness toward other people
|
|
||||||
* Being respectful of differing opinions, viewpoints, and experiences
|
|
||||||
* Giving and gracefully accepting constructive feedback
|
|
||||||
* Accepting responsibility and apologizing to those affected by our mistakes,
|
|
||||||
and learning from the experience
|
|
||||||
* Focusing on what is best not just for us as individuals, but for the
|
|
||||||
overall community
|
|
||||||
|
|
||||||
Examples of unacceptable behavior include:
|
|
||||||
|
|
||||||
* The use of sexualized language or imagery, and sexual attention or
|
|
||||||
advances of any kind
|
|
||||||
* Trolling, insulting or derogatory comments, and personal or political attacks
|
|
||||||
* Public or private harassment
|
|
||||||
* Publishing others' private information, such as a physical or email
|
|
||||||
address, without their explicit permission
|
|
||||||
* Other conduct which could reasonably be considered inappropriate in a
|
|
||||||
professional setting
|
|
||||||
|
|
||||||
### Enforcement Responsibilities
|
|
||||||
|
|
||||||
Community leaders are responsible for clarifying and enforcing our standards of
|
|
||||||
acceptable behavior and will take appropriate and fair corrective action in
|
|
||||||
response to any behavior that they deem inappropriate, threatening, offensive,
|
|
||||||
or harmful.
|
|
||||||
|
|
||||||
Community leaders have the right and responsibility to remove, edit, or reject
|
|
||||||
comments, commits, code, wiki edits, issues, and other contributions that are
|
|
||||||
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
|
||||||
decisions when appropriate.
|
|
||||||
|
|
||||||
### Scope
|
|
||||||
|
|
||||||
This Code of Conduct applies within all community spaces, and also applies when
|
|
||||||
an individual is officially representing the community in public spaces.
|
|
||||||
Examples of representing our community include using an official e-mail address,
|
|
||||||
posting via an official social media account, or acting as an appointed
|
|
||||||
representative at an online or offline event.
|
|
||||||
|
|
||||||
### Enforcement
|
|
||||||
|
|
||||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
||||||
reported to the community leaders responsible for enforcement at <emailvalidatorrfc.ccreport@gmail.com>.
|
|
||||||
All complaints will be reviewed and investigated promptly and fairly.
|
|
||||||
|
|
||||||
All community leaders are obligated to respect the privacy and security of the
|
|
||||||
reporter of any incident.
|
|
||||||
|
|
||||||
#### Enforcement Guidelines
|
|
||||||
|
|
||||||
Community leaders will follow these Community Impact Guidelines in determining
|
|
||||||
the consequences for any action they deem in violation of this Code of Conduct:
|
|
||||||
|
|
||||||
#### 1. Correction
|
|
||||||
|
|
||||||
**Community Impact**: Use of inappropriate language or other behavior deemed
|
|
||||||
unprofessional or unwelcome in the community.
|
|
||||||
|
|
||||||
**Consequence**: A private, written warning from community leaders, providing
|
|
||||||
clarity around the nature of the violation and an explanation of why the
|
|
||||||
behavior was inappropriate. A public apology may be requested.
|
|
||||||
|
|
||||||
#### 2. Warning
|
|
||||||
|
|
||||||
**Community Impact**: A violation through a single incident or series
|
|
||||||
of actions.
|
|
||||||
|
|
||||||
**Consequence**: A warning with consequences for continued behavior. No
|
|
||||||
interaction with the people involved, including unsolicited interaction with
|
|
||||||
those enforcing the Code of Conduct, for a specified period of time. This
|
|
||||||
includes avoiding interactions in community spaces as well as external channels
|
|
||||||
like social media. Violating these terms may lead to a temporary or
|
|
||||||
permanent ban.
|
|
||||||
|
|
||||||
#### 3. Temporary Ban
|
|
||||||
|
|
||||||
**Community Impact**: A serious violation of community standards, including
|
|
||||||
sustained inappropriate behavior.
|
|
||||||
|
|
||||||
**Consequence**: A temporary ban from any sort of interaction or public
|
|
||||||
communication with the community for a specified period of time. No public or
|
|
||||||
private interaction with the people involved, including unsolicited interaction
|
|
||||||
with those enforcing the Code of Conduct, is allowed during this period.
|
|
||||||
Violating these terms may lead to a permanent ban.
|
|
||||||
|
|
||||||
#### 4. Permanent Ban
|
|
||||||
|
|
||||||
**Community Impact**: Demonstrating a pattern of violation of community
|
|
||||||
standards, including sustained inappropriate behavior, harassment of an
|
|
||||||
individual, or aggression toward or disparagement of classes of individuals.
|
|
||||||
|
|
||||||
**Consequence**: A permanent ban from any sort of public interaction within
|
|
||||||
the community.
|
|
||||||
|
|
||||||
### Attribution
|
|
||||||
|
|
||||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
|
||||||
version 2.0, available at
|
|
||||||
[https://www.contributor-covenant.org/version/2/0/code_of_conduct.html][v2.0].
|
|
||||||
|
|
||||||
Community Impact Guidelines were inspired by
|
|
||||||
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
|
|
||||||
|
|
||||||
For answers to common questions about this code of conduct, see the FAQ at
|
|
||||||
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available
|
|
||||||
at [https://www.contributor-covenant.org/translations][translations].
|
|
||||||
|
|
||||||
[homepage]: https://www.contributor-covenant.org
|
|
||||||
[v2.0]: https://www.contributor-covenant.org/version/2/0/code_of_conduct.html
|
|
||||||
[Mozilla CoC]: https://github.com/mozilla/diversity
|
|
||||||
[FAQ]: https://www.contributor-covenant.org/faq
|
|
||||||
[translations]: https://www.contributor-covenant.org/translations
|
|
||||||
|
|
@ -1,19 +0,0 @@
|
||||||
Copyright (c) 2013-2022 Eduardo Gulias Davis
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is furnished
|
|
||||||
to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
THE SOFTWARE.
|
|
||||||
|
|
@ -1,37 +0,0 @@
|
||||||
{
|
|
||||||
"name": "egulias/email-validator",
|
|
||||||
"description": "A library for validating emails against several RFCs",
|
|
||||||
"homepage": "https://github.com/egulias/EmailValidator",
|
|
||||||
"keywords": ["email", "validation", "validator", "emailvalidation", "emailvalidator"],
|
|
||||||
"license": "MIT",
|
|
||||||
"authors": [
|
|
||||||
{"name": "Eduardo Gulias Davis"}
|
|
||||||
],
|
|
||||||
"extra": {
|
|
||||||
"branch-alias": {
|
|
||||||
"dev-master": "3.0.x-dev"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"require": {
|
|
||||||
"php": ">=7.2",
|
|
||||||
"doctrine/lexer": "^1.2|^2",
|
|
||||||
"symfony/polyfill-intl-idn": "^1.15"
|
|
||||||
},
|
|
||||||
"require-dev": {
|
|
||||||
"phpunit/phpunit": "^8.5.8|^9.3.3",
|
|
||||||
"vimeo/psalm": "^4"
|
|
||||||
},
|
|
||||||
"suggest": {
|
|
||||||
"ext-intl": "PHP Internationalization Libraries are required to use the SpoofChecking validation"
|
|
||||||
},
|
|
||||||
"autoload": {
|
|
||||||
"psr-4": {
|
|
||||||
"Egulias\\EmailValidator\\": "src"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"autoload-dev": {
|
|
||||||
"psr-4": {
|
|
||||||
"Egulias\\EmailValidator\\Tests\\": "tests"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,345 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Egulias\EmailValidator;
|
|
||||||
|
|
||||||
use Doctrine\Common\Lexer\AbstractLexer;
|
|
||||||
use Doctrine\Common\Lexer\Token;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @extends AbstractLexer<int, string>
|
|
||||||
*/
|
|
||||||
class EmailLexer extends AbstractLexer
|
|
||||||
{
|
|
||||||
//ASCII values
|
|
||||||
public const S_EMPTY = null;
|
|
||||||
public const C_NUL = 0;
|
|
||||||
public const S_HTAB = 9;
|
|
||||||
public const S_LF = 10;
|
|
||||||
public const S_CR = 13;
|
|
||||||
public const S_SP = 32;
|
|
||||||
public const EXCLAMATION = 33;
|
|
||||||
public const S_DQUOTE = 34;
|
|
||||||
public const NUMBER_SIGN = 35;
|
|
||||||
public const DOLLAR = 36;
|
|
||||||
public const PERCENTAGE = 37;
|
|
||||||
public const AMPERSAND = 38;
|
|
||||||
public const S_SQUOTE = 39;
|
|
||||||
public const S_OPENPARENTHESIS = 40;
|
|
||||||
public const S_CLOSEPARENTHESIS = 41;
|
|
||||||
public const ASTERISK = 42;
|
|
||||||
public const S_PLUS = 43;
|
|
||||||
public const S_COMMA = 44;
|
|
||||||
public const S_HYPHEN = 45;
|
|
||||||
public const S_DOT = 46;
|
|
||||||
public const S_SLASH = 47;
|
|
||||||
public const S_COLON = 58;
|
|
||||||
public const S_SEMICOLON = 59;
|
|
||||||
public const S_LOWERTHAN = 60;
|
|
||||||
public const S_EQUAL = 61;
|
|
||||||
public const S_GREATERTHAN = 62;
|
|
||||||
public const QUESTIONMARK = 63;
|
|
||||||
public const S_AT = 64;
|
|
||||||
public const S_OPENBRACKET = 91;
|
|
||||||
public const S_BACKSLASH = 92;
|
|
||||||
public const S_CLOSEBRACKET = 93;
|
|
||||||
public const CARET = 94;
|
|
||||||
public const S_UNDERSCORE = 95;
|
|
||||||
public const S_BACKTICK = 96;
|
|
||||||
public const S_OPENCURLYBRACES = 123;
|
|
||||||
public const S_PIPE = 124;
|
|
||||||
public const S_CLOSECURLYBRACES = 125;
|
|
||||||
public const S_TILDE = 126;
|
|
||||||
public const C_DEL = 127;
|
|
||||||
public const INVERT_QUESTIONMARK= 168;
|
|
||||||
public const INVERT_EXCLAMATION = 173;
|
|
||||||
public const GENERIC = 300;
|
|
||||||
public const S_IPV6TAG = 301;
|
|
||||||
public const INVALID = 302;
|
|
||||||
public const CRLF = 1310;
|
|
||||||
public const S_DOUBLECOLON = 5858;
|
|
||||||
public const ASCII_INVALID_FROM = 127;
|
|
||||||
public const ASCII_INVALID_TO = 199;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* US-ASCII visible characters not valid for atext (@link http://tools.ietf.org/html/rfc5322#section-3.2.3)
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
protected $charValue = [
|
|
||||||
'{' => self::S_OPENCURLYBRACES,
|
|
||||||
'}' => self::S_CLOSECURLYBRACES,
|
|
||||||
'(' => self::S_OPENPARENTHESIS,
|
|
||||||
')' => self::S_CLOSEPARENTHESIS,
|
|
||||||
'<' => self::S_LOWERTHAN,
|
|
||||||
'>' => self::S_GREATERTHAN,
|
|
||||||
'[' => self::S_OPENBRACKET,
|
|
||||||
']' => self::S_CLOSEBRACKET,
|
|
||||||
':' => self::S_COLON,
|
|
||||||
';' => self::S_SEMICOLON,
|
|
||||||
'@' => self::S_AT,
|
|
||||||
'\\' => self::S_BACKSLASH,
|
|
||||||
'/' => self::S_SLASH,
|
|
||||||
',' => self::S_COMMA,
|
|
||||||
'.' => self::S_DOT,
|
|
||||||
"'" => self::S_SQUOTE,
|
|
||||||
"`" => self::S_BACKTICK,
|
|
||||||
'"' => self::S_DQUOTE,
|
|
||||||
'-' => self::S_HYPHEN,
|
|
||||||
'::' => self::S_DOUBLECOLON,
|
|
||||||
' ' => self::S_SP,
|
|
||||||
"\t" => self::S_HTAB,
|
|
||||||
"\r" => self::S_CR,
|
|
||||||
"\n" => self::S_LF,
|
|
||||||
"\r\n" => self::CRLF,
|
|
||||||
'IPv6' => self::S_IPV6TAG,
|
|
||||||
'' => self::S_EMPTY,
|
|
||||||
'\0' => self::C_NUL,
|
|
||||||
'*' => self::ASTERISK,
|
|
||||||
'!' => self::EXCLAMATION,
|
|
||||||
'&' => self::AMPERSAND,
|
|
||||||
'^' => self::CARET,
|
|
||||||
'$' => self::DOLLAR,
|
|
||||||
'%' => self::PERCENTAGE,
|
|
||||||
'~' => self::S_TILDE,
|
|
||||||
'|' => self::S_PIPE,
|
|
||||||
'_' => self::S_UNDERSCORE,
|
|
||||||
'=' => self::S_EQUAL,
|
|
||||||
'+' => self::S_PLUS,
|
|
||||||
'¿' => self::INVERT_QUESTIONMARK,
|
|
||||||
'?' => self::QUESTIONMARK,
|
|
||||||
'#' => self::NUMBER_SIGN,
|
|
||||||
'¡' => self::INVERT_EXCLAMATION,
|
|
||||||
];
|
|
||||||
|
|
||||||
public const INVALID_CHARS_REGEX = "/[^\p{S}\p{C}\p{Cc}]+/iu";
|
|
||||||
|
|
||||||
public const VALID_UTF8_REGEX = '/\p{Cc}+/u';
|
|
||||||
|
|
||||||
public const CATCHABLE_PATTERNS = [
|
|
||||||
'[a-zA-Z]+[46]?', //ASCII and domain literal
|
|
||||||
'[^\x00-\x7F]', //UTF-8
|
|
||||||
'[0-9]+',
|
|
||||||
'\r\n',
|
|
||||||
'::',
|
|
||||||
'\s+?',
|
|
||||||
'.',
|
|
||||||
];
|
|
||||||
|
|
||||||
public const NON_CATCHABLE_PATTERNS = [
|
|
||||||
'[\xA0-\xff]+',
|
|
||||||
];
|
|
||||||
|
|
||||||
public const MODIFIERS = 'iu';
|
|
||||||
|
|
||||||
/** @var bool */
|
|
||||||
protected $hasInvalidTokens = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var array
|
|
||||||
*
|
|
||||||
* @psalm-var array{value:string, type:null|int, position:int}|array<empty, empty>
|
|
||||||
*/
|
|
||||||
protected $previous = [];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The last matched/seen token.
|
|
||||||
*
|
|
||||||
* @var array|Token
|
|
||||||
*
|
|
||||||
* @psalm-suppress NonInvariantDocblockPropertyType
|
|
||||||
* @psalm-var array{value:string, type:null|int, position:int}|Token<int, string>
|
|
||||||
*/
|
|
||||||
public $token;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The next token in the input.
|
|
||||||
*
|
|
||||||
* @var array|Token|null
|
|
||||||
*
|
|
||||||
* @psalm-suppress NonInvariantDocblockPropertyType
|
|
||||||
* @psalm-var array{position: int, type: int|null|string, value: int|string}|Token<int, string>|null
|
|
||||||
*/
|
|
||||||
public $lookahead;
|
|
||||||
|
|
||||||
/** @psalm-var array{value:'', type:null, position:0} */
|
|
||||||
private static $nullToken = [
|
|
||||||
'value' => '',
|
|
||||||
'type' => null,
|
|
||||||
'position' => 0,
|
|
||||||
];
|
|
||||||
|
|
||||||
/** @var string */
|
|
||||||
private $accumulator = '';
|
|
||||||
|
|
||||||
/** @var bool */
|
|
||||||
private $hasToRecord = false;
|
|
||||||
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->previous = $this->token = self::$nullToken;
|
|
||||||
$this->lookahead = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function reset() : void
|
|
||||||
{
|
|
||||||
$this->hasInvalidTokens = false;
|
|
||||||
parent::reset();
|
|
||||||
$this->previous = $this->token = self::$nullToken;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param int $type
|
|
||||||
* @throws \UnexpectedValueException
|
|
||||||
* @return boolean
|
|
||||||
*
|
|
||||||
* @psalm-suppress InvalidScalarArgument
|
|
||||||
*/
|
|
||||||
public function find($type) : bool
|
|
||||||
{
|
|
||||||
$search = clone $this;
|
|
||||||
$search->skipUntil($type);
|
|
||||||
|
|
||||||
if (!$search->lookahead) {
|
|
||||||
throw new \UnexpectedValueException($type . ' not found');
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* moveNext
|
|
||||||
*
|
|
||||||
* @return boolean
|
|
||||||
*/
|
|
||||||
public function moveNext() : bool
|
|
||||||
{
|
|
||||||
if ($this->hasToRecord && $this->previous === self::$nullToken) {
|
|
||||||
$this->accumulator .= ((array) $this->token)['value'];
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->previous = (array) $this->token;
|
|
||||||
|
|
||||||
if($this->lookahead === null) {
|
|
||||||
$this->lookahead = self::$nullToken;
|
|
||||||
}
|
|
||||||
|
|
||||||
$hasNext = parent::moveNext();
|
|
||||||
|
|
||||||
if ($this->hasToRecord) {
|
|
||||||
$this->accumulator .= ((array) $this->token)['value'];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $hasNext;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieve token type. Also processes the token value if necessary.
|
|
||||||
*
|
|
||||||
* @param string $value
|
|
||||||
* @throws \InvalidArgumentException
|
|
||||||
* @return integer
|
|
||||||
*/
|
|
||||||
protected function getType(&$value)
|
|
||||||
{
|
|
||||||
$encoded = $value;
|
|
||||||
|
|
||||||
if (mb_detect_encoding($value, 'auto', true) !== 'UTF-8') {
|
|
||||||
$encoded = mb_convert_encoding($value, 'UTF-8', 'Windows-1252');
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->isValid($encoded)) {
|
|
||||||
return $this->charValue[$encoded];
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->isNullType($encoded)) {
|
|
||||||
return self::C_NUL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->isInvalidChar($encoded)) {
|
|
||||||
$this->hasInvalidTokens = true;
|
|
||||||
return self::INVALID;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return self::GENERIC;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function isValid(string $value) : bool
|
|
||||||
{
|
|
||||||
return isset($this->charValue[$value]);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function isNullType(string $value) : bool
|
|
||||||
{
|
|
||||||
return $value === "\0";
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function isInvalidChar(string $value) : bool
|
|
||||||
{
|
|
||||||
return !preg_match(self::INVALID_CHARS_REGEX, $value);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function isUTF8Invalid(string $value) : bool
|
|
||||||
{
|
|
||||||
return preg_match(self::VALID_UTF8_REGEX, $value) !== false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function hasInvalidTokens() : bool
|
|
||||||
{
|
|
||||||
return $this->hasInvalidTokens;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* getPrevious
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getPrevious() : array
|
|
||||||
{
|
|
||||||
return $this->previous;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Lexical catchable patterns.
|
|
||||||
*
|
|
||||||
* @return string[]
|
|
||||||
*/
|
|
||||||
protected function getCatchablePatterns() : array
|
|
||||||
{
|
|
||||||
return self::CATCHABLE_PATTERNS;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Lexical non-catchable patterns.
|
|
||||||
*
|
|
||||||
* @return string[]
|
|
||||||
*/
|
|
||||||
protected function getNonCatchablePatterns() : array
|
|
||||||
{
|
|
||||||
return self::NON_CATCHABLE_PATTERNS;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function getModifiers() : string
|
|
||||||
{
|
|
||||||
return self::MODIFIERS;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getAccumulatedValues() : string
|
|
||||||
{
|
|
||||||
return $this->accumulator;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function startRecording() : void
|
|
||||||
{
|
|
||||||
$this->hasToRecord = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stopRecording() : void
|
|
||||||
{
|
|
||||||
$this->hasToRecord = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function clearRecorded() : void
|
|
||||||
{
|
|
||||||
$this->accumulator = '';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,90 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Egulias\EmailValidator;
|
|
||||||
|
|
||||||
use Egulias\EmailValidator\Result\Result;
|
|
||||||
use Egulias\EmailValidator\Parser\LocalPart;
|
|
||||||
use Egulias\EmailValidator\Parser\DomainPart;
|
|
||||||
use Egulias\EmailValidator\Result\ValidEmail;
|
|
||||||
use Egulias\EmailValidator\Result\InvalidEmail;
|
|
||||||
use Egulias\EmailValidator\Warning\EmailTooLong;
|
|
||||||
use Egulias\EmailValidator\Result\Reason\NoLocalPart;
|
|
||||||
|
|
||||||
class EmailParser extends Parser
|
|
||||||
{
|
|
||||||
public const EMAIL_MAX_LENGTH = 254;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $domainPart = '';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $localPart = '';
|
|
||||||
|
|
||||||
public function parse(string $str) : Result
|
|
||||||
{
|
|
||||||
$result = parent::parse($str);
|
|
||||||
|
|
||||||
$this->addLongEmailWarning($this->localPart, $this->domainPart);
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function preLeftParsing(): Result
|
|
||||||
{
|
|
||||||
if (!$this->hasAtToken()) {
|
|
||||||
return new InvalidEmail(new NoLocalPart(), $this->lexer->token["value"]);
|
|
||||||
}
|
|
||||||
return new ValidEmail();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function parseLeftFromAt(): Result
|
|
||||||
{
|
|
||||||
return $this->processLocalPart();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function parseRightFromAt(): Result
|
|
||||||
{
|
|
||||||
return $this->processDomainPart();
|
|
||||||
}
|
|
||||||
|
|
||||||
private function processLocalPart() : Result
|
|
||||||
{
|
|
||||||
$localPartParser = new LocalPart($this->lexer);
|
|
||||||
$localPartResult = $localPartParser->parse();
|
|
||||||
$this->localPart = $localPartParser->localPart();
|
|
||||||
$this->warnings = array_merge($localPartParser->getWarnings(), $this->warnings);
|
|
||||||
|
|
||||||
return $localPartResult;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function processDomainPart() : Result
|
|
||||||
{
|
|
||||||
$domainPartParser = new DomainPart($this->lexer);
|
|
||||||
$domainPartResult = $domainPartParser->parse();
|
|
||||||
$this->domainPart = $domainPartParser->domainPart();
|
|
||||||
$this->warnings = array_merge($domainPartParser->getWarnings(), $this->warnings);
|
|
||||||
|
|
||||||
return $domainPartResult;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getDomainPart() : string
|
|
||||||
{
|
|
||||||
return $this->domainPart;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getLocalPart() : string
|
|
||||||
{
|
|
||||||
return $this->localPart;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function addLongEmailWarning(string $localPart, string $parsedDomainPart) : void
|
|
||||||
{
|
|
||||||
if (strlen($localPart . '@' . $parsedDomainPart) > self::EMAIL_MAX_LENGTH) {
|
|
||||||
$this->warnings[EmailTooLong::CODE] = new EmailTooLong();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,67 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Egulias\EmailValidator;
|
|
||||||
|
|
||||||
use Egulias\EmailValidator\Result\InvalidEmail;
|
|
||||||
use Egulias\EmailValidator\Validation\EmailValidation;
|
|
||||||
|
|
||||||
class EmailValidator
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var EmailLexer
|
|
||||||
*/
|
|
||||||
private $lexer;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var Warning\Warning[]
|
|
||||||
*/
|
|
||||||
private $warnings = [];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var ?InvalidEmail
|
|
||||||
*/
|
|
||||||
private $error;
|
|
||||||
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->lexer = new EmailLexer();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $email
|
|
||||||
* @param EmailValidation $emailValidation
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function isValid(string $email, EmailValidation $emailValidation)
|
|
||||||
{
|
|
||||||
$isValid = $emailValidation->isValid($email, $this->lexer);
|
|
||||||
$this->warnings = $emailValidation->getWarnings();
|
|
||||||
$this->error = $emailValidation->getError();
|
|
||||||
|
|
||||||
return $isValid;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return boolean
|
|
||||||
*/
|
|
||||||
public function hasWarnings()
|
|
||||||
{
|
|
||||||
return !empty($this->warnings);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getWarnings()
|
|
||||||
{
|
|
||||||
return $this->warnings;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return InvalidEmail|null
|
|
||||||
*/
|
|
||||||
public function getError()
|
|
||||||
{
|
|
||||||
return $this->error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,91 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Egulias\EmailValidator;
|
|
||||||
|
|
||||||
use Egulias\EmailValidator\Result\Result;
|
|
||||||
use Egulias\EmailValidator\Parser\IDLeftPart;
|
|
||||||
use Egulias\EmailValidator\Parser\IDRightPart;
|
|
||||||
use Egulias\EmailValidator\Result\ValidEmail;
|
|
||||||
use Egulias\EmailValidator\Result\InvalidEmail;
|
|
||||||
use Egulias\EmailValidator\Warning\EmailTooLong;
|
|
||||||
use Egulias\EmailValidator\Result\Reason\NoLocalPart;
|
|
||||||
|
|
||||||
class MessageIDParser extends Parser
|
|
||||||
{
|
|
||||||
|
|
||||||
public const EMAILID_MAX_LENGTH = 254;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $idLeft = '';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $idRight = '';
|
|
||||||
|
|
||||||
public function parse(string $str) : Result
|
|
||||||
{
|
|
||||||
$result = parent::parse($str);
|
|
||||||
|
|
||||||
$this->addLongEmailWarning($this->idLeft, $this->idRight);
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function preLeftParsing(): Result
|
|
||||||
{
|
|
||||||
if (!$this->hasAtToken()) {
|
|
||||||
return new InvalidEmail(new NoLocalPart(), $this->lexer->token["value"]);
|
|
||||||
}
|
|
||||||
return new ValidEmail();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function parseLeftFromAt(): Result
|
|
||||||
{
|
|
||||||
return $this->processIDLeft();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function parseRightFromAt(): Result
|
|
||||||
{
|
|
||||||
return $this->processIDRight();
|
|
||||||
}
|
|
||||||
|
|
||||||
private function processIDLeft() : Result
|
|
||||||
{
|
|
||||||
$localPartParser = new IDLeftPart($this->lexer);
|
|
||||||
$localPartResult = $localPartParser->parse();
|
|
||||||
$this->idLeft = $localPartParser->localPart();
|
|
||||||
$this->warnings = array_merge($localPartParser->getWarnings(), $this->warnings);
|
|
||||||
|
|
||||||
return $localPartResult;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function processIDRight() : Result
|
|
||||||
{
|
|
||||||
$domainPartParser = new IDRightPart($this->lexer);
|
|
||||||
$domainPartResult = $domainPartParser->parse();
|
|
||||||
$this->idRight = $domainPartParser->domainPart();
|
|
||||||
$this->warnings = array_merge($domainPartParser->getWarnings(), $this->warnings);
|
|
||||||
|
|
||||||
return $domainPartResult;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getLeftPart() : string
|
|
||||||
{
|
|
||||||
return $this->idLeft;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getRightPart() : string
|
|
||||||
{
|
|
||||||
return $this->idRight;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function addLongEmailWarning(string $localPart, string $parsedDomainPart) : void
|
|
||||||
{
|
|
||||||
if (strlen($localPart . '@' . $parsedDomainPart) > self::EMAILID_MAX_LENGTH) {
|
|
||||||
$this->warnings[EmailTooLong::CODE] = new EmailTooLong();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,78 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Egulias\EmailValidator;
|
|
||||||
|
|
||||||
use Egulias\EmailValidator\Result\Result;
|
|
||||||
use Egulias\EmailValidator\Result\ValidEmail;
|
|
||||||
use Egulias\EmailValidator\Result\InvalidEmail;
|
|
||||||
use Egulias\EmailValidator\Result\Reason\ExpectingATEXT;
|
|
||||||
|
|
||||||
abstract class Parser
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var Warning\Warning[]
|
|
||||||
*/
|
|
||||||
protected $warnings = [];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var EmailLexer
|
|
||||||
*/
|
|
||||||
protected $lexer;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* id-left "@" id-right
|
|
||||||
*/
|
|
||||||
abstract protected function parseRightFromAt() : Result;
|
|
||||||
abstract protected function parseLeftFromAt() : Result;
|
|
||||||
abstract protected function preLeftParsing() : Result;
|
|
||||||
|
|
||||||
|
|
||||||
public function __construct(EmailLexer $lexer)
|
|
||||||
{
|
|
||||||
$this->lexer = $lexer;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function parse(string $str) : Result
|
|
||||||
{
|
|
||||||
$this->lexer->setInput($str);
|
|
||||||
|
|
||||||
if ($this->lexer->hasInvalidTokens()) {
|
|
||||||
return new InvalidEmail(new ExpectingATEXT("Invalid tokens found"), $this->lexer->token["value"]);
|
|
||||||
}
|
|
||||||
|
|
||||||
$preParsingResult = $this->preLeftParsing();
|
|
||||||
if ($preParsingResult->isInvalid()) {
|
|
||||||
return $preParsingResult;
|
|
||||||
}
|
|
||||||
|
|
||||||
$localPartResult = $this->parseLeftFromAt();
|
|
||||||
|
|
||||||
if ($localPartResult->isInvalid()) {
|
|
||||||
return $localPartResult;
|
|
||||||
}
|
|
||||||
|
|
||||||
$domainPartResult = $this->parseRightFromAt();
|
|
||||||
|
|
||||||
if ($domainPartResult->isInvalid()) {
|
|
||||||
return $domainPartResult;
|
|
||||||
}
|
|
||||||
|
|
||||||
return new ValidEmail();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return Warning\Warning[]
|
|
||||||
*/
|
|
||||||
public function getWarnings() : array
|
|
||||||
{
|
|
||||||
return $this->warnings;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function hasAtToken() : bool
|
|
||||||
{
|
|
||||||
$this->lexer->moveNext();
|
|
||||||
$this->lexer->moveNext();
|
|
||||||
|
|
||||||
return ((array) $this->lexer->token)['type'] !== EmailLexer::S_AT;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,104 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Egulias\EmailValidator\Parser;
|
|
||||||
|
|
||||||
use Egulias\EmailValidator\EmailLexer;
|
|
||||||
use Egulias\EmailValidator\Result\Result;
|
|
||||||
use Egulias\EmailValidator\Warning\QuotedPart;
|
|
||||||
use Egulias\EmailValidator\Result\InvalidEmail;
|
|
||||||
use Egulias\EmailValidator\Parser\CommentStrategy\CommentStrategy;
|
|
||||||
use Egulias\EmailValidator\Result\Reason\UnclosedComment;
|
|
||||||
use Egulias\EmailValidator\Result\Reason\UnOpenedComment;
|
|
||||||
use Egulias\EmailValidator\Warning\Comment as WarningComment;
|
|
||||||
|
|
||||||
class Comment extends PartParser
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
private $openedParenthesis = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var CommentStrategy
|
|
||||||
*/
|
|
||||||
private $commentStrategy;
|
|
||||||
|
|
||||||
public function __construct(EmailLexer $lexer, CommentStrategy $commentStrategy)
|
|
||||||
{
|
|
||||||
$this->lexer = $lexer;
|
|
||||||
$this->commentStrategy = $commentStrategy;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function parse() : Result
|
|
||||||
{
|
|
||||||
if (((array) $this->lexer->token)['type'] === EmailLexer::S_OPENPARENTHESIS) {
|
|
||||||
$this->openedParenthesis++;
|
|
||||||
if($this->noClosingParenthesis()) {
|
|
||||||
return new InvalidEmail(new UnclosedComment(), ((array) $this->lexer->token)['value']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (((array) $this->lexer->token)['type'] === EmailLexer::S_CLOSEPARENTHESIS) {
|
|
||||||
return new InvalidEmail(new UnOpenedComment(), ((array) $this->lexer->token)['value']);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->warnings[WarningComment::CODE] = new WarningComment();
|
|
||||||
|
|
||||||
$moreTokens = true;
|
|
||||||
while ($this->commentStrategy->exitCondition($this->lexer, $this->openedParenthesis) && $moreTokens){
|
|
||||||
|
|
||||||
if ($this->lexer->isNextToken(EmailLexer::S_OPENPARENTHESIS)) {
|
|
||||||
$this->openedParenthesis++;
|
|
||||||
}
|
|
||||||
$this->warnEscaping();
|
|
||||||
if($this->lexer->isNextToken(EmailLexer::S_CLOSEPARENTHESIS)) {
|
|
||||||
$this->openedParenthesis--;
|
|
||||||
}
|
|
||||||
$moreTokens = $this->lexer->moveNext();
|
|
||||||
}
|
|
||||||
|
|
||||||
if($this->openedParenthesis >= 1) {
|
|
||||||
return new InvalidEmail(new UnclosedComment(), ((array) $this->lexer->token)['value']);
|
|
||||||
}
|
|
||||||
if ($this->openedParenthesis < 0) {
|
|
||||||
return new InvalidEmail(new UnOpenedComment(), ((array) $this->lexer->token)['value']);
|
|
||||||
}
|
|
||||||
|
|
||||||
$finalValidations = $this->commentStrategy->endOfLoopValidations($this->lexer);
|
|
||||||
|
|
||||||
$this->warnings = array_merge($this->warnings, $this->commentStrategy->getWarnings());
|
|
||||||
|
|
||||||
return $finalValidations;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
private function warnEscaping() : bool
|
|
||||||
{
|
|
||||||
//Backslash found
|
|
||||||
if (((array) $this->lexer->token)['type'] !== EmailLexer::S_BACKSLASH) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$this->lexer->isNextTokenAny(array(EmailLexer::S_SP, EmailLexer::S_HTAB, EmailLexer::C_DEL))) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->warnings[QuotedPart::CODE] =
|
|
||||||
new QuotedPart($this->lexer->getPrevious()['type'], ((array) $this->lexer->token)['type']);
|
|
||||||
return true;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private function noClosingParenthesis() : bool
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
$this->lexer->find(EmailLexer::S_CLOSEPARENTHESIS);
|
|
||||||
return false;
|
|
||||||
} catch (\RuntimeException $e) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,18 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Egulias\EmailValidator\Parser\CommentStrategy;
|
|
||||||
|
|
||||||
use Egulias\EmailValidator\EmailLexer;
|
|
||||||
use Egulias\EmailValidator\Result\Result;
|
|
||||||
|
|
||||||
interface CommentStrategy
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Return "true" to continue, "false" to exit
|
|
||||||
*/
|
|
||||||
public function exitCondition(EmailLexer $lexer, int $openedParenthesis) : bool;
|
|
||||||
|
|
||||||
public function endOfLoopValidations(EmailLexer $lexer) : Result;
|
|
||||||
|
|
||||||
public function getWarnings() : array;
|
|
||||||
}
|
|
||||||
|
|
@ -1,37 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Egulias\EmailValidator\Parser\CommentStrategy;
|
|
||||||
|
|
||||||
use Egulias\EmailValidator\EmailLexer;
|
|
||||||
use Egulias\EmailValidator\Result\Result;
|
|
||||||
use Egulias\EmailValidator\Result\ValidEmail;
|
|
||||||
use Egulias\EmailValidator\Result\InvalidEmail;
|
|
||||||
use Egulias\EmailValidator\Result\Reason\ExpectingATEXT;
|
|
||||||
|
|
||||||
class DomainComment implements CommentStrategy
|
|
||||||
{
|
|
||||||
public function exitCondition(EmailLexer $lexer, int $openedParenthesis) : bool
|
|
||||||
{
|
|
||||||
if (($openedParenthesis === 0 && $lexer->isNextToken(EmailLexer::S_DOT))){ // || !$internalLexer->moveNext()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function endOfLoopValidations(EmailLexer $lexer) : Result
|
|
||||||
{
|
|
||||||
//test for end of string
|
|
||||||
if (!$lexer->isNextToken(EmailLexer::S_DOT)) {
|
|
||||||
return new InvalidEmail(new ExpectingATEXT('DOT not found near CLOSEPARENTHESIS'), ((array) $lexer->token)['value']);
|
|
||||||
}
|
|
||||||
//add warning
|
|
||||||
//Address is valid within the message but cannot be used unmodified for the envelope
|
|
||||||
return new ValidEmail();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getWarnings(): array
|
|
||||||
{
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,37 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Egulias\EmailValidator\Parser\CommentStrategy;
|
|
||||||
|
|
||||||
use Egulias\EmailValidator\EmailLexer;
|
|
||||||
use Egulias\EmailValidator\Result\Result;
|
|
||||||
use Egulias\EmailValidator\Result\ValidEmail;
|
|
||||||
use Egulias\EmailValidator\Warning\CFWSNearAt;
|
|
||||||
use Egulias\EmailValidator\Result\InvalidEmail;
|
|
||||||
use Egulias\EmailValidator\Result\Reason\ExpectingATEXT;
|
|
||||||
|
|
||||||
class LocalComment implements CommentStrategy
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
private $warnings = [];
|
|
||||||
|
|
||||||
public function exitCondition(EmailLexer $lexer, int $openedParenthesis) : bool
|
|
||||||
{
|
|
||||||
return !$lexer->isNextToken(EmailLexer::S_AT);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function endOfLoopValidations(EmailLexer $lexer) : Result
|
|
||||||
{
|
|
||||||
if (!$lexer->isNextToken(EmailLexer::S_AT)) {
|
|
||||||
return new InvalidEmail(new ExpectingATEXT('ATEX is not expected after closing comments'), ((array) $lexer->token)['value']);
|
|
||||||
}
|
|
||||||
$this->warnings[CFWSNearAt::CODE] = new CFWSNearAt();
|
|
||||||
return new ValidEmail();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getWarnings(): array
|
|
||||||
{
|
|
||||||
return $this->warnings;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,211 +0,0 @@
|
||||||
<?php
|
|
||||||
namespace Egulias\EmailValidator\Parser;
|
|
||||||
|
|
||||||
use Egulias\EmailValidator\EmailLexer;
|
|
||||||
use Egulias\EmailValidator\Result\Result;
|
|
||||||
use Egulias\EmailValidator\Result\ValidEmail;
|
|
||||||
use Egulias\EmailValidator\Result\InvalidEmail;
|
|
||||||
use Egulias\EmailValidator\Warning\CFWSWithFWS;
|
|
||||||
use Egulias\EmailValidator\Warning\IPV6BadChar;
|
|
||||||
use Egulias\EmailValidator\Result\Reason\CRNoLF;
|
|
||||||
use Egulias\EmailValidator\Warning\IPV6ColonEnd;
|
|
||||||
use Egulias\EmailValidator\Warning\IPV6MaxGroups;
|
|
||||||
use Egulias\EmailValidator\Warning\ObsoleteDTEXT;
|
|
||||||
use Egulias\EmailValidator\Warning\AddressLiteral;
|
|
||||||
use Egulias\EmailValidator\Warning\IPV6ColonStart;
|
|
||||||
use Egulias\EmailValidator\Warning\IPV6Deprecated;
|
|
||||||
use Egulias\EmailValidator\Warning\IPV6GroupCount;
|
|
||||||
use Egulias\EmailValidator\Warning\IPV6DoubleColon;
|
|
||||||
use Egulias\EmailValidator\Result\Reason\ExpectingDTEXT;
|
|
||||||
use Egulias\EmailValidator\Result\Reason\UnusualElements;
|
|
||||||
use Egulias\EmailValidator\Warning\DomainLiteral as WarningDomainLiteral;
|
|
||||||
|
|
||||||
class DomainLiteral extends PartParser
|
|
||||||
{
|
|
||||||
public const IPV4_REGEX = '/\\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/';
|
|
||||||
|
|
||||||
public const OBSOLETE_WARNINGS = [
|
|
||||||
EmailLexer::INVALID,
|
|
||||||
EmailLexer::C_DEL,
|
|
||||||
EmailLexer::S_LF,
|
|
||||||
EmailLexer::S_BACKSLASH
|
|
||||||
];
|
|
||||||
|
|
||||||
public function parse() : Result
|
|
||||||
{
|
|
||||||
$this->addTagWarnings();
|
|
||||||
|
|
||||||
$IPv6TAG = false;
|
|
||||||
$addressLiteral = '';
|
|
||||||
|
|
||||||
do {
|
|
||||||
if (((array) $this->lexer->token)['type'] === EmailLexer::C_NUL) {
|
|
||||||
return new InvalidEmail(new ExpectingDTEXT(), ((array) $this->lexer->token)['value']);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->addObsoleteWarnings();
|
|
||||||
|
|
||||||
if ($this->lexer->isNextTokenAny(array(EmailLexer::S_OPENBRACKET, EmailLexer::S_OPENBRACKET))) {
|
|
||||||
return new InvalidEmail(new ExpectingDTEXT(), ((array) $this->lexer->token)['value']);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->lexer->isNextTokenAny(
|
|
||||||
array(EmailLexer::S_HTAB, EmailLexer::S_SP, EmailLexer::CRLF)
|
|
||||||
)) {
|
|
||||||
$this->warnings[CFWSWithFWS::CODE] = new CFWSWithFWS();
|
|
||||||
$this->parseFWS();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->lexer->isNextToken(EmailLexer::S_CR)) {
|
|
||||||
return new InvalidEmail(new CRNoLF(), ((array) $this->lexer->token)['value']);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (((array) $this->lexer->token)['type'] === EmailLexer::S_BACKSLASH) {
|
|
||||||
return new InvalidEmail(new UnusualElements(((array) $this->lexer->token)['value']), ((array) $this->lexer->token)['value']);
|
|
||||||
}
|
|
||||||
if (((array) $this->lexer->token)['type'] === EmailLexer::S_IPV6TAG) {
|
|
||||||
$IPv6TAG = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (((array) $this->lexer->token)['type'] === EmailLexer::S_CLOSEBRACKET) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
$addressLiteral .= ((array) $this->lexer->token)['value'];
|
|
||||||
|
|
||||||
} while ($this->lexer->moveNext());
|
|
||||||
|
|
||||||
|
|
||||||
//Encapsulate
|
|
||||||
$addressLiteral = str_replace('[', '', $addressLiteral);
|
|
||||||
$isAddressLiteralIPv4 = $this->checkIPV4Tag($addressLiteral);
|
|
||||||
|
|
||||||
if (!$isAddressLiteralIPv4) {
|
|
||||||
return new ValidEmail();
|
|
||||||
} else {
|
|
||||||
$addressLiteral = $this->convertIPv4ToIPv6($addressLiteral);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$IPv6TAG) {
|
|
||||||
$this->warnings[WarningDomainLiteral::CODE] = new WarningDomainLiteral();
|
|
||||||
return new ValidEmail();
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->warnings[AddressLiteral::CODE] = new AddressLiteral();
|
|
||||||
|
|
||||||
$this->checkIPV6Tag($addressLiteral);
|
|
||||||
|
|
||||||
return new ValidEmail();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $addressLiteral
|
|
||||||
* @param int $maxGroups
|
|
||||||
*/
|
|
||||||
public function checkIPV6Tag($addressLiteral, $maxGroups = 8) : void
|
|
||||||
{
|
|
||||||
$prev = $this->lexer->getPrevious();
|
|
||||||
if ($prev['type'] === EmailLexer::S_COLON) {
|
|
||||||
$this->warnings[IPV6ColonEnd::CODE] = new IPV6ColonEnd();
|
|
||||||
}
|
|
||||||
|
|
||||||
$IPv6 = substr($addressLiteral, 5);
|
|
||||||
//Daniel Marschall's new IPv6 testing strategy
|
|
||||||
$matchesIP = explode(':', $IPv6);
|
|
||||||
$groupCount = count($matchesIP);
|
|
||||||
$colons = strpos($IPv6, '::');
|
|
||||||
|
|
||||||
if (count(preg_grep('/^[0-9A-Fa-f]{0,4}$/', $matchesIP, PREG_GREP_INVERT)) !== 0) {
|
|
||||||
$this->warnings[IPV6BadChar::CODE] = new IPV6BadChar();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($colons === false) {
|
|
||||||
// We need exactly the right number of groups
|
|
||||||
if ($groupCount !== $maxGroups) {
|
|
||||||
$this->warnings[IPV6GroupCount::CODE] = new IPV6GroupCount();
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($colons !== strrpos($IPv6, '::')) {
|
|
||||||
$this->warnings[IPV6DoubleColon::CODE] = new IPV6DoubleColon();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($colons === 0 || $colons === (strlen($IPv6) - 2)) {
|
|
||||||
// RFC 4291 allows :: at the start or end of an address
|
|
||||||
//with 7 other groups in addition
|
|
||||||
++$maxGroups;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($groupCount > $maxGroups) {
|
|
||||||
$this->warnings[IPV6MaxGroups::CODE] = new IPV6MaxGroups();
|
|
||||||
} elseif ($groupCount === $maxGroups) {
|
|
||||||
$this->warnings[IPV6Deprecated::CODE] = new IPV6Deprecated();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function convertIPv4ToIPv6(string $addressLiteralIPv4) : string
|
|
||||||
{
|
|
||||||
$matchesIP = [];
|
|
||||||
$IPv4Match = preg_match(self::IPV4_REGEX, $addressLiteralIPv4, $matchesIP);
|
|
||||||
|
|
||||||
// Extract IPv4 part from the end of the address-literal (if there is one)
|
|
||||||
if ($IPv4Match > 0) {
|
|
||||||
$index = (int) strrpos($addressLiteralIPv4, $matchesIP[0]);
|
|
||||||
//There's a match but it is at the start
|
|
||||||
if ($index > 0) {
|
|
||||||
// Convert IPv4 part to IPv6 format for further testing
|
|
||||||
return substr($addressLiteralIPv4, 0, $index) . '0:0';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $addressLiteralIPv4;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $addressLiteral
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
protected function checkIPV4Tag($addressLiteral) : bool
|
|
||||||
{
|
|
||||||
$matchesIP = [];
|
|
||||||
$IPv4Match = preg_match(self::IPV4_REGEX, $addressLiteral, $matchesIP);
|
|
||||||
|
|
||||||
// Extract IPv4 part from the end of the address-literal (if there is one)
|
|
||||||
|
|
||||||
if ($IPv4Match > 0) {
|
|
||||||
$index = strrpos($addressLiteral, $matchesIP[0]);
|
|
||||||
//There's a match but it is at the start
|
|
||||||
if ($index === 0) {
|
|
||||||
$this->warnings[AddressLiteral::CODE] = new AddressLiteral();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function addObsoleteWarnings() : void
|
|
||||||
{
|
|
||||||
if(in_array(((array) $this->lexer->token)['type'], self::OBSOLETE_WARNINGS)) {
|
|
||||||
$this->warnings[ObsoleteDTEXT::CODE] = new ObsoleteDTEXT();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function addTagWarnings() : void
|
|
||||||
{
|
|
||||||
if ($this->lexer->isNextToken(EmailLexer::S_COLON)) {
|
|
||||||
$this->warnings[IPV6ColonStart::CODE] = new IPV6ColonStart();
|
|
||||||
}
|
|
||||||
if ($this->lexer->isNextToken(EmailLexer::S_IPV6TAG)) {
|
|
||||||
$lexer = clone $this->lexer;
|
|
||||||
$lexer->moveNext();
|
|
||||||
if ($lexer->isNextToken(EmailLexer::S_DOUBLECOLON)) {
|
|
||||||
$this->warnings[IPV6ColonStart::CODE] = new IPV6ColonStart();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,316 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Egulias\EmailValidator\Parser;
|
|
||||||
|
|
||||||
use Doctrine\Common\Lexer\Token;
|
|
||||||
use Egulias\EmailValidator\EmailLexer;
|
|
||||||
use Egulias\EmailValidator\Warning\TLD;
|
|
||||||
use Egulias\EmailValidator\Result\Result;
|
|
||||||
use Egulias\EmailValidator\Result\ValidEmail;
|
|
||||||
use Egulias\EmailValidator\Result\InvalidEmail;
|
|
||||||
use Egulias\EmailValidator\Result\Reason\DotAtEnd;
|
|
||||||
use Egulias\EmailValidator\Result\Reason\DotAtStart;
|
|
||||||
use Egulias\EmailValidator\Warning\DeprecatedComment;
|
|
||||||
use Egulias\EmailValidator\Result\Reason\CRLFAtTheEnd;
|
|
||||||
use Egulias\EmailValidator\Result\Reason\LabelTooLong;
|
|
||||||
use Egulias\EmailValidator\Result\Reason\NoDomainPart;
|
|
||||||
use Egulias\EmailValidator\Result\Reason\ConsecutiveAt;
|
|
||||||
use Egulias\EmailValidator\Result\Reason\DomainTooLong;
|
|
||||||
use Egulias\EmailValidator\Result\Reason\CharNotAllowed;
|
|
||||||
use Egulias\EmailValidator\Result\Reason\DomainHyphened;
|
|
||||||
use Egulias\EmailValidator\Result\Reason\ExpectingATEXT;
|
|
||||||
use Egulias\EmailValidator\Parser\CommentStrategy\DomainComment;
|
|
||||||
use Egulias\EmailValidator\Result\Reason\ExpectingDomainLiteralClose;
|
|
||||||
use Egulias\EmailValidator\Parser\DomainLiteral as DomainLiteralParser;
|
|
||||||
|
|
||||||
class DomainPart extends PartParser
|
|
||||||
{
|
|
||||||
public const DOMAIN_MAX_LENGTH = 253;
|
|
||||||
public const LABEL_MAX_LENGTH = 63;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $domainPart = '';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $label = '';
|
|
||||||
|
|
||||||
public function parse() : Result
|
|
||||||
{
|
|
||||||
$this->lexer->clearRecorded();
|
|
||||||
$this->lexer->startRecording();
|
|
||||||
|
|
||||||
$this->lexer->moveNext();
|
|
||||||
|
|
||||||
$domainChecks = $this->performDomainStartChecks();
|
|
||||||
if ($domainChecks->isInvalid()) {
|
|
||||||
return $domainChecks;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (((array) $this->lexer->token)['type'] === EmailLexer::S_AT) {
|
|
||||||
return new InvalidEmail(new ConsecutiveAt(), ((array) $this->lexer->token)['value']);
|
|
||||||
}
|
|
||||||
|
|
||||||
$result = $this->doParseDomainPart();
|
|
||||||
if ($result->isInvalid()) {
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
$end = $this->checkEndOfDomain();
|
|
||||||
if ($end->isInvalid()) {
|
|
||||||
return $end;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->lexer->stopRecording();
|
|
||||||
$this->domainPart = $this->lexer->getAccumulatedValues();
|
|
||||||
|
|
||||||
$length = strlen($this->domainPart);
|
|
||||||
if ($length > self::DOMAIN_MAX_LENGTH) {
|
|
||||||
return new InvalidEmail(new DomainTooLong(), ((array) $this->lexer->token)['value']);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new ValidEmail();
|
|
||||||
}
|
|
||||||
|
|
||||||
private function checkEndOfDomain() : Result
|
|
||||||
{
|
|
||||||
$prev = $this->lexer->getPrevious();
|
|
||||||
if ($prev['type'] === EmailLexer::S_DOT) {
|
|
||||||
return new InvalidEmail(new DotAtEnd(), ((array) $this->lexer->token)['value']);
|
|
||||||
}
|
|
||||||
if ($prev['type'] === EmailLexer::S_HYPHEN) {
|
|
||||||
return new InvalidEmail(new DomainHyphened('Hypen found at the end of the domain'), $prev['value']);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (((array) $this->lexer->token)['type'] === EmailLexer::S_SP) {
|
|
||||||
return new InvalidEmail(new CRLFAtTheEnd(), $prev['value']);
|
|
||||||
}
|
|
||||||
return new ValidEmail();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private function performDomainStartChecks() : Result
|
|
||||||
{
|
|
||||||
$invalidTokens = $this->checkInvalidTokensAfterAT();
|
|
||||||
if ($invalidTokens->isInvalid()) {
|
|
||||||
return $invalidTokens;
|
|
||||||
}
|
|
||||||
|
|
||||||
$missingDomain = $this->checkEmptyDomain();
|
|
||||||
if ($missingDomain->isInvalid()) {
|
|
||||||
return $missingDomain;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (((array) $this->lexer->token)['type'] === EmailLexer::S_OPENPARENTHESIS) {
|
|
||||||
$this->warnings[DeprecatedComment::CODE] = new DeprecatedComment();
|
|
||||||
}
|
|
||||||
return new ValidEmail();
|
|
||||||
}
|
|
||||||
|
|
||||||
private function checkEmptyDomain() : Result
|
|
||||||
{
|
|
||||||
$thereIsNoDomain = ((array) $this->lexer->token)['type'] === EmailLexer::S_EMPTY ||
|
|
||||||
(((array) $this->lexer->token)['type'] === EmailLexer::S_SP &&
|
|
||||||
!$this->lexer->isNextToken(EmailLexer::GENERIC));
|
|
||||||
|
|
||||||
if ($thereIsNoDomain) {
|
|
||||||
return new InvalidEmail(new NoDomainPart(), ((array) $this->lexer->token)['value']);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new ValidEmail();
|
|
||||||
}
|
|
||||||
|
|
||||||
private function checkInvalidTokensAfterAT() : Result
|
|
||||||
{
|
|
||||||
if (((array) $this->lexer->token)['type'] === EmailLexer::S_DOT) {
|
|
||||||
return new InvalidEmail(new DotAtStart(), ((array) $this->lexer->token)['value']);
|
|
||||||
}
|
|
||||||
if (((array) $this->lexer->token)['type'] === EmailLexer::S_HYPHEN) {
|
|
||||||
return new InvalidEmail(new DomainHyphened('After AT'), ((array) $this->lexer->token)['value']);
|
|
||||||
}
|
|
||||||
return new ValidEmail();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function parseComments(): Result
|
|
||||||
{
|
|
||||||
$commentParser = new Comment($this->lexer, new DomainComment());
|
|
||||||
$result = $commentParser->parse();
|
|
||||||
$this->warnings = array_merge($this->warnings, $commentParser->getWarnings());
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function doParseDomainPart() : Result
|
|
||||||
{
|
|
||||||
$tldMissing = true;
|
|
||||||
$hasComments = false;
|
|
||||||
$domain = '';
|
|
||||||
do {
|
|
||||||
$prev = $this->lexer->getPrevious();
|
|
||||||
|
|
||||||
$notAllowedChars = $this->checkNotAllowedChars($this->lexer->token);
|
|
||||||
if ($notAllowedChars->isInvalid()) {
|
|
||||||
return $notAllowedChars;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (((array) $this->lexer->token)['type'] === EmailLexer::S_OPENPARENTHESIS ||
|
|
||||||
((array) $this->lexer->token)['type'] === EmailLexer::S_CLOSEPARENTHESIS ) {
|
|
||||||
$hasComments = true;
|
|
||||||
$commentsResult = $this->parseComments();
|
|
||||||
|
|
||||||
//Invalid comment parsing
|
|
||||||
if($commentsResult->isInvalid()) {
|
|
||||||
return $commentsResult;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$dotsResult = $this->checkConsecutiveDots();
|
|
||||||
if ($dotsResult->isInvalid()) {
|
|
||||||
return $dotsResult;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (((array) $this->lexer->token)['type'] === EmailLexer::S_OPENBRACKET) {
|
|
||||||
$literalResult = $this->parseDomainLiteral();
|
|
||||||
|
|
||||||
$this->addTLDWarnings($tldMissing);
|
|
||||||
return $literalResult;
|
|
||||||
}
|
|
||||||
|
|
||||||
$labelCheck = $this->checkLabelLength();
|
|
||||||
if ($labelCheck->isInvalid()) {
|
|
||||||
return $labelCheck;
|
|
||||||
}
|
|
||||||
|
|
||||||
$FwsResult = $this->parseFWS();
|
|
||||||
if($FwsResult->isInvalid()) {
|
|
||||||
return $FwsResult;
|
|
||||||
}
|
|
||||||
|
|
||||||
$domain .= ((array) $this->lexer->token)['value'];
|
|
||||||
|
|
||||||
if (((array) $this->lexer->token)['type'] === EmailLexer::S_DOT && $this->lexer->isNextToken(EmailLexer::GENERIC)) {
|
|
||||||
$tldMissing = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$exceptionsResult = $this->checkDomainPartExceptions($prev, $hasComments);
|
|
||||||
if ($exceptionsResult->isInvalid()) {
|
|
||||||
return $exceptionsResult;
|
|
||||||
}
|
|
||||||
$this->lexer->moveNext();
|
|
||||||
|
|
||||||
} while (null !== ((array) $this->lexer->token)['type']);
|
|
||||||
|
|
||||||
$labelCheck = $this->checkLabelLength(true);
|
|
||||||
if ($labelCheck->isInvalid()) {
|
|
||||||
return $labelCheck;
|
|
||||||
}
|
|
||||||
$this->addTLDWarnings($tldMissing);
|
|
||||||
|
|
||||||
$this->domainPart = $domain;
|
|
||||||
return new ValidEmail();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @psalm-param array|Token<int, string> $token
|
|
||||||
*/
|
|
||||||
private function checkNotAllowedChars($token) : Result
|
|
||||||
{
|
|
||||||
$notAllowed = [EmailLexer::S_BACKSLASH => true, EmailLexer::S_SLASH=> true];
|
|
||||||
if (isset($notAllowed[((array) $token)['type']])) {
|
|
||||||
return new InvalidEmail(new CharNotAllowed(), ((array) $token)['value']);
|
|
||||||
}
|
|
||||||
return new ValidEmail();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return Result
|
|
||||||
*/
|
|
||||||
protected function parseDomainLiteral() : Result
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
$this->lexer->find(EmailLexer::S_CLOSEBRACKET);
|
|
||||||
} catch (\RuntimeException $e) {
|
|
||||||
return new InvalidEmail(new ExpectingDomainLiteralClose(), ((array) $this->lexer->token)['value']);
|
|
||||||
}
|
|
||||||
|
|
||||||
$domainLiteralParser = new DomainLiteralParser($this->lexer);
|
|
||||||
$result = $domainLiteralParser->parse();
|
|
||||||
$this->warnings = array_merge($this->warnings, $domainLiteralParser->getWarnings());
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function checkDomainPartExceptions(array $prev, bool $hasComments) : Result
|
|
||||||
{
|
|
||||||
if (((array) $this->lexer->token)['type'] === EmailLexer::S_OPENBRACKET && $prev['type'] !== EmailLexer::S_AT) {
|
|
||||||
return new InvalidEmail(new ExpectingATEXT('OPENBRACKET not after AT'), ((array) $this->lexer->token)['value']);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (((array) $this->lexer->token)['type'] === EmailLexer::S_HYPHEN && $this->lexer->isNextToken(EmailLexer::S_DOT)) {
|
|
||||||
return new InvalidEmail(new DomainHyphened('Hypen found near DOT'), ((array) $this->lexer->token)['value']);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (((array) $this->lexer->token)['type'] === EmailLexer::S_BACKSLASH
|
|
||||||
&& $this->lexer->isNextToken(EmailLexer::GENERIC)) {
|
|
||||||
return new InvalidEmail(new ExpectingATEXT('Escaping following "ATOM"'), ((array) $this->lexer->token)['value']);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->validateTokens($hasComments);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function validateTokens(bool $hasComments) : Result
|
|
||||||
{
|
|
||||||
$validDomainTokens = array(
|
|
||||||
EmailLexer::GENERIC => true,
|
|
||||||
EmailLexer::S_HYPHEN => true,
|
|
||||||
EmailLexer::S_DOT => true,
|
|
||||||
);
|
|
||||||
|
|
||||||
if ($hasComments) {
|
|
||||||
$validDomainTokens[EmailLexer::S_OPENPARENTHESIS] = true;
|
|
||||||
$validDomainTokens[EmailLexer::S_CLOSEPARENTHESIS] = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isset($validDomainTokens[((array) $this->lexer->token)['type']])) {
|
|
||||||
return new InvalidEmail(new ExpectingATEXT('Invalid token in domain: ' . ((array) $this->lexer->token)['value']), ((array) $this->lexer->token)['value']);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new ValidEmail();
|
|
||||||
}
|
|
||||||
|
|
||||||
private function checkLabelLength(bool $isEndOfDomain = false) : Result
|
|
||||||
{
|
|
||||||
if (((array) $this->lexer->token)['type'] === EmailLexer::S_DOT || $isEndOfDomain) {
|
|
||||||
if ($this->isLabelTooLong($this->label)) {
|
|
||||||
return new InvalidEmail(new LabelTooLong(), ((array) $this->lexer->token)['value']);
|
|
||||||
}
|
|
||||||
$this->label = '';
|
|
||||||
}
|
|
||||||
$this->label .= ((array) $this->lexer->token)['value'];
|
|
||||||
return new ValidEmail();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private function isLabelTooLong(string $label) : bool
|
|
||||||
{
|
|
||||||
if (preg_match('/[^\x00-\x7F]/', $label)) {
|
|
||||||
idn_to_ascii($label, IDNA_DEFAULT, INTL_IDNA_VARIANT_UTS46, $idnaInfo);
|
|
||||||
return (bool) ($idnaInfo['errors'] & IDNA_ERROR_LABEL_TOO_LONG);
|
|
||||||
}
|
|
||||||
return strlen($label) > self::LABEL_MAX_LENGTH;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function addTLDWarnings(bool $isTLDMissing) : void
|
|
||||||
{
|
|
||||||
if ($isTLDMissing) {
|
|
||||||
$this->warnings[TLD::CODE] = new TLD();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function domainPart() : string
|
|
||||||
{
|
|
||||||
return $this->domainPart;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,87 +0,0 @@
|
||||||
<?php
|
|
||||||
namespace Egulias\EmailValidator\Parser;
|
|
||||||
|
|
||||||
use Egulias\EmailValidator\EmailLexer;
|
|
||||||
use Egulias\EmailValidator\Result\ValidEmail;
|
|
||||||
use Egulias\EmailValidator\Result\InvalidEmail;
|
|
||||||
use Egulias\EmailValidator\Warning\CFWSWithFWS;
|
|
||||||
use Egulias\EmailValidator\Warning\QuotedString;
|
|
||||||
use Egulias\EmailValidator\Result\Reason\ExpectingATEXT;
|
|
||||||
use Egulias\EmailValidator\Result\Reason\UnclosedQuotedString;
|
|
||||||
use Egulias\EmailValidator\Result\Result;
|
|
||||||
|
|
||||||
class DoubleQuote extends PartParser
|
|
||||||
{
|
|
||||||
public function parse() : Result
|
|
||||||
{
|
|
||||||
|
|
||||||
$validQuotedString = $this->checkDQUOTE();
|
|
||||||
if($validQuotedString->isInvalid()) return $validQuotedString;
|
|
||||||
|
|
||||||
$special = [
|
|
||||||
EmailLexer::S_CR => true,
|
|
||||||
EmailLexer::S_HTAB => true,
|
|
||||||
EmailLexer::S_LF => true
|
|
||||||
];
|
|
||||||
|
|
||||||
$invalid = [
|
|
||||||
EmailLexer::C_NUL => true,
|
|
||||||
EmailLexer::S_HTAB => true,
|
|
||||||
EmailLexer::S_CR => true,
|
|
||||||
EmailLexer::S_LF => true
|
|
||||||
];
|
|
||||||
|
|
||||||
$setSpecialsWarning = true;
|
|
||||||
|
|
||||||
$this->lexer->moveNext();
|
|
||||||
|
|
||||||
while (((array) $this->lexer->token)['type'] !== EmailLexer::S_DQUOTE && null !== ((array) $this->lexer->token)['type']) {
|
|
||||||
if (isset($special[((array) $this->lexer->token)['type']]) && $setSpecialsWarning) {
|
|
||||||
$this->warnings[CFWSWithFWS::CODE] = new CFWSWithFWS();
|
|
||||||
$setSpecialsWarning = false;
|
|
||||||
}
|
|
||||||
if (((array) $this->lexer->token)['type'] === EmailLexer::S_BACKSLASH && $this->lexer->isNextToken(EmailLexer::S_DQUOTE)) {
|
|
||||||
$this->lexer->moveNext();
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->lexer->moveNext();
|
|
||||||
|
|
||||||
if (!$this->escaped() && isset($invalid[((array) $this->lexer->token)['type']])) {
|
|
||||||
return new InvalidEmail(new ExpectingATEXT("Expecting ATEXT between DQUOTE"), ((array) $this->lexer->token)['value']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$prev = $this->lexer->getPrevious();
|
|
||||||
|
|
||||||
if ($prev['type'] === EmailLexer::S_BACKSLASH) {
|
|
||||||
$validQuotedString = $this->checkDQUOTE();
|
|
||||||
if($validQuotedString->isInvalid()) return $validQuotedString;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$this->lexer->isNextToken(EmailLexer::S_AT) && $prev['type'] !== EmailLexer::S_BACKSLASH) {
|
|
||||||
return new InvalidEmail(new ExpectingATEXT("Expecting ATEXT between DQUOTE"), ((array) $this->lexer->token)['value']);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new ValidEmail();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function checkDQUOTE() : Result
|
|
||||||
{
|
|
||||||
$previous = $this->lexer->getPrevious();
|
|
||||||
|
|
||||||
if ($this->lexer->isNextToken(EmailLexer::GENERIC) && $previous['type'] === EmailLexer::GENERIC) {
|
|
||||||
$description = 'https://tools.ietf.org/html/rfc5322#section-3.2.4 - quoted string should be a unit';
|
|
||||||
return new InvalidEmail(new ExpectingATEXT($description), ((array) $this->lexer->token)['value']);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
$this->lexer->find(EmailLexer::S_DQUOTE);
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
return new InvalidEmail(new UnclosedQuotedString(), ((array) $this->lexer->token)['value']);
|
|
||||||
}
|
|
||||||
$this->warnings[QuotedString::CODE] = new QuotedString($previous['value'], ((array) $this->lexer->token)['value']);
|
|
||||||
|
|
||||||
return new ValidEmail();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,86 +0,0 @@
|
||||||
<?php
|
|
||||||
namespace Egulias\EmailValidator\Parser;
|
|
||||||
|
|
||||||
use Egulias\EmailValidator\EmailLexer;
|
|
||||||
use Egulias\EmailValidator\Warning\CFWSNearAt;
|
|
||||||
use Egulias\EmailValidator\Result\InvalidEmail;
|
|
||||||
use Egulias\EmailValidator\Warning\CFWSWithFWS;
|
|
||||||
use Egulias\EmailValidator\Result\Reason\CRNoLF;
|
|
||||||
use Egulias\EmailValidator\Result\Reason\AtextAfterCFWS;
|
|
||||||
use Egulias\EmailValidator\Result\Reason\CRLFAtTheEnd;
|
|
||||||
use Egulias\EmailValidator\Result\Reason\CRLFX2;
|
|
||||||
use Egulias\EmailValidator\Result\Reason\ExpectingCTEXT;
|
|
||||||
use Egulias\EmailValidator\Result\Result;
|
|
||||||
use Egulias\EmailValidator\Result\ValidEmail;
|
|
||||||
|
|
||||||
class FoldingWhiteSpace extends PartParser
|
|
||||||
{
|
|
||||||
public const FWS_TYPES = [
|
|
||||||
EmailLexer::S_SP,
|
|
||||||
EmailLexer::S_HTAB,
|
|
||||||
EmailLexer::S_CR,
|
|
||||||
EmailLexer::S_LF,
|
|
||||||
EmailLexer::CRLF
|
|
||||||
];
|
|
||||||
|
|
||||||
public function parse() : Result
|
|
||||||
{
|
|
||||||
if (!$this->isFWS()) {
|
|
||||||
return new ValidEmail();
|
|
||||||
}
|
|
||||||
|
|
||||||
$previous = $this->lexer->getPrevious();
|
|
||||||
|
|
||||||
$resultCRLF = $this->checkCRLFInFWS();
|
|
||||||
if ($resultCRLF->isInvalid()) {
|
|
||||||
return $resultCRLF;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (((array) $this->lexer->token)['type'] === EmailLexer::S_CR) {
|
|
||||||
return new InvalidEmail(new CRNoLF(), ((array) $this->lexer->token)['value']);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->lexer->isNextToken(EmailLexer::GENERIC) && $previous['type'] !== EmailLexer::S_AT) {
|
|
||||||
return new InvalidEmail(new AtextAfterCFWS(), ((array) $this->lexer->token)['value']);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (((array) $this->lexer->token)['type'] === EmailLexer::S_LF || ((array) $this->lexer->token)['type'] === EmailLexer::C_NUL) {
|
|
||||||
return new InvalidEmail(new ExpectingCTEXT(), ((array) $this->lexer->token)['value']);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->lexer->isNextToken(EmailLexer::S_AT) || $previous['type'] === EmailLexer::S_AT) {
|
|
||||||
$this->warnings[CFWSNearAt::CODE] = new CFWSNearAt();
|
|
||||||
} else {
|
|
||||||
$this->warnings[CFWSWithFWS::CODE] = new CFWSWithFWS();
|
|
||||||
}
|
|
||||||
|
|
||||||
return new ValidEmail();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function checkCRLFInFWS() : Result
|
|
||||||
{
|
|
||||||
if (((array) $this->lexer->token)['type'] !== EmailLexer::CRLF) {
|
|
||||||
return new ValidEmail();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$this->lexer->isNextTokenAny(array(EmailLexer::S_SP, EmailLexer::S_HTAB))) {
|
|
||||||
return new InvalidEmail(new CRLFX2(), ((array) $this->lexer->token)['value']);
|
|
||||||
}
|
|
||||||
|
|
||||||
//this has no coverage. Condition is repeated from above one
|
|
||||||
if (!$this->lexer->isNextTokenAny(array(EmailLexer::S_SP, EmailLexer::S_HTAB))) {
|
|
||||||
return new InvalidEmail(new CRLFAtTheEnd(), ((array) $this->lexer->token)['value']);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new ValidEmail();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function isFWS() : bool
|
|
||||||
{
|
|
||||||
if ($this->escaped()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return in_array(((array) $this->lexer->token)['type'], self::FWS_TYPES);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,15 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Egulias\EmailValidator\Parser;
|
|
||||||
|
|
||||||
use Egulias\EmailValidator\Result\Result;
|
|
||||||
use Egulias\EmailValidator\Result\InvalidEmail;
|
|
||||||
use Egulias\EmailValidator\Result\Reason\CommentsInIDRight;
|
|
||||||
|
|
||||||
class IDLeftPart extends LocalPart
|
|
||||||
{
|
|
||||||
protected function parseComments(): Result
|
|
||||||
{
|
|
||||||
return new InvalidEmail(new CommentsInIDRight(), ((array) $this->lexer->token)['value']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,29 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Egulias\EmailValidator\Parser;
|
|
||||||
|
|
||||||
use Egulias\EmailValidator\EmailLexer;
|
|
||||||
use Egulias\EmailValidator\Result\Result;
|
|
||||||
use Egulias\EmailValidator\Result\ValidEmail;
|
|
||||||
use Egulias\EmailValidator\Result\InvalidEmail;
|
|
||||||
use Egulias\EmailValidator\Result\Reason\ExpectingATEXT;
|
|
||||||
|
|
||||||
class IDRightPart extends DomainPart
|
|
||||||
{
|
|
||||||
protected function validateTokens(bool $hasComments) : Result
|
|
||||||
{
|
|
||||||
$invalidDomainTokens = [
|
|
||||||
EmailLexer::S_DQUOTE => true,
|
|
||||||
EmailLexer::S_SQUOTE => true,
|
|
||||||
EmailLexer::S_BACKTICK => true,
|
|
||||||
EmailLexer::S_SEMICOLON => true,
|
|
||||||
EmailLexer::S_GREATERTHAN => true,
|
|
||||||
EmailLexer::S_LOWERTHAN => true,
|
|
||||||
];
|
|
||||||
|
|
||||||
if (isset($invalidDomainTokens[((array) $this->lexer->token)['type']])) {
|
|
||||||
return new InvalidEmail(new ExpectingATEXT('Invalid token in domain: ' . ((array) $this->lexer->token)['value']), ((array) $this->lexer->token)['value']);
|
|
||||||
}
|
|
||||||
return new ValidEmail();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,165 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Egulias\EmailValidator\Parser;
|
|
||||||
|
|
||||||
use Egulias\EmailValidator\EmailLexer;
|
|
||||||
use Egulias\EmailValidator\Result\Result;
|
|
||||||
use Egulias\EmailValidator\Result\ValidEmail;
|
|
||||||
use Egulias\EmailValidator\Result\InvalidEmail;
|
|
||||||
use Egulias\EmailValidator\Warning\LocalTooLong;
|
|
||||||
use Egulias\EmailValidator\Result\Reason\DotAtEnd;
|
|
||||||
use Egulias\EmailValidator\Result\Reason\DotAtStart;
|
|
||||||
use Egulias\EmailValidator\Result\Reason\ConsecutiveDot;
|
|
||||||
use Egulias\EmailValidator\Result\Reason\ExpectingATEXT;
|
|
||||||
use Egulias\EmailValidator\Parser\CommentStrategy\LocalComment;
|
|
||||||
|
|
||||||
class LocalPart extends PartParser
|
|
||||||
{
|
|
||||||
public const INVALID_TOKENS = [
|
|
||||||
EmailLexer::S_COMMA => EmailLexer::S_COMMA,
|
|
||||||
EmailLexer::S_CLOSEBRACKET => EmailLexer::S_CLOSEBRACKET,
|
|
||||||
EmailLexer::S_OPENBRACKET => EmailLexer::S_OPENBRACKET,
|
|
||||||
EmailLexer::S_GREATERTHAN => EmailLexer::S_GREATERTHAN,
|
|
||||||
EmailLexer::S_LOWERTHAN => EmailLexer::S_LOWERTHAN,
|
|
||||||
EmailLexer::S_COLON => EmailLexer::S_COLON,
|
|
||||||
EmailLexer::S_SEMICOLON => EmailLexer::S_SEMICOLON,
|
|
||||||
EmailLexer::INVALID => EmailLexer::INVALID
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
private $localPart = '';
|
|
||||||
|
|
||||||
|
|
||||||
public function parse() : Result
|
|
||||||
{
|
|
||||||
$this->lexer->startRecording();
|
|
||||||
|
|
||||||
while (((array) $this->lexer->token)['type'] !== EmailLexer::S_AT && null !== ((array) $this->lexer->token)['type']) {
|
|
||||||
if ($this->hasDotAtStart()) {
|
|
||||||
return new InvalidEmail(new DotAtStart(), ((array) $this->lexer->token)['value']);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (((array) $this->lexer->token)['type'] === EmailLexer::S_DQUOTE) {
|
|
||||||
$dquoteParsingResult = $this->parseDoubleQuote();
|
|
||||||
|
|
||||||
//Invalid double quote parsing
|
|
||||||
if($dquoteParsingResult->isInvalid()) {
|
|
||||||
return $dquoteParsingResult;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (((array) $this->lexer->token)['type'] === EmailLexer::S_OPENPARENTHESIS ||
|
|
||||||
((array) $this->lexer->token)['type'] === EmailLexer::S_CLOSEPARENTHESIS ) {
|
|
||||||
$commentsResult = $this->parseComments();
|
|
||||||
|
|
||||||
//Invalid comment parsing
|
|
||||||
if($commentsResult->isInvalid()) {
|
|
||||||
return $commentsResult;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (((array) $this->lexer->token)['type'] === EmailLexer::S_DOT && $this->lexer->isNextToken(EmailLexer::S_DOT)) {
|
|
||||||
return new InvalidEmail(new ConsecutiveDot(), ((array) $this->lexer->token)['value']);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (((array) $this->lexer->token)['type'] === EmailLexer::S_DOT &&
|
|
||||||
$this->lexer->isNextToken(EmailLexer::S_AT)
|
|
||||||
) {
|
|
||||||
return new InvalidEmail(new DotAtEnd(), ((array) $this->lexer->token)['value']);
|
|
||||||
}
|
|
||||||
|
|
||||||
$resultEscaping = $this->validateEscaping();
|
|
||||||
if ($resultEscaping->isInvalid()) {
|
|
||||||
return $resultEscaping;
|
|
||||||
}
|
|
||||||
|
|
||||||
$resultToken = $this->validateTokens(false);
|
|
||||||
if ($resultToken->isInvalid()) {
|
|
||||||
return $resultToken;
|
|
||||||
}
|
|
||||||
|
|
||||||
$resultFWS = $this->parseLocalFWS();
|
|
||||||
if($resultFWS->isInvalid()) {
|
|
||||||
return $resultFWS;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->lexer->moveNext();
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->lexer->stopRecording();
|
|
||||||
$this->localPart = rtrim($this->lexer->getAccumulatedValues(), '@');
|
|
||||||
if (strlen($this->localPart) > LocalTooLong::LOCAL_PART_LENGTH) {
|
|
||||||
$this->warnings[LocalTooLong::CODE] = new LocalTooLong();
|
|
||||||
}
|
|
||||||
|
|
||||||
return new ValidEmail();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function validateTokens(bool $hasComments) : Result
|
|
||||||
{
|
|
||||||
if (isset(self::INVALID_TOKENS[((array) $this->lexer->token)['type']])) {
|
|
||||||
return new InvalidEmail(new ExpectingATEXT('Invalid token found'), ((array) $this->lexer->token)['value']);
|
|
||||||
}
|
|
||||||
return new ValidEmail();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function localPart() : string
|
|
||||||
{
|
|
||||||
return $this->localPart;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function parseLocalFWS() : Result
|
|
||||||
{
|
|
||||||
$foldingWS = new FoldingWhiteSpace($this->lexer);
|
|
||||||
$resultFWS = $foldingWS->parse();
|
|
||||||
if ($resultFWS->isValid()) {
|
|
||||||
$this->warnings = array_merge($this->warnings, $foldingWS->getWarnings());
|
|
||||||
}
|
|
||||||
return $resultFWS;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function hasDotAtStart() : bool
|
|
||||||
{
|
|
||||||
return ((array) $this->lexer->token)['type'] === EmailLexer::S_DOT && null === $this->lexer->getPrevious()['type'];
|
|
||||||
}
|
|
||||||
|
|
||||||
private function parseDoubleQuote() : Result
|
|
||||||
{
|
|
||||||
$dquoteParser = new DoubleQuote($this->lexer);
|
|
||||||
$parseAgain = $dquoteParser->parse();
|
|
||||||
$this->warnings = array_merge($this->warnings, $dquoteParser->getWarnings());
|
|
||||||
|
|
||||||
return $parseAgain;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function parseComments(): Result
|
|
||||||
{
|
|
||||||
$commentParser = new Comment($this->lexer, new LocalComment());
|
|
||||||
$result = $commentParser->parse();
|
|
||||||
$this->warnings = array_merge($this->warnings, $commentParser->getWarnings());
|
|
||||||
if($result->isInvalid()) {
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function validateEscaping() : Result
|
|
||||||
{
|
|
||||||
//Backslash found
|
|
||||||
if (((array) $this->lexer->token)['type'] !== EmailLexer::S_BACKSLASH) {
|
|
||||||
return new ValidEmail();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->lexer->isNextToken(EmailLexer::GENERIC)) {
|
|
||||||
return new InvalidEmail(new ExpectingATEXT('Found ATOM after escaping'), ((array) $this->lexer->token)['value']);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$this->lexer->isNextTokenAny(array(EmailLexer::S_SP, EmailLexer::S_HTAB, EmailLexer::C_DEL))) {
|
|
||||||
return new ValidEmail();
|
|
||||||
}
|
|
||||||
|
|
||||||
return new ValidEmail();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,63 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Egulias\EmailValidator\Parser;
|
|
||||||
|
|
||||||
use Egulias\EmailValidator\EmailLexer;
|
|
||||||
use Egulias\EmailValidator\Result\InvalidEmail;
|
|
||||||
use Egulias\EmailValidator\Result\Reason\ConsecutiveDot;
|
|
||||||
use Egulias\EmailValidator\Result\Result;
|
|
||||||
use Egulias\EmailValidator\Result\ValidEmail;
|
|
||||||
|
|
||||||
abstract class PartParser
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
protected $warnings = [];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var EmailLexer
|
|
||||||
*/
|
|
||||||
protected $lexer;
|
|
||||||
|
|
||||||
public function __construct(EmailLexer $lexer)
|
|
||||||
{
|
|
||||||
$this->lexer = $lexer;
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract public function parse() : Result;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return \Egulias\EmailValidator\Warning\Warning[]
|
|
||||||
*/
|
|
||||||
public function getWarnings()
|
|
||||||
{
|
|
||||||
return $this->warnings;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function parseFWS() : Result
|
|
||||||
{
|
|
||||||
$foldingWS = new FoldingWhiteSpace($this->lexer);
|
|
||||||
$resultFWS = $foldingWS->parse();
|
|
||||||
$this->warnings = array_merge($this->warnings, $foldingWS->getWarnings());
|
|
||||||
return $resultFWS;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function checkConsecutiveDots() : Result
|
|
||||||
{
|
|
||||||
if (((array) $this->lexer->token)['type'] === EmailLexer::S_DOT && $this->lexer->isNextToken(EmailLexer::S_DOT)) {
|
|
||||||
return new InvalidEmail(new ConsecutiveDot(), ((array) $this->lexer->token)['value']);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new ValidEmail();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function escaped() : bool
|
|
||||||
{
|
|
||||||
$previous = $this->lexer->getPrevious();
|
|
||||||
|
|
||||||
return $previous && $previous['type'] === EmailLexer::S_BACKSLASH
|
|
||||||
&&
|
|
||||||
((array) $this->lexer->token)['type'] !== EmailLexer::GENERIC;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,46 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Egulias\EmailValidator\Result;
|
|
||||||
|
|
||||||
use Egulias\EmailValidator\Result\Reason\Reason;
|
|
||||||
|
|
||||||
class InvalidEmail implements Result
|
|
||||||
{
|
|
||||||
private $token;
|
|
||||||
/**
|
|
||||||
* @var Reason
|
|
||||||
*/
|
|
||||||
protected $reason;
|
|
||||||
|
|
||||||
public function __construct(Reason $reason, string $token)
|
|
||||||
{
|
|
||||||
$this->token = $token;
|
|
||||||
$this->reason = $reason;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function isValid(): bool
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function isInvalid(): bool
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function description(): string
|
|
||||||
{
|
|
||||||
return $this->reason->description() . " in char " . $this->token;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function code(): int
|
|
||||||
{
|
|
||||||
return $this->reason->code();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function reason() : Reason
|
|
||||||
{
|
|
||||||
return $this->reason;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,56 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Egulias\EmailValidator\Result;
|
|
||||||
|
|
||||||
use Egulias\EmailValidator\Result\Reason\EmptyReason;
|
|
||||||
use Egulias\EmailValidator\Result\Reason\Reason;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @psalm-suppress PropertyNotSetInConstructor
|
|
||||||
*/
|
|
||||||
class MultipleErrors extends InvalidEmail
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var Reason[]
|
|
||||||
*/
|
|
||||||
private $reasons = [];
|
|
||||||
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public function addReason(Reason $reason) : void
|
|
||||||
{
|
|
||||||
$this->reasons[$reason->code()] = $reason;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return Reason[]
|
|
||||||
*/
|
|
||||||
public function getReasons() : array
|
|
||||||
{
|
|
||||||
return $this->reasons;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function reason() : Reason
|
|
||||||
{
|
|
||||||
return 0 !== count($this->reasons)
|
|
||||||
? current($this->reasons)
|
|
||||||
: new EmptyReason();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function description() : string
|
|
||||||
{
|
|
||||||
$description = '';
|
|
||||||
foreach($this->reasons as $reason) {
|
|
||||||
$description .= $reason->description() . PHP_EOL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $description;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function code() : int
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Egulias\EmailValidator\Result\Reason;
|
|
||||||
|
|
||||||
class AtextAfterCFWS implements Reason
|
|
||||||
{
|
|
||||||
public function code() : int
|
|
||||||
{
|
|
||||||
return 133;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function description() : string
|
|
||||||
{
|
|
||||||
return 'ATEXT found after CFWS';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,19 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Egulias\EmailValidator\Result\Reason;
|
|
||||||
|
|
||||||
class CRLFAtTheEnd implements Reason
|
|
||||||
{
|
|
||||||
public const CODE = 149;
|
|
||||||
public const REASON = "CRLF at the end";
|
|
||||||
|
|
||||||
public function code() : int
|
|
||||||
{
|
|
||||||
return 149;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function description() : string
|
|
||||||
{
|
|
||||||
return 'CRLF at the end';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Egulias\EmailValidator\Result\Reason;
|
|
||||||
|
|
||||||
class CRLFX2 implements Reason
|
|
||||||
{
|
|
||||||
public function code() : int
|
|
||||||
{
|
|
||||||
return 148;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function description() : string
|
|
||||||
{
|
|
||||||
return 'CR LF tokens found twice';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Egulias\EmailValidator\Result\Reason;
|
|
||||||
|
|
||||||
class CRNoLF implements Reason
|
|
||||||
{
|
|
||||||
public function code() : int
|
|
||||||
{
|
|
||||||
return 150;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function description() : string
|
|
||||||
{
|
|
||||||
return 'Missing LF after CR';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Egulias\EmailValidator\Result\Reason;
|
|
||||||
|
|
||||||
class CharNotAllowed implements Reason
|
|
||||||
{
|
|
||||||
public function code() : int
|
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function description() : string
|
|
||||||
{
|
|
||||||
return "Character not allowed";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Egulias\EmailValidator\Result\Reason;
|
|
||||||
|
|
||||||
class CommaInDomain implements Reason
|
|
||||||
{
|
|
||||||
public function code() : int
|
|
||||||
{
|
|
||||||
return 200;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function description() : string
|
|
||||||
{
|
|
||||||
return "Comma ',' is not allowed in domain part";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Egulias\EmailValidator\Result\Reason;
|
|
||||||
|
|
||||||
class CommentsInIDRight implements Reason
|
|
||||||
{
|
|
||||||
public function code() : int
|
|
||||||
{
|
|
||||||
return 400;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function description() : string
|
|
||||||
{
|
|
||||||
return 'Comments are not allowed in IDRight for message-id';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,17 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Egulias\EmailValidator\Result\Reason;
|
|
||||||
|
|
||||||
class ConsecutiveAt implements Reason
|
|
||||||
{
|
|
||||||
public function code() : int
|
|
||||||
{
|
|
||||||
return 128;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function description() : string
|
|
||||||
{
|
|
||||||
return '@ found after another @';
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Egulias\EmailValidator\Result\Reason;
|
|
||||||
|
|
||||||
class ConsecutiveDot implements Reason
|
|
||||||
{
|
|
||||||
public function code() : int
|
|
||||||
{
|
|
||||||
return 132;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function description() : string
|
|
||||||
{
|
|
||||||
return 'Concecutive DOT found';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,13 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Egulias\EmailValidator\Result\Reason;
|
|
||||||
|
|
||||||
abstract class DetailedReason implements Reason
|
|
||||||
{
|
|
||||||
protected $detailedDescription;
|
|
||||||
|
|
||||||
public function __construct(string $details)
|
|
||||||
{
|
|
||||||
$this->detailedDescription = $details;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Egulias\EmailValidator\Result\Reason;
|
|
||||||
|
|
||||||
class DomainAcceptsNoMail implements Reason
|
|
||||||
{
|
|
||||||
public function code() : int
|
|
||||||
{
|
|
||||||
return 154;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function description() : string
|
|
||||||
{
|
|
||||||
return 'Domain accepts no mail (Null MX, RFC7505)';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Egulias\EmailValidator\Result\Reason;
|
|
||||||
|
|
||||||
class DomainHyphened extends DetailedReason
|
|
||||||
{
|
|
||||||
public function code() : int
|
|
||||||
{
|
|
||||||
return 144;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function description() : string
|
|
||||||
{
|
|
||||||
return 'S_HYPHEN found in domain';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Egulias\EmailValidator\Result\Reason;
|
|
||||||
|
|
||||||
class DomainTooLong implements Reason
|
|
||||||
{
|
|
||||||
public function code() : int
|
|
||||||
{
|
|
||||||
return 244;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function description() : string
|
|
||||||
{
|
|
||||||
return 'Domain is longer than 253 characters';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Egulias\EmailValidator\Result\Reason;
|
|
||||||
|
|
||||||
class DotAtEnd implements Reason
|
|
||||||
{
|
|
||||||
public function code() : int
|
|
||||||
{
|
|
||||||
return 142;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function description() : string
|
|
||||||
{
|
|
||||||
return 'Dot at the end';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Egulias\EmailValidator\Result\Reason;
|
|
||||||
|
|
||||||
class DotAtStart implements Reason
|
|
||||||
{
|
|
||||||
public function code() : int
|
|
||||||
{
|
|
||||||
return 141;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function description() : string
|
|
||||||
{
|
|
||||||
return "Starts with a DOT";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Egulias\EmailValidator\Result\Reason;
|
|
||||||
|
|
||||||
class EmptyReason implements Reason
|
|
||||||
{
|
|
||||||
public function code() : int
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function description() : string
|
|
||||||
{
|
|
||||||
return 'Empty reason';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,26 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Egulias\EmailValidator\Result\Reason;
|
|
||||||
|
|
||||||
class ExceptionFound implements Reason
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var \Exception
|
|
||||||
*/
|
|
||||||
private $exception;
|
|
||||||
|
|
||||||
public function __construct(\Exception $exception)
|
|
||||||
{
|
|
||||||
$this->exception = $exception;
|
|
||||||
|
|
||||||
}
|
|
||||||
public function code() : int
|
|
||||||
{
|
|
||||||
return 999;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function description() : string
|
|
||||||
{
|
|
||||||
return $this->exception->getMessage();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Egulias\EmailValidator\Result\Reason;
|
|
||||||
|
|
||||||
class ExpectingATEXT extends DetailedReason
|
|
||||||
{
|
|
||||||
public function code() : int
|
|
||||||
{
|
|
||||||
return 137;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function description() : string
|
|
||||||
{
|
|
||||||
return "Expecting ATEXT (Printable US-ASCII). Extended: " . $this->detailedDescription;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Egulias\EmailValidator\Result\Reason;
|
|
||||||
|
|
||||||
class ExpectingCTEXT implements Reason
|
|
||||||
{
|
|
||||||
public function code() : int
|
|
||||||
{
|
|
||||||
return 139;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function description() : string
|
|
||||||
{
|
|
||||||
return 'Expecting CTEXT';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Egulias\EmailValidator\Result\Reason;
|
|
||||||
|
|
||||||
class ExpectingDTEXT implements Reason
|
|
||||||
{
|
|
||||||
public function code() : int
|
|
||||||
{
|
|
||||||
return 129;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function description() : string
|
|
||||||
{
|
|
||||||
return 'Expecting DTEXT';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Egulias\EmailValidator\Result\Reason;
|
|
||||||
|
|
||||||
class ExpectingDomainLiteralClose implements Reason
|
|
||||||
{
|
|
||||||
public function code() : int
|
|
||||||
{
|
|
||||||
return 137;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function description() : string
|
|
||||||
{
|
|
||||||
return "Closing bracket ']' for domain literal not found";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Egulias\EmailValidator\Result\Reason;
|
|
||||||
|
|
||||||
class LabelTooLong implements Reason
|
|
||||||
{
|
|
||||||
public function code() : int
|
|
||||||
{
|
|
||||||
return 245;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function description() : string
|
|
||||||
{
|
|
||||||
return 'Domain "label" is longer than 63 characters';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Egulias\EmailValidator\Result\Reason;
|
|
||||||
|
|
||||||
class LocalOrReservedDomain implements Reason
|
|
||||||
{
|
|
||||||
public function code() : int
|
|
||||||
{
|
|
||||||
return 153;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function description() : string
|
|
||||||
{
|
|
||||||
return 'Local, mDNS or reserved domain (RFC2606, RFC6762)';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Egulias\EmailValidator\Result\Reason;
|
|
||||||
|
|
||||||
class NoDNSRecord implements Reason
|
|
||||||
{
|
|
||||||
public function code() : int
|
|
||||||
{
|
|
||||||
return 5;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function description() : string
|
|
||||||
{
|
|
||||||
return 'No MX or A DSN record was found for this email';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Egulias\EmailValidator\Result\Reason;
|
|
||||||
|
|
||||||
class NoDomainPart implements Reason
|
|
||||||
{
|
|
||||||
public function code() : int
|
|
||||||
{
|
|
||||||
return 131;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function description() : string
|
|
||||||
{
|
|
||||||
return 'No domain part found';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Egulias\EmailValidator\Result\Reason;
|
|
||||||
|
|
||||||
class NoLocalPart implements Reason
|
|
||||||
{
|
|
||||||
public function code() : int
|
|
||||||
{
|
|
||||||
return 130;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function description() : string
|
|
||||||
{
|
|
||||||
return "No local part";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Egulias\EmailValidator\Result\Reason;
|
|
||||||
|
|
||||||
class RFCWarnings implements Reason
|
|
||||||
{
|
|
||||||
public function code() : int
|
|
||||||
{
|
|
||||||
return 997;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function description() : string
|
|
||||||
{
|
|
||||||
return 'Warnings found after validating';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Egulias\EmailValidator\Result\Reason;
|
|
||||||
|
|
||||||
interface Reason
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Code for user land to act upon;
|
|
||||||
*/
|
|
||||||
public function code() : int;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Short description of the result, human readable.
|
|
||||||
*/
|
|
||||||
public function description() : string;
|
|
||||||
}
|
|
||||||
|
|
@ -1,17 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Egulias\EmailValidator\Result\Reason;
|
|
||||||
|
|
||||||
class SpoofEmail implements Reason
|
|
||||||
{
|
|
||||||
public function code() : int
|
|
||||||
{
|
|
||||||
return 298;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function description() : string
|
|
||||||
{
|
|
||||||
return 'The email contains mixed UTF8 chars that makes it suspicious';
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Egulias\EmailValidator\Result\Reason;
|
|
||||||
|
|
||||||
class UnOpenedComment implements Reason
|
|
||||||
{
|
|
||||||
public function code() : int
|
|
||||||
{
|
|
||||||
return 152;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function description(): string
|
|
||||||
{
|
|
||||||
return 'Missing opening comment parentheses - https://tools.ietf.org/html/rfc5322#section-3.2.2';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,19 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Egulias\EmailValidator\Result\Reason;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Used on SERVFAIL, TIMEOUT or other runtime and network errors
|
|
||||||
*/
|
|
||||||
class UnableToGetDNSRecord extends NoDNSRecord
|
|
||||||
{
|
|
||||||
public function code() : int
|
|
||||||
{
|
|
||||||
return 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function description() : string
|
|
||||||
{
|
|
||||||
return 'Unable to get DNS records for the host';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Egulias\EmailValidator\Result\Reason;
|
|
||||||
|
|
||||||
class UnclosedComment implements Reason
|
|
||||||
{
|
|
||||||
public function code() : int
|
|
||||||
{
|
|
||||||
return 146;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function description(): string
|
|
||||||
{
|
|
||||||
return 'No closing comment token found';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Egulias\EmailValidator\Result\Reason;
|
|
||||||
|
|
||||||
class UnclosedQuotedString implements Reason
|
|
||||||
{
|
|
||||||
public function code() : int
|
|
||||||
{
|
|
||||||
return 145;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function description() : string
|
|
||||||
{
|
|
||||||
return "Unclosed quoted string";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,26 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Egulias\EmailValidator\Result\Reason;
|
|
||||||
|
|
||||||
class UnusualElements implements Reason
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var string $element
|
|
||||||
*/
|
|
||||||
private $element = '';
|
|
||||||
|
|
||||||
public function __construct(string $element)
|
|
||||||
{
|
|
||||||
$this->element = $element;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function code() : int
|
|
||||||
{
|
|
||||||
return 201;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function description() : string
|
|
||||||
{
|
|
||||||
return 'Unusual element found, wourld render invalid in majority of cases. Element found: ' . $this->element;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,27 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Egulias\EmailValidator\Result;
|
|
||||||
|
|
||||||
interface Result
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Is validation result valid?
|
|
||||||
*/
|
|
||||||
public function isValid() : bool;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Is validation result invalid?
|
|
||||||
* Usually the inverse of isValid()
|
|
||||||
*/
|
|
||||||
public function isInvalid() : bool;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Short description of the result, human readable.
|
|
||||||
*/
|
|
||||||
public function description() : string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Code for user land to act upon.
|
|
||||||
*/
|
|
||||||
public function code() : int;
|
|
||||||
}
|
|
||||||
|
|
@ -1,13 +0,0 @@
|
||||||
<?php
|
|
||||||
namespace Egulias\EmailValidator\Result;
|
|
||||||
|
|
||||||
use Egulias\EmailValidator\Result\Reason\SpoofEmail as ReasonSpoofEmail;
|
|
||||||
|
|
||||||
class SpoofEmail extends InvalidEmail
|
|
||||||
{
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->reason = new ReasonSpoofEmail();
|
|
||||||
parent::__construct($this->reason, '');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,27 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Egulias\EmailValidator\Result;
|
|
||||||
|
|
||||||
class ValidEmail implements Result
|
|
||||||
{
|
|
||||||
public function isValid(): bool
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function isInvalid(): bool
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function description(): string
|
|
||||||
{
|
|
||||||
return "Valid email";
|
|
||||||
}
|
|
||||||
|
|
||||||
public function code(): int
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,191 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Egulias\EmailValidator\Validation;
|
|
||||||
|
|
||||||
use Egulias\EmailValidator\EmailLexer;
|
|
||||||
use Egulias\EmailValidator\Result\InvalidEmail;
|
|
||||||
use Egulias\EmailValidator\Result\Reason\DomainAcceptsNoMail;
|
|
||||||
use Egulias\EmailValidator\Result\Reason\LocalOrReservedDomain;
|
|
||||||
use Egulias\EmailValidator\Result\Reason\NoDNSRecord as ReasonNoDNSRecord;
|
|
||||||
use Egulias\EmailValidator\Result\Reason\UnableToGetDNSRecord;
|
|
||||||
use Egulias\EmailValidator\Warning\NoDNSMXRecord;
|
|
||||||
|
|
||||||
class DNSCheckValidation implements EmailValidation
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
protected const DNS_RECORD_TYPES_TO_CHECK = DNS_MX + DNS_A + DNS_AAAA;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reserved Top Level DNS Names (https://tools.ietf.org/html/rfc2606#section-2),
|
|
||||||
* mDNS and private DNS Namespaces (https://tools.ietf.org/html/rfc6762#appendix-G)
|
|
||||||
*/
|
|
||||||
public const RESERVED_DNS_TOP_LEVEL_NAMES = [
|
|
||||||
// Reserved Top Level DNS Names
|
|
||||||
'test',
|
|
||||||
'example',
|
|
||||||
'invalid',
|
|
||||||
'localhost',
|
|
||||||
|
|
||||||
// mDNS
|
|
||||||
'local',
|
|
||||||
|
|
||||||
// Private DNS Namespaces
|
|
||||||
'intranet',
|
|
||||||
'internal',
|
|
||||||
'private',
|
|
||||||
'corp',
|
|
||||||
'home',
|
|
||||||
'lan',
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
private $warnings = [];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var InvalidEmail|null
|
|
||||||
*/
|
|
||||||
private $error;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
private $mxRecords = [];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var DNSGetRecordWrapper
|
|
||||||
*/
|
|
||||||
private $dnsGetRecord;
|
|
||||||
|
|
||||||
public function __construct(?DNSGetRecordWrapper $dnsGetRecord = null)
|
|
||||||
{
|
|
||||||
if (!function_exists('idn_to_ascii')) {
|
|
||||||
throw new \LogicException(sprintf('The %s class requires the Intl extension.', __CLASS__));
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($dnsGetRecord == null) {
|
|
||||||
$dnsGetRecord = new DNSGetRecordWrapper();
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->dnsGetRecord = $dnsGetRecord;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function isValid(string $email, EmailLexer $emailLexer) : bool
|
|
||||||
{
|
|
||||||
// use the input to check DNS if we cannot extract something similar to a domain
|
|
||||||
$host = $email;
|
|
||||||
|
|
||||||
// Arguable pattern to extract the domain. Not aiming to validate the domain nor the email
|
|
||||||
if (false !== $lastAtPos = strrpos($email, '@')) {
|
|
||||||
$host = substr($email, $lastAtPos + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the domain parts
|
|
||||||
$hostParts = explode('.', $host);
|
|
||||||
|
|
||||||
$isLocalDomain = count($hostParts) <= 1;
|
|
||||||
$isReservedTopLevel = in_array($hostParts[(count($hostParts) - 1)], self::RESERVED_DNS_TOP_LEVEL_NAMES, true);
|
|
||||||
|
|
||||||
// Exclude reserved top level DNS names
|
|
||||||
if ($isLocalDomain || $isReservedTopLevel) {
|
|
||||||
$this->error = new InvalidEmail(new LocalOrReservedDomain(), $host);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->checkDns($host);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getError() : ?InvalidEmail
|
|
||||||
{
|
|
||||||
return $this->error;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getWarnings() : array
|
|
||||||
{
|
|
||||||
return $this->warnings;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $host
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
protected function checkDns($host)
|
|
||||||
{
|
|
||||||
$variant = INTL_IDNA_VARIANT_UTS46;
|
|
||||||
|
|
||||||
$host = rtrim(idn_to_ascii($host, IDNA_DEFAULT, $variant), '.') . '.';
|
|
||||||
|
|
||||||
return $this->validateDnsRecords($host);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Validate the DNS records for given host.
|
|
||||||
*
|
|
||||||
* @param string $host A set of DNS records in the format returned by dns_get_record.
|
|
||||||
*
|
|
||||||
* @return bool True on success.
|
|
||||||
*/
|
|
||||||
private function validateDnsRecords($host) : bool
|
|
||||||
{
|
|
||||||
$dnsRecordsResult = $this->dnsGetRecord->getRecords($host, static::DNS_RECORD_TYPES_TO_CHECK);
|
|
||||||
|
|
||||||
if ($dnsRecordsResult->withError()) {
|
|
||||||
$this->error = new InvalidEmail(new UnableToGetDNSRecord(), '');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$dnsRecords = $dnsRecordsResult->getRecords();
|
|
||||||
|
|
||||||
// No MX, A or AAAA DNS records
|
|
||||||
if ($dnsRecords === []) {
|
|
||||||
$this->error = new InvalidEmail(new ReasonNoDNSRecord(), '');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// For each DNS record
|
|
||||||
foreach ($dnsRecords as $dnsRecord) {
|
|
||||||
if (!$this->validateMXRecord($dnsRecord)) {
|
|
||||||
// No MX records (fallback to A or AAAA records)
|
|
||||||
if (empty($this->mxRecords)) {
|
|
||||||
$this->warnings[NoDNSMXRecord::CODE] = new NoDNSMXRecord();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Validate an MX record
|
|
||||||
*
|
|
||||||
* @param array $dnsRecord Given DNS record.
|
|
||||||
*
|
|
||||||
* @return bool True if valid.
|
|
||||||
*/
|
|
||||||
private function validateMxRecord($dnsRecord) : bool
|
|
||||||
{
|
|
||||||
if (!isset($dnsRecord['type'])) {
|
|
||||||
$this->error = new InvalidEmail(new ReasonNoDNSRecord(), '');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($dnsRecord['type'] !== 'MX') {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// "Null MX" record indicates the domain accepts no mail (https://tools.ietf.org/html/rfc7505)
|
|
||||||
if (empty($dnsRecord['target']) || $dnsRecord['target'] === '.') {
|
|
||||||
$this->error = new InvalidEmail(new DomainAcceptsNoMail(), "");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->mxRecords[] = $dnsRecord;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,28 +0,0 @@
|
||||||
<?php
|
|
||||||
namespace Egulias\EmailValidator\Validation;
|
|
||||||
|
|
||||||
class DNSGetRecordWrapper
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @param string $host
|
|
||||||
* @param int $type
|
|
||||||
*/
|
|
||||||
public function getRecords(string $host, int $type) : DNSRecords
|
|
||||||
{
|
|
||||||
// A workaround to fix https://bugs.php.net/bug.php?id=73149
|
|
||||||
/** @psalm-suppress InvalidArgument */
|
|
||||||
set_error_handler(
|
|
||||||
static function (int $errorLevel, string $errorMessage): ?bool {
|
|
||||||
throw new \RuntimeException("Unable to get DNS record for the host: $errorMessage");
|
|
||||||
}
|
|
||||||
);
|
|
||||||
try {
|
|
||||||
// Get all MX, A and AAAA DNS records for host
|
|
||||||
return new DNSRecords(dns_get_record($host, $type));
|
|
||||||
} catch (\RuntimeException $exception) {
|
|
||||||
return new DNSRecords([], true);
|
|
||||||
} finally {
|
|
||||||
restore_error_handler();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,35 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Egulias\EmailValidator\Validation;
|
|
||||||
|
|
||||||
class DNSRecords
|
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var array $records
|
|
||||||
*/
|
|
||||||
private $records = [];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var bool $error
|
|
||||||
*/
|
|
||||||
private $error = false;
|
|
||||||
|
|
||||||
public function __construct(array $records, bool $error = false)
|
|
||||||
{
|
|
||||||
$this->records = $records;
|
|
||||||
$this->error = $error;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getRecords() : array
|
|
||||||
{
|
|
||||||
return $this->records;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function withError() : bool
|
|
||||||
{
|
|
||||||
return $this->error;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,34 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Egulias\EmailValidator\Validation;
|
|
||||||
|
|
||||||
use Egulias\EmailValidator\EmailLexer;
|
|
||||||
use Egulias\EmailValidator\Result\InvalidEmail;
|
|
||||||
use Egulias\EmailValidator\Warning\Warning;
|
|
||||||
|
|
||||||
interface EmailValidation
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Returns true if the given email is valid.
|
|
||||||
*
|
|
||||||
* @param string $email The email you want to validate.
|
|
||||||
* @param EmailLexer $emailLexer The email lexer.
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function isValid(string $email, EmailLexer $emailLexer) : bool;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the validation error.
|
|
||||||
*
|
|
||||||
* @return InvalidEmail|null
|
|
||||||
*/
|
|
||||||
public function getError() : ?InvalidEmail;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the validation warnings.
|
|
||||||
*
|
|
||||||
* @return Warning[]
|
|
||||||
*/
|
|
||||||
public function getWarnings() : array;
|
|
||||||
}
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Egulias\EmailValidator\Validation\Exception;
|
|
||||||
|
|
||||||
use Exception;
|
|
||||||
|
|
||||||
class EmptyValidationList extends \InvalidArgumentException
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @param int $code
|
|
||||||
*/
|
|
||||||
public function __construct($code = 0, ?Exception $previous = null)
|
|
||||||
{
|
|
||||||
parent::__construct("Empty validation list is not allowed", $code, $previous);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,52 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Egulias\EmailValidator\Validation\Extra;
|
|
||||||
|
|
||||||
use \Spoofchecker;
|
|
||||||
use Egulias\EmailValidator\EmailLexer;
|
|
||||||
use Egulias\EmailValidator\Result\SpoofEmail;
|
|
||||||
use Egulias\EmailValidator\Result\InvalidEmail;
|
|
||||||
use Egulias\EmailValidator\Validation\EmailValidation;
|
|
||||||
|
|
||||||
class SpoofCheckValidation implements EmailValidation
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var InvalidEmail|null
|
|
||||||
*/
|
|
||||||
private $error;
|
|
||||||
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
if (!extension_loaded('intl')) {
|
|
||||||
throw new \LogicException(sprintf('The %s class requires the Intl extension.', __CLASS__));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @psalm-suppress InvalidArgument
|
|
||||||
*/
|
|
||||||
public function isValid(string $email, EmailLexer $emailLexer) : bool
|
|
||||||
{
|
|
||||||
$checker = new Spoofchecker();
|
|
||||||
$checker->setChecks(Spoofchecker::SINGLE_SCRIPT);
|
|
||||||
|
|
||||||
if ($checker->isSuspicious($email)) {
|
|
||||||
$this->error = new SpoofEmail();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->error === null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return InvalidEmail
|
|
||||||
*/
|
|
||||||
public function getError() : ?InvalidEmail
|
|
||||||
{
|
|
||||||
return $this->error;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getWarnings() : array
|
|
||||||
{
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,51 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Egulias\EmailValidator\Validation;
|
|
||||||
|
|
||||||
use Egulias\EmailValidator\EmailLexer;
|
|
||||||
use Egulias\EmailValidator\MessageIDParser;
|
|
||||||
use Egulias\EmailValidator\Result\InvalidEmail;
|
|
||||||
use Egulias\EmailValidator\Result\Reason\ExceptionFound;
|
|
||||||
|
|
||||||
class MessageIDValidation implements EmailValidation
|
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
private $warnings = [];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var ?InvalidEmail
|
|
||||||
*/
|
|
||||||
private $error;
|
|
||||||
|
|
||||||
public function isValid(string $email, EmailLexer $emailLexer): bool
|
|
||||||
{
|
|
||||||
$parser = new MessageIDParser($emailLexer);
|
|
||||||
try {
|
|
||||||
$result = $parser->parse($email);
|
|
||||||
$this->warnings = $parser->getWarnings();
|
|
||||||
if ($result->isInvalid()) {
|
|
||||||
/** @psalm-suppress PropertyTypeCoercion */
|
|
||||||
$this->error = $result;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} catch (\Exception $invalid) {
|
|
||||||
$this->error = new InvalidEmail(new ExceptionFound($invalid), '');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getWarnings(): array
|
|
||||||
{
|
|
||||||
return $this->warnings;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getError(): ?InvalidEmail
|
|
||||||
{
|
|
||||||
return $this->error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,117 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Egulias\EmailValidator\Validation;
|
|
||||||
|
|
||||||
use Egulias\EmailValidator\EmailLexer;
|
|
||||||
use Egulias\EmailValidator\Result\InvalidEmail;
|
|
||||||
use Egulias\EmailValidator\Validation\Exception\EmptyValidationList;
|
|
||||||
use Egulias\EmailValidator\Result\MultipleErrors;
|
|
||||||
|
|
||||||
class MultipleValidationWithAnd implements EmailValidation
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* If one of validations fails, the remaining validations will be skipped.
|
|
||||||
* This means MultipleErrors will only contain a single error, the first found.
|
|
||||||
*/
|
|
||||||
public const STOP_ON_ERROR = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* All of validations will be invoked even if one of them got failure.
|
|
||||||
* So MultipleErrors will contain all causes.
|
|
||||||
*/
|
|
||||||
public const ALLOW_ALL_ERRORS = 1;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var EmailValidation[]
|
|
||||||
*/
|
|
||||||
private $validations = [];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
private $warnings = [];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var MultipleErrors|null
|
|
||||||
*/
|
|
||||||
private $error;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
private $mode;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param EmailValidation[] $validations The validations.
|
|
||||||
* @param int $mode The validation mode (one of the constants).
|
|
||||||
*/
|
|
||||||
public function __construct(array $validations, $mode = self::ALLOW_ALL_ERRORS)
|
|
||||||
{
|
|
||||||
if (count($validations) == 0) {
|
|
||||||
throw new EmptyValidationList();
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->validations = $validations;
|
|
||||||
$this->mode = $mode;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function isValid(string $email, EmailLexer $emailLexer) : bool
|
|
||||||
{
|
|
||||||
$result = true;
|
|
||||||
foreach ($this->validations as $validation) {
|
|
||||||
$emailLexer->reset();
|
|
||||||
$validationResult = $validation->isValid($email, $emailLexer);
|
|
||||||
$result = $result && $validationResult;
|
|
||||||
$this->warnings = array_merge($this->warnings, $validation->getWarnings());
|
|
||||||
if (!$validationResult) {
|
|
||||||
$this->processError($validation);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->shouldStop($result)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function initErrorStorage() : void
|
|
||||||
{
|
|
||||||
if (null === $this->error) {
|
|
||||||
$this->error = new MultipleErrors();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function processError(EmailValidation $validation) : void
|
|
||||||
{
|
|
||||||
if (null !== $validation->getError()) {
|
|
||||||
$this->initErrorStorage();
|
|
||||||
/** @psalm-suppress PossiblyNullReference */
|
|
||||||
$this->error->addReason($validation->getError()->reason());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function shouldStop(bool $result) : bool
|
|
||||||
{
|
|
||||||
return !$result && $this->mode === self::STOP_ON_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the validation errors.
|
|
||||||
*/
|
|
||||||
public function getError() : ?InvalidEmail
|
|
||||||
{
|
|
||||||
return $this->error;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function getWarnings() : array
|
|
||||||
{
|
|
||||||
return $this->warnings;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,41 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Egulias\EmailValidator\Validation;
|
|
||||||
|
|
||||||
use Egulias\EmailValidator\EmailLexer;
|
|
||||||
use Egulias\EmailValidator\Result\InvalidEmail;
|
|
||||||
use Egulias\EmailValidator\Result\Reason\RFCWarnings;
|
|
||||||
|
|
||||||
class NoRFCWarningsValidation extends RFCValidation
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var InvalidEmail|null
|
|
||||||
*/
|
|
||||||
private $error;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function isValid(string $email, EmailLexer $emailLexer) : bool
|
|
||||||
{
|
|
||||||
if (!parent::isValid($email, $emailLexer)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (empty($this->getWarnings())) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->error = new InvalidEmail(new RFCWarnings(), '');
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function getError() : ?InvalidEmail
|
|
||||||
{
|
|
||||||
return $this->error ?: parent::getError();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,55 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Egulias\EmailValidator\Validation;
|
|
||||||
|
|
||||||
use Egulias\EmailValidator\EmailLexer;
|
|
||||||
use Egulias\EmailValidator\EmailParser;
|
|
||||||
use Egulias\EmailValidator\Result\InvalidEmail;
|
|
||||||
use Egulias\EmailValidator\Result\Reason\ExceptionFound;
|
|
||||||
|
|
||||||
class RFCValidation implements EmailValidation
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var EmailParser|null
|
|
||||||
*/
|
|
||||||
private $parser;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
private $warnings = [];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var ?InvalidEmail
|
|
||||||
*/
|
|
||||||
private $error;
|
|
||||||
|
|
||||||
public function isValid(string $email, EmailLexer $emailLexer) : bool
|
|
||||||
{
|
|
||||||
$this->parser = new EmailParser($emailLexer);
|
|
||||||
try {
|
|
||||||
$result = $this->parser->parse($email);
|
|
||||||
$this->warnings = $this->parser->getWarnings();
|
|
||||||
if ($result->isInvalid()) {
|
|
||||||
/** @psalm-suppress PropertyTypeCoercion */
|
|
||||||
$this->error = $result;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} catch (\Exception $invalid) {
|
|
||||||
$this->error = new InvalidEmail(new ExceptionFound($invalid), '');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getError() : ?InvalidEmail
|
|
||||||
{
|
|
||||||
return $this->error;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getWarnings() : array
|
|
||||||
{
|
|
||||||
return $this->warnings;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,14 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Egulias\EmailValidator\Warning;
|
|
||||||
|
|
||||||
class AddressLiteral extends Warning
|
|
||||||
{
|
|
||||||
public const CODE = 12;
|
|
||||||
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->message = 'Address literal in domain part';
|
|
||||||
$this->rfcNumber = 5321;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,13 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Egulias\EmailValidator\Warning;
|
|
||||||
|
|
||||||
class CFWSNearAt extends Warning
|
|
||||||
{
|
|
||||||
public const CODE = 49;
|
|
||||||
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->message = "Deprecated folding white space near @";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,13 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Egulias\EmailValidator\Warning;
|
|
||||||
|
|
||||||
class CFWSWithFWS extends Warning
|
|
||||||
{
|
|
||||||
public const CODE = 18;
|
|
||||||
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->message = 'Folding whites space followed by folding white space';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,13 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Egulias\EmailValidator\Warning;
|
|
||||||
|
|
||||||
class Comment extends Warning
|
|
||||||
{
|
|
||||||
public const CODE = 17;
|
|
||||||
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->message = "Comments found in this email";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,13 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Egulias\EmailValidator\Warning;
|
|
||||||
|
|
||||||
class DeprecatedComment extends Warning
|
|
||||||
{
|
|
||||||
public const CODE = 37;
|
|
||||||
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->message = 'Deprecated comments';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,14 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Egulias\EmailValidator\Warning;
|
|
||||||
|
|
||||||
class DomainLiteral extends Warning
|
|
||||||
{
|
|
||||||
public const CODE = 70;
|
|
||||||
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->message = 'Domain Literal';
|
|
||||||
$this->rfcNumber = 5322;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,15 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Egulias\EmailValidator\Warning;
|
|
||||||
|
|
||||||
use Egulias\EmailValidator\EmailParser;
|
|
||||||
|
|
||||||
class EmailTooLong extends Warning
|
|
||||||
{
|
|
||||||
public const CODE = 66;
|
|
||||||
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->message = 'Email is too long, exceeds ' . EmailParser::EMAIL_MAX_LENGTH;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,14 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Egulias\EmailValidator\Warning;
|
|
||||||
|
|
||||||
class IPV6BadChar extends Warning
|
|
||||||
{
|
|
||||||
public const CODE = 74;
|
|
||||||
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->message = 'Bad char in IPV6 domain literal';
|
|
||||||
$this->rfcNumber = 5322;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,14 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Egulias\EmailValidator\Warning;
|
|
||||||
|
|
||||||
class IPV6ColonEnd extends Warning
|
|
||||||
{
|
|
||||||
public const CODE = 77;
|
|
||||||
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->message = ':: found at the end of the domain literal';
|
|
||||||
$this->rfcNumber = 5322;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,14 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Egulias\EmailValidator\Warning;
|
|
||||||
|
|
||||||
class IPV6ColonStart extends Warning
|
|
||||||
{
|
|
||||||
public const CODE = 76;
|
|
||||||
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->message = ':: found at the start of the domain literal';
|
|
||||||
$this->rfcNumber = 5322;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,14 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Egulias\EmailValidator\Warning;
|
|
||||||
|
|
||||||
class IPV6Deprecated extends Warning
|
|
||||||
{
|
|
||||||
public const CODE = 13;
|
|
||||||
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->message = 'Deprecated form of IPV6';
|
|
||||||
$this->rfcNumber = 5321;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,14 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Egulias\EmailValidator\Warning;
|
|
||||||
|
|
||||||
class IPV6DoubleColon extends Warning
|
|
||||||
{
|
|
||||||
public const CODE = 73;
|
|
||||||
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->message = 'Double colon found after IPV6 tag';
|
|
||||||
$this->rfcNumber = 5322;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,14 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Egulias\EmailValidator\Warning;
|
|
||||||
|
|
||||||
class IPV6GroupCount extends Warning
|
|
||||||
{
|
|
||||||
public const CODE = 72;
|
|
||||||
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->message = 'Group count is not IPV6 valid';
|
|
||||||
$this->rfcNumber = 5322;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,14 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Egulias\EmailValidator\Warning;
|
|
||||||
|
|
||||||
class IPV6MaxGroups extends Warning
|
|
||||||
{
|
|
||||||
public const CODE = 75;
|
|
||||||
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->message = 'Reached the maximum number of IPV6 groups allowed';
|
|
||||||
$this->rfcNumber = 5321;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue