|
0
|
1 |
<?php |
|
|
2 |
/* |
|
|
3 |
* $Id$ |
|
|
4 |
* |
|
|
5 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
|
6 |
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
|
7 |
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
|
8 |
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
|
9 |
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
|
10 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
|
11 |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
|
12 |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
|
13 |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
|
14 |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
|
15 |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
|
16 |
* |
|
|
17 |
* This software consists of voluntary contributions made by many individuals |
|
|
18 |
* and is licensed under the LGPL. For more information, see |
|
|
19 |
* <http://www.doctrine-project.org>. |
|
|
20 |
*/ |
|
|
21 |
|
|
|
22 |
namespace Doctrine\ORM\Tools\Console\Command; |
|
|
23 |
|
|
|
24 |
use Symfony\Component\Console\Input\InputArgument, |
|
|
25 |
Symfony\Component\Console\Input\InputOption, |
|
|
26 |
Symfony\Component\Console, |
|
|
27 |
Doctrine\ORM\Tools\Console\MetadataFilter; |
|
|
28 |
|
|
|
29 |
/** |
|
|
30 |
* Command to (re)generate the proxy classes used by doctrine. |
|
|
31 |
* |
|
|
32 |
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL |
|
|
33 |
* @link www.doctrine-project.org |
|
|
34 |
* @since 2.0 |
|
|
35 |
* @version $Revision$ |
|
|
36 |
* @author Benjamin Eberlei <kontakt@beberlei.de> |
|
|
37 |
* @author Guilherme Blanco <guilhermeblanco@hotmail.com> |
|
|
38 |
* @author Jonathan Wage <jonwage@gmail.com> |
|
|
39 |
* @author Roman Borschel <roman@code-factory.org> |
|
|
40 |
*/ |
|
|
41 |
class GenerateProxiesCommand extends Console\Command\Command |
|
|
42 |
{ |
|
|
43 |
/** |
|
|
44 |
* @see Console\Command\Command |
|
|
45 |
*/ |
|
|
46 |
protected function configure() |
|
|
47 |
{ |
|
|
48 |
$this |
|
|
49 |
->setName('orm:generate-proxies') |
|
|
50 |
->setDescription('Generates proxy classes for entity classes.') |
|
|
51 |
->setDefinition(array( |
|
|
52 |
new InputOption( |
|
|
53 |
'filter', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, |
|
|
54 |
'A string pattern used to match entities that should be processed.' |
|
|
55 |
), |
|
|
56 |
new InputArgument( |
|
|
57 |
'dest-path', InputArgument::OPTIONAL, |
|
|
58 |
'The path to generate your proxy classes. If none is provided, it will attempt to grab from configuration.' |
|
|
59 |
), |
|
|
60 |
)) |
|
|
61 |
->setHelp(<<<EOT |
|
|
62 |
Generates proxy classes for entity classes. |
|
|
63 |
EOT |
|
|
64 |
); |
|
|
65 |
} |
|
|
66 |
|
|
|
67 |
/** |
|
|
68 |
* @see Console\Command\Command |
|
|
69 |
*/ |
|
|
70 |
protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output) |
|
|
71 |
{ |
|
|
72 |
$em = $this->getHelper('em')->getEntityManager(); |
|
|
73 |
|
|
|
74 |
$metadatas = $em->getMetadataFactory()->getAllMetadata(); |
|
|
75 |
$metadatas = MetadataFilter::filter($metadatas, $input->getOption('filter')); |
|
|
76 |
|
|
|
77 |
// Process destination directory |
|
|
78 |
if (($destPath = $input->getArgument('dest-path')) === null) { |
|
|
79 |
$destPath = $em->getConfiguration()->getProxyDir(); |
|
|
80 |
} |
|
|
81 |
|
|
|
82 |
if ( ! is_dir($destPath)) { |
|
|
83 |
mkdir($destPath, 0777, true); |
|
|
84 |
} |
|
|
85 |
|
|
|
86 |
$destPath = realpath($destPath); |
|
|
87 |
|
|
|
88 |
if ( ! file_exists($destPath)) { |
|
|
89 |
throw new \InvalidArgumentException( |
|
|
90 |
sprintf("Proxies destination directory '<info>%s</info>' does not exist.", $destPath) |
|
|
91 |
); |
|
|
92 |
} else if ( ! is_writable($destPath)) { |
|
|
93 |
throw new \InvalidArgumentException( |
|
|
94 |
sprintf("Proxies destination directory '<info>%s</info>' does not have write permissions.", $destPath) |
|
|
95 |
); |
|
|
96 |
} |
|
|
97 |
|
|
|
98 |
if ( count($metadatas)) { |
|
|
99 |
foreach ($metadatas as $metadata) { |
|
|
100 |
$output->write( |
|
|
101 |
sprintf('Processing entity "<info>%s</info>"', $metadata->name) . PHP_EOL |
|
|
102 |
); |
|
|
103 |
} |
|
|
104 |
|
|
|
105 |
// Generating Proxies |
|
|
106 |
$em->getProxyFactory()->generateProxyClasses($metadatas, $destPath); |
|
|
107 |
|
|
|
108 |
// Outputting information message |
|
|
109 |
$output->write(PHP_EOL . sprintf('Proxy classes generated to "<info>%s</INFO>"', $destPath) . PHP_EOL); |
|
|
110 |
} else { |
|
|
111 |
$output->write('No Metadata Classes to process.' . PHP_EOL); |
|
|
112 |
} |
|
|
113 |
|
|
|
114 |
} |
|
|
115 |
} |