Skip to content

Commit

Permalink
Merge pull request #26 from chives/dev
Browse files Browse the repository at this point in the history
Upgrade dependencies, require symfony ^3.4, fixtures bundle ^3.1, allow symfony ^4.0
  • Loading branch information
rn0 authored Mar 19, 2019
2 parents c4de20d + 9c47b97 commit 7f087f7
Show file tree
Hide file tree
Showing 51 changed files with 287 additions and 72 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ sudo: false

matrix:
include:
- php: 7.0
- php: 7.1
env: COMPOSER_FLAGS='--prefer-lowest --prefer-stable'
- php: 7.0
- php: 7.3

before_install:
- composer self-update
Expand Down
11 changes: 9 additions & 2 deletions Behat/Context/CommandContext.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
<?php

/**
* (c) FSi sp. z o.o. <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace FSi\Bundle\TerytDatabaseBundle\Behat\Context;

use Behat\Symfony2Extension\Context\KernelAwareContext;
use FSi\Bundle\TerytDatabaseBundle\Behat\Context\Console\ApplicationTester;
use Guzzle\Http\Message\Response;
use Guzzle\Plugin\Mock\MockPlugin;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\HttpKernel\KernelInterface;

Expand Down
9 changes: 9 additions & 0 deletions Behat/Context/Console/ApplicationTester.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?php

/**
* (c) FSi sp. z o.o. <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace FSi\Bundle\TerytDatabaseBundle\Behat\Context\Console;

use Symfony\Bundle\FrameworkBundle\Console\Application;
Expand Down
11 changes: 10 additions & 1 deletion Behat/Context/DataContext.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?php

/**
* (c) FSi sp. z o.o. <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace FSi\Bundle\TerytDatabaseBundle\Behat\Context;

use Behat\Behat\Hook\Scope\BeforeScenarioScope;
Expand Down Expand Up @@ -294,4 +303,4 @@ protected function findPlaceByName($name)
->getRepository('FSiTerytDbBundle:Place')
->findOneByName($name);
}
}
}
9 changes: 9 additions & 0 deletions Behat/Context/DownloadTerytCommandContext.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?php

/**
* (c) FSi sp. z o.o. <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace FSi\Bundle\TerytDatabaseBundle\Behat\Context;

use Behat\Symfony2Extension\Context\KernelAwareContext;
Expand Down
12 changes: 10 additions & 2 deletions Behat/Context/ImportTerytCommandContext.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
<?php

/**
* (c) FSi sp. z o.o. <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace FSi\Bundle\TerytDatabaseBundle\Behat\Context;

use Behat\Gherkin\Node\PyStringNode;
use Behat\Gherkin\Node\TableNode;
use Behat\Symfony2Extension\Context\KernelAwareContext;
use Behat\Symfony2Extension\Context\KernelAwareInterface;
use Symfony\Component\HttpKernel\KernelInterface;

class ImportTerytCommandContext implements KernelAwareContext
Expand Down Expand Up @@ -291,4 +299,4 @@ private function getStreetRepository()
->getManager()
->getRepository('FSiTerytDbBundle:Street');
}
}
}
9 changes: 9 additions & 0 deletions Behat/Fixtures/Project/app/AppKernel.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?php

/**
* (c) FSi sp. z o.o. <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;

Expand Down
36 changes: 28 additions & 8 deletions Command/TerytDownloadCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,52 @@
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace FSi\Bundle\TerytDatabaseBundle\Command;

use FSi\Bundle\TerytDatabaseBundle\Teryt\Api\Client;
use SplTempFileObject;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Filesystem\Filesystem;

abstract class TerytDownloadCommand extends ContainerAwareCommand
abstract class TerytDownloadCommand extends Command
{
protected function getDefaultTargetPath()
/**
* @var Client
*/
private $client;

/**
* @var string
*/
private $rootDir;

public function __construct(Client $client, string $rootDir)
{
parent::__construct();

$this->client = $client;
$this->rootDir = $rootDir;
}

protected function getDefaultTargetPath(): string
{
return $this->getContainer()->getParameter('kernel.root_dir') . '/teryt';
return $this->rootDir . '/teryt';
}

protected function getApiClient() : Client
protected function getApiClient(): Client
{
return $this->getContainer()->get('fsi_teryt_db.api_client');
return $this->client;
}

protected function saveFile(SplTempFileObject $file, string $path, string $fileName)
protected function saveFile(SplTempFileObject $file, string $path, string $fileName): void
{
$filesystem = new Filesystem();
$filesystem->dumpFile(sprintf('%s/%s', $path, $fileName), $file->fread($this->getFileSize($file)));
}

