mirror of
				https://github.com/crypto-pro-web/crypto-pro-php.git
				synced 2025-10-31 02:13:23 +03:00 
			
		
		
		
	Словари с поиском
This commit is contained in:
		
							parent
							
								
									141e439575
								
							
						
					
					
						commit
						05a93163dc
					
				
							
								
								
									
										32
									
								
								src/Dictionary/AbstractDictionary.php
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										32
									
								
								src/Dictionary/AbstractDictionary.php
									
									
									
									
									
										Executable file
									
								
							| @ -0,0 +1,32 @@ | ||||
| <?php | ||||
| 
 | ||||
| namespace Webmasterskaya\CryptoPro\Dictionary; | ||||
| 
 | ||||
| abstract class AbstractDictionary implements DictionaryInterface | ||||
| { | ||||
| 	protected const MAP = []; | ||||
| 
 | ||||
| 	protected static function getResult($data) | ||||
| 	{ | ||||
| 		$implements = class_implements(static::class) ?: []; | ||||
| 
 | ||||
| 		$options = []; | ||||
| 
 | ||||
| 		if (!!$implements[TitleAwareInterface::class]) | ||||
| 		{ | ||||
| 			$options['title'] = $data['title'] ?? null; | ||||
| 		} | ||||
| 
 | ||||
| 		if (!!$implements[OIDAwareInterface::class]) | ||||
| 		{ | ||||
| 			$options['OID'] = $data['OID'] ?? null; | ||||
| 		} | ||||
| 
 | ||||
| 		if (!!$implements[RDNAwareInterface::class]) | ||||
| 		{ | ||||
| 			$options['RDN'] = $data['RDN'] ?? null; | ||||
| 		} | ||||
| 
 | ||||
| 		return DictionaryItem::getItem($options); | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										8
									
								
								src/Dictionary/DescriptionAwareInterface.php
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										8
									
								
								src/Dictionary/DescriptionAwareInterface.php
									
									
									
									
									
										Executable file
									
								
							| @ -0,0 +1,8 @@ | ||||
| <?php | ||||
| 
 | ||||
| namespace Webmasterskaya\CryptoPro\Dictionary; | ||||
| 
 | ||||
| interface DescriptionAwareInterface | ||||
| { | ||||
| 
 | ||||
| } | ||||
							
								
								
									
										8
									
								
								src/Dictionary/DictionaryInterface.php
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										8
									
								
								src/Dictionary/DictionaryInterface.php
									
									
									
									
									
										Executable file
									
								
							| @ -0,0 +1,8 @@ | ||||
| <?php | ||||
| 
 | ||||
| namespace Webmasterskaya\CryptoPro\Dictionary; | ||||
| 
 | ||||
| interface DictionaryInterface | ||||
| { | ||||
| 
 | ||||
| } | ||||
							
								
								
									
										34
									
								
								src/Dictionary/DictionaryItem.php
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										34
									
								
								src/Dictionary/DictionaryItem.php
									
									
									
									
									
										Executable file
									
								
							| @ -0,0 +1,34 @@ | ||||
| <?php | ||||
| 
 | ||||
| namespace Webmasterskaya\CryptoPro\Dictionary; | ||||
| 
 | ||||
| abstract class DictionaryItem | ||||
| { | ||||
| 	protected $options; | ||||
| 
 | ||||
| 	protected function __construct(array $options) | ||||
| 	{ | ||||
| 		$this->options = $options; | ||||
| 	} | ||||
| 
 | ||||
| 	public function __get($name) | ||||
| 	{ | ||||
| 		if (!isset($this->options[$name])) | ||||
| 		{ | ||||
| 			user_error("Can't set property: " . __CLASS__ . "->" . $name); | ||||
| 		} | ||||
| 
 | ||||
| 		return $this->options[$name]; | ||||
| 	} | ||||
| 
 | ||||
| 	public function __set($name, $value) | ||||
| 	{ | ||||
| 		user_error("Can't set property: " . __CLASS__ . "->" . $name); | ||||
| 	} | ||||
| 
 | ||||
| 	public static function getItem(array $options) | ||||
| 	{ | ||||
| 		return new class($options) extends DictionaryItem { | ||||
| 		}; | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										104
									
								
								src/Dictionary/IssuerTagsDictionary.php
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										104
									
								
								src/Dictionary/IssuerTagsDictionary.php
									
									
									
									
									
										Executable file
									
								
							| @ -0,0 +1,104 @@ | ||||
| <?php | ||||
| 
 | ||||
| namespace Webmasterskaya\CryptoPro\Dictionary; | ||||
| 
 | ||||
| class IssuerTagsDictionary extends AbstractDictionary implements RDNAwareInterface, TitleAwareInterface, OIDAwareInterface | ||||
| { | ||||
| 	use RDNAwareTrait; | ||||
| 	use TitleAwareTrait; | ||||
| 	use OIDAwareTrait; | ||||
| 
 | ||||
| 	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'            => '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'], | ||||
| 			], | ||||
| 		]; | ||||
| } | ||||
							
								
								
									
										8
									
								
								src/Dictionary/OIDAwareInterface.php
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										8
									
								
								src/Dictionary/OIDAwareInterface.php
									
									
									
									
									
										Executable file
									
								
							| @ -0,0 +1,8 @@ | ||||
| <?php | ||||
| 
 | ||||
| namespace Webmasterskaya\CryptoPro\Dictionary; | ||||
| 
 | ||||
| interface OIDAwareInterface | ||||
| { | ||||
| 	public static function getByOID(string $oid); | ||||
| } | ||||
							
								
								
									
										34
									
								
								src/Dictionary/OIDAwareTrait.php
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										34
									
								
								src/Dictionary/OIDAwareTrait.php
									
									
									
									
									
										Executable file
									
								
							| @ -0,0 +1,34 @@ | ||||
| <?php | ||||
| 
 | ||||
| namespace Webmasterskaya\CryptoPro\Dictionary; | ||||
| 
 | ||||
| trait OIDAwareTrait | ||||
| { | ||||
| 	public static function getByOID(string $oid) | ||||
| 	{ | ||||
| 		$oid = mb_strtolower(trim($oid)); | ||||
| 
 | ||||
| 		$map = self::getOIDMap(); | ||||
| 
 | ||||
| 		return isset($map[$oid]) ? self::getResult($map[$oid]) : null; | ||||
| 	} | ||||
| 
 | ||||
| 	protected static function getOIDMap() | ||||
| 	{ | ||||
| 		static $OIDMap; | ||||
| 
 | ||||
| 		if (!isset($OIDMap)) | ||||
| 		{ | ||||
| 			foreach (self::MAP as $row) | ||||
| 			{ | ||||
| 				if (isset($row['OID'])) | ||||
| 				{ | ||||
| 					$variant          = mb_strtolower($row['OID']); | ||||
| 					$OIDMap[$variant] = $row; | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 
 | ||||
| 		return $OIDMap; | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										8
									
								
								src/Dictionary/RDNAwareInterface.php
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										8
									
								
								src/Dictionary/RDNAwareInterface.php
									
									
									
									
									
										Executable file
									
								
							| @ -0,0 +1,8 @@ | ||||
| <?php | ||||
| 
 | ||||
| namespace Webmasterskaya\CryptoPro\Dictionary; | ||||
| 
 | ||||
| interface RDNAwareInterface | ||||
| { | ||||
| 	public static function getByRDN(string $RDN); | ||||
| } | ||||
							
								
								
									
										34
									
								
								src/Dictionary/RDNAwareTrait.php
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										34
									
								
								src/Dictionary/RDNAwareTrait.php
									
									
									
									
									
										Executable file
									
								
							| @ -0,0 +1,34 @@ | ||||
| <?php | ||||
| 
 | ||||
| namespace Webmasterskaya\CryptoPro\Dictionary; | ||||
| 
 | ||||
| trait RDNAwareTrait | ||||
| { | ||||
| 	public static function getByRDN(string $RDN) | ||||
| 	{ | ||||
| 		$RDN = mb_strtolower(trim($RDN)); | ||||
| 
 | ||||
| 		$map = self::getRDNMap(); | ||||
| 
 | ||||
| 		return isset($map[$RDN]) ? self::getResult($map[$RDN]) : null; | ||||
| 	} | ||||
| 
 | ||||
| 	protected static function getRDNMap() | ||||
| 	{ | ||||
| 		static $RDNMap; | ||||
| 
 | ||||
| 		if (!isset($RDNMap)) | ||||
| 		{ | ||||
| 			foreach (self::MAP as $row) | ||||
| 			{ | ||||
| 				if (isset($row['RDN'])) | ||||
| 				{ | ||||
| 					$variant          = mb_strtolower($row['RDN']); | ||||
| 					$RDNMap[$variant] = $row; | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 
 | ||||
| 		return $RDNMap; | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										116
									
								
								src/Dictionary/SubjectTagsDictionary.php
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										116
									
								
								src/Dictionary/SubjectTagsDictionary.php
									
									
									
									
									
										Executable file
									
								
							| @ -0,0 +1,116 @@ | ||||
| <?php | ||||
| 
 | ||||
| namespace Webmasterskaya\CryptoPro\Dictionary; | ||||
| 
 | ||||
| class SubjectTagsDictionary extends AbstractDictionary implements RDNAwareInterface, TitleAwareInterface, OIDAwareInterface | ||||
| { | ||||
| 	use RDNAwareTrait; | ||||
| 	use TitleAwareTrait; | ||||
| 	use OIDAwareTrait; | ||||
| 
 | ||||
| 	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'            => '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'], | ||||
| 			], | ||||
| 		]; | ||||
| } | ||||
							
								
								
									
										8
									
								
								src/Dictionary/TitleAwareInterface.php
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										8
									
								
								src/Dictionary/TitleAwareInterface.php
									
									
									
									
									
										Executable file
									
								
							| @ -0,0 +1,8 @@ | ||||
| <?php | ||||
| 
 | ||||
| namespace Webmasterskaya\CryptoPro\Dictionary; | ||||
| 
 | ||||
| interface TitleAwareInterface | ||||
| { | ||||
| 	public static function getByTitle(string $title); | ||||
| } | ||||
							
								
								
									
										57
									
								
								src/Dictionary/TitleAwareTrait.php
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										57
									
								
								src/Dictionary/TitleAwareTrait.php
									
									
									
									
									
										Executable file
									
								
							| @ -0,0 +1,57 @@ | ||||
| <?php | ||||
| 
 | ||||
| namespace Webmasterskaya\CryptoPro\Dictionary; | ||||
| 
 | ||||
| trait TitleAwareTrait | ||||
| { | ||||
| 	public static function getByTitle(string $title) | ||||
| 	{ | ||||
| 		$title = mb_strtolower(trim($title)); | ||||
| 
 | ||||
| 		$map = self::getTitleMap(); | ||||
| 
 | ||||
| 		return isset($map[$title]) ? self::getResult($map[$title]) : null; | ||||
| 	} | ||||
| 
 | ||||
| 	protected static function getTitleMap() | ||||
| 	{ | ||||
| 		static $titleMap; | ||||
| 
 | ||||
| 		if (!isset($titleMap)) | ||||
| 		{ | ||||
| 			foreach (self::MAP as $row) | ||||
| 			{ | ||||
| 				if (isset($row['title_variants'])) | ||||
| 				{ | ||||
| 					if (is_string($row['title_variants'])) | ||||
| 					{ | ||||
| 						$variant            = mb_strtolower($row['title_variants']); | ||||
| 						$titleMap[$variant] = $row; | ||||
| 					} | ||||
| 					else | ||||
| 					{ | ||||
| 						foreach ($row['title_variants'] as $variant) | ||||
| 						{ | ||||
| 							$variant            = mb_strtolower($variant); | ||||
| 							$titleMap[$variant] = $row; | ||||
| 						} | ||||
| 					} | ||||
| 				} | ||||
| 
 | ||||
| 				if (isset($row['title'])) | ||||
| 				{ | ||||
| 					$variant            = mb_strtolower($row['title']); | ||||
| 					$titleMap[$variant] = $row; | ||||
| 				} | ||||
| 
 | ||||
| 				if (isset($row['RDN'])) | ||||
| 				{ | ||||
| 					$variant            = mb_strtolower($row['RDN']); | ||||
| 					$titleMap[$variant] = $row; | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 
 | ||||
| 		return $titleMap; | ||||
| 	} | ||||
| } | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user