|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace DoctrineDataFixtureModule; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\ORM\EntityManager; |
|
6
|
|
|
use Symfony\Component\Console\Application; |
|
7
|
|
|
use Zend\ModuleManager\Feature\AutoloaderProviderInterface; |
|
8
|
|
|
use Zend\ModuleManager\Feature\ServiceProviderInterface; |
|
9
|
|
|
use Zend\ModuleManager\Feature\ConfigProviderInterface; |
|
10
|
|
|
use Zend\EventManager\EventInterface; |
|
11
|
|
|
use Zend\ModuleManager\ModuleManager; |
|
12
|
|
|
use Doctrine\ORM\Tools\Console\ConsoleRunner; |
|
13
|
|
|
use DoctrineDataFixtureModule\Command\ImportCommand; |
|
14
|
|
|
use DoctrineDataFixtureModule\Service\FixtureFactory; |
|
15
|
|
|
use Zend\ServiceManager\ServiceLocatorInterface; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Base module for Doctrine Data Fixture. |
|
19
|
|
|
* |
|
20
|
|
|
* @license MIT |
|
21
|
|
|
* @link www.doctrine-project.org |
|
22
|
|
|
* @author Martin Shwalbe <[email protected]>s |
|
23
|
|
|
* @author Rob van der Lee <[email protected]> |
|
24
|
|
|
*/ |
|
25
|
|
|
class Module implements |
|
26
|
|
|
AutoloaderProviderInterface, |
|
27
|
|
|
ServiceProviderInterface, |
|
28
|
|
|
ConfigProviderInterface |
|
29
|
|
|
{ |
|
30
|
|
|
/** |
|
31
|
|
|
* @var ModuleManager |
|
32
|
|
|
*/ |
|
33
|
|
|
protected $moduleManager; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @param ModuleManager $e |
|
37
|
|
|
*/ |
|
38
|
|
|
public function init(ModuleManager $e) |
|
39
|
|
|
{ |
|
40
|
|
|
$events = $e->getEventManager()->getSharedManager(); |
|
41
|
|
|
|
|
42
|
|
|
// Attach to helper set event and load the entity manager helper. |
|
43
|
|
|
$events->attach('doctrine', 'loadCli.post', function (EventInterface $e) { |
|
44
|
|
|
/* @var $cli Application */ |
|
45
|
|
|
$cli = $e->getTarget(); |
|
46
|
|
|
/* @var $sm ServiceLocatorInterface */ |
|
47
|
|
|
$sm = $e->getParam('ServiceManager'); |
|
48
|
|
|
/** @var EntityManager $em */ |
|
49
|
|
|
$em = $cli->getHelperSet()->get('em')->getEntityManager(); |
|
|
|
|
|
|
50
|
|
|
/** @var array $paths */ |
|
51
|
|
|
$paths = $sm->get('doctrine.configuration.fixtures'); |
|
52
|
|
|
|
|
53
|
|
|
$importCommand = new ImportCommand($sm); |
|
54
|
|
|
$importCommand->setEntityManager($em); |
|
55
|
|
|
$importCommand->setPaths($paths); |
|
56
|
|
|
|
|
57
|
|
|
ConsoleRunner::addCommands($cli); |
|
58
|
|
|
|
|
59
|
|
|
$cli->addCommands([ |
|
60
|
|
|
$importCommand |
|
61
|
|
|
]); |
|
62
|
|
|
}); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @return array|mixed|\Traversable |
|
67
|
|
|
*/ |
|
68
|
|
|
public function getConfig() |
|
69
|
|
|
{ |
|
70
|
|
|
return include __DIR__ . '/../../config/module.config.php'; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @return array|\Zend\ServiceManager\Config |
|
75
|
|
|
*/ |
|
76
|
|
|
public function getServiceConfig() |
|
77
|
|
|
{ |
|
78
|
|
|
return ['factories' => $this->getConfig()['factories']]; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @return array |
|
83
|
|
|
*/ |
|
84
|
|
|
public function getAutoloaderConfig() |
|
85
|
|
|
{ |
|
86
|
|
|
return ['Zend\Loader\StandardAutoloader' => $this->getConfig()['Zend\Loader\StandardAutoloader']]; |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|