1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
4
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
5
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
6
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
7
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
8
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
9
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
10
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
11
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
12
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
13
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
14
|
|
|
* |
15
|
|
|
* This software consists of voluntary contributions made by many individuals |
16
|
|
|
* and is licensed under the MIT license. For more information, see |
17
|
|
|
* <http://www.doctrine-project.org>. |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
namespace DoctrineORMModule; |
21
|
|
|
|
22
|
|
|
use Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper; |
23
|
|
|
use Doctrine\ORM\EntityManager; |
24
|
|
|
use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper; |
25
|
|
|
use Symfony\Component\Console\Application; |
26
|
|
|
use Symfony\Component\Console\Helper\QuestionHelper; |
27
|
|
|
use Zend\EventManager\EventInterface; |
28
|
|
|
use Zend\ModuleManager\Feature\ConfigProviderInterface; |
29
|
|
|
use Zend\ModuleManager\Feature\DependencyIndicatorInterface; |
30
|
|
|
use Zend\ModuleManager\Feature\InitProviderInterface; |
31
|
|
|
use Zend\ModuleManager\ModuleManagerInterface; |
32
|
|
|
use Zend\ServiceManager\ServiceLocatorInterface; |
33
|
|
|
use Zend\Stdlib\ArrayUtils; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Base module for Doctrine ORM. |
37
|
|
|
* |
38
|
|
|
* @license MIT |
39
|
|
|
* @link www.doctrine-project.org |
40
|
|
|
* @author Kyle Spraggs <[email protected]> |
41
|
|
|
* @author Marco Pivetta <[email protected]> |
42
|
|
|
*/ |
43
|
|
|
class Module implements |
44
|
|
|
ConfigProviderInterface, |
45
|
|
|
InitProviderInterface, |
46
|
|
|
DependencyIndicatorInterface |
47
|
|
|
{ |
48
|
|
|
/** |
49
|
|
|
* {@inheritDoc} |
50
|
|
|
*/ |
51
|
56 |
|
public function init(ModuleManagerInterface $manager) |
52
|
|
|
{ |
53
|
56 |
|
$events = $manager->getEventManager(); |
54
|
|
|
// Initialize logger collector once the profiler is initialized itself |
55
|
56 |
|
$events->attach( |
56
|
56 |
|
'profiler_init', |
57
|
|
|
function () use ($manager) { |
58
|
|
|
$manager->getEvent()->getParam('ServiceManager')->get('doctrine.sql_logger_collector.orm_default'); |
|
|
|
|
59
|
|
|
} |
60
|
56 |
|
); |
61
|
56 |
|
$events->getSharedManager()->attach('doctrine', 'loadCli.post', [$this, 'initializeConsole']); |
62
|
56 |
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* {@inheritDoc} |
66
|
|
|
*/ |
67
|
56 |
|
public function getConfig() |
68
|
|
|
{ |
69
|
56 |
|
$provider = new ConfigProvider(); |
70
|
|
|
|
71
|
|
|
return [ |
72
|
56 |
|
'controllers' => $provider->getControllerConfig(), |
73
|
56 |
|
'doctrine' => $provider->getDoctrineConfig(), |
74
|
56 |
|
'doctrine_factories' => $provider->getDoctrineFactoryConfig(), |
75
|
56 |
|
'form_elements' => $provider->getFormElementConfig(), |
76
|
56 |
|
'hydrators' => $provider->getHydratorConfig(), |
77
|
56 |
|
'router' => $provider->getRouterConfig(), |
78
|
56 |
|
'service_manager' => $provider->getDependencyConfig(), |
79
|
56 |
|
'view_manager' => $provider->getViewManagerConfig(), |
80
|
56 |
|
'zenddevelopertools' => $provider->getZendDeveloperToolConfig(), |
81
|
56 |
|
]; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* {@inheritDoc} |
86
|
|
|
*/ |
87
|
56 |
|
public function getModuleDependencies() |
88
|
|
|
{ |
89
|
56 |
|
return ['DoctrineModule']; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Initializes the console with additional commands from the ORM, DBAL and (optionally) DBAL\Migrations |
94
|
|
|
* |
95
|
|
|
* @param \Zend\EventManager\EventInterface $event |
96
|
|
|
* @return void |
97
|
|
|
*/ |
98
|
2 |
|
public function initializeConsole(EventInterface $event) |
99
|
|
|
{ |
100
|
|
|
/** @var $cli Application */ |
101
|
2 |
|
$cli = $event->getTarget(); |
102
|
|
|
/** @var $serviceLocator ServiceLocatorInterface */ |
103
|
2 |
|
$serviceLocator = $event->getParam('ServiceManager'); |
104
|
|
|
|
105
|
|
|
$commands = [ |
106
|
2 |
|
'doctrine.dbal_cmd.runsql', |
107
|
2 |
|
'doctrine.dbal_cmd.import', |
108
|
2 |
|
'doctrine.orm_cmd.clear_cache_metadata', |
109
|
2 |
|
'doctrine.orm_cmd.clear_cache_result', |
110
|
2 |
|
'doctrine.orm_cmd.clear_cache_query', |
111
|
2 |
|
'doctrine.orm_cmd.schema_tool_create', |
112
|
2 |
|
'doctrine.orm_cmd.schema_tool_update', |
113
|
2 |
|
'doctrine.orm_cmd.schema_tool_drop', |
114
|
2 |
|
'doctrine.orm_cmd.ensure_production_settings', |
115
|
2 |
|
'doctrine.orm_cmd.convert_d1_schema', |
116
|
2 |
|
'doctrine.orm_cmd.generate_repositories', |
117
|
2 |
|
'doctrine.orm_cmd.generate_entities', |
118
|
2 |
|
'doctrine.orm_cmd.generate_proxies', |
119
|
2 |
|
'doctrine.orm_cmd.convert_mapping', |
120
|
2 |
|
'doctrine.orm_cmd.run_dql', |
121
|
2 |
|
'doctrine.orm_cmd.validate_schema', |
122
|
2 |
|
'doctrine.orm_cmd.info', |
123
|
2 |
|
]; |
124
|
|
|
|
125
|
2 |
|
if (class_exists(\Doctrine\DBAL\Migrations\Version::class)) { |
126
|
2 |
|
$commands = ArrayUtils::merge( |
127
|
2 |
|
$commands, |
128
|
|
|
[ |
129
|
2 |
|
'doctrine.migrations_cmd.execute', |
130
|
2 |
|
'doctrine.migrations_cmd.generate', |
131
|
2 |
|
'doctrine.migrations_cmd.migrate', |
132
|
2 |
|
'doctrine.migrations_cmd.status', |
133
|
2 |
|
'doctrine.migrations_cmd.version', |
134
|
2 |
|
'doctrine.migrations_cmd.diff', |
135
|
2 |
|
'doctrine.migrations_cmd.latest', |
136
|
|
|
] |
137
|
2 |
|
); |
138
|
2 |
|
} |
139
|
|
|
|
140
|
2 |
|
$cli->addCommands(array_map([$serviceLocator, 'get'], $commands)); |
141
|
|
|
|
142
|
|
|
/** @var $entityManager EntityManager */ |
143
|
2 |
|
$entityManager = $serviceLocator->get('doctrine.entitymanager.orm_default'); |
144
|
2 |
|
$helperSet = $cli->getHelperSet(); |
145
|
|
|
|
146
|
2 |
|
$helperSet->set(new QuestionHelper(), 'dialog'); |
147
|
2 |
|
$helperSet->set(new ConnectionHelper($entityManager->getConnection()), 'db'); |
148
|
2 |
|
$helperSet->set(new EntityManagerHelper($entityManager), 'em'); |
149
|
2 |
|
} |
150
|
|
|
} |
151
|
|
|
|
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.