Update Parserus

This commit is contained in:
Visman 2021-02-24 18:43:04 +07:00
parent e3218dc78a
commit 18ea8f76d9
6 changed files with 59 additions and 54 deletions

View file

@ -31,7 +31,7 @@
"ext-intl" : "*",
"ext-json": "*",
"artoodetoo/dirk": "dev-visman",
"miovisman/parserus": "dev-master",
"miovisman/parserus": "^1.1.0",
"miovisman/normemail": "dev-master",
"psr/simple-cache": "^1.0.1",
"psr/log": "^1.1.3"

16
composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "b612a4d27e51006ea2d160f511b1a78f",
"content-hash": "23fbddba7eeaeb83366d5468a344e816",
"packages": [
{
"name": "artoodetoo/dirk",
@ -113,22 +113,21 @@
},
{
"name": "miovisman/parserus",
"version": "dev-master",
"version": "1.1.0",
"source": {
"type": "git",
"url": "https://github.com/MioVisman/Parserus.git",
"reference": "78bd7626abce40938910aae45e3ed0e6bfb91502"
"reference": "fa93c5e26dd500bf2489bb4fe46a6d3046546c31"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/MioVisman/Parserus/zipball/78bd7626abce40938910aae45e3ed0e6bfb91502",
"reference": "78bd7626abce40938910aae45e3ed0e6bfb91502",
"url": "https://api.github.com/repos/MioVisman/Parserus/zipball/fa93c5e26dd500bf2489bb4fe46a6d3046546c31",
"reference": "fa93c5e26dd500bf2489bb4fe46a6d3046546c31",
"shasum": ""
},
"require": {
"php": ">=7.3.0"
},
"default-branch": true,
"type": "library",
"autoload": {
"psr-0": {
@ -154,9 +153,9 @@
],
"support": {
"issues": "https://github.com/MioVisman/Parserus/issues",
"source": "https://github.com/MioVisman/Parserus/tree/master"
"source": "https://github.com/MioVisman/Parserus/tree/1.1.0"
},
"time": "2021-01-06T13:36:08+00:00"
"time": "2021-02-24T11:22:35+00:00"
},
{
"name": "psr/log",
@ -267,7 +266,6 @@
"minimum-stability": "dev",
"stability-flags": {
"artoodetoo/dirk": 20,
"miovisman/parserus": 20,
"miovisman/normemail": 20
},
"prefer-stable": false,

View file

@ -65,13 +65,12 @@ private static $installed = array (
),
'miovisman/parserus' =>
array (
'pretty_version' => 'dev-master',
'version' => 'dev-master',
'pretty_version' => '1.1.0',
'version' => '1.1.0.0',
'aliases' =>
array (
0 => '9999999-dev',
),
'reference' => '78bd7626abce40938910aae45e3ed0e6bfb91502',
'reference' => 'fa93c5e26dd500bf2489bb4fe46a6d3046546c31',
),
'psr/log' =>
array (

View file

@ -107,24 +107,23 @@
},
{
"name": "miovisman/parserus",
"version": "dev-master",
"version_normalized": "dev-master",
"version": "1.1.0",
"version_normalized": "1.1.0.0",
"source": {
"type": "git",
"url": "https://github.com/MioVisman/Parserus.git",
"reference": "78bd7626abce40938910aae45e3ed0e6bfb91502"
"reference": "fa93c5e26dd500bf2489bb4fe46a6d3046546c31"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/MioVisman/Parserus/zipball/78bd7626abce40938910aae45e3ed0e6bfb91502",
"reference": "78bd7626abce40938910aae45e3ed0e6bfb91502",
"url": "https://api.github.com/repos/MioVisman/Parserus/zipball/fa93c5e26dd500bf2489bb4fe46a6d3046546c31",
"reference": "fa93c5e26dd500bf2489bb4fe46a6d3046546c31",
"shasum": ""
},
"require": {
"php": ">=7.3.0"
},
"time": "2021-01-06T13:36:08+00:00",
"default-branch": true,
"time": "2021-02-24T11:22:35+00:00",
"type": "library",
"installation-source": "dist",
"autoload": {
@ -151,7 +150,7 @@
],
"support": {
"issues": "https://github.com/MioVisman/Parserus/issues",
"source": "https://github.com/MioVisman/Parserus/tree/master"
"source": "https://github.com/MioVisman/Parserus/tree/1.1.0"
},
"install-path": "../miovisman/parserus"
},

View file

@ -42,13 +42,12 @@
),
'miovisman/parserus' =>
array (
'pretty_version' => 'dev-master',
'version' => 'dev-master',
'pretty_version' => '1.1.0',
'version' => '1.1.0.0',
'aliases' =>
array (
0 => '9999999-dev',
),
'reference' => '78bd7626abce40938910aae45e3ed0e6bfb91502',
'reference' => 'fa93c5e26dd500bf2489bb4fe46a6d3046546c31',
),
'psr/log' =>
array (

View file

@ -127,6 +127,29 @@ class Parserus
*/
protected $maxDepth;
/**
* Массив шаблонов с текстом ошибок парсера
* @var array
*/
protected $defLang = [
1 => '[%1$s] tag in blacklist',
2 => '[%1$s] tag not in whitelist',
3 => '[%1$s] tag can\'t be opened in [%2$s] tag',
4 => 'No start tag found for [/%1$s] tag',
5 => 'Found [/%1$s] tag for single [%1$s] tag',
6 => 'No attributes in [%1$s] tag',
7 => 'Primary attribute is forbidden in [%1$s] tag',
8 => 'Secondary attribute is forbidden in [%1$s] tag',
9 => 'Attribute \'%2$s\' does not match pattern in [%1$s] tag',
10 => '[%1$s] tag contains unknown secondary attribute \'%2$s\'',
11 => 'Body of [%1$s] tag does not match pattern',
12 => '[%1$s] tag was opened within itself, this is not allowed',
13 => 'Missing attribute \'%2$s\' in [%1$s] tag',
14 => 'All tags are empty',
15 => 'The depth of the tag tree is greater than %1$s',
16 => '[%1$s] tag is enclosed in itself more than %2$s times',
];
/**
* Конструктор
*
@ -1351,42 +1374,29 @@ class Parserus
*
* @param array $lang Массив строк шаблонов описания ошибок
* @param array $errors Массив, который дополняется ошибками
* @param bool $retTpl Флаг возрата результата в виде массива с шаблоном в первом элементе
*
* @return array
*/
public function getErrors(array $lang = [], array $errors = []): array
public function getErrors(array $lang = [], array $errors = [], bool $retTpl = false): array
{
$defLang = [
1 => 'Тег [%1$s] находится в черном списке',
2 => 'Тег [%1$s] отсутствует в белом списке',
3 => 'Тег [%1$s] нельзя открыть внутри тега [%2$s]',
4 => 'Не найден начальный тег для парного тега [/%1$s]',
5 => 'Найден парный тег [/%1$s] для одиночного тега [%1$s]',
6 => 'В теге [%1$s] отсутствуют атрибуты',
7 => 'Тег [%1$s=...] не может содержать первичный атрибут',
8 => 'Тег [%1$s ...] не может содержать вторичные атрибуты',
9 => 'Атрибут \'%2$s\' тега [%1$s] не соответствует шаблону',
10 => 'Тег [%1$s ...] содержит неизвестный вторичный атрибут \'%2$s\'',
11 => 'Тело тега [%1$s] не соответствует шаблону',
12 => 'Тег [%1$s] нельзя открыть внутри аналогичного тега',
13 => 'В теге [%1$s] отсутствует обязательный атрибут \'%2$s\'',
14 => 'Все теги пустые',
15 => 'Глубина дерева тегов больше %1$s',
16 => 'Тег [%1$s] вложен в себя больше %2$s раз',
];
foreach ($this->errors as $args) {
$err = array_shift($args);
$key = array_key_first($args);
$err = $args[$key];
$text = $lang[$err] ?? ($this->defLang[$err] ?? 'Unknown error');
if (isset($lang[$err])) {
$text = $lang[$err];
} elseif (isset($defLang[$err])) {
$text = $defLang[$err];
if ($retTpl) {
$args[$key] = $text;
$errors[] = $args;
} else {
$text = 'Unknown error';
$errors[] = vsprintf(
$text,
array_map(
[$this, 'e'],
array_slice($args, 1)
)
);
}
$errors[] = vsprintf($text, array_map([$this, 'e'], $args));
}
return $errors;