Skip to content

Commit

Permalink
Pass data importer to list builder
Browse files Browse the repository at this point in the history
  • Loading branch information
umpirsky committed Jan 4, 2016
1 parent d691e77 commit d11beea
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 84 deletions.
1 change: 1 addition & 0 deletions bin/build
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
include __DIR__ . '/../vendor/autoload.php';

(new Umpirsky\Country\Builder\Builder(
new Umpirsky\Country\Importer\Source\Country(),
__DIR__.'/../data'
))->run();
40 changes: 19 additions & 21 deletions src/Umpirsky/Country/Builder/Build.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Filesystem\Filesystem;
use Umpirsky\Country\Exporter\Iterator as ExporterIterator;
use Umpirsky\Country\Importer\Iterator as ImporterIterator;
use Umpirsky\Country\Importer\ImporterInterface;

class Build extends Command
{
Expand All @@ -31,18 +31,19 @@ class Build extends Command
protected $exporterIterator;

/**
* @var ImporterIterator
* @var ImporterInterface
*/
protected $importerIterator;
protected $importer;

/**
* @param string $path base path to build files
* @param ImporterInterface $importer
* @param string $path base path to build files
*/
public function __construct($path)
public function __construct(ImporterInterface $importer, $path)
{
parent::__construct('build');
$this->exporterIterator = new ExporterIterator();
$this->importerIterator = new ImporterIterator();
$this->importer = $importer;
$this->path = $path;
}

Expand All @@ -68,22 +69,19 @@ protected function execute(InputInterface $input, OutputInterface $output)
$this->filesystem = new Filesystem();
$this->filesystem->mkdir($this->path);

$verbose = $input->getOption('verbose');
foreach ($this->importerIterator as $importer) {
$this->filesystem->mkdir($importerDir = $this->path.'/'.$importer->getSource());
foreach ($importer->getLanguages() as $language) {
if (null === $input->getArgument('language') || $input->getArgument('language') === $language) {
$this->filesystem->mkdir($exporterDir = $importerDir.'/'.$language);
$data = $importer->getData($language);
$this->filesystem->mkdir($importerDir = $this->path.'/'.$this->importer->getSource());
foreach ($this->importer->getLanguages() as $language) {
if (null === $input->getArgument('language') || $input->getArgument('language') === $language) {
$this->filesystem->mkdir($exporterDir = $importerDir.'/'.$language);
$data = $this->importer->getData($language);

foreach ($this->exporterIterator as $exporter) {
if (null === $input->getArgument('format') || $input->getArgument('format') === $exporter->getFormat()) {
$file = $exporterDir.'/'.$importer->getSource().'.'.$exporter->getFormat();
$this->filesystem->touch($file);
file_put_contents($file, $exporter->export($data));
if ($verbose) {
$output->write('<info>[file+]</info> '.$file.PHP_EOL);
}
foreach ($this->exporterIterator as $exporter) {
if (null === $input->getArgument('format') || $input->getArgument('format') === $exporter->getFormat()) {
$file = $exporterDir.'/'.$this->importer->getSource().'.'.$exporter->getFormat();
$this->filesystem->touch($file);
file_put_contents($file, $exporter->export($data));
if ($input->getOption('verbose')) {
$output->write('<info>[file+]</info> '.$file.PHP_EOL);
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/Umpirsky/Country/Builder/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
namespace Umpirsky\Country\Builder;

use Symfony\Component\Console\Application;
use Umpirsky\Country\Importer\ImporterInterface;

class Builder extends Application
{
public function __construct($path)
public function __construct(ImporterInterface $importer, $path)
{
parent::__construct('List builder');

$this->add($build = new Build($path));
$this->add($build = new Build($importer, $path));
$this->setDefaultCommand($build->getName());
}
}
61 changes: 0 additions & 61 deletions src/Umpirsky/Country/Importer/Iterator.php

This file was deleted.

0 comments on commit d11beea

Please sign in to comment.