Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Inject the service locator instance into all SL-aware fixtures on add #30

Closed
wants to merge 4 commits into from
Closed
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
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hounddog/doctrine-data-fixture-module",
"description": "Zend Framework 2 Module that provides Doctrine Data-Fixture functionality",
"name": "ontario/doctrine-data-fixture-module",
"description": "Zend Framework 2 Module that provides Doctrine Data-Fixture with Fixteres SL injection functionality",
"type": "library",
"license": "MIT",
"keywords": [
Expand All @@ -9,11 +9,11 @@
"module",
"zf2"
],
"homepage": "http://www.doctrine-project.org/",
"homepage": "http://www.ontario.pp.ua/",
"authors": [
{
"name": "Martin Shwalbe",
"email": "martin.shwalbe@gmail.com"
"name": "Yuriy V. Yukhimenko",
"email": "netmorpheusua@gmail.com"
}
],
"require": {
Expand Down
41 changes: 26 additions & 15 deletions src/DoctrineDataFixtureModule/Command/ImportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@
use Symfony\Component\Console\Input\InputOption;
use Doctrine\ORM\Tools\SchemaTool;
use Doctrine\DBAL\Migrations\Configuration\Configuration;
use DoctrineDataFixtureModule\Loader\ServiceLocatorAwareLoader as Loader;
use Doctrine\Common\DataFixtures\Executor\ORMExecutor;
use Doctrine\Common\DataFixtures\Purger\ORMPurger;
use DoctrineDataFixtureModule\Loader\ServiceLocatorAwareLoader;
use Zend\ServiceManager\ServiceLocatorAwareInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

/**
Expand All @@ -40,25 +41,15 @@
* @since 2.0
* @author Jonathan Wage <jonwage@gmail.com>
*/
class ImportCommand extends Command
class ImportCommand extends Command implements ServiceLocatorAwareInterface
{
protected $paths;

protected $em;

/**
* Service Locator instance
* @var Zend\ServiceManager\ServiceLocatorInterface
*/
protected $serviceLocator;

protected $sl;

const PURGE_MODE_TRUNCATE = 2;

public function __construct(ServiceLocatorInterface $serviceLocator)
{
$this->serviceLocator = $serviceLocator;
parent::__construct();
}

protected function configure()
{
Expand All @@ -77,7 +68,7 @@ protected function configure()

public function execute(InputInterface $input, OutputInterface $output)
{
$loader = new ServiceLocatorAwareLoader($this->serviceLocator);
$loader = new Loader($this->sl);
$purger = new ORMPurger();

if ($input->getOption('purge-with-truncate')) {
Expand All @@ -101,4 +92,24 @@ public function setEntityManager($em)
{
$this->em = $em;
}

/**
* Set service locator
*
* @param ServiceLocatorInterface $serviceLocator
*/
public function setServiceLocator(ServiceLocatorInterface $serviceLocator)
{
$this->sl = $serviceLocator;
}

/**
* Get service locator
*
* @return ServiceLocatorInterface
*/
public function getServiceLocator()
{
return $this->sl;
}
}
5 changes: 3 additions & 2 deletions src/DoctrineDataFixtureModule/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,14 @@ public function init(ModuleManager $e)
/* @var $cli \Symfony\Component\Console\Application */
$cli = $e->getTarget();

/* @var $sm ServiceLocatorInterface */
/* @var $sm \Zend\ServiceManager\ServiceLocatorInterface */
$sm = $e->getParam('ServiceManager');
$em = $sm->get('doctrine.entitymanager.orm_default');
$paths = $sm->get('doctrine.configuration.fixtures');

$importCommand = new ImportCommand($sm);
$importCommand = new ImportCommand();
$importCommand->setEntityManager($em);
$importCommand->setServiceLocator($sm);
$importCommand->setPath($paths);
ConsoleRunner::addCommands($cli);
$cli->addCommands(array(
Expand Down