Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@

namespace Sirian\YMLParser;

use Sirian\YMLParser\Factory\Factory;
use Sirian\YMLParser\Builder\BuilderInterface;
use Sirian\YMLParser\Factory\FactoryInterface;
use Sirian\YMLParser\Offer\Offer;
use Sirian\YMLParser\Storage\StorageInterface;

class Builder
class Builder implements BuilderInterface
{
/**
* @var Factory
* @var FactoryInterface
*/
private $factory;

/**
* @var Storage
* @var StorageInterface
*/
private $storage;

Expand All @@ -22,7 +24,7 @@ class Builder
*/
private $shop;

public function __construct(Factory $factory, Storage $storage)
public function __construct(FactoryInterface $factory, StorageInterface $storage)
{
$this->factory = $factory;
$this->storage = $storage;
Expand All @@ -37,7 +39,7 @@ public function getShop()
}

/**
* @return Offer[]
* @return \Generator|Offer[]
*/
public function getOffers()
{
Expand Down
19 changes: 19 additions & 0 deletions src/Builder/BuilderInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Sirian\YMLParser\Builder;

use Sirian\YMLParser\Offer\Offer;
use Sirian\YMLParser\Shop;

interface BuilderInterface
{
/**
* @return Shop
*/
public function getShop();

/**
* @return \Generator|Offer[]
*/
public function getOffers();
}
15 changes: 14 additions & 1 deletion src/Factory/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@

namespace Sirian\YMLParser\Factory;

use Sirian\YMLParser\Builder;
use Sirian\YMLParser\Category;
use Sirian\YMLParser\Currency;
use Sirian\YMLParser\Offer\BookOffer;
use Sirian\YMLParser\Offer\Offer;
use Sirian\YMLParser\Offer\VendorModelOffer;
use Sirian\YMLParser\Param;
use Sirian\YMLParser\Shop;
use Sirian\YMLParser\Storage;
use Sirian\YMLParser\Storage\StorageInterface;

class Factory
class Factory implements FactoryInterface
{
public function createParam()
{
Expand Down Expand Up @@ -42,4 +45,14 @@ public function createOffer($type)
return new Offer();
}
}

public function createStorage()
{
return new Storage();
}

public function createBuilder(StorageInterface $storage)
{
return new Builder($this, $storage);
}
}
47 changes: 47 additions & 0 deletions src/Factory/FactoryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace Sirian\YMLParser\Factory;

use Sirian\YMLParser\Builder\BuilderInterface;
use Sirian\YMLParser\Category;
use Sirian\YMLParser\Currency;
use Sirian\YMLParser\Offer\Offer;
use Sirian\YMLParser\Param;
use Sirian\YMLParser\Storage\StorageInterface;

interface FactoryInterface
{
/**
* @return Param
*/
public function createParam();

public function createShop();

/**
* @return Category
*/
public function createCategory();

/**
* @return Currency
*/
public function createCurrency();

/**
* @param $type
* @return Offer
*/
public function createOffer($type);

/**
* @return StorageInterface
*/
public function createStorage();

/**
* @param StorageInterface $storage
* @return BuilderInterface
*/
public function createBuilder(StorageInterface $storage);
}
15 changes: 10 additions & 5 deletions src/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

namespace Sirian\YMLParser;

use Sirian\YMLParser\Builder\BuilderInterface;
use Sirian\YMLParser\Exception\YMLException;
use Sirian\YMLParser\Factory\Factory;
use Sirian\YMLParser\Factory\FactoryInterface;

class Parser
{
Expand All @@ -12,7 +14,7 @@ class Parser

private $path = [];

public function __construct(Factory $factory = null)
public function __construct(FactoryInterface $factory = null)
{
if (null == $factory) {
$factory = new Factory();
Expand All @@ -22,6 +24,11 @@ public function __construct(Factory $factory = null)
$this->factory = $factory;
}

/**
* @param $file
* @return BuilderInterface
* @throws YMLException
*/
public function parse($file)
{
$this->path = [];
Expand All @@ -45,7 +52,7 @@ protected function read()
throw new YMLException('Invalid YML file');
}

$storage = new Storage();
$storage = $this->factory->createStorage();

do {
if ('yml_catalog/shop/offers' == $this->getPath()) {
Expand All @@ -63,11 +70,9 @@ protected function read()

$storage->setShopXML($shopXML);

return new Builder($this->factory, $storage);
return $this->factory->createBuilder($storage);
}



private function moveToShop()
{
$xml = $this->xmlReader;
Expand Down
4 changes: 3 additions & 1 deletion src/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Sirian\YMLParser;

class Storage
use Sirian\YMLParser\Storage\StorageInterface;

class Storage implements StorageInterface
{
protected $file;

Expand Down
13 changes: 13 additions & 0 deletions src/Storage/StorageInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Sirian\YMLParser\Storage;


interface StorageInterface
{
public function setShopXML($shopXML);
public function getShopXML();
public function addOfferXML($xml);
public function getNextOfferXML();
public function getOffersCount();
}