Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
lireincore committed Sep 2, 2016
0 parents commit dcc442b
Show file tree
Hide file tree
Showing 21 changed files with 3,282 additions and 0 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2016 LireinCore

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# YML (Yandex Market Language) parser

[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE)

## About

[YML (Yandex Market Language)](https://yandex.ru/support/partnermarket/yml/about-yml.xml) parser for PHP.

## Install

Add the `lireincore/ymlparser` package to your `require` section in the `composer.json` file.

``` bash
$ composer require lireincore/ymlparser
```

## Usage

```php
use LireinCore\YMLParser\YML;

$yml = new YML();
$yml->parse($filepath);
$date = $yml->getDate();
$shop = $yml->getShop();
/**@var \LireinCore\YMLParser\Offer\AOffer $offer*/
foreach ($yml->getOffers() as $offer) {
//...
}
```

## Testing

``` bash
$ phpunit
```

## License

The MIT License (MIT). Please see [License File](LICENSE) for more information.
30 changes: 30 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "lireincore/ymlparser",
"type": "library",
"description": "YML (Yandex Market Language) parser",
"keywords": ["yml", "parser", "yandex", "market"],
"homepage": "https://github.com/lireincore/ymlparser",
"license": "MIT",
"authors": [
{
"name": "LireinCore",
"email": "[email protected]"
}
],
"require": {
"php": ">=5.4"
},
"require-dev": {
"phpunit/phpunit": ">=4.0"
},
"autoload": {
"psr-4": {
"LireinCore\\YMLParser\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"LireinCore\\YMLParser\\Test\\": "tests"
}
}
}
92 changes: 92 additions & 0 deletions example.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?xml version="1.0" encoding="windows-1251"?>
<yml_catalog date="2016-02-05 17:22">
<shop>
<name>ABC</name>
<company>ABC inc.</company>
<url>http://www.abc.ru/</url>

<currencies>
<currency id="RUR" rate="1"/>
<currency id="USD" rate="80"/>
</currencies>

<categories>
<category id="1278">Ýëåêòðîíèêà</category>
<category id="3761" parentId="1278">Òåëåâèçîðû</category>
<category id="1553" parentId="3761">Ìåäèà-ïëååðû</category>
<category id="3798">Áûòîâàÿ òåõíèêà</category>
<category id="1293" parentId="3798">Õîëîäèëüíèêè</category>
</categories>

<delivery-options>
<option cost="500" days="0" order-before="15"/>
<option cost="300" days="1-3"/>
</delivery-options>

<cpa>1</cpa>

<offers>
<offer id="158" available="true" bid="23" cbid="43">
<url>http://www.abc.ru/158.html</url>
<price from="true">55690</price>
<currencyId>RUR</currencyId>
<categoryId>1293</categoryId>
<picture>http://www.abc.ru/1580.jpg</picture>
<picture>http://www.abc.ru/1581.jpg</picture>
<picture>http://www.abc.ru/1582.jpg</picture>
<picture>http://www.abc.ru/1583.jpg</picture>
<store>false</store>
<delivery>true</delivery>
<name>Ñìàðòôîí Apple iPhone 6s 128gb Space Gray</name>
<vendor>Apple</vendor>
<model>iPhone 6s 128gb Space Gray</model>
<description>Îïèñàíèå òîâàðà 1</description>
<sales_notes>Íåîáõîäèìà ïðåäîïëàòà 50%</sales_notes>
<barcode>7564756475648</barcode>
<age unit="month">0</age>
<manufacturer_warranty>false</manufacturer_warranty>
<param name="Òèï">ìîíîáëîê</param>
<param name="Ìàòåðèàë">àëþìèíèé</param>
<param name="Wi-Fi" unit="">åñòü</param>
<param name="Ðàçìåð ýêðàíà" unit="äþéì">27</param>
<param name="Ðàçìåð îïåðàòèâíîé ïàìÿòè" unit="Ìá">4096</param>
<param name="Îáú¸ì æåñòêîãî äèñêà" unit="Òá">1</param>
<param name="Âåñ" unit="êã">13.8</param>
</offer>

