|
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 Doctrine\ORM\Tools\Console; |
|
21
|
|
|
|
|
22
|
|
|
use Symfony\Component\Console\Application; |
|
23
|
|
|
use Symfony\Component\Console\Helper\HelperSet; |
|
24
|
|
|
use Doctrine\ORM\Version; |
|
25
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
26
|
|
|
|
|
27
|
|
|
use Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper; |
|
28
|
|
|
use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Handles running the Console Tools inside Symfony Console context. |
|
32
|
|
|
*/ |
|
33
|
|
|
class ConsoleRunner |
|
34
|
|
|
{ |
|
35
|
|
|
/** |
|
36
|
|
|
* Create a Symfony Console HelperSet |
|
37
|
|
|
* |
|
38
|
|
|
* @param EntityManagerInterface $entityManager |
|
39
|
|
|
* @return HelperSet |
|
40
|
|
|
*/ |
|
41
|
|
|
public static function createHelperSet(EntityManagerInterface $entityManager) |
|
42
|
|
|
{ |
|
43
|
|
|
return new HelperSet( |
|
44
|
|
|
[ |
|
45
|
|
|
'db' => new ConnectionHelper($entityManager->getConnection()), |
|
46
|
|
|
'em' => new EntityManagerHelper($entityManager) |
|
47
|
|
|
] |
|
48
|
|
|
); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Runs console with the given helperset. |
|
53
|
|
|
* |
|
54
|
|
|
* @param \Symfony\Component\Console\Helper\HelperSet $helperSet |
|
55
|
|
|
* @param \Symfony\Component\Console\Command\Command[] $commands |
|
56
|
|
|
* |
|
57
|
|
|
* @return void |
|
58
|
|
|
*/ |
|
59
|
|
|
static public function run(HelperSet $helperSet, $commands = []) |
|
|
|
|
|
|
60
|
|
|
{ |
|
61
|
|
|
$cli = self::createApplication($helperSet, $commands); |
|
62
|
|
|
$cli->run(); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Creates a console application with the given helperset and |
|
67
|
|
|
* optional commands. |
|
68
|
|
|
* |
|
69
|
|
|
* @param \Symfony\Component\Console\Helper\HelperSet $helperSet |
|
70
|
|
|
* @param array $commands |
|
71
|
|
|
* |
|
72
|
|
|
* @return \Symfony\Component\Console\Application |
|
73
|
|
|
*/ |
|
74
|
1 |
|
static public function createApplication(HelperSet $helperSet, $commands = []) |
|
|
|
|
|
|
75
|
|
|
{ |
|
76
|
1 |
|
$cli = new Application('Doctrine Command Line Interface', Version::VERSION); |
|
77
|
1 |
|
$cli->setCatchExceptions(true); |
|
78
|
1 |
|
$cli->setHelperSet($helperSet); |
|
79
|
1 |
|
self::addCommands($cli); |
|
80
|
1 |
|
$cli->addCommands($commands); |
|
81
|
|
|
|
|
82
|
1 |
|
return $cli; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @param Application $cli |
|
87
|
|
|
* |
|
88
|
|
|
* @return void |
|
89
|
|
|
*/ |
|
90
|
1 |
|
static public function addCommands(Application $cli) |
|
|
|
|
|
|
91
|
|
|
{ |
|
92
|
1 |
|
$cli->addCommands( |
|
93
|
|
|
[ |
|
94
|
|
|
// DBAL Commands |
|
95
|
1 |
|
new \Doctrine\DBAL\Tools\Console\Command\RunSqlCommand(), |
|
96
|
1 |
|
new \Doctrine\DBAL\Tools\Console\Command\ImportCommand(), |
|
97
|
|
|
|
|
98
|
|
|
// ORM Commands |
|
99
|
1 |
|
new \Doctrine\ORM\Tools\Console\Command\ClearCache\CollectionRegionCommand(), |
|
100
|
1 |
|
new \Doctrine\ORM\Tools\Console\Command\ClearCache\EntityRegionCommand(), |
|
101
|
1 |
|
new \Doctrine\ORM\Tools\Console\Command\ClearCache\MetadataCommand(), |
|
102
|
1 |
|
new \Doctrine\ORM\Tools\Console\Command\ClearCache\QueryCommand(), |
|
103
|
1 |
|
new \Doctrine\ORM\Tools\Console\Command\ClearCache\QueryRegionCommand(), |
|
104
|
1 |
|
new \Doctrine\ORM\Tools\Console\Command\ClearCache\ResultCommand(), |
|
105
|
1 |
|
new \Doctrine\ORM\Tools\Console\Command\SchemaTool\CreateCommand(), |
|
106
|
1 |
|
new \Doctrine\ORM\Tools\Console\Command\SchemaTool\UpdateCommand(), |
|
107
|
1 |
|
new \Doctrine\ORM\Tools\Console\Command\SchemaTool\DropCommand(), |
|
108
|
1 |
|
new \Doctrine\ORM\Tools\Console\Command\EnsureProductionSettingsCommand(), |
|
109
|
1 |
|
new \Doctrine\ORM\Tools\Console\Command\ConvertDoctrine1SchemaCommand(), |
|
110
|
1 |
|
new \Doctrine\ORM\Tools\Console\Command\GenerateRepositoriesCommand(), |
|
111
|
1 |
|
new \Doctrine\ORM\Tools\Console\Command\GenerateEntitiesCommand(), |
|
112
|
1 |
|
new \Doctrine\ORM\Tools\Console\Command\GenerateProxiesCommand(), |
|
113
|
1 |
|
new \Doctrine\ORM\Tools\Console\Command\ConvertMappingCommand(), |
|
114
|
1 |
|
new \Doctrine\ORM\Tools\Console\Command\RunDqlCommand(), |
|
115
|
1 |
|
new \Doctrine\ORM\Tools\Console\Command\ValidateSchemaCommand(), |
|
116
|
1 |
|
new \Doctrine\ORM\Tools\Console\Command\InfoCommand(), |
|
117
|
1 |
|
new \Doctrine\ORM\Tools\Console\Command\MappingDescribeCommand(), |
|
118
|
|
|
] |
|
119
|
|
|
); |
|
120
|
1 |
|
} |
|
121
|
|
|
|
|
122
|
|
|
static public function printCliConfigTemplate() |
|
|
|
|
|
|
123
|
|
|
{ |
|
124
|
|
|
echo <<<'HELP' |
|
125
|
|
|
You are missing a "cli-config.php" or "config/cli-config.php" file in your |
|
126
|
|
|
project, which is required to get the Doctrine Console working. You can use the |
|
127
|
|
|
following sample as a template: |
|
128
|
|
|
|
|
129
|
|
|
<?php |
|
130
|
|
|
use Doctrine\ORM\Tools\Console\ConsoleRunner; |
|
131
|
|
|
|
|
132
|
|
|
// replace with file to your own project bootstrap |
|
133
|
|
|
require_once 'bootstrap.php'; |
|
134
|
|
|
|
|
135
|
|
|
// replace with mechanism to retrieve EntityManager in your app |
|
136
|
|
|
$entityManager = GetEntityManager(); |
|
137
|
|
|
|
|
138
|
|
|
return ConsoleRunner::createHelperSet($entityManager); |
|
139
|
|
|
|
|
140
|
|
|
HELP; |
|
141
|
|
|
|
|
142
|
|
|
} |
|
143
|
|
|
} |
|
144
|
|
|
|