2017 © Pedro Peláez
 

library ymlparser

Parser for yml(yandex.market.ru) files

image

serkin/ymlparser

Parser for yml(yandex.market.ru) files

  • Monday, April 4, 2016
  • by serkin
  • Repository
  • 2 Watchers
  • 8 Stars
  • 334 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 1 Open issues
  • 4 Versions
  • 16 % Grown

The README.md

YML Parser

Parser for yml(yandex.market.ru) files., (*1)

Build Status Coverage Status Scrutinizer Code Quality Latest Stable Version Total Downloads Latest Unstable Version License, (*2)

YMLParser out of box uses two types of parsing: * XMLReader - for medium and large xml files * SimpleXML - for small xml files, (*3)

## Installation

via Composer:, (*4)

composer require serkin/ymlparser ~1.1

## Usage

Getting all offers from file

include 'vendor/autoload.php';

$filename = '/path/to/file/file.xml';

//   XMLReader driver - for medium and large xml files
//   SimpleXML driver - for small xml files

$parser = new \YMLParser\YMLParser(new \YMLParser\Driver\XMLReader);
$parser->open($filename); // throws \Exception if $filename doesn't exist or empty
foreach($parser->getOffers() as $offer): // YMLParser::getOffers() returns \Generator
    echo $offer['url'];
endforeach;

Getting all offers from file with applied filter

YMLParser::getOffers() can take filter function as an argument. Filter should be an anonymous function which returns true or false, (*5)

include 'vendor/autoload.php';

$filename = '/path/to/file/file.xml';

$parser = new \YMLParser\YMLParser(new \YMLParser\Driver\SimpleXML);
$parser->open($filename);

// We want offers only with not empty url subelements
$filter = function($element) { return !empty($element['url']); }; 
$offers = iterator_to_array($parser->getOffers($filter));

// Let's get all params from first offer if they are exist
foreach($offers[0]['params'] as $param):
    echo $param['name'] . ' - ' . $param['value'];
endforeach;

Dependencies

  • PHP: >= 5.5
  • xmlrpc extension
  • mbstring extension

Contribution

  • Send a pull request

Licence

  • MIT

TODO

  • getCurrencies()
  • setDefaultCurrency()
  • Offers price according set defaultCurrency

Tests

phpunit

It is extensible

You can create your own Driver. All you have to do is to implement YMLParser\Driver\DriverInterface interface in your class, (*6)

The Versions

04/04 2016

dev-master

9999999-dev https://github.com/serkin/ymlparser

Parser for yml(yandex.market.ru) files

  Sources   Download

MIT

The Requires

  • php >=5.5
  • ext-xmlrpc *
  • ext-mbstring *

 

The Development Requires

yml yandex

02/06 2015

dev-develop

dev-develop https://github.com/serkin/ymlparser

Parser for yml(yandex.market.ru) files

  Sources   Download

MIT

The Requires

  • php >=5.5
  • ext-xmlrpc *
  • ext-mbstring *

 

The Development Requires

yml yandex

30/04 2015

v1.1.2

1.1.2.0 https://github.com/serkin/ymlparser

Parser for yml(yandex.market.ru) files

  Sources   Download

MIT

The Requires

  • php >=5.5
  • ext-xmlrpc *
  • ext-mbstring *

 

The Development Requires

yml yandex

29/04 2015

v1.1.1

1.1.1.0 https://github.com/serkin/ymlparser

Parser for yml(yandex.market.ru) files

  Sources   Download

MIT

The Requires

  • php >=5.5
  • ext-xmlrpc *

 

The Development Requires

yml yandex