1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Doctrine\ORM\Tools\Console\Command; |
6
|
|
|
|
7
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
8
|
|
|
use Doctrine\ORM\Tools\Console\MetadataFilter; |
9
|
|
|
use Symfony\Component\Console\Command\Command; |
10
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
11
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
12
|
|
|
use Symfony\Component\Console\Input\InputOption; |
13
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
14
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Command to (re)generate the proxy classes used by doctrine. |
18
|
|
|
*/ |
19
|
|
|
class GenerateProxiesCommand extends Command |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* {@inheritdoc} |
23
|
|
|
*/ |
24
|
|
|
protected function configure() |
25
|
|
|
{ |
26
|
|
|
$this->setName('orm:generate-proxies') |
27
|
|
|
->setAliases(['orm:generate:proxies']) |
28
|
|
|
->setDescription('Generates proxy classes for entity classes') |
29
|
|
|
->addArgument('dest-path', InputArgument::OPTIONAL, 'The path to generate your proxy classes. If none is provided, it will attempt to grab from configuration.') |
30
|
|
|
->addOption('filter', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'A string pattern used to match entities that should be processed.') |
31
|
|
|
->setHelp('Generates proxy classes for entity classes.'); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* {@inheritdoc} |
36
|
|
|
*/ |
37
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
38
|
|
|
{ |
39
|
|
|
$ui = new SymfonyStyle($input, $output); |
40
|
|
|
|
41
|
|
|
/** @var EntityManagerInterface $em */ |
42
|
|
|
$em = $this->getHelper('em')->getEntityManager(); |
43
|
|
|
|
44
|
|
|
$metadatas = $em->getMetadataFactory()->getAllMetadata(); |
45
|
|
|
$metadatas = MetadataFilter::filter($metadatas, $input->getOption('filter')); |
46
|
|
|
$destPath = $input->getArgument('dest-path'); |
47
|
|
|
|
48
|
|
|
// Process destination directory |
49
|
|
|
if ($destPath === null) { |
50
|
|
|
$destPath = $em->getConfiguration()->getProxyDir(); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
if (! is_dir($destPath)) { |
54
|
|
|
mkdir($destPath, 0775, true); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
$destPath = realpath($destPath); |
58
|
|
|
|
59
|
|
|
if (! file_exists($destPath)) { |
60
|
|
|
throw new \InvalidArgumentException( |
61
|
|
|
sprintf("Proxies destination directory '<info>%s</info>' does not exist.", $em->getConfiguration()->getProxyDir()) |
62
|
|
|
); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
if (! is_writable($destPath)) { |
66
|
|
|
throw new \InvalidArgumentException( |
67
|
|
|
sprintf("Proxies destination directory '<info>%s</info>' does not have write permissions.", $destPath) |
68
|
|
|
); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
if (empty($metadatas)) { |
72
|
|
|
$ui->success('No Metadata Classes to process.'); |
73
|
|
|
return; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
foreach ($metadatas as $metadata) { |
77
|
|
|
$ui->text(sprintf('Processing entity "<info>%s</info>"', $metadata->getClassName())); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
// Generating Proxies |
81
|
|
|
$em->getProxyFactory()->generateProxyClasses($metadatas, $destPath); |
82
|
|
|
|
83
|
|
|
// Outputting information message |
84
|
|
|
$ui->newLine(); |
85
|
|
|
$ui->text(sprintf('Proxy classes generated to "<info>%s</info>"', $destPath)); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|