Добавил наследование значений констант словарей

This commit is contained in:
Artem Vasilev 2022-11-08 18:12:30 +03:00
parent c18de16139
commit 18a156a586
9 changed files with 189 additions and 211 deletions

View File

@ -29,4 +29,20 @@ abstract class AbstractDictionary implements DictionaryInterface
return DictionaryItem::getItem($options); return DictionaryItem::getItem($options);
} }
public static function getMap()
{
$map = [];
$class = static::class;
do
{
array_push($map, ...$class::MAP);
} while (($class = get_parent_class($class)) != self::class);
array_push($map, ...$class::MAP);
return $map;
}
} }

View File

@ -0,0 +1,10 @@
<?php
namespace Webmasterskaya\CryptoPro\Dictionary;
abstract class AbstractTagsDictionary extends AbstractDictionary implements RDNAwareInterface, TitleAwareInterface, OIDAwareInterface
{
use RDNAwareTrait;
use TitleAwareTrait;
use OIDAwareTrait;
}

View File

@ -0,0 +1,40 @@
<?php
namespace Webmasterskaya\CryptoPro\Dictionary;
class AdditionalTagsDictionary extends StandardTagsDictionary
{
protected const MAP
= [
[
'RDN' => 'OGRN',
'OID' => '1.2.643.100.1',
'title' => 'ОГРН',
'title_variants' => ['ОГРН'],
],
[
'RDN' => 'SNILS',
'OID' => '1.2.643.100.3',
'title' => 'СНИЛС',
'title_variants' => ['СНИЛС'],
],
[
'RDN' => 'INN',
'OID' => '1.2.643.3.131.1.1',
'title' => 'ИНН',
'title_variants' => ['ИННФЛ', 'ИНН ФЛ'],
],
[
'RDN' => 'INNLE',
'OID' => '1.2.643.100.4',
'title' => 'ИНН организации',
'title_variants' => ['ИННЮЛ', 'ИНН ЮЛ', 'INN LE'],
],
[
'RDN' => 'OGRNIP',
'OID' => '1.2.643.100.5',
'title' => 'ОГРНИП',
'title_variants' => ['ОГРНИП'],
],
];
}

View File

@ -2,103 +2,15 @@
namespace Webmasterskaya\CryptoPro\Dictionary; namespace Webmasterskaya\CryptoPro\Dictionary;
class IssuerTagsDictionary extends AbstractDictionary implements RDNAwareInterface, TitleAwareInterface, OIDAwareInterface class IssuerTagsDictionary extends AdditionalTagsDictionary
{ {
use RDNAwareTrait;
use TitleAwareTrait;
use OIDAwareTrait;
protected const MAP protected const MAP
= [ = [
[
'RDN' => 'UN',
'OID' => '1.2.840.113549.1.9.2',
'title' => 'Неструктурированное имя',
'title_variants' => ['unstructuredName'],
],
[ [
'RDN' => 'CN', 'RDN' => 'CN',
'OID' => '2.5.4.3', 'OID' => '2.5.4.3',
'title' => 'Удостоверяющий центр', 'title' => 'Удостоверяющий центр',
'title_variants' => ['commonName'], 'title_variants' => ['commonName'],
], ],
[
'RDN' => 'C',
'OID' => '2.5.4.6',
'title' => 'Страна',
'title_variants' => ['countryName'],
],
[
'RDN' => 'S',
'OID' => '2.5.4.8',
'title' => 'Регион',
'title_variants' => ['ST', 'stateOrProvinceName'],
],
[
'RDN' => 'STREET',
'OID' => '2.5.4.9',
'title' => 'Адрес',
'title_variants' => ['streetAddress'],
],
[
'RDN' => 'O',
'OID' => '2.5.4.10',
'title' => 'Компания',
'title_variants' => ['organizationName'],
],
[
'RDN' => 'OU',
'OID' => '2.5.4.11',
'title' => 'Тип',
'title_variants' => ['organizationalUnitName'],
],
[
'RDN' => 'T',
'OID' => '2.5.4.12',
'title' => 'Должность',
'title_variants' => ['TITLE'],
],
[
'RDN' => 'OGRN',
'OID' => '1.2.643.100.1',
'title' => 'ОГРН',
'title_variants' => ['ОГРН'],
],
[
'RDN' => 'OGRNIP',
'OID' => '1.2.643.100.5',
'title' => 'ОГРНИП',
'title_variants' => ['ОГРНИП'],
],
[
'RDN' => 'SNILS',
'OID' => '1.2.643.100.3',
'title' => 'СНИЛС',
'title_variants' => ['СНИЛС'],
],
[
'RDN' => 'INN',
'OID' => '1.2.643.3.131.1.1',
'title' => 'ИНН',
'title_variants' => ['ИННФЛ', 'ИНН ФЛ'],
],
[
'RDN' => 'INNLE',
'OID' => '1.2.643.100.4',
'title' => 'ИНН организации',
'title_variants' => ['ИННЮЛ', 'ИНН ЮЛ', 'INN LE'],
],
[
'RDN' => 'E',
'OID' => '1.2.840.113549.1.9.1',
'title' => 'Email',
'title_variants' => ['email', 'emailAddress', 'pkcs9email'],
],
[
'RDN' => 'L',
'OID' => '2.5.4.7',
'title' => 'Город',
'title_variants' => ['localityName'],
],
]; ];
} }

View File

@ -8,9 +8,9 @@ trait OIDAwareTrait
{ {
$oid = mb_strtolower(trim($oid)); $oid = mb_strtolower(trim($oid));
$map = self::getOIDMap(); $map = static::getOIDMap();
return isset($map[$oid]) ? self::getResult($map[$oid]) : null; return isset($map[$oid]) ? static::getResult($map[$oid]) : null;
} }
protected static function getOIDMap() protected static function getOIDMap()
@ -19,12 +19,15 @@ trait OIDAwareTrait
if (!isset($OIDMap)) if (!isset($OIDMap))
{ {
foreach (self::MAP as $row) foreach (static::getMap() as $row)
{ {
if (isset($row['OID'])) if (isset($row['OID']))
{ {
$variant = mb_strtolower($row['OID']); $variant = mb_strtolower($row['OID']);
$OIDMap[$variant] = $row; if (!isset($OIDMap[$variant]))
{
$OIDMap[$variant] = $row;
}
} }
} }
} }

View File

@ -8,9 +8,9 @@ trait RDNAwareTrait
{ {
$RDN = mb_strtolower(trim($RDN)); $RDN = mb_strtolower(trim($RDN));
$map = self::getRDNMap(); $map = static::getRDNMap();
return isset($map[$RDN]) ? self::getResult($map[$RDN]) : null; return isset($map[$RDN]) ? static::getResult($map[$RDN]) : null;
} }
protected static function getRDNMap() protected static function getRDNMap()
@ -19,12 +19,15 @@ trait RDNAwareTrait
if (!isset($RDNMap)) if (!isset($RDNMap))
{ {
foreach (self::MAP as $row) foreach (static::getMap() as $row)
{ {
if (isset($row['RDN'])) if (isset($row['RDN']))
{ {
$variant = mb_strtolower($row['RDN']); $variant = mb_strtolower($row['RDN']);
$RDNMap[$variant] = $row; if (!isset($RDNMap[$variant]))
{
$RDNMap[$variant] = $row;
}
} }
} }
} }

View File

@ -0,0 +1,82 @@
<?php
namespace Webmasterskaya\CryptoPro\Dictionary;
class StandardTagsDictionary extends AbstractTagsDictionary
{
protected const MAP
= [
[
'RDN' => 'UN',
'OID' => '1.2.840.113549.1.9.2',
'title' => 'Неструктурированное имя',
'title_variants' => ['unstructuredName'],
],
[
'RDN' => 'CN',
'OID' => '2.5.4.3',
'title' => 'Удостоверяющий центр',
'title_variants' => ['commonName'],
],
[
'RDN' => 'SN',
'OID' => '2.5.4.4',
'title' => 'Фамилия',
'title_variants' => ['surname'],
],
[
'RDN' => 'G',
'OID' => '2.5.4.42',
'title' => 'Имя Отчество',
'title_variants' => ['givenName', 'gn'],
],
[
'RDN' => 'C',
'OID' => '2.5.4.6',
'title' => 'Страна',
'title_variants' => ['countryName'],
],
[
'RDN' => 'S',
'OID' => '2.5.4.8',
'title' => 'Регион',
'title_variants' => ['ST', 'stateOrProvinceName'],
],
[
'RDN' => 'L',
'OID' => '2.5.4.7',
'title' => 'Город',
'title_variants' => ['localityName'],
],
[
'RDN' => 'STREET',
'OID' => '2.5.4.9',
'title' => 'Адрес',
'title_variants' => ['streetAddress'],
],
[
'RDN' => 'O',
'OID' => '2.5.4.10',
'title' => 'Компания',
'title_variants' => ['organizationName'],
],
[
'RDN' => 'OU',
'OID' => '2.5.4.11',
'title' => 'Отдел/подразделение',
'title_variants' => ['organizationalUnitName'],
],
[
'RDN' => 'T',
'OID' => '2.5.4.12',
'title' => 'Должность',
'title_variants' => ['TITLE'],
],
[
'RDN' => 'E',
'OID' => '1.2.840.113549.1.9.1',
'title' => 'Email',
'title_variants' => ['email', 'emailAddress', 'pkcs9email'],
],
];
}

View File

@ -2,115 +2,15 @@
namespace Webmasterskaya\CryptoPro\Dictionary; namespace Webmasterskaya\CryptoPro\Dictionary;
class SubjectTagsDictionary extends AbstractDictionary implements RDNAwareInterface, TitleAwareInterface, OIDAwareInterface class SubjectTagsDictionary extends AdditionalTagsDictionary
{ {
use RDNAwareTrait;
use TitleAwareTrait;
use OIDAwareTrait;
protected const MAP protected const MAP
= [ = [
[
'RDN' => 'UN',
'OID' => '1.2.840.113549.1.9.2',
'title' => 'Неструктурированное имя',
'title_variants' => ['unstructuredName'],
],
[ [
'RDN' => 'CN', 'RDN' => 'CN',
'OID' => '2.5.4.3', 'OID' => '2.5.4.3',
'title' => 'Владелец', 'title' => 'Владелец',
'title_variants' => ['commonName'], 'title_variants' => ['commonName'],
], ],
[
'RDN' => 'SN',
'OID' => '2.5.4.4',
'title' => 'Фамилия',
'title_variants' => ['surname'],
],
[
'RDN' => 'G',
'OID' => '2.5.4.42',
'title' => 'Имя Отчество',
'title_variants' => ['givenName', 'gn'],
],
[
'RDN' => 'C',
'OID' => '2.5.4.6',
'title' => 'Страна',
'title_variants' => ['countryName'],
],
[
'RDN' => 'S',
'OID' => '2.5.4.8',
'title' => 'Регион',
'title_variants' => ['ST', 'stateOrProvinceName'],
],
[
'RDN' => 'STREET',
'OID' => '2.5.4.9',
'title' => 'Адрес',
'title_variants' => ['streetAddress'],
],
[
'RDN' => 'O',
'OID' => '2.5.4.10',
'title' => 'Компания',
'title_variants' => ['organizationName'],
],
[
'RDN' => 'OU',
'OID' => '2.5.4.11',
'title' => 'Отдел/подразделение',
'title_variants' => ['organizationalUnitName'],
],
[
'RDN' => 'T',
'OID' => '2.5.4.12',
'title' => 'Должность',
'title_variants' => ['TITLE'],
],
[
'RDN' => 'OGRN',
'OID' => '1.2.643.100.1',
'title' => 'ОГРН',
'title_variants' => ['ОГРН'],
],
[
'RDN' => 'OGRNIP',
'OID' => '1.2.643.100.5',
'title' => 'ОГРНИП',
'title_variants' => ['ОГРНИП'],
],
[
'RDN' => 'SNILS',
'OID' => '1.2.643.100.3',
'title' => 'СНИЛС',
'title_variants' => ['СНИЛС'],
],
[
'RDN' => 'INN',
'OID' => '1.2.643.3.131.1.1',
'title' => 'ИНН',
'title_variants' => ['ИННФЛ', 'ИНН ФЛ'],
],
[
'RDN' => 'INNLE',
'OID' => '1.2.643.100.4',
'title' => 'ИНН организации',
'title_variants' => ['ИННЮЛ', 'ИНН ЮЛ', 'INN LE'],
],
[
'RDN' => 'E',
'OID' => '1.2.840.113549.1.9.1',
'title' => 'Email',
'title_variants' => ['email', 'emailAddress', 'pkcs9email'],
],
[
'RDN' => 'L',
'OID' => '2.5.4.7',
'title' => 'Город',
'title_variants' => ['localityName'],
],
]; ];
} }

View File

@ -8,9 +8,9 @@ trait TitleAwareTrait
{ {
$title = mb_strtolower(trim($title)); $title = mb_strtolower(trim($title));
$map = self::getTitleMap(); $map = static::getTitleMap();
return isset($map[$title]) ? self::getResult($map[$title]) : null; return isset($map[$title]) ? static::getResult($map[$title]) : null;
} }
protected static function getTitleMap() protected static function getTitleMap()
@ -19,35 +19,47 @@ trait TitleAwareTrait
if (!isset($titleMap)) if (!isset($titleMap))
{ {
foreach (self::MAP as $row) foreach (static::getMap() as $row)
{ {
if (isset($row['title_variants'])) if (isset($row['title_variants']))
{ {
if (is_string($row['title_variants'])) if (is_string($row['title_variants']))
{ {
$variant = mb_strtolower($row['title_variants']); $variant = mb_strtolower($row['title_variants']);
$titleMap[$variant] = $row; if (!isset($titleMap[$variant]))
{
$titleMap[$variant] = $row;
}
} }
else else
{ {
foreach ($row['title_variants'] as $variant) foreach ($row['title_variants'] as $variant)
{ {
$variant = mb_strtolower($variant); $variant = mb_strtolower($variant);
$titleMap[$variant] = $row; if (!isset($titleMap[$variant]))
{
$titleMap[$variant] = $row;
}
} }
} }
} }
if (isset($row['title'])) if (isset($row['title']))
{ {
$variant = mb_strtolower($row['title']); $variant = mb_strtolower($row['title']);
$titleMap[$variant] = $row; if (!isset($titleMap[$variant]))
{
$titleMap[$variant] = $row;
}
} }
if (isset($row['RDN'])) if (isset($row['RDN']))
{ {
$variant = mb_strtolower($row['RDN']); $variant = mb_strtolower($row['RDN']);
$titleMap[$variant] = $row; if (!isset($titleMap[$variant]))
{
$titleMap[$variant] = $row;
}
} }
} }
} }