<offer id="159" available="true" cbid="35">
<url>http://www.abc.ru/159.html</url>
<price>3045.5</price>
<currencyId>RUR</currencyId>
<categoryId>1293</categoryId>
<picture>http://www.abc.ru/1590.jpg</picture>
<picture>http://www.abc.ru/1591.jpg</picture>
<store>false</store>
<delivery>true</delivery>
<name>Íàóøíèêè Koss Sporta Pro</name>
<vendor>Koss</vendor>
<model>Sporta Pro</model>
<description>Îïèñàíèå òîâàðà</description>
<sales_notes>Ïîêóïêà â äåíü çàêàçà</sales_notes>
<cpa>0</cpa>
<delivery-options>
<option cost="1000" days="1" order-before="15"/>
</delivery-options>
<outlets>
<outlet id="2" instock="50" booking="true"/>
<outlet id="3" instock="100" booking="false"/>
</outlets>
<barcode>7564756475648</barcode>
<age>0</age>
<manufacturer_warranty>true</manufacturer_warranty>
<param name="Òèï">12344</param>
<param name="Ìàòåðèàë">asdfgadfg</param>
<param name="Wi-Fi" unit="">àãà</param>
<param name="Ðàçìåð ýêðàíà" unit="äþéì">27</param>
<param name="Ðàçìåð îïåðàòèâíîé ïàìÿòè" unit="Ìá">4096</param>
<param name="Îáú¸ì æåñòêîãî äèñêà" unit="Òá">1</param>
<param name="Âåñ" unit="êã">13.8</param>
</offer>
</offers>
</shop>
</yml_catalog>
94 changes: 94 additions & 0 deletions src/Category.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php

namespace LireinCore\YMLParser;

class Category
{
/**
* @var int
*/
protected $id;

/**
* @var int
*/
protected $parentId;

/**
* @var string
*/
protected $name;

/**
* @param array $attributes
* @return $this
*/
public function setAttributes($attributes)
{
foreach ($attributes as $name => $value) {
$setter = 'set' . str_replace(['-', '_'], '', $name);
if (method_exists($this, $setter)) {
$this->$setter($value);
}
}

return $this;
}

/**
* @return int
*/
public function getId()
{
return $this->id;
}

/**
* @param int $value
* @return $this
*/
public function setId($value)
{
$this->id = (int)$value;

return $this;
}

/**
* @return int
*/
public function getParentId()
{
return $this->parentId;
}

/**
* @param int $value
* @return $this
*/
public function setParentId($value)
{
$this->parentId = (int)$value;

return $this;
}

/**
* @return string
*/
public function getName()
{
return $this->name;
}

/**
* @param string $value
* @return $this
*/
public function setName($value)
{
$this->name = (string)$value;

return $this;
}
}
107 changes: 107 additions & 0 deletions src/Currency.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?php

namespace LireinCore\YMLParser;

class Currency
{
const CURRENCY_RUR = 'RUR';
const CURRENCY_RUB = 'RUB';
const CURRENCY_UAH = 'UAH';
const CURRENCY_BYN = 'BYN';
const CURRENCY_KZT = 'KZT';
const CURRENCY_USD = 'USD';
const CURRENCY_EUR = 'EUR';

const EXCHANGE_RATE_CBRF = 'CBRF';
const EXCHANGE_RATE_NBU = 'NBU';
const EXCHANGE_RATE_NBK = 'NBK';
const EXCHANGE_RATE_CB = 'CB';

/**
* @var string
*/
protected $id;

/**
* @var float|string
*/
protected $rate;

/**
* @var int
*/
protected $plus = 0;

/**
* @param array $attributes
* @return $this
*/
public function setAttributes($attributes)
{
foreach ($attributes as $name => $value) {
$setter = 'set' . str_replace(['-', '_'], '', $name);
if (method_exists($this, $setter)) {
$this->$setter($value);
}
}

return $this;
}

/**
* @return string
*/
public function getId()
{
return $this->id;
}

/**
* @param string $value
* @return $this
*/
public function setId($value)
{
$this->id = (string)$value;

return $this;
}

/**
* @return float|string
*/
public function getRate()
{
return $this->rate;
}

/**
* @param float|string $value
* @return $this
*/
public function setRate($value)
{
$this->rate = is_numeric($value) ? (float)$value : (string)$value;

return $this;
}

/**
* @return int
*/
public function getPlus()
{
return $this->plus;
}

/**
* @param int $value
* @return $this
*/
public function setPlus($value)
{
$this->plus = (int)$value;

return $this;
}
}
Loading

0 comments on commit dcc442b

Please sign in to comment.