1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Sonata Project package. |
7
|
|
|
* |
8
|
|
|
* (c) Thomas Rabaix <[email protected]> |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Sonata\EasyExtendsBundle\Command; |
15
|
|
|
|
16
|
|
|
use Doctrine\Bundle\DoctrineBundle\Registry; |
17
|
|
|
use Doctrine\ORM\Tools\Export\ClassMetadataExporter; |
18
|
|
|
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; |
19
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
20
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
21
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Generate Application entities from bundle entities. |
25
|
|
|
* |
26
|
|
|
* NEXT_MAJOR: stop extending ContainerAwareCommand. |
27
|
|
|
* |
28
|
|
|
* @author Thomas Rabaix <[email protected]> |
29
|
|
|
*/ |
30
|
|
|
class DumpMappingCommand extends ContainerAwareCommand |
|
|
|
|
31
|
|
|
{ |
32
|
|
|
/** |
33
|
|
|
* @var Registry|null |
34
|
|
|
*/ |
35
|
|
|
private $registry; |
36
|
|
|
|
37
|
|
|
public function __construct(string $name = null, Registry $registry = null) |
38
|
|
|
{ |
39
|
|
|
parent::__construct($name); |
40
|
|
|
|
41
|
|
|
if (null === $registry) { |
42
|
|
|
@trigger_error(sprintf( |
|
|
|
|
43
|
|
|
'Not providing a registry to "%s" is deprecated since 2.x and will no longer be possible in 3.0', |
44
|
|
|
\get_class($this) |
45
|
|
|
), E_USER_DEPRECATED); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
$this->registry = $registry; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* {@inheritdoc} |
53
|
|
|
*/ |
54
|
|
|
protected function configure() |
55
|
|
|
{ |
56
|
|
|
$this->setName('sonata:easy-extends:dump-mapping'); |
57
|
|
|
$this->setDescription('Dump some mapping information (debug only)'); |
58
|
|
|
|
59
|
|
|
$this->addArgument('manager', InputArgument::OPTIONAL, 'The manager name to use', false); |
|
|
|
|
60
|
|
|
$this->addArgument('model', InputArgument::OPTIONAL, 'The class to dump', false); |
|
|
|
|
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* {@inheritdoc} |
65
|
|
|
*/ |
66
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): ?int |
67
|
|
|
{ |
68
|
|
|
$factory = $this->getDoctrineRegistry()->getManager($input->getArgument('manager'))->getMetadataFactory(); |
|
|
|
|
69
|
|
|
|
70
|
|
|
$metadata = $factory->getMetadataFor($input->getArgument('model')); |
71
|
|
|
|
72
|
|
|
$cme = new ClassMetadataExporter(); |
73
|
|
|
$exporter = $cme->getExporter('php'); |
74
|
|
|
|
75
|
|
|
$output->writeln($exporter->exportClassMetadata($metadata)); |
76
|
|
|
$output->writeln('Done!'); |
77
|
|
|
|
78
|
|
|
return 0; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
private function getDoctrineRegistry(): Registry |
82
|
|
|
{ |
83
|
|
|
if (null === $this->registry) { |
84
|
|
|
return $this->getContainer()->get('doctrine'); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
return $this->registry; |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.