|
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\Command; |
|
21
|
|
|
|
|
22
|
|
|
use Doctrine\ORM\Tools\Console\MetadataFilter; |
|
23
|
|
|
use Doctrine\ORM\Tools\EntityRepositoryGenerator; |
|
24
|
|
|
use Symfony\Component\Console\Command\Command; |
|
25
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
26
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
27
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
28
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
29
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Command to generate repository classes for mapping information. |
|
33
|
|
|
* |
|
34
|
|
|
* @link www.doctrine-project.org |
|
35
|
|
|
* @since 2.0 |
|
36
|
|
|
* @author Benjamin Eberlei <[email protected]> |
|
37
|
|
|
* @author Guilherme Blanco <[email protected]> |
|
38
|
|
|
* @author Jonathan Wage <[email protected]> |
|
39
|
|
|
* @author Roman Borschel <[email protected]> |
|
40
|
|
|
* |
|
41
|
|
|
* @deprecated 3.0 This class is being removed from the ORM and won't have any replacement |
|
42
|
|
|
*/ |
|
43
|
|
|
class GenerateRepositoriesCommand extends Command |
|
44
|
|
|
{ |
|
45
|
|
|
/** |
|
46
|
|
|
* {@inheritdoc} |
|
47
|
|
|
*/ |
|
48
|
3 |
|
protected function configure() |
|
49
|
|
|
{ |
|
50
|
3 |
|
$this->setName('orm:generate-repositories') |
|
51
|
3 |
|
->setAliases(['orm:generate:repositories']) |
|
52
|
3 |
|
->setDescription('Generate repository classes from your mapping information') |
|
53
|
3 |
|
->addArgument('dest-path', InputArgument::REQUIRED, 'The path to generate your repository classes.') |
|
54
|
3 |
|
->addOption('filter', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'A string pattern used to match entities that should be processed.') |
|
55
|
3 |
|
->setHelp('Generate repository classes from your mapping information.'); |
|
56
|
3 |
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* {@inheritdoc} |
|
60
|
|
|
*/ |
|
61
|
3 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
62
|
|
|
{ |
|
63
|
3 |
|
$ui = new SymfonyStyle($input, $output); |
|
64
|
3 |
|
$ui->warning('Command ' . $this->getName() . ' is deprecated and will be removed in Doctrine 3.0.'); |
|
65
|
|
|
|
|
66
|
3 |
|
$em = $this->getHelper('em')->getEntityManager(); |
|
67
|
|
|
|
|
68
|
3 |
|
$metadatas = $em->getMetadataFactory()->getAllMetadata(); |
|
69
|
3 |
|
$metadatas = MetadataFilter::filter($metadatas, $input->getOption('filter')); |
|
70
|
|
|
|
|
71
|
3 |
|
$repositoryName = $em->getConfiguration()->getDefaultRepositoryClassName(); |
|
72
|
|
|
|
|
73
|
|
|
// Process destination directory |
|
74
|
3 |
|
$destPath = realpath($input->getArgument('dest-path')); |
|
|
|
|
|
|
75
|
|
|
|
|
76
|
3 |
|
if ( ! file_exists($destPath)) { |
|
77
|
|
|
throw new \InvalidArgumentException( |
|
78
|
|
|
sprintf("Entities destination directory '<info>%s</info>' does not exist.", $input->getArgument('dest-path')) |
|
|
|
|
|
|
79
|
|
|
); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
3 |
|
if ( ! is_writable($destPath)) { |
|
83
|
|
|
throw new \InvalidArgumentException( |
|
84
|
|
|
sprintf("Entities destination directory '<info>%s</info>' does not have write permissions.", $destPath) |
|
85
|
|
|
); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
3 |
|
if (empty($metadatas)) { |
|
89
|
1 |
|
$ui->success('No Metadata Classes to process.'); |
|
90
|
1 |
|
return 0; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
2 |
|
$numRepositories = 0; |
|
94
|
2 |
|
$generator = new EntityRepositoryGenerator(); |
|
|
|
|
|
|
95
|
|
|
|
|
96
|
2 |
|
$generator->setDefaultRepositoryName($repositoryName); |
|
97
|
|
|
|
|
98
|
2 |
|
foreach ($metadatas as $metadata) { |
|
99
|
2 |
|
if ($metadata->customRepositoryClassName) { |
|
100
|
2 |
|
$ui->text(sprintf('Processing repository "<info>%s</info>"', $metadata->customRepositoryClassName)); |
|
101
|
|
|
|
|
102
|
2 |
|
$generator->writeEntityRepositoryClass($metadata->customRepositoryClassName, $destPath); |
|
103
|
|
|
|
|
104
|
2 |
|
++$numRepositories; |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
2 |
|
if ($numRepositories === 0) { |
|
109
|
|
|
$ui->text('No Repository classes were found to be processed.'); |
|
110
|
|
|
return 0; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
// Outputting information message |
|
114
|
2 |
|
$ui->newLine(); |
|
115
|
2 |
|
$ui->text(sprintf('Repository classes generated to "<info>%s</info>"', $destPath)); |
|
116
|
|
|
|
|
117
|
2 |
|
return 0; |
|
118
|
|
|
} |
|
119
|
|
|
} |
|
120
|
|
|
|