private function getFileSize(SplTempFileObject $file) : int
private function getFileSize(SplTempFileObject $file): int
{
$file->fseek(0, SEEK_END);
$size = $file->ftell();
Expand Down
6 changes: 4 additions & 2 deletions Command/TerytDownloadPlacesDatabaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace FSi\Bundle\TerytDatabaseBundle\Command;

use Symfony\Component\Console\Input\InputArgument;
Expand All @@ -15,7 +17,7 @@

class TerytDownloadPlacesDatabaseCommand extends TerytDownloadCommand
{
protected function configure()
protected function configure(): void
{
$this->setName('teryt:download:places')
->setDescription('Download teryt places (SIMC) database files')
Expand All @@ -32,7 +34,7 @@ protected function configure()
);
}

protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): void
{
$this->saveFile(
$this->getApiClient()->getPlacesData(),
Expand Down
6 changes: 4 additions & 2 deletions Command/TerytDownloadPlacesDictionaryDatabaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace FSi\Bundle\TerytDatabaseBundle\Command;

use Symfony\Component\Console\Input\InputArgument;
Expand All @@ -15,7 +17,7 @@

class TerytDownloadPlacesDictionaryDatabaseCommand extends TerytDownloadCommand
{
protected function configure()
protected function configure(): void
{
$this->setName('teryt:download:places-dictionary')
->setDescription('Download teryt places dictionary (WMRODZ) database files')
Expand All @@ -32,7 +34,7 @@ protected function configure()
);
}

protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): void
{
$this->saveFile(
$this->getApiClient()->getPlacesDictionaryData(),
Expand Down
6 changes: 4 additions & 2 deletions Command/TerytDownloadStreetsDatabaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace FSi\Bundle\TerytDatabaseBundle\Command;

use Symfony\Component\Console\Input\InputArgument;
Expand All @@ -15,7 +17,7 @@

class TerytDownloadStreetsDatabaseCommand extends TerytDownloadCommand
{
protected function configure()
protected function configure(): void
{
$this->setName('teryt:download:streets')
->setDescription('Download teryt streets database files')
Expand All @@ -32,7 +34,7 @@ protected function configure()
);
}

protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): void
{
$this->saveFile(
$this->getApiClient()->getStreetsData(),
Expand Down
6 changes: 4 additions & 2 deletions Command/TerytDownloadTerritorialDivisionDatabaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace FSi\Bundle\TerytDatabaseBundle\Command;

use Symfony\Component\Console\Input\InputArgument;
Expand All @@ -15,7 +17,7 @@

class TerytDownloadTerritorialDivisionDatabaseCommand extends TerytDownloadCommand
{
protected function configure()
protected function configure(): void
{
$this->setName('teryt:download:territorial-division')
->setDescription('Download teryt territorial division (TERC) database files')
Expand All @@ -32,7 +34,7 @@ protected function configure()
);
}

protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): void
{
$this->saveFile(
$this->getApiClient()->getTerritorialDivisionData(),
Expand Down
28 changes: 20 additions & 8 deletions Command/TerytImportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,28 @@
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace FSi\Bundle\TerytDatabaseBundle\Command;

use Doctrine\Common\Persistence\ManagerRegistry;
use Doctrine\Common\Persistence\ObjectManager;
use Hobnob\XmlStreamReader\Parser;
use SimpleXMLElement;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

abstract class TerytImportCommand extends ContainerAwareCommand
abstract class TerytImportCommand extends Command
{
const FLUSH_FREQUENCY = 2000;

/**
* @var ManagerRegistry
*/
private $managerRegistry;

/** @var resource */
protected $handle;

Expand All @@ -29,11 +37,18 @@ abstract class TerytImportCommand extends ContainerAwareCommand
*/
private $progressBar;

public function __construct(ManagerRegistry $managerRegistry)
{
parent::__construct();

$this->managerRegistry = $managerRegistry;
}

private $recordsCount = 0;

/**
* @param SimpleXMLElement $node
* @param \Doctrine\Common\Persistence\ObjectManager $om
* @param ObjectManager $om
* @return \FSi\Bundle\TerytDatabaseBundle\Teryt\Import\NodeConverter
*/
abstract public function getNodeConverter(SimpleXMLElement $node, ObjectManager $om);
Expand Down Expand Up @@ -135,11 +150,8 @@ private function importXmlFile(Parser $xmlParser, $xmlFile)
fclose($this->handle);
}

/**
* @return ObjectManager
*/
private function getObjectManager()
private function getObjectManager(): ObjectManager
{
return $this->getContainer()->get('doctrine')->getManager();
return $this->managerRegistry->getManager();
}
}
2 changes: 2 additions & 0 deletions Command/TerytImportPlacesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace FSi\Bundle\TerytDatabaseBundle\Command;

use Doctrine\Common\Persistence\ObjectManager;
Expand Down
2 changes: 2 additions & 0 deletions Command/TerytImportPlacesDictionaryCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace FSi\Bundle\TerytDatabaseBundle\Command;

use Doctrine\Common\Persistence\ObjectManager;
Expand Down
2 changes: 2 additions & 0 deletions Command/TerytImportStreetsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace FSi\Bundle\TerytDatabaseBundle\Command;

use Doctrine\Common\Persistence\ObjectManager;
Expand Down
2 changes: 2 additions & 0 deletions Command/TerytImportTerritorialDivisionCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace FSi\Bundle\TerytDatabaseBundle\Command;

use Doctrine\Common\Persistence\ObjectManager;
Expand Down
Loading

0 comments on commit 7f087f7

Please sign in to comment.