Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
mapper.php
1<?php
2
3namespace Bitrix\Seo\LeadAds;
4
6
13class Mapper
14{
15 protected $map = [];
16
20 public function __construct(array $items = [])
21 {
22 $this->setItems($items);
23 }
24
32 public function getCrmName($adsName)
33 {
34 $item = $this->getMapItem(null, $adsName);
35 return empty($item) ? null : $item['CRM_NAME'];
36 }
37
45 public function getAdsName($crmName)
46 {
47 $item = $this->getMapItem($crmName, null);
48 return empty($item) ? null : $item['ADS_NAME'];
49 }
50
58 public function setItems(array $items = [])
59 {
60 $this->map = [];
61 foreach ($items as $item)
62 {
63 if (empty($item['CRM_NAME']))
64 {
65 throw new ArgumentNullException('CRM_NAME');
66 }
67 if (empty($item['ADS_NAME']))
68 {
69 throw new ArgumentNullException('ADS_NAME');
70 }
71
72 $this->addItem($item['CRM_NAME'], $item['ADS_NAME']);
73 }
74
75 return $this;
76 }
77
87 public function addItem($crmName, string $adsName)
88 {
89 if (empty($crmName))
90 {
91 throw new ArgumentNullException('$crmName');
92 }
93 if (empty($adsName))
94 {
95 throw new ArgumentNullException('$adsName');
96 }
97
98 $this->map[] = [
99 'CRM_NAME' => $crmName,
100 'ADS_NAME' => $adsName,
101 ];
102
103 return $this;
104 }
105
106 protected function getMapItem($crmName = null, $adsName = null)
107 {
108 if (empty($crmName) && empty($adsName))
109 {
110 return null;
111 }
112
113 foreach ($this->map as $item)
114 {
115 if ($crmName && $item['CRM_NAME'] === $crmName)
116 {
117 return $item;
118 }
119
120 if ($adsName && $item['ADS_NAME'] === $adsName)
121 {
122 return $item;
123 }
124 }
125
126 return null;
127 }
128}
setItems(array $items=[])
Definition mapper.php:58
__construct(array $items=[])
Definition mapper.php:20
getMapItem($crmName=null, $adsName=null)
Definition mapper.php:106
addItem($crmName, string $adsName)
Definition mapper.php:87