├── LICENSE ├── README.md ├── composer.json ├── src ├── Category.php ├── Currency.php ├── DeliveryOption.php ├── Exception │ ├── AException.php │ └── FileNotFoundException.php ├── Offer │ ├── ABookOffer.php │ ├── AExtOffer.php │ ├── AMainOffer.php │ ├── AOffer.php │ ├── Age.php │ ├── ArtistTitleOffer.php │ ├── AudioBookOffer.php │ ├── BookOffer.php │ ├── EventTicketOffer.php │ ├── MedicineOffer.php │ ├── Outlet.php │ ├── Param.php │ ├── SimpleOffer.php │ ├── TourOffer.php │ └── VendorModelOffer.php ├── Shop.php ├── TError.php ├── TYML.php └── YML.php └── yml.xsd /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 LireinCore 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # YML (Yandex Market Language) parser 2 | 3 | [![Latest Stable Version](https://poser.pugx.org/lireincore/ymlparser/v/stable)](https://packagist.org/packages/lireincore/ymlparser) 4 | [![Total Downloads](https://poser.pugx.org/lireincore/ymlparser/downloads)](https://packagist.org/packages/lireincore/ymlparser) 5 | [![License](https://poser.pugx.org/lireincore/ymlparser/license)](https://packagist.org/packages/lireincore/ymlparser) 6 | 7 | ## About 8 | 9 | [YML (Yandex Market Language)](https://yandex.ru/support/partnermarket/yml/about-yml.xml) streaming parser with validation. 10 | Based on XMLReader. Suitable for large files. 11 | 12 | ## Install 13 | 14 | Add the `"lireincore/ymlparser": "^3.2"` package to your `require` section in the `composer.json` file 15 | 16 | or 17 | 18 | ``` bash 19 | $ php composer.phar require lireincore/ymlparser 20 | ``` 21 | 22 | ## Usage 23 | 24 | ```php 25 | use LireinCore\YMLParser\YML; 26 | 27 | $yml = new YML(); 28 | try { 29 | $yml->parse($filepath); 30 | $date = $yml->getDate(); 31 | $shop = $yml->getShop(); 32 | if ($shop->isValid()) { 33 | $offersCount = $shop->getOffersCount(); 34 | $shopData = $shop->getData(); 35 | //... 36 | foreach ($yml->getOffers() as $offer) { 37 | if ($offer->isValid()) { 38 | $offerCategoryHierarchy = $shop->getCategoryHierarchy($offer->getCategoryId()); 39 | $offerData = $offer->getData(); 40 | //... 41 | } else { 42 | var_dump($offer->getErrors()); 43 | //... 44 | } 45 | } 46 | } else { 47 | var_dump($shop->getErrors()); 48 | //... 49 | } 50 | } catch (\Exception $e) { 51 | echo $e->getMessage(); 52 | //... 53 | } 54 | ``` 55 | 56 | ## License 57 | 58 | The MIT License (MIT). Please see [License File](LICENSE) for more information. -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "lireincore/ymlparser", 3 | "description": "YML (Yandex Market Language) parser", 4 | "type": "library", 5 | "keywords": ["yml", "parser", "yandex", "market"], 6 | "homepage": "https://github.com/lireincore/ymlparser", 7 | "license": "MIT", 8 | "support": { 9 | "issues": "https://github.com/lireincore/ymlparser/issues", 10 | "source": "https://github.com/lireincore/ymlparser" 11 | }, 12 | "authors": [ 13 | { 14 | "name": "lirein", 15 | "email": "lirein@inbox.ru" 16 | } 17 | ], 18 | "require": { 19 | "php": ">=5.5", 20 | "ext-xmlreader": "*" 21 | }, 22 | "autoload": { 23 | "psr-4": { 24 | "LireinCore\\YMLParser\\": "src" 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /src/Category.php: -------------------------------------------------------------------------------- 1 | id === null) { 31 | $this->addError("Category: missing required attribute 'id'"); 32 | } elseif (!is_numeric($this->id) || (int)$this->id <= 0) { 33 | $this->addError("Category: incorrect value in attribute 'id'"); 34 | } 35 | if ($this->parentId !== null && (!is_numeric($this->parentId) || (int)$this->parentId <= 0)) { 36 | $this->addError("Category: incorrect value in attribute 'parentId'"); 37 | } 38 | if (!$this->name) { 39 | $this->addError('Category: incorrect value'); 40 | } 41 | 42 | return empty($this->errors); 43 | } 44 | 45 | /** 46 | * @param array $attributes 47 | * @return $this 48 | */ 49 | public function addAttributes($attributes) 50 | { 51 | foreach ($attributes as $name => $value) { 52 | $this->addField($name, $value); 53 | } 54 | 55 | return $this; 56 | } 57 | 58 | /** 59 | * @return int|null 60 | */ 61 | public function getId() 62 | { 63 | return $this->id === null ? null : (int)$this->id; 64 | } 65 | 66 | /** 67 | * @param string $value 68 | * @return $this 69 | */ 70 | public function setId($value) 71 | { 72 | $this->id = $value; 73 | 74 | return $this; 75 | } 76 | 77 | /** 78 | * @return int|null 79 | */ 80 | public function getParentId() 81 | { 82 | return $this->parentId === null ? null : (int)$this->parentId; 83 | } 84 | 85 | /** 86 | * @param int $value 87 | * @return $this 88 | */ 89 | public function setParentId($value) 90 | { 91 | $this->parentId = $value; 92 | 93 | return $this; 94 | } 95 | 96 | /** 97 | * @return string|null 98 | */ 99 | public function getName() 100 | { 101 | return $this->name; 102 | } 103 | 104 | /** 105 | * @param string $value 106 | * @return $this 107 | */ 108 | public function setName($value) 109 | { 110 | $this->name = $value; 111 | 112 | return $this; 113 | } 114 | } -------------------------------------------------------------------------------- /src/Currency.php: -------------------------------------------------------------------------------- 1 | id === null) { 33 | $this->addError("Currency: missing required attribute 'id'"); 34 | } elseif (!in_array($this->id, ['RUR', 'RUB', 'UAH', 'BYN', 'BYR', 'KZT', 'USD', 'EUR'], true)) { 35 | $this->addError("Currency: incorrect value in attribute 'id'"); 36 | } 37 | if ($this->rate === null) { 38 | $this->addError("Currency: missing required attribute 'rate'"); 39 | } elseif (!(in_array($this->rate, ['CBRF', 'NBU', 'NBK', 'CB'], true) || (is_numeric($this->rate) && (float)$this->rate > 0))) { 40 | $this->addError("Currency: incorrect value in attribute 'rate'"); 41 | } 42 | if ($this->plus !== null && (int)$this->plus < 0) { 43 | $this->addError("Currency: incorrect value in attribute 'plus'"); 44 | } 45 | return empty($this->errors); 46 | } 47 | 48 | /** 49 | * @param array $attributes 50 | * @return $this 51 | */ 52 | public function addAttributes($attributes) 53 | { 54 | foreach ($attributes as $name => $value) { 55 | $this->addField($name, $value); 56 | } 57 | 58 | return $this; 59 | } 60 | 61 | /** 62 | * @return string|null 63 | */ 64 | public function getId() 65 | { 66 | return $this->id; 67 | } 68 | 69 | /** 70 | * @param string $value 71 | * @return $this 72 | */ 73 | public function setId($value) 74 | { 75 | $this->id = $value; 76 | 77 | return $this; 78 | } 79 | 80 | /** 81 | * @return float|string|null 82 | */ 83 | public function getRate() 84 | { 85 | return is_numeric($this->rate) ? (float)$this->rate : $this->rate; 86 | } 87 | 88 | /** 89 | * @param string $value 90 | * @return $this 91 | */ 92 | public function setRate($value) 93 | { 94 | $this->rate = $value; 95 | 96 | return $this; 97 | } 98 | 99 | /** 100 | * @return int|null 101 | */ 102 | public function getPlus() 103 | { 104 | return $this->plus === null ? null : (int)$this->plus; 105 | } 106 | 107 | /** 108 | * @param string $value 109 | * @return $this 110 | */ 111 | public function setPlus($value) 112 | { 113 | $this->plus = $value; 114 | 115 | return $this; 116 | } 117 | } -------------------------------------------------------------------------------- /src/DeliveryOption.php: -------------------------------------------------------------------------------- 1 | cost === null) { 33 | $this->addError("DeliveryOption: missing required attribute 'cost'"); 34 | } elseif (!is_numeric($this->cost) || ((int)$this->cost) < 0) { 35 | $this->addError("DeliveryOption: incorrect value in attribute 'cost'"); 36 | } 37 | 38 | if ($this->days === null) { 39 | $this->addError("DeliveryOption: missing required attribute 'days'"); 40 | } 41 | 42 | if ($this->orderBefore !== null && (!is_numeric($this->orderBefore) || (int)$this->orderBefore < 0 || (int)$this->orderBefore > 24)) { 43 | $this->addError("DeliveryOption: incorrect value in attribute 'order-before'"); 44 | } 45 | 46 | return empty($this->errors); 47 | } 48 | 49 | /** 50 | * @param array $attributes 51 | * @return $this 52 | */ 53 | public function addAttributes($attributes) 54 | { 55 | foreach ($attributes as $name => $value) { 56 | $this->addField($name, $value); 57 | } 58 | 59 | return $this; 60 | } 61 | 62 | /** 63 | * @return int|null 64 | */ 65 | public function getCost() 66 | { 67 | return $this->cost === null ? null : (int)$this->cost; 68 | } 69 | 70 | /** 71 | * @param string $value 72 | * @return $this 73 | */ 74 | public function setCost($value) 75 | { 76 | $this->cost = $value; 77 | 78 | return $this; 79 | } 80 | 81 | /** 82 | * @return string|null 83 | */ 84 | public function getDays() 85 | { 86 | return $this->days; 87 | } 88 | 89 | /** 90 | * @param string $value 91 | * @return $this 92 | */ 93 | public function setDays($value) 94 | { 95 | $this->days = $value; 96 | 97 | return $this; 98 | } 99 | 100 | /** 101 | * @return int|null 102 | */ 103 | public function getOrderBefore() 104 | { 105 | return $this->orderBefore === null ? null : (int)$this->orderBefore; 106 | } 107 | 108 | /** 109 | * @param string $value 110 | * @return $this 111 | */ 112 | public function setOrderBefore($value) 113 | { 114 | $this->orderBefore = $value; 115 | 116 | return $this; 117 | } 118 | } -------------------------------------------------------------------------------- /src/Exception/AException.php: -------------------------------------------------------------------------------- 1 | name === null) { 76 | $this->addError("Offer: missing required attribute 'name'"); 77 | } 78 | if ($this->year !== null && !is_numeric($this->year)) { 79 | $this->addError("Offer: incorrect value in attribute 'year'"); 80 | } 81 | if ($this->volume !== null && (!is_numeric($this->volume) || (int)$this->volume <= 0)) { 82 | $this->addError("Offer: incorrect value in attribute 'volume'"); 83 | } 84 | if ($this->part !== null && (!is_numeric($this->part) || (int)$this->part <= 0)) { 85 | $this->addError("Offer: incorrect value in attribute 'part'"); 86 | } 87 | return $isValid && empty($this->errors); 88 | } 89 | 90 | /** 91 | * @return string|null 92 | */ 93 | public function getAuthor() 94 | { 95 | return $this->author; 96 | } 97 | 98 | /** 99 | * @param string $value 100 | * @return $this 101 | */ 102 | public function setAuthor($value) 103 | { 104 | $this->author = $value; 105 | 106 | return $this; 107 | } 108 | 109 | /** 110 | * @return string|null 111 | */ 112 | public function getName() 113 | { 114 | return $this->name; 115 | } 116 | 117 | /** 118 | * @param string $value 119 | * @return $this 120 | */ 121 | public function setName($value) 122 | { 123 | $this->name = $value; 124 | 125 | return $this; 126 | } 127 | 128 | /** 129 | * @return string|null 130 | */ 131 | public function getPublisher() 132 | { 133 | return $this->publisher; 134 | } 135 | 136 | /** 137 | * @param string $value 138 | * @return $this 139 | */ 140 | public function setPublisher($value) 141 | { 142 | $this->publisher = $value; 143 | 144 | return $this; 145 | } 146 | 147 | /** 148 | * @return string|null 149 | */ 150 | public function getSeries() 151 | { 152 | return $this->series; 153 | } 154 | 155 | /** 156 | * @param string $value 157 | * @return $this 158 | */ 159 | public function setSeries($value) 160 | { 161 | $this->series = $value; 162 | 163 | return $this; 164 | } 165 | 166 | /** 167 | * @return int|null 168 | */ 169 | public function getYear() 170 | { 171 | return $this->year === null ? null : (int)$this->year; 172 | } 173 | 174 | /** 175 | * @param string $value 176 | * @return $this 177 | */ 178 | public function setYear($value) 179 | { 180 | $this->year = $value; 181 | 182 | return $this; 183 | } 184 | 185 | /** 186 | * @return string|null 187 | */ 188 | public function getISBN() 189 | { 190 | return $this->ISBN; 191 | } 192 | 193 | /** 194 | * @param string $value 195 | * @return $this 196 | */ 197 | public function setISBN($value) 198 | { 199 | $this->ISBN = $value; 200 | 201 | return $this; 202 | } 203 | 204 | /** 205 | * @return int|null 206 | */ 207 | public function getVolume() 208 | { 209 | return $this->volume === null ? null : (int)$this->volume; 210 | } 211 | 212 | /** 213 | * @param string $value 214 | * @return $this 215 | */ 216 | public function setVolume($value) 217 | { 218 | $this->volume = $value; 219 | 220 | return $this; 221 | } 222 | 223 | /** 224 | * @return int|null 225 | */ 226 | public function getPart() 227 | { 228 | return $this->part === null ? null : (int)$this->part; 229 | } 230 | 231 | /** 232 | * @param string $value 233 | * @return $this 234 | */ 235 | public function setPart($value) 236 | { 237 | $this->part = $value; 238 | 239 | return $this; 240 | } 241 | 242 | /** 243 | * @return string|null 244 | */ 245 | public function getLanguage() 246 | { 247 | return $this->language; 248 | } 249 | 250 | /** 251 | * @param string $value 252 | * @return $this 253 | */ 254 | public function setLanguage($value) 255 | { 256 | $this->language = $value; 257 | 258 | return $this; 259 | } 260 | 261 | /** 262 | * @return string|null 263 | */ 264 | public function getTableOfContents() 265 | { 266 | return $this->tableOfContents; 267 | } 268 | 269 | /** 270 | * @param string $value 271 | * @return $this 272 | */ 273 | public function setTableOfContents($value) 274 | { 275 | $this->tableOfContents = $value; 276 | 277 | return $this; 278 | } 279 | } -------------------------------------------------------------------------------- /src/Offer/AExtOffer.php: -------------------------------------------------------------------------------- 1 | fee !== null && (!is_numeric($this->fee) || (int)$this->fee <= 0)) { 71 | $this->addError("Offer: incorrect value in attribute 'fee'"); 72 | } 73 | if ($this->localDeliveryCost !== null && (!is_numeric($this->localDeliveryCost) || ((int)$this->localDeliveryCost) < 0)) { 74 | $this->addError("Offer: incorrect value in attribute 'local_delivery_cost'"); 75 | } 76 | if ($this->delivery === true && !$this->deliveryOptions && $this->localDeliveryCost === null) { 77 | $this->addError("Offer: attribute 'delivery-options' is required when 'delivery' is true"); 78 | } 79 | if ($this->manufacturerWarranty !== null && $this->manufacturerWarranty !== 'true' && $this->manufacturerWarranty !== 'false') { 80 | $this->addError("Offer: incorrect value in attribute 'manufacturer_warranty'"); 81 | } 82 | if ($this->downloadable !== null && $this->downloadable !== 'true' && $this->downloadable !== 'false') { 83 | $this->addError("Offer: incorrect value in attribute 'downloadable'"); 84 | } 85 | if ($this->adult !== null && $this->adult !== 'true' && $this->adult !== 'false') { 86 | $this->addError("Offer: incorrect value in attribute 'adult'"); 87 | } 88 | $subIsValid = true; 89 | if ($this->deliveryOptions) { 90 | foreach ($this->deliveryOptions as $deliveryOption) { 91 | if (!$deliveryOption->isValid()) { 92 | $subIsValid = false; 93 | } 94 | } 95 | } 96 | if ($this->age && !$this->age->isValid()) { 97 | $subIsValid = false; 98 | } 99 | return $isValid && empty($this->errors) && $subIsValid; 100 | } 101 | 102 | /** 103 | * @return array 104 | */ 105 | public function getErrors() 106 | { 107 | $errors[] = parent::getErrors(); 108 | 109 | if ($this->deliveryOptions) { 110 | foreach ($this->deliveryOptions as $deliveryOption) { 111 | $errors[] = $deliveryOption->getErrors(); 112 | } 113 | } 114 | if ($this->age) { 115 | $errors[] = $this->age->getErrors(); 116 | } 117 | 118 | return 1 !== count($errors) ? call_user_func_array('array_merge', $errors) : $errors[0]; 119 | } 120 | 121 | /** 122 | * @param array $attrNode 123 | * @return $this 124 | */ 125 | public function addAttribute(array $attrNode) 126 | { 127 | if ($attrNode['name'] === 'delivery-options') { 128 | foreach ($attrNode['nodes'] as $subNode) { 129 | $this->addDeliveryOption((new DeliveryOption())->addAttributes($subNode['attributes'])); 130 | } 131 | } elseif ($attrNode['name'] === 'age') { 132 | $this->setAge((new Age())->addAttributes($attrNode['attributes'] + ['value' => $attrNode['value']])); 133 | } else { 134 | parent::addAttribute($attrNode); 135 | } 136 | 137 | return $this; 138 | } 139 | 140 | /** 141 | * @return int|null 142 | */ 143 | public function getFee() 144 | { 145 | return $this->fee === null ? null : (int)$this->fee; 146 | } 147 | 148 | /** 149 | * @param string $value 150 | * @return $this 151 | */ 152 | public function setFee($value) 153 | { 154 | $this->fee = $value; 155 | 156 | return $this; 157 | } 158 | 159 | /** 160 | * @return string|null 161 | */ 162 | public function getMarketCategory() 163 | { 164 | return $this->marketCategory; 165 | } 166 | 167 | /** 168 | * @param string $value 169 | * @return $this 170 | */ 171 | public function setMarketCategory($value) 172 | { 173 | $this->marketCategory = $value; 174 | 175 | return $this; 176 | } 177 | 178 | /** 179 | * @return int|null 180 | */ 181 | public function getLocalDeliveryCost() 182 | { 183 | return $this->localDeliveryCost === null ? null : (int)$this->localDeliveryCost; 184 | } 185 | 186 | /** 187 | * @param string $value 188 | * @return $this 189 | */ 190 | public function setLocalDeliveryCost($value) 191 | { 192 | $this->localDeliveryCost = $value; 193 | 194 | return $this; 195 | } 196 | 197 | /** 198 | * @return DeliveryOption[]|null 199 | */ 200 | public function getDeliveryOptions() 201 | { 202 | return $this->deliveryOptions ?: null; 203 | } 204 | 205 | /** 206 | * @param DeliveryOption[] $value 207 | * @return $this 208 | */ 209 | public function setDeliveryOptions(array $value) 210 | { 211 | foreach ($value as $deliveryOption) { 212 | $this->addDeliveryOption($deliveryOption); 213 | } 214 | 215 | return $this; 216 | } 217 | 218 | /** 219 | * @param DeliveryOption $value 220 | * @return $this 221 | */ 222 | public function addDeliveryOption(DeliveryOption $value) 223 | { 224 | $this->deliveryOptions[] = $value; 225 | 226 | return $this; 227 | } 228 | 229 | /** 230 | * @return bool|null 231 | */ 232 | public function getManufacturerWarranty() 233 | { 234 | $result = $this->manufacturerWarranty === null ? null : ($this->manufacturerWarranty === 'false' ? false : (bool)$this->manufacturerWarranty); 235 | 236 | return $result; 237 | } 238 | 239 | /** 240 | * @param string $value 241 | * @return $this 242 | */ 243 | public function setManufacturerWarranty($value) 244 | { 245 | $this->manufacturerWarranty = $value; 246 | 247 | return $this; 248 | } 249 | 250 | /** 251 | * @return bool|null 252 | */ 253 | public function getDownloadable() 254 | { 255 | return $this->downloadable === null ? null : ($this->downloadable === 'false' ? false : (bool)$this->downloadable); 256 | } 257 | 258 | /** 259 | * @param string $value 260 | * @return $this 261 | */ 262 | public function setDownloadable($value) 263 | { 264 | $this->downloadable = $value; 265 | 266 | return $this; 267 | } 268 | 269 | /** 270 | * @return bool|null 271 | */ 272 | public function getAdult() 273 | { 274 | return $this->adult === null ? null : ($this->adult === 'false' ? false : (bool)$this->adult); 275 | } 276 | 277 | /** 278 | * @param string $value 279 | * @return $this 280 | */ 281 | public function setAdult($value) 282 | { 283 | $this->adult = $value; 284 | 285 | return $this; 286 | } 287 | 288 | /** 289 | * @return Age|null 290 | */ 291 | public function getAge() 292 | { 293 | return $this->age; 294 | } 295 | 296 | /** 297 | * @param Age $value 298 | * @return $this 299 | */ 300 | public function setAge(Age $value) 301 | { 302 | $this->age = $value; 303 | 304 | return $this; 305 | } 306 | } -------------------------------------------------------------------------------- /src/Offer/AMainOffer.php: -------------------------------------------------------------------------------- 1 | minQuantity !== null && (!is_numeric($this->minQuantity) || (int)$this->minQuantity <= 0)) { 70 | $this->addError("Offer: incorrect value in attribute 'min-quantity'"); 71 | } 72 | 73 | if ($this->stepQuantity !== null && (!is_numeric($this->stepQuantity) || (int)$this->stepQuantity <= 0)) { 74 | $this->addError("Offer: incorrect value in attribute 'step-quantity'"); 75 | } 76 | 77 | if ($this->groupId !== null && !is_numeric($this->groupId)) { 78 | $this->addError("Offer: incorrect value in attribute 'group_id'"); 79 | } 80 | 81 | if ($this->from !== null && $this->from !== 'true' && $this->from !== 'false') { 82 | $this->addError("Price: incorrect value in attribute 'from'"); 83 | } 84 | 85 | return $isValid && empty($this->errors); 86 | } 87 | 88 | /** 89 | * @param array $attrNode 90 | * @return $this 91 | */ 92 | /*public function addAttribute(array $attrNode) 93 | { 94 | //if ($attrNode['name'] == 'price') { 95 | // if (isset($attrNode['attributes']['from'])) $this->setField('from', $attrNode['attributes']['from']); 96 | //} 97 | 98 | parent::addAttribute($attrNode); 99 | 100 | return $this; 101 | }*/ 102 | 103 | /** 104 | * @return int|null 105 | */ 106 | public function getMinQuantity() 107 | { 108 | return $this->minQuantity === null ? null : (int)$this->minQuantity; 109 | } 110 | 111 | /** 112 | * @param string $value 113 | * @return $this 114 | */ 115 | public function setMinQuantity($value) 116 | { 117 | $this->minQuantity = $value; 118 | 119 | return $this; 120 | } 121 | 122 | /** 123 | * @return int|null 124 | */ 125 | public function getStepQuantity() 126 | { 127 | return $this->stepQuantity === null ? null : (int)$this->stepQuantity; 128 | } 129 | 130 | /** 131 | * @param string $value 132 | * @return $this 133 | */ 134 | public function setStepQuantity($value) 135 | { 136 | $this->stepQuantity = $value; 137 | 138 | return $this; 139 | } 140 | 141 | /** 142 | * @return int|null 143 | */ 144 | public function getGroupId() 145 | { 146 | return $this->groupId === null ? null : (int)$this->groupId; 147 | } 148 | 149 | /** 150 | * @param string $value 151 | * @return $this 152 | */ 153 | public function setGroupId($value) 154 | { 155 | $this->groupId = $value; 156 | 157 | return $this; 158 | } 159 | 160 | /** 161 | * @return string|null 162 | */ 163 | public function getRec() 164 | { 165 | return $this->rec; 166 | } 167 | 168 | /** 169 | * @param string $value 170 | * @return $this 171 | */ 172 | public function setRec($value) 173 | { 174 | $this->rec = $value; 175 | 176 | return $this; 177 | } 178 | 179 | /** 180 | * @return bool|null 181 | */ 182 | public function getFrom() 183 | { 184 | return $this->from === null ? null : ($this->from === 'false' ? false : (bool)$this->from); 185 | } 186 | 187 | /** 188 | * @param string $value 189 | * @return $this 190 | */ 191 | public function setFrom($value) 192 | { 193 | $this->from = $value; 194 | 195 | return $this; 196 | } 197 | 198 | /** 199 | * @return string|null 200 | */ 201 | public function getVendor() 202 | { 203 | return $this->vendor; 204 | } 205 | 206 | /** 207 | * @param string $value 208 | * @return $this 209 | */ 210 | public function setVendor($value) 211 | { 212 | $this->vendor = $value; 213 | 214 | return $this; 215 | } 216 | 217 | /** 218 | * @return string|null 219 | */ 220 | public function getVendorCode() 221 | { 222 | return $this->vendorCode; 223 | } 224 | 225 | /** 226 | * @param string $value 227 | * @return $this 228 | */ 229 | public function setVendorCode($value) 230 | { 231 | $this->vendorCode = $value; 232 | 233 | return $this; 234 | } 235 | 236 | /** 237 | * @return string|null 238 | */ 239 | public function getModel() 240 | { 241 | return $this->model; 242 | } 243 | 244 | /** 245 | * @param string $value 246 | * @return $this 247 | */ 248 | public function setModel($value) 249 | { 250 | $this->model = $value; 251 | 252 | return $this; 253 | } 254 | } -------------------------------------------------------------------------------- /src/Offer/AOffer.php: -------------------------------------------------------------------------------- 1 | id === null) { 157 | $this->addError("Offer: missing required attribute 'id'"); 158 | } elseif (!$this->id) { 159 | $this->addError("Offer: incorrect value in attribute 'id'"); 160 | } 161 | 162 | if ($this->bid !== null && (!is_numeric($this->bid) || (int)$this->bid <= 0)) { 163 | $this->addError("Offer: incorrect value in attribute 'bid'"); 164 | } 165 | 166 | if ($this->cbid !== null && (!is_numeric($this->cbid) || (int)$this->cbid <= 0)) { 167 | $this->addError("Offer: incorrect value in attribute 'cbid'"); 168 | } 169 | 170 | if ($this->available === null) { 171 | if ($this->getPickup()) { 172 | $this->addError("Offer: attribute 'available' is required when 'pickup' is true"); 173 | } 174 | } elseif ($this->available !== 'true' && $this->available !== 'false') { 175 | $this->addError("Offer: incorrect value in attribute 'available'"); 176 | } 177 | 178 | if ($this->price === null) { 179 | $this->addError("Offer: missing required attribute 'price'"); 180 | } elseif (!is_numeric($this->price) || (float)$this->price <= 0) { 181 | $this->addError("Offer: incorrect value in attribute 'price'"); 182 | } 183 | 184 | if ($this->oldprice !== null && (!is_numeric($this->oldprice) || (float)$this->oldprice <= (float)$this->price)) { 185 | $this->addError("Offer: incorrect value in attribute 'oldprice'"); 186 | } 187 | 188 | if ($this->vat !== null && !in_array($this->vat, [ 189 | '1', '2', '3', '4', '5', '6', 'VAT_18', 'VAT_18_118', 'VAT_10', 'VAT_10_110', 'VAT_0', 'NO_VAT' 190 | ], true)) 191 | { 192 | $this->addError("Offer: incorrect value in attribute 'vat'"); 193 | } 194 | 195 | if ($this->currencyId === null) { 196 | $this->addError("Offer: missing required attribute 'currencyId'"); 197 | } elseif (!$this->currencyId) { 198 | $this->addError("Offer: incorrect value in attribute 'currencyId'"); 199 | } 200 | 201 | if ($this->categoryId === null) { 202 | $this->addError("Offer: missing required attribute 'categoryId'"); 203 | } elseif (!$this->categoryId) { 204 | $this->addError("Offer: incorrect value in attribute 'categoryId'"); 205 | } 206 | 207 | if ($this->store !== null && $this->store !== 'true' && $this->store !== 'false') { 208 | $this->addError("Offer: incorrect value in attribute 'store'"); 209 | } 210 | 211 | if ($this->pickup !== null && $this->pickup !== 'true' && $this->pickup !== 'false') { 212 | $this->addError("Offer: incorrect value in attribute 'pickup'"); 213 | } 214 | 215 | if ($this->delivery !== null && $this->delivery !== 'true' && $this->delivery !== 'false') { 216 | $this->addError("Offer: incorrect value in attribute 'delivery'"); 217 | } 218 | 219 | if ($this->weight !== null && (!is_numeric($this->weight) || (float)$this->weight <= 0)) { 220 | $this->addError("Offer: incorrect value in attribute 'weight'"); 221 | } 222 | 223 | $subIsValid = true; 224 | if ($this->outlets) { 225 | foreach ($this->outlets as $outlet) { 226 | if (!$outlet->isValid()) { 227 | $subIsValid = false; 228 | } 229 | } 230 | } 231 | if ($this->params) { 232 | foreach ($this->params as $param) { 233 | if (!$param->isValid()) { 234 | $subIsValid = false; 235 | } 236 | } 237 | } 238 | 239 | return empty($this->errors) && $subIsValid; 240 | } 241 | 242 | /** 243 | * @return array 244 | */ 245 | public function getErrors() 246 | { 247 | $errors[] = $this->errors; 248 | 249 | if ($this->outlets) { 250 | foreach ($this->outlets as $outlet) { 251 | $errors[] = $outlet->getErrors(); 252 | } 253 | } 254 | if ($this->params) { 255 | foreach ($this->params as $param) { 256 | $errors[] = $param->getErrors(); 257 | } 258 | } 259 | 260 | return 1 === count($errors) ? $errors[0] : call_user_func_array('array_merge', $errors); 261 | } 262 | 263 | /** 264 | * @param array $offerNode 265 | * @return $this 266 | */ 267 | public function fillOffer(array $offerNode) 268 | { 269 | foreach ($offerNode['attributes'] as $name => $value) { 270 | $this->addField($name, $value); 271 | } 272 | 273 | foreach ($offerNode['nodes'] as $attrNode) { 274 | $this->addAttribute($attrNode); 275 | } 276 | 277 | return $this; 278 | } 279 | 280 | /** 281 | * @param array $attrNode 282 | * @return $this 283 | */ 284 | public function addAttribute(array $attrNode) 285 | { 286 | if ($attrNode['name'] === 'outlets') { 287 | foreach ($attrNode['nodes'] as $subNode) { 288 | $this->addOutlet((new Outlet())->addAttributes($subNode['attributes'])); 289 | } 290 | } elseif ($attrNode['name'] === 'picture') { 291 | $this->addPicture($attrNode['value']); 292 | } elseif ($attrNode['name'] === 'barcode') { 293 | $this->addBarcode($attrNode['value']); 294 | } elseif ($attrNode['name'] === 'param') { 295 | $this->addParam((new Param())->addAttributes($attrNode['attributes'] + ['value' => $attrNode['value']])); 296 | } else { 297 | if (!is_null($attrNode['value'])) { 298 | $this->addField($attrNode['name'], $attrNode['value']); 299 | } 300 | if (!empty($attrNode['attributes'])) { 301 | foreach ($attrNode['attributes'] as $name => $value) { 302 | $this->addField($name, $value); 303 | } 304 | } 305 | } 306 | 307 | return $this; 308 | } 309 | 310 | /** 311 | * @return string|null 312 | */ 313 | public function getId() 314 | { 315 | return $this->id; 316 | } 317 | 318 | /** 319 | * @param string $value 320 | * @return $this 321 | */ 322 | public function setId($value) 323 | { 324 | $this->id = $value; 325 | 326 | return $this; 327 | } 328 | 329 | /** 330 | * @return int|null 331 | */ 332 | public function getBid() 333 | { 334 | return $this->bid === null ? null : (int)$this->bid; 335 | } 336 | 337 | /** 338 | * @param string $value 339 | * @return $this 340 | */ 341 | public function setBid($value) 342 | { 343 | $this->bid = $value; 344 | 345 | return $this; 346 | } 347 | 348 | /** 349 | * @return int|null 350 | */ 351 | public function getCbid() 352 | { 353 | return $this->cbid === null ? null : (int)$this->cbid; 354 | } 355 | 356 | /** 357 | * @param string $value 358 | * @return $this 359 | */ 360 | public function setCbid($value) 361 | { 362 | $this->cbid = $value; 363 | 364 | return $this; 365 | } 366 | 367 | /** 368 | * @return bool|null 369 | */ 370 | public function getAvailable() 371 | { 372 | return $this->available === null ? null : ($this->available === 'false' ? false : (bool)$this->available); 373 | } 374 | 375 | /** 376 | * @param string $value 377 | * @return $this 378 | */ 379 | public function setAvailable($value) 380 | { 381 | $this->available = $value; 382 | 383 | return $this; 384 | } 385 | 386 | /** 387 | * @return string|null 388 | */ 389 | public function getUrl() 390 | { 391 | return $this->url; 392 | } 393 | 394 | /** 395 | * @param string $value 396 | * @return $this 397 | */ 398 | public function setUrl($value) 399 | { 400 | $this->url = $value; 401 | 402 | return $this; 403 | } 404 | 405 | /** 406 | * @return float|null 407 | */ 408 | public function getPrice() 409 | { 410 | return $this->price === null ? null : (float)$this->price; 411 | } 412 | 413 | /** 414 | * @param string $value 415 | * @return $this 416 | */ 417 | public function setPrice($value) 418 | { 419 | $this->price = $value; 420 | 421 | return $this; 422 | } 423 | 424 | /** 425 | * @return float|null 426 | */ 427 | public function getOldprice() 428 | { 429 | return $this->oldprice === null ? null : (float)$this->oldprice; 430 | } 431 | 432 | /** 433 | * @param string $value 434 | * @return $this 435 | */ 436 | public function setOldprice($value) 437 | { 438 | $this->oldprice = $value; 439 | 440 | return $this; 441 | } 442 | 443 | /** 444 | * @return int|string|null 445 | */ 446 | public function getVat() 447 | { 448 | return is_numeric($this->vat) ? (int)$this->vat : $this->vat; 449 | } 450 | 451 | /** 452 | * @param string $value 453 | * @return $this 454 | */ 455 | public function setVat($value) 456 | { 457 | $this->vat = $value; 458 | 459 | return $this; 460 | } 461 | 462 | /** 463 | * @return string|null 464 | */ 465 | public function getCurrencyId() 466 | { 467 | return $this->currencyId; 468 | } 469 | 470 | /** 471 | * @param string $value 472 | * @return $this 473 | */ 474 | public function setCurrencyId($value) 475 | { 476 | $this->currencyId = $value; 477 | 478 | return $this; 479 | } 480 | 481 | /** 482 | * @return int|null 483 | */ 484 | public function getCategoryId() 485 | { 486 | return $this->categoryId === null ? null : (int)$this->categoryId; 487 | } 488 | 489 | /** 490 | * @param string $value 491 | * @return $this 492 | */ 493 | public function setCategoryId($value) 494 | { 495 | $this->categoryId = $value; 496 | 497 | return $this; 498 | } 499 | 500 | /** 501 | * @return string[]|null 502 | */ 503 | public function getPictures() 504 | { 505 | return $this->pictures ?: null; 506 | } 507 | 508 | /** 509 | * @param string[] $value 510 | * @return $this 511 | */ 512 | public function setPictures(array $value) 513 | { 514 | foreach ($value as $picture) { 515 | $this->addPicture($picture); 516 | } 517 | 518 | return $this; 519 | } 520 | 521 | /** 522 | * @param string $value 523 | * @return $this 524 | */ 525 | public function addPicture($value) 526 | { 527 | $this->pictures[] = $value; 528 | 529 | return $this; 530 | } 531 | 532 | /** 533 | * @return bool|null 534 | */ 535 | public function getStore() 536 | { 537 | return $this->store === null ? null : ($this->store === 'false' ? false : (bool)$this->store); 538 | } 539 | 540 | /** 541 | * @param string $value 542 | * @return $this 543 | */ 544 | public function setStore($value) 545 | { 546 | $this->store = $value; 547 | 548 | return $this; 549 | } 550 | 551 | /** 552 | * @return bool|null 553 | */ 554 | public function getPickup() 555 | { 556 | return $this->pickup === null ? null : ($this->pickup === 'false' ? false : (bool)$this->pickup); 557 | } 558 | 559 | /** 560 | * @param string $value 561 | * @return $this 562 | */ 563 | public function setPickup($value) 564 | { 565 | $this->pickup = $value; 566 | 567 | return $this; 568 | } 569 | 570 | /** 571 | * @return bool|null 572 | */ 573 | public function getDelivery() 574 | { 575 | return $this->delivery === null ? null : ($this->delivery === 'false' ? false : (bool)$this->delivery); 576 | } 577 | 578 | /** 579 | * @param string $value 580 | * @return $this 581 | */ 582 | public function setDelivery($value) 583 | { 584 | $this->delivery = $value; 585 | 586 | return $this; 587 | } 588 | 589 | /** 590 | * @return Outlet[]|null 591 | */ 592 | public function getOutlets() 593 | { 594 | return $this->outlets ?: null; 595 | } 596 | 597 | /** 598 | * @param Outlet[] $value 599 | * @return $this 600 | */ 601 | public function setOutlets(array $value) 602 | { 603 | foreach ($value as $outlet) { 604 | $this->addOutlet($outlet); 605 | } 606 | 607 | return $this; 608 | } 609 | 610 | /** 611 | * @param Outlet $value 612 | * @return $this 613 | */ 614 | public function addOutlet(Outlet $value) 615 | { 616 | $this->outlets[] = $value; 617 | 618 | return $this; 619 | } 620 | 621 | /** 622 | * @return string|null 623 | */ 624 | public function getDescription() 625 | { 626 | return $this->description; 627 | } 628 | 629 | /** 630 | * @param string $value 631 | * @return $this 632 | */ 633 | public function setDescription($value) 634 | { 635 | $this->description = $value; 636 | 637 | return $this; 638 | } 639 | 640 | /** 641 | * @return string|null 642 | */ 643 | public function getSalesNotes() 644 | { 645 | return $this->salesNotes; 646 | } 647 | 648 | /** 649 | * @param string $value 650 | * @return $this 651 | */ 652 | public function setSalesNotes($value) 653 | { 654 | $this->salesNotes = $value; 655 | 656 | return $this; 657 | } 658 | 659 | /** 660 | * @return string|null 661 | */ 662 | public function getCountryOfOrigin() 663 | { 664 | return $this->countryOfOrigin; 665 | } 666 | 667 | /** 668 | * @param string $value 669 | * @return $this 670 | */ 671 | public function setCountryOfOrigin($value) 672 | { 673 | $this->countryOfOrigin = $value; 674 | 675 | return $this; 676 | } 677 | 678 | /** 679 | * @return string[]|null 680 | */ 681 | public function getBarcodes() 682 | { 683 | return $this->barcodes ?: null; 684 | } 685 | 686 | /*** 687 | * @param string[] $value 688 | * @return $this 689 | */ 690 | public function setBarcodes(array $value) 691 | { 692 | foreach ($value as $barcode) { 693 | $this->addBarcode($barcode); 694 | } 695 | 696 | return $this; 697 | } 698 | 699 | /** 700 | * @param string $value 701 | * @return $this 702 | */ 703 | public function addBarcode($value) 704 | { 705 | $this->barcodes[] = $value; 706 | 707 | return $this; 708 | } 709 | 710 | /** 711 | * @return bool|null 712 | */ 713 | public function getCpa() 714 | { 715 | return $this->cpa === null ? null : ($this->cpa === '1'); 716 | } 717 | 718 | /** 719 | * @param string $value 720 | * @return $this 721 | */ 722 | public function setCpa($value) 723 | { 724 | $this->cpa = $value; 725 | 726 | return $this; 727 | } 728 | 729 | /** 730 | * @return string|null 731 | */ 732 | public function getExpiry() 733 | { 734 | return $this->expiry; 735 | } 736 | 737 | /** 738 | * @param string $value 739 | * @return $this 740 | */ 741 | public function setExpiry($value) 742 | { 743 | $this->expiry = $value; 744 | 745 | return $this; 746 | } 747 | 748 | /** 749 | * @return float|null 750 | */ 751 | public function getWeight() 752 | { 753 | return $this->weight === null ? null : (float)$this->weight; 754 | } 755 | 756 | /** 757 | * @param string $value 758 | * @return $this 759 | */ 760 | public function setWeight($value) 761 | { 762 | $this->weight = $value; 763 | 764 | return $this; 765 | } 766 | 767 | /** 768 | * @return string|null 769 | */ 770 | public function getDimensions() 771 | { 772 | return $this->dimensions; 773 | } 774 | 775 | /** 776 | * @param string $value 777 | * @return $this 778 | */ 779 | public function setDimensions($value) 780 | { 781 | $this->dimensions = $value; 782 | 783 | return $this; 784 | } 785 | 786 | /** 787 | * @return Param[]|null 788 | */ 789 | public function getParams() 790 | { 791 | return $this->params ?: null; 792 | } 793 | 794 | /** 795 | * @param Param[] $value 796 | * @return $this 797 | */ 798 | public function setParams(array $value) 799 | { 800 | foreach ($value as $param) { 801 | $this->addParam($param); 802 | } 803 | 804 | return $this; 805 | } 806 | 807 | /** 808 | * @param Param $value 809 | * @return $this 810 | */ 811 | public function addParam(Param $value) 812 | { 813 | $this->params[] = $value; 814 | 815 | return $this; 816 | } 817 | } -------------------------------------------------------------------------------- /src/Offer/Age.php: -------------------------------------------------------------------------------- 1 | unit === null) { 29 | $this->addError("Age: missing required attribute 'unit'"); 30 | } elseif ($this->unit !== 'year' && $this->unit !== 'month') { 31 | $this->addError("Age: incorrect value in attribute 'unit'"); 32 | } 33 | 34 | if ($this->unit === 'year' && !in_array((string)$this->value, ['0', '6', '12', '16', '18'], true)) { 35 | $this->addError('Age: incorrect value'); 36 | } elseif ($this->unit === 'month' && !in_array((string)$this->value, ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12'], true)) { 37 | $this->addError('Age: incorrect value'); 38 | } 39 | 40 | 41 | return empty($this->errors); 42 | } 43 | 44 | /** 45 | * @param array $attributes 46 | * @return $this 47 | */ 48 | public function addAttributes($attributes) 49 | { 50 | foreach ($attributes as $name => $value) { 51 | $this->addField($name, $value); 52 | } 53 | 54 | return $this; 55 | } 56 | 57 | /** 58 | * @return string|null 59 | */ 60 | public function getUnit() 61 | { 62 | return $this->unit; 63 | } 64 | 65 | /** 66 | * @param string $value 67 | * @return $this 68 | */ 69 | public function setUnit($value) 70 | { 71 | $this->unit = $value; 72 | 73 | return $this; 74 | } 75 | 76 | /** 77 | * @return int|null 78 | */ 79 | public function getValue() 80 | { 81 | return $this->value === null ? null : (int)$this->value; 82 | } 83 | 84 | /** 85 | * @param string $value 86 | * @return $this 87 | */ 88 | public function setValue($value) 89 | { 90 | $this->value = $value; 91 | 92 | return $this; 93 | } 94 | } -------------------------------------------------------------------------------- /src/Offer/ArtistTitleOffer.php: -------------------------------------------------------------------------------- 1 | title === null) { 66 | $this->addError("Offer: missing required attribute 'title'"); 67 | } 68 | 69 | if ($this->year !== null && !is_numeric($this->year)) { 70 | $this->addError("Offer: incorrect value in attribute 'year'"); 71 | } 72 | 73 | return $isValid && empty($this->errors); 74 | } 75 | 76 | /** 77 | * @return string|null 78 | */ 79 | public function getArtist() 80 | { 81 | return $this->artist; 82 | } 83 | 84 | /** 85 | * @param string $value 86 | * @return $this 87 | */ 88 | public function setArtist($value) 89 | { 90 | $this->artist = $value; 91 | 92 | return $this; 93 | } 94 | 95 | /** 96 | * @return string|null 97 | */ 98 | public function getTitle() 99 | { 100 | return $this->title; 101 | } 102 | 103 | /** 104 | * @param string $value 105 | * @return $this 106 | */ 107 | public function setTitle($value) 108 | { 109 | $this->title = $value; 110 | 111 | return $this; 112 | } 113 | 114 | /** 115 | * @return int|null 116 | */ 117 | public function getYear() 118 | { 119 | return $this->year === null ? null : (int)$this->year; 120 | } 121 | 122 | /** 123 | * @param string $value 124 | * @return $this 125 | */ 126 | public function setYear($value) 127 | { 128 | $this->year = $value; 129 | 130 | return $this; 131 | } 132 | 133 | /** 134 | * @return string|null 135 | */ 136 | public function getMedia() 137 | { 138 | return $this->media; 139 | } 140 | 141 | /** 142 | * @param string $value 143 | * @return $this 144 | */ 145 | public function setMedia($value) 146 | { 147 | $this->media = $value; 148 | 149 | return $this; 150 | } 151 | 152 | /** 153 | * @return string|null 154 | */ 155 | public function getStarring() 156 | { 157 | return $this->starring; 158 | } 159 | 160 | /** 161 | * @param string $value 162 | * @return $this 163 | */ 164 | public function setStarring($value) 165 | { 166 | $this->starring = $value; 167 | 168 | return $this; 169 | } 170 | 171 | /** 172 | * @return string|null 173 | */ 174 | public function getDirector() 175 | { 176 | return $this->director; 177 | } 178 | 179 | /** 180 | * @param string $value 181 | * @return $this 182 | */ 183 | public function setDirector($value) 184 | { 185 | $this->director = $value; 186 | 187 | return $this; 188 | } 189 | 190 | /** 191 | * @return string|null 192 | */ 193 | public function getOriginalName() 194 | { 195 | return $this->originalName; 196 | } 197 | 198 | /** 199 | * @param string $value 200 | * @return $this 201 | */ 202 | public function setOriginalName($value) 203 | { 204 | $this->originalName = $value; 205 | 206 | return $this; 207 | } 208 | 209 | /** 210 | * @return string|null 211 | */ 212 | public function getCountry() 213 | { 214 | return $this->country; 215 | } 216 | 217 | /** 218 | * @param string $value 219 | * @return $this 220 | */ 221 | public function setCountry($value) 222 | { 223 | $this->country = $value; 224 | 225 | return $this; 226 | } 227 | } -------------------------------------------------------------------------------- /src/Offer/AudioBookOffer.php: -------------------------------------------------------------------------------- 1 | performedBy; 49 | } 50 | 51 | /** 52 | * @param string $value 53 | * @return $this 54 | */ 55 | public function setPerformedBy($value) 56 | { 57 | $this->performedBy = $value; 58 | 59 | return $this; 60 | } 61 | 62 | /** 63 | * @return string|null 64 | */ 65 | public function getPerformanceType() 66 | { 67 | return $this->performanceType; 68 | } 69 | 70 | /** 71 | * @param string $value 72 | * @return $this 73 | */ 74 | public function setPerformanceType($value) 75 | { 76 | $this->performanceType = $value; 77 | 78 | return $this; 79 | } 80 | 81 | /** 82 | * @return string|null 83 | */ 84 | public function getStorage() 85 | { 86 | return $this->storage; 87 | } 88 | 89 | /** 90 | * @param string $value 91 | * @return $this 92 | */ 93 | public function setStorage($value) 94 | { 95 | $this->storage = $value; 96 | 97 | return $this; 98 | } 99 | 100 | /** 101 | * @return string|null 102 | */ 103 | public function getFormat() 104 | { 105 | return $this->format; 106 | } 107 | 108 | /** 109 | * @param string $value 110 | * @return $this 111 | */ 112 | public function setFormat($value) 113 | { 114 | $this->format = $value; 115 | 116 | return $this; 117 | } 118 | 119 | /** 120 | * @return string|null 121 | */ 122 | public function getRecordingLength() 123 | { 124 | return $this->recordingLength; 125 | } 126 | 127 | /** 128 | * @param string $value 129 | * @return $this 130 | */ 131 | public function setRecordingLength($value) 132 | { 133 | $this->recordingLength = $value; 134 | 135 | return $this; 136 | } 137 | } -------------------------------------------------------------------------------- /src/Offer/BookOffer.php: -------------------------------------------------------------------------------- 1 | pageExtent !== null && (!is_numeric($this->pageExtent) || (int)$this->volume <= 0)) { 36 | $this->addError("Offer: incorrect value in attribute 'page_extent'"); 37 | } 38 | 39 | return $isValid && empty($this->errors); 40 | } 41 | 42 | /** 43 | * @return string|null 44 | */ 45 | public function getBinding() 46 | { 47 | return $this->binding; 48 | } 49 | 50 | /** 51 | * @param string $value 52 | * @return $this 53 | */ 54 | public function setBinding($value) 55 | { 56 | $this->binding = $value; 57 | 58 | return $this; 59 | } 60 | 61 | /** 62 | * @return int|null 63 | */ 64 | public function getPageExtent() 65 | { 66 | return $this->pageExtent === null ? null : (int)$this->pageExtent; 67 | } 68 | 69 | /** 70 | * @param string $value 71 | * @return $this 72 | */ 73 | public function setPageExtent($value) 74 | { 75 | $this->pageExtent = $value; 76 | 77 | return $this; 78 | } 79 | } -------------------------------------------------------------------------------- /src/Offer/EventTicketOffer.php: -------------------------------------------------------------------------------- 1 | name === null) { 61 | $this->addError("Offer: missing required attribute 'name'"); 62 | } 63 | 64 | if ($this->place === null) { 65 | $this->addError("Offer: missing required attribute 'place'"); 66 | } 67 | 68 | if ($this->date === null) { 69 | $this->addError("Offer: missing required attribute 'date'"); 70 | } 71 | 72 | if ($this->isPremiere !== null && $this->isPremiere !== '0' && $this->isPremiere !== '1') { 73 | $this->addError("Offer: incorrect value in attribute 'is_premiere'"); 74 | } 75 | 76 | if ($this->isKids !== null && $this->isKids !== '0' && $this->isKids !== '1') { 77 | $this->addError("Offer: incorrect value in attribute 'is_kids'"); 78 | } 79 | 80 | return $isValid && empty($this->errors); 81 | } 82 | 83 | /** 84 | * @return string|null 85 | */ 86 | public function getName() 87 | { 88 | return $this->name; 89 | } 90 | 91 | /** 92 | * @param string $value 93 | * @return $this 94 | */ 95 | public function setName($value) 96 | { 97 | $this->name = $value; 98 | 99 | return $this; 100 | } 101 | 102 | /** 103 | * @return string|null 104 | */ 105 | public function getPlace() 106 | { 107 | return $this->place; 108 | } 109 | 110 | /** 111 | * @param string $value 112 | * @return $this 113 | */ 114 | public function setPlace($value) 115 | { 116 | $this->place = $value; 117 | 118 | return $this; 119 | } 120 | 121 | /** 122 | * @return string|null 123 | */ 124 | public function getHall() 125 | { 126 | return $this->hall; 127 | } 128 | 129 | /** 130 | * @param string $value 131 | * @return $this 132 | */ 133 | public function setHall($value) 134 | { 135 | $this->hall = $value; 136 | 137 | return $this; 138 | } 139 | 140 | /** 141 | * @return string|null 142 | */ 143 | public function getHallPart() 144 | { 145 | return $this->hallPart; 146 | } 147 | 148 | /** 149 | * @param string $value 150 | * @return $this 151 | */ 152 | public function setHallPart($value) 153 | { 154 | $this->hallPart = $value; 155 | 156 | return $this; 157 | } 158 | 159 | /** 160 | * @return string|null 161 | */ 162 | public function getDate() 163 | { 164 | return $this->date; 165 | } 166 | 167 | /** 168 | * @param string $value 169 | * @return $this 170 | */ 171 | public function setDate($value) 172 | { 173 | $this->date = $value; 174 | 175 | return $this; 176 | } 177 | 178 | /** 179 | * @return bool|null 180 | */ 181 | public function getIsPremiere() 182 | { 183 | return $this->isPremiere === null ? null : (bool)$this->isPremiere; 184 | } 185 | 186 | /** 187 | * @param string $value 188 | * @return $this 189 | */ 190 | public function setIsPremiere($value) 191 | { 192 | $this->isPremiere = $value; 193 | 194 | return $this; 195 | } 196 | 197 | /** 198 | * @return bool|null 199 | */ 200 | public function getIsKids() 201 | { 202 | return $this->isKids === null ? null : (bool)$this->isKids; 203 | } 204 | 205 | /** 206 | * @param string $value 207 | * @return $this 208 | */ 209 | public function setIsKids($value) 210 | { 211 | $this->isKids = $value; 212 | 213 | return $this; 214 | } 215 | } -------------------------------------------------------------------------------- /src/Offer/MedicineOffer.php: -------------------------------------------------------------------------------- 1 | name === null) { 41 | $this->addError("Offer: missing required attribute 'name'"); 42 | } 43 | 44 | if ($this->delivery === null) { 45 | $this->addError("Offer: missing required attribute 'delivery'"); 46 | } elseif ($this->delivery !== 'false') { 47 | $this->addError("Offer: incorrect value in attribute 'delivery'"); 48 | } 49 | 50 | if ($this->pickup === null) { 51 | $this->addError("Offer: missing required attribute 'pickup'"); 52 | } elseif ($this->pickup !== 'true') { 53 | $this->addError("Offer: incorrect value in attribute 'pickup'"); 54 | } 55 | 56 | if ($this->cpa !== null && $this->cpa !== '0') { 57 | $this->addError("Offer: incorrect value in attribute 'cpa'"); 58 | } 59 | 60 | return $isValid && empty($this->errors); 61 | } 62 | 63 | /** 64 | * @return string|null 65 | */ 66 | public function getName() 67 | { 68 | return $this->name; 69 | } 70 | 71 | /** 72 | * @param string $value 73 | * @return $this 74 | */ 75 | public function setName($value) 76 | { 77 | $this->name = $value; 78 | 79 | return $this; 80 | } 81 | 82 | /** 83 | * @return string|null 84 | */ 85 | public function getVendor() 86 | { 87 | return $this->vendor; 88 | } 89 | 90 | /** 91 | * @param string $value 92 | * @return $this 93 | */ 94 | public function setVendor($value) 95 | { 96 | $this->vendor = $value; 97 | 98 | return $this; 99 | } 100 | 101 | /** 102 | * @return string|null 103 | */ 104 | public function getVendorCode() 105 | { 106 | return $this->vendorCode; 107 | } 108 | 109 | /** 110 | * @param string $value 111 | * @return $this 112 | */ 113 | public function setVendorCode($value) 114 | { 115 | $this->vendorCode = $value; 116 | 117 | return $this; 118 | } 119 | } -------------------------------------------------------------------------------- /src/Offer/Outlet.php: -------------------------------------------------------------------------------- 1 | id === null) { 37 | $this->addError("Outlet: missing required attribute 'id'"); 38 | } elseif (!$this->id) { 39 | $this->addError("Outlet: incorrect value in attribute 'id'"); 40 | } 41 | 42 | if ($this->instock !== null && (!is_numeric($this->instock) || (int)$this->instock < 0)) { 43 | $this->addError("Outlet: incorrect value in attribute 'instock'"); 44 | } 45 | 46 | if ($this->booking !== null && $this->booking !== 'true' && $this->booking !== 'false') { 47 | $this->addError("Outlet: incorrect value in attribute 'booking'"); 48 | } 49 | 50 | return empty($this->errors); 51 | } 52 | 53 | /** 54 | * @param array $attributes 55 | * @return $this 56 | */ 57 | public function addAttributes($attributes) 58 | { 59 | foreach ($attributes as $name => $value) { 60 | $this->addField($name, $value); 61 | } 62 | 63 | return $this; 64 | } 65 | 66 | /** 67 | * @return string|null //todo: int? 68 | */ 69 | public function getId() 70 | { 71 | return $this->id; 72 | } 73 | 74 | /** 75 | * @param string $value 76 | * @return $this 77 | */ 78 | public function setId($value) 79 | { 80 | $this->id = $value; 81 | 82 | return $this; 83 | } 84 | 85 | /** 86 | * @return int|null 87 | */ 88 | public function getInstock() 89 | { 90 | return $this->instock === null ? null : (int)$this->instock; 91 | } 92 | 93 | /** 94 | * @param string $value 95 | * @return $this 96 | */ 97 | public function setInstock($value) 98 | { 99 | $this->instock = $value; 100 | 101 | return $this; 102 | } 103 | 104 | /** 105 | * @return bool|null 106 | */ 107 | public function getBooking() 108 | { 109 | return $this->booking === null ? null : ($this->booking === 'false' ? false : (bool)$this->booking); 110 | } 111 | 112 | /** 113 | * @param string $value 114 | * @return $this 115 | */ 116 | public function setBooking($value) 117 | { 118 | $this->booking = $value; 119 | 120 | return $this; 121 | } 122 | } -------------------------------------------------------------------------------- /src/Offer/Param.php: -------------------------------------------------------------------------------- 1 | name === null) { 35 | $this->addError("Param: missing required attribute 'name'"); 36 | } elseif (!$this->name) { 37 | $this->addError("Param: incorrect value in attribute 'name'"); 38 | } 39 | 40 | if (!$this->value) { 41 | $this->addError('Param: incorrect value'); 42 | } 43 | 44 | return empty($this->errors); 45 | } 46 | 47 | /** 48 | * @param array $attributes 49 | * @return $this 50 | */ 51 | public function addAttributes($attributes) 52 | { 53 | foreach ($attributes as $name => $value) { 54 | $this->addField($name, $value); 55 | } 56 | 57 | return $this; 58 | } 59 | 60 | /** 61 | * @return string|null 62 | */ 63 | public function getName() 64 | { 65 | return $this->name; 66 | } 67 | 68 | /** 69 | * @param string $value 70 | * @return $this 71 | */ 72 | public function setName($value) 73 | { 74 | $this->name = $value; 75 | 76 | return $this; 77 | } 78 | 79 | /** 80 | * @return string|null 81 | */ 82 | public function getUnit() 83 | { 84 | return $this->unit; 85 | } 86 | 87 | /** 88 | * @param string $value 89 | * @return $this 90 | */ 91 | public function setUnit($value) 92 | { 93 | $this->unit = $value; 94 | 95 | return $this; 96 | } 97 | 98 | /** 99 | * @return string|null 100 | */ 101 | public function getValue() 102 | { 103 | return $this->value; 104 | } 105 | 106 | /** 107 | * @param string $value 108 | * @return $this 109 | */ 110 | public function setValue($value) 111 | { 112 | $this->value = $value; 113 | 114 | return $this; 115 | } 116 | } -------------------------------------------------------------------------------- /src/Offer/SimpleOffer.php: -------------------------------------------------------------------------------- 1 | name === null) { 31 | $this->addError("Offer: missing required attribute 'name'"); 32 | } 33 | 34 | return $isValid && empty($this->errors); 35 | } 36 | 37 | /** 38 | * @return string|null 39 | */ 40 | public function getName() 41 | { 42 | return $this->name; 43 | } 44 | 45 | /** 46 | * @param string $value 47 | * @return $this 48 | */ 49 | public function setName($value) 50 | { 51 | $this->name = $value; 52 | 53 | return $this; 54 | } 55 | } -------------------------------------------------------------------------------- /src/Offer/TourOffer.php: -------------------------------------------------------------------------------- 1 | name === null) { 98 | $this->addError("Offer: missing required attribute 'name'"); 99 | } 100 | if ($this->days === null) { 101 | $this->addError("Offer: missing required attribute 'days'"); 102 | } elseif (!is_numeric($this->days) || (int)$this->days <= 0) { 103 | $this->addError("Offer: incorrect value in attribute 'days'"); 104 | } 105 | 106 | if ($this->included === null) { 107 | $this->addError("Offer: missing required attribute 'included'"); 108 | } 109 | 110 | if ($this->transport === null) { 111 | $this->addError("Offer: missing required attribute 'transport'"); 112 | } 113 | 114 | if ($this->priceMin !== null && (!is_numeric($this->priceMin) || (float)$this->priceMin <= 0)) { 115 | $this->addError("Offer: incorrect value in attribute 'price_min'"); 116 | } 117 | 118 | if ($this->priceMax !== null && (!is_numeric($this->priceMax) || ((float)$this->priceMax <= 0 119 | || ($this->priceMin !== null && (float)$this->priceMin >= (float)$this->priceMax))) 120 | ) { 121 | $this->addError("Offer: incorrect value in attribute 'price_max'"); 122 | } 123 | 124 | return $isValid && empty($this->errors); 125 | } 126 | 127 | /** 128 | * @param array $attrNode 129 | * @return $this 130 | */ 131 | public function addAttribute(array $attrNode) 132 | { 133 | if ($attrNode['name'] === 'dataTour') { 134 | $this->addDataTour($attrNode['value']); 135 | } else { 136 | parent::addAttribute($attrNode); 137 | } 138 | 139 | return $this; 140 | } 141 | 142 | /** 143 | * @return string|null 144 | */ 145 | public function getWorldRegion() 146 | { 147 | return $this->worldRegion; 148 | } 149 | 150 | /** 151 | * @param string $value 152 | * @return $this 153 | */ 154 | public function setWorldRegion($value) 155 | { 156 | $this->worldRegion = $value; 157 | 158 | return $this; 159 | } 160 | 161 | /** 162 | * @return string|null 163 | */ 164 | public function getCountry() 165 | { 166 | return $this->country; 167 | } 168 | 169 | /** 170 | * @param string $value 171 | * @return $this 172 | */ 173 | public function setCountry($value) 174 | { 175 | $this->country = $value; 176 | 177 | return $this; 178 | } 179 | 180 | /** 181 | * @return string|null 182 | */ 183 | public function getRegion() 184 | { 185 | return $this->region; 186 | } 187 | 188 | /** 189 | * @param string $value 190 | * @return $this 191 | */ 192 | public function setRegion($value) 193 | { 194 | $this->region = $value; 195 | 196 | return $this; 197 | } 198 | 199 | /** 200 | * @return int|null 201 | */ 202 | public function getDays() 203 | { 204 | return $this->days === null ? null : (int)$this->days; 205 | } 206 | 207 | /** 208 | * @param string $value 209 | * @return $this 210 | */ 211 | public function setDays($value) 212 | { 213 | $this->days = $value; 214 | 215 | return $this; 216 | } 217 | 218 | /** 219 | * @return string[]|null 220 | */ 221 | public function getDataTours() 222 | { 223 | return $this->dataTours ?: null; 224 | } 225 | 226 | /** 227 | * @param string[] $value 228 | * @return $this 229 | */ 230 | public function setDataTours(array $value) 231 | { 232 | foreach ($value as $dataTour) { 233 | $this->addDataTour($dataTour); 234 | } 235 | 236 | return $this; 237 | } 238 | 239 | /** 240 | * @param string $value 241 | * @return $this 242 | */ 243 | public function addDataTour($value) 244 | { 245 | $this->dataTours[] = $value; 246 | 247 | return $this; 248 | } 249 | 250 | /** 251 | * @return string|null 252 | */ 253 | public function getName() 254 | { 255 | return $this->name; 256 | } 257 | 258 | /** 259 | * @param string $value 260 | * @return $this 261 | */ 262 | public function setName($value) 263 | { 264 | $this->name = $value; 265 | 266 | return $this; 267 | } 268 | 269 | /** 270 | * @return string|null 271 | */ 272 | public function getHotelStars() 273 | { 274 | return $this->hotelStars; 275 | } 276 | 277 | /** 278 | * @param string $value 279 | * @return $this 280 | */ 281 | public function setHotelStars($value) 282 | { 283 | $this->hotelStars = $value; 284 | 285 | return $this; 286 | } 287 | 288 | /** 289 | * @return string|null 290 | */ 291 | public function getRoom() 292 | { 293 | return $this->room; 294 | } 295 | 296 | /** 297 | * @param string $value 298 | * @return $this 299 | */ 300 | public function setRoom($value) 301 | { 302 | $this->room = $value; 303 | 304 | return $this; 305 | } 306 | 307 | /** 308 | * @return string|null 309 | */ 310 | public function getMeal() 311 | { 312 | return $this->meal; 313 | } 314 | 315 | /** 316 | * @param string $value 317 | * @return $this 318 | */ 319 | public function setMeal($value) 320 | { 321 | $this->meal = $value; 322 | 323 | return $this; 324 | } 325 | 326 | /** 327 | * @return string|null 328 | */ 329 | public function getIncluded() 330 | { 331 | return $this->included; 332 | } 333 | 334 | /** 335 | * @param string $value 336 | * @return $this 337 | */ 338 | public function setIncluded($value) 339 | { 340 | $this->included = $value; 341 | 342 | return $this; 343 | } 344 | 345 | /** 346 | * @return string|null 347 | */ 348 | public function getTransport() 349 | { 350 | return $this->transport; 351 | } 352 | 353 | /** 354 | * @param string $value 355 | * @return $this 356 | */ 357 | public function setTransport($value) 358 | { 359 | $this->transport = $value; 360 | 361 | return $this; 362 | } 363 | 364 | /** 365 | * @return float|null 366 | */ 367 | public function getPriceMin() 368 | { 369 | return $this->priceMin === null ? null : (float)$this->priceMin; 370 | } 371 | 372 | /** 373 | * @param string $value 374 | * @return $this 375 | */ 376 | public function setPriceMin($value) 377 | { 378 | $this->priceMin = $value; 379 | 380 | return $this; 381 | } 382 | 383 | /** 384 | * @return float|null 385 | */ 386 | public function getPriceMax() 387 | { 388 | return $this->priceMax === null ? null : (float)$this->priceMax; 389 | } 390 | 391 | /** 392 | * @param string $value 393 | * @return $this 394 | */ 395 | public function setPriceMax($value) 396 | { 397 | $this->priceMax = $value; 398 | 399 | return $this; 400 | } 401 | 402 | /** 403 | * @return string|null 404 | */ 405 | public function getOptions() 406 | { 407 | return $this->options; 408 | } 409 | 410 | /** 411 | * @param string $value 412 | * @return $this 413 | */ 414 | public function setOptions($value) 415 | { 416 | $this->options = $value; 417 | 418 | return $this; 419 | } 420 | } -------------------------------------------------------------------------------- /src/Offer/VendorModelOffer.php: -------------------------------------------------------------------------------- 1 | model === null) { 31 | $this->addError("Offer: missing required attribute 'model'"); 32 | } 33 | if ($this->vendor === null) { 34 | $this->addError("Offer: missing required attribute 'vendor'"); 35 | } 36 | 37 | return $isValid && empty($this->errors); 38 | } 39 | 40 | /** 41 | * @return string|null 42 | */ 43 | public function getTypePrefix() 44 | { 45 | return $this->typePrefix; 46 | } 47 | 48 | /** 49 | * @param string $value 50 | * @return $this 51 | */ 52 | public function setTypePrefix($value) 53 | { 54 | $this->typePrefix = $value; 55 | 56 | return $this; 57 | } 58 | } -------------------------------------------------------------------------------- /src/Shop.php: -------------------------------------------------------------------------------- 1 | offersCount === 0) { 102 | $this->addError('Shop: no offers'); 103 | } 104 | 105 | 106 | if ($this->name === null) { 107 | $this->addError("Shop: missing required attribute 'name'"); 108 | } elseif (!$this->name) { 109 | $this->addError("Shop: incorrect value in attribute 'name'"); 110 | } 111 | 112 | if ($this->company === null) { 113 | $this->addError("Shop: missing required attribute 'company'"); 114 | } elseif (!$this->company) { 115 | $this->addError("Shop: incorrect value in attribute 'company'"); 116 | } 117 | 118 | if ($this->url === null) { 119 | $this->addError("Shop: missing required attribute 'url'"); 120 | } elseif (!$this->url) { 121 | $this->addError("Shop: incorrect value in attribute 'url'"); 122 | } 123 | 124 | if (!$this->currencies) { 125 | $this->addError("Shop: missing required attribute 'currencies'"); 126 | } 127 | 128 | if (!$this->categories) { 129 | $this->addError("Shop: missing required attribute 'categories'"); 130 | } 131 | 132 | 133 | if ($this->localDeliveryCost !== null && (!is_numeric($this->localDeliveryCost) || ((int)$this->localDeliveryCost) < 0)) { 134 | $this->addError("Shop: incorrect value in attribute 'local_delivery_cost'"); 135 | } 136 | 137 | 138 | $subIsValid = true; 139 | if ($this->currencies) { 140 | foreach ($this->currencies as $currency) { 141 | if (!$currency->isValid()) { 142 | $subIsValid = false; 143 | } 144 | } 145 | } 146 | if ($this->categories) { 147 | foreach ($this->categories as $category) { 148 | if (!$category->isValid()) { 149 | $subIsValid = false; 150 | } 151 | } 152 | } 153 | if ($this->deliveryOptions) { 154 | foreach ($this->deliveryOptions as $deliveryOption) { 155 | if (!$deliveryOption->isValid()) { 156 | $subIsValid = false; 157 | } 158 | } 159 | } 160 | 161 | return empty($this->errors) && $subIsValid; 162 | } 163 | 164 | /** 165 | * @return array 166 | */ 167 | public function getErrors() 168 | { 169 | $errors[] = $this->errors; 170 | 171 | if ($this->currencies) { 172 | foreach ($this->currencies as $currency) { 173 | $errors[] = $currency->getErrors(); 174 | } 175 | } 176 | if ($this->categories) { 177 | foreach ($this->categories as $category) { 178 | $errors[] = $category->getErrors(); 179 | } 180 | } 181 | if ($this->deliveryOptions) { 182 | foreach ($this->deliveryOptions as $deliveryOption) { 183 | $errors[] = $deliveryOption->getErrors(); 184 | } 185 | } 186 | 187 | $errors = count($errors) > 1 ? call_user_func_array('array_merge', $errors) : $errors[0]; 188 | 189 | return $errors; 190 | } 191 | 192 | /** 193 | * @param array $shopNode 194 | * @return $this 195 | */ 196 | public function fillShop(array $shopNode) 197 | { 198 | foreach ($shopNode['nodes'] as $attrNode) { 199 | $this->addAttribute($attrNode); 200 | } 201 | 202 | return $this; 203 | } 204 | 205 | /** 206 | * @param array $attrNode 207 | * @return $this 208 | */ 209 | public function addAttribute(array $attrNode) 210 | { 211 | if ($attrNode['name'] === 'currencies') { 212 | foreach ($attrNode['nodes'] as $subNode) { 213 | $this->addCurrency((new Currency())->addAttributes($subNode['attributes'])); 214 | } 215 | } elseif ($attrNode['name'] === 'categories') { 216 | foreach ($attrNode['nodes'] as $subNode) { 217 | $this->addCategory((new Category())->addAttributes($subNode['attributes'] + ['name' => $subNode['value']])); 218 | } 219 | } elseif ($attrNode['name'] === 'delivery-options') { 220 | foreach ($attrNode['nodes'] as $subNode) { 221 | $this->addDeliveryOption((new DeliveryOption())->addAttributes($subNode['attributes'])); 222 | } 223 | } else { 224 | if (null !== $attrNode['value']) { 225 | $this->addField($attrNode['name'], $attrNode['value']); 226 | } 227 | if (!empty($attrNode['attributes'])) { 228 | foreach ($attrNode['attributes'] as $name => $value) { 229 | $this->addField($name, $value); 230 | } 231 | } 232 | } 233 | 234 | return $this; 235 | } 236 | 237 | /** 238 | * @return array 239 | */ 240 | public function getData() 241 | { 242 | $data = $this->toArray(); 243 | unset($data['errors'], $data['offersCount']); 244 | 245 | return $data; 246 | } 247 | 248 | /** 249 | * @return string|null 250 | */ 251 | public function getName() 252 | { 253 | return $this->name; 254 | } 255 | 256 | /** 257 | * @param string $value 258 | * @return $this 259 | */ 260 | public function setName($value) 261 | { 262 | $this->name = $value; 263 | 264 | return $this; 265 | } 266 | 267 | /** 268 | * @return string|null 269 | */ 270 | public function getCompany() 271 | { 272 | return $this->company; 273 | } 274 | 275 | /** 276 | * @param string $value 277 | * @return $this 278 | */ 279 | public function setCompany($value) 280 | { 281 | $this->company = $value; 282 | 283 | return $this; 284 | } 285 | 286 | /** 287 | * @return string|null 288 | */ 289 | public function getUrl() 290 | { 291 | return $this->url; 292 | } 293 | 294 | /** 295 | * @param string $value 296 | * @return $this 297 | */ 298 | public function setUrl($value) 299 | { 300 | $this->url = $value; 301 | 302 | return $this; 303 | } 304 | 305 | /** 306 | * @return string|null 307 | */ 308 | public function getPlatform() 309 | { 310 | return $this->platform; 311 | } 312 | 313 | /** 314 | * @param string $value 315 | * @return $this 316 | */ 317 | public function setPlatform($value) 318 | { 319 | $this->platform = $value; 320 | return $this; 321 | } 322 | 323 | /** 324 | * @return string|null 325 | */ 326 | public function getVersion() 327 | { 328 | return $this->version; 329 | } 330 | 331 | /** 332 | * @param string $value 333 | * @return $this 334 | */ 335 | public function setVersion($value) 336 | { 337 | $this->version = $value; 338 | return $this; 339 | } 340 | 341 | /** 342 | * @return string|null 343 | */ 344 | public function getAgency() 345 | { 346 | return $this->agency; 347 | } 348 | 349 | /** 350 | * @param string $value 351 | * @return $this 352 | */ 353 | public function setAgency($value) 354 | { 355 | $this->agency = $value; 356 | return $this; 357 | } 358 | 359 | /** 360 | * @return string|null 361 | */ 362 | public function getEmail() 363 | { 364 | return $this->email; 365 | } 366 | 367 | /** 368 | * @param string $value 369 | * @return $this 370 | */ 371 | public function setEmail($value) 372 | { 373 | $this->email = $value; 374 | return $this; 375 | } 376 | 377 | /** 378 | * @return string 379 | */ 380 | public function getPhone() 381 | { 382 | return $this->phone; 383 | } 384 | 385 | /** 386 | * @param string $phone 387 | * @return $this 388 | */ 389 | public function setPhone($phone) 390 | { 391 | $this->phone = $phone; 392 | return $this; 393 | } 394 | 395 | /** 396 | * @param string $id 397 | * @return Currency|null 398 | */ 399 | public function getCurrency($id) 400 | { 401 | return array_key_exists($id, $this->currencies) ? $this->currencies[$id] : null; 402 | } 403 | 404 | /** 405 | * @return Currency[]|null 406 | */ 407 | public function getCurrencies() 408 | { 409 | return $this->currencies ?: null; 410 | } 411 | 412 | /** 413 | * @param Currency[] $value 414 | * @return $this 415 | */ 416 | public function setCurrencies(array $value) 417 | { 418 | foreach ($value as $currency) { 419 | $this->addCurrency($currency); 420 | } 421 | 422 | return $this; 423 | } 424 | 425 | /** 426 | * @param Currency $value 427 | * @return $this 428 | */ 429 | public function addCurrency(Currency $value) 430 | { 431 | $this->currencies[$value->getId()] = $value; 432 | 433 | return $this; 434 | } 435 | 436 | /** 437 | * @param string $id 438 | * @return Category|null 439 | */ 440 | public function getCategory($id) 441 | { 442 | return array_key_exists($id, $this->categories) ? $this->categories[$id] : null; 443 | } 444 | 445 | /** 446 | * @param string $id 447 | * @return Category|null 448 | */ 449 | public function getCategoryParent($id) 450 | { 451 | if (array_key_exists($id, $this->categories) 452 | && null !== ($parentId = $this->categories[$id]->getParentId()) 453 | && array_key_exists($parentId, $this->categories) 454 | ) { 455 | return $this->categories[$parentId]; 456 | } 457 | 458 | return null; 459 | } 460 | 461 | /** 462 | * @param string $id 463 | * @return Category[]|null 464 | */ 465 | public function getCategoryHierarchy($id) 466 | { 467 | $parents = []; 468 | $ids = []; 469 | 470 | if (array_key_exists($id, $this->categories)) { 471 | $parents[] = $this->categories[$id]; 472 | $pid = $id; 473 | $ids[] = $pid; 474 | 475 | while (null !== $parent = $this->getCategoryParent($pid)) { 476 | $pid = $parent->getId(); 477 | 478 | if (in_array($pid, $ids, true)) { 479 | break; 480 | } 481 | $ids[] = $pid; 482 | array_unshift($parents, $parent); 483 | } 484 | } 485 | 486 | return $parents; 487 | } 488 | 489 | /** 490 | * @return Category[]|null 491 | */ 492 | public function getCategories() 493 | { 494 | return $this->categories ?: null; 495 | } 496 | 497 | /** 498 | * @param Category[] $value 499 | * @return $this 500 | */ 501 | public function setCategories(array $value) 502 | { 503 | foreach ($value as $category) { 504 | $this->addCategory($category); 505 | } 506 | 507 | return $this; 508 | } 509 | 510 | /** 511 | * @param Category $value 512 | * @return $this 513 | */ 514 | public function addCategory(Category $value) 515 | { 516 | $this->categories[$value->getId()] = $value; 517 | 518 | return $this; 519 | } 520 | 521 | /** 522 | * @return DeliveryOption[]|null 523 | */ 524 | public function getDeliveryOptions() 525 | { 526 | return $this->deliveryOptions ?: null; 527 | } 528 | 529 | /** 530 | * @param DeliveryOption[] $value 531 | * @return $this 532 | */ 533 | public function setDeliveryOptions(array $value) 534 | { 535 | foreach ($value as $deliveryOption) { 536 | $this->addDeliveryOption($deliveryOption); 537 | } 538 | 539 | return $this; 540 | } 541 | 542 | /** 543 | * @param DeliveryOption $value 544 | * @return $this 545 | */ 546 | public function addDeliveryOption(DeliveryOption $value) 547 | { 548 | $this->deliveryOptions[] = $value; 549 | 550 | return $this; 551 | } 552 | 553 | /** 554 | * @return int|null 555 | */ 556 | public function getLocalDeliveryCost() 557 | { 558 | return $this->localDeliveryCost === null ? null : (int)$this->localDeliveryCost; 559 | } 560 | 561 | /** 562 | * @param string $value 563 | * @return $this 564 | */ 565 | public function setLocalDeliveryCost($value) 566 | { 567 | $this->localDeliveryCost = $value; 568 | 569 | return $this; 570 | } 571 | 572 | /** 573 | * @return bool|null 574 | */ 575 | public function getCpa() 576 | { 577 | return $this->cpa === null ? null : ($this->cpa === '1'); 578 | } 579 | 580 | /** 581 | * @param string $value 582 | * @return $this 583 | */ 584 | public function setCpa($value) 585 | { 586 | $this->cpa = $value; 587 | 588 | return $this; 589 | } 590 | 591 | /** 592 | * @return int 593 | */ 594 | public function getOffersCount() 595 | { 596 | return $this->offersCount; 597 | } 598 | 599 | /** 600 | * @param int $value 601 | * @return $this 602 | */ 603 | public function setOffersCount($value) 604 | { 605 | $this->offersCount = (int)$value; 606 | 607 | return $this; 608 | } 609 | } -------------------------------------------------------------------------------- /src/TError.php: -------------------------------------------------------------------------------- 1 | toArray(); 18 | unset($data['errors']); 19 | 20 | return $data; 21 | } 22 | 23 | /** 24 | * @return array 25 | */ 26 | public function getErrors() 27 | { 28 | return $this->errors; 29 | } 30 | 31 | /** 32 | * @param $errorMessage 33 | */ 34 | protected function addError($errorMessage) 35 | { 36 | $this->errors[] = $errorMessage; 37 | } 38 | } -------------------------------------------------------------------------------- /src/TYML.php: -------------------------------------------------------------------------------- 1 | $setter($value); 21 | } 22 | 23 | return $this; 24 | } 25 | 26 | /** 27 | * @return array 28 | */ 29 | protected function toArray() 30 | { 31 | $array = []; 32 | 33 | foreach ($this as $key => $value) { 34 | if (is_object($value) && method_exists($value, 'getData')) { 35 | $array[$key] = $value->getData(); 36 | } elseif (is_array($value)) { 37 | if (!empty($value)) { 38 | $array[$key] = $this->getArray($value); 39 | } 40 | } else { 41 | $getter = 'get' . $key; 42 | if (method_exists($this, $getter)) { 43 | $getValue = $this->$getter(); 44 | if ($getValue !== null) { 45 | $array[$key] = $getValue; 46 | } 47 | } elseif ($value !== null) { 48 | $array[$key] = $value; 49 | } 50 | } 51 | } 52 | 53 | return $array; 54 | } 55 | 56 | /** 57 | * @param array $value 58 | * @return array 59 | */ 60 | protected function getArray($value) 61 | { 62 | $subArray = []; 63 | 64 | foreach ($value as $subKey => $subValue) { 65 | if (is_object($subValue) && method_exists($subValue, 'getData')) { 66 | $subArray[$subKey] = $subValue->getData(); 67 | } elseif (is_array($subValue)) { 68 | $subArray[$subKey] = $this->getArray($subValue); 69 | } else { 70 | $getter = 'get' . $subKey; 71 | if (method_exists($this, $getter)) { 72 | $getValue = $this->$getter(); 73 | if ($getValue !== null) { 74 | $subArray[$subKey] = $getValue; 75 | } 76 | } elseif ($subValue !== null) { 77 | $subArray[$subKey] = $subValue; 78 | } 79 | } 80 | } 81 | 82 | return $subArray; 83 | } 84 | } -------------------------------------------------------------------------------- /src/YML.php: -------------------------------------------------------------------------------- 1 | XMLReader = new \XMLReader(); 58 | } 59 | 60 | /** 61 | * @param string $uri 62 | * @param string|bool $schema 63 | * @throws \Exception 64 | */ 65 | public function parse($uri, $schema = true) 66 | { 67 | $this->uri = $uri; 68 | if ($schema === true) { 69 | $this->schema = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'yml.xsd'; 70 | } elseif (is_string($schema)) { 71 | $this->schema = $schema; 72 | } 73 | 74 | $this->open(); 75 | 76 | while ($this->read()) { 77 | if ($this->path === 'yml_catalog') { 78 | $this->date = $this->XMLReader->getAttribute('date'); 79 | while ($this->read()) { 80 | if ($this->path === 'yml_catalog/shop') { 81 | $this->shop = $this->parseShop(); 82 | break; 83 | } 84 | } 85 | break; 86 | } 87 | } 88 | 89 | $this->close(); 90 | } 91 | 92 | /** 93 | * @return string 94 | */ 95 | public function getDate() 96 | { 97 | return $this->date; 98 | } 99 | 100 | /** 101 | * @return Shop 102 | */ 103 | public function getShop() 104 | { 105 | return $this->shop; 106 | } 107 | 108 | /** 109 | * @return \Generator|SimpleOffer[]|VendorModelOffer[]|BookOffer[]|AudioBookOffer[]|ArtistTitleOffer[]|MedicineOffer[]|EventTicketOffer[]|TourOffer[] 110 | * @throws \Exception 111 | */ 112 | public function getOffers() 113 | { 114 | $this->open(); 115 | 116 | while ($this->read()) { 117 | if ($this->path === 'yml_catalog/shop/offers') { 118 | while ($this->read()) { 119 | if ($this->path === 'yml_catalog/shop/offers/offer') { 120 | yield $this->parseOffer(); 121 | } elseif ($this->path === 'yml_catalog/shop') { 122 | break; 123 | } 124 | } 125 | break; 126 | } 127 | } 128 | 129 | $this->close(); 130 | } 131 | 132 | /** 133 | * @return Shop 134 | * @throws \Exception 135 | */ 136 | protected function parseShop() 137 | { 138 | $xml = $this->XMLReader; 139 | $shop = new Shop(); 140 | $nodes = []; 141 | 142 | while ($this->read()) { 143 | if ($this->path === 'yml_catalog/shop/offers') { 144 | $shop->setOffersCount($this->parseOffersCount()); 145 | } elseif ($xml->nodeType === \XMLReader::ELEMENT) { 146 | $nodes[] = $this->parseNode('yml_catalog/shop'); 147 | } elseif ($this->path === 'yml_catalog') { 148 | break; 149 | } 150 | } 151 | 152 | $shop->fillShop(['name' => 'shop', 'attributes' => [], 'value' => null, 'nodes' => $nodes]); 153 | 154 | return $shop; 155 | } 156 | 157 | /** 158 | * @return SimpleOffer|VendorModelOffer|BookOffer|AudioBookOffer|ArtistTitleOffer|MedicineOffer|EventTicketOffer|TourOffer 159 | * @throws \Exception 160 | */ 161 | protected function parseOffer() 162 | { 163 | $offerNode = $this->parseNode('yml_catalog/shop/offers'); 164 | 165 | $type = isset($offerNode['attributes']['type']) ? $offerNode['attributes']['type'] : null; 166 | return $this->createOffer($type)->fillOffer($offerNode); 167 | 168 | } 169 | 170 | /** 171 | * @param string $basePath 172 | * @return array 173 | * @throws \Exception 174 | */ 175 | protected function parseNode($basePath) 176 | { 177 | $xml = $this->XMLReader; 178 | $name = $xml->name; 179 | $path = $basePath . '/' . $name; 180 | $value = ''; 181 | $nodes = []; 182 | $isEmpty = $xml->isEmptyElement; 183 | 184 | $attributes = $this->parseAttributes(); 185 | 186 | if (!$isEmpty) { 187 | while ($this->read()) { 188 | if ($xml->nodeType === \XMLReader::ELEMENT) { 189 | $nodes[] = $this->parseNode($path); 190 | } elseif (($xml->nodeType === \XMLReader::TEXT || $xml->nodeType === \XMLReader::CDATA) && $xml->hasValue) { 191 | $value .= $xml->value; 192 | } elseif ($this->path === $basePath) { 193 | break; 194 | } 195 | } 196 | } 197 | $value = trim($value) ?: null; 198 | 199 | return ['name' => $name, 'attributes' => $attributes, 'value' => $value, 'nodes' => $nodes]; 200 | } 201 | 202 | /** 203 | * @return array 204 | */ 205 | protected function parseAttributes() 206 | { 207 | $xml = $this->XMLReader; 208 | $attributes = []; 209 | 210 | if ($xml->hasAttributes) { 211 | while ($xml->moveToNextAttribute()) { 212 | $attributes[$xml->name] = $xml->value; 213 | } 214 | } 215 | 216 | return $attributes; 217 | } 218 | 219 | /** 220 | * @return int 221 | * @throws \Exception 222 | */ 223 | protected function parseOffersCount() 224 | { 225 | $xml = $this->XMLReader; 226 | $count = 0; 227 | 228 | while ($this->read()) { 229 | if ($this->path === 'yml_catalog/shop/offers/offer') { 230 | $count++; 231 | break; 232 | } 233 | } 234 | 235 | while ($xml->next($xml->localName)) { 236 | $count++; 237 | } 238 | 239 | return $count; 240 | } 241 | 242 | /** 243 | * @throws FileNotFoundException 244 | */ 245 | protected function open() 246 | { 247 | $uri = (string)$this->uri; 248 | if (!$this->XMLReader->open($uri)) { 249 | throw new FileNotFoundException("Failed to open XML file '{$uri}'"); 250 | } 251 | 252 | if (!empty($this->schema)) { 253 | $schema = $this->schema; 254 | if (!$this->XMLReader->setSchema($schema)) { 255 | throw new FileNotFoundException("Failed to open XML Schema file '{$schema}'"); 256 | } 257 | } 258 | } 259 | 260 | protected function close() 261 | { 262 | $this->pathArr = []; 263 | $this->path = ''; 264 | $this->XMLReader->close(); 265 | } 266 | 267 | /** 268 | * @return bool 269 | * @throws \Exception 270 | */ 271 | protected function read() 272 | { 273 | $xml = $this->XMLReader; 274 | 275 | if ($xml->read()) { 276 | if ($xml->nodeType === \XMLReader::ELEMENT && !$xml->isEmptyElement) { 277 | $this->pathArr[] = $xml->name; 278 | $this->path = implode('/', $this->pathArr); 279 | } elseif ($xml->nodeType === \XMLReader::END_ELEMENT) { 280 | array_pop($this->pathArr); 281 | $this->path = implode('/', $this->pathArr); 282 | } 283 | return true; 284 | } 285 | 286 | return false; 287 | } 288 | 289 | /** 290 | * @param $type 291 | * @return SimpleOffer|VendorModelOffer|BookOffer|AudioBookOffer|ArtistTitleOffer|MedicineOffer|EventTicketOffer|TourOffer 292 | */ 293 | protected function createOffer($type) 294 | { 295 | switch ($type) { 296 | case 'vendor.model': 297 | return new VendorModelOffer(); 298 | case 'book': 299 | return new BookOffer(); 300 | case 'audiobook': 301 | return new AudioBookOffer(); 302 | case 'artist.title': 303 | return new ArtistTitleOffer(); 304 | case 'medicine': 305 | return new MedicineOffer(); 306 | case 'event-ticket': 307 | return new EventTicketOffer(); 308 | case 'tour': 309 | return new TourOffer(); 310 | default: 311 | return new SimpleOffer(); 312 | } 313 | } 314 | } -------------------------------------------------------------------------------- /yml.xsd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | --------------------------------------------------------------------------------