PageRenderTime 41ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/doctrine/orm/lib/Doctrine/ORM/Tools/Console/Command/GenerateProxiesCommand.php

https://bitbucket.org/iiic/iszp
PHP | 112 lines | 62 code | 13 blank | 37 comment | 8 complexity | b0c0f0d5bdd4d08475701dd02cacdd78 MD5 | raw file
  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. namespace Doctrine\ORM\Tools\Console\Command;
  20. use Symfony\Component\Console\Input\InputArgument,
  21. Symfony\Component\Console\Input\InputOption,
  22. Symfony\Component\Console,
  23. Doctrine\ORM\Tools\Console\MetadataFilter;
  24. /**
  25. * Command to (re)generate the proxy classes used by doctrine.
  26. *
  27. *
  28. * @link www.doctrine-project.org
  29. * @since 2.0
  30. * @author Benjamin Eberlei <kontakt@beberlei.de>
  31. * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
  32. * @author Jonathan Wage <jonwage@gmail.com>
  33. * @author Roman Borschel <roman@code-factory.org>
  34. */
  35. class GenerateProxiesCommand extends Console\Command\Command
  36. {
  37. /**
  38. * @see Console\Command\Command
  39. */
  40. protected function configure()
  41. {
  42. $this
  43. ->setName('orm:generate-proxies')
  44. ->setDescription('Generates proxy classes for entity classes.')
  45. ->setDefinition(array(
  46. new InputOption(
  47. 'filter', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
  48. 'A string pattern used to match entities that should be processed.'
  49. ),
  50. new InputArgument(
  51. 'dest-path', InputArgument::OPTIONAL,
  52. 'The path to generate your proxy classes. If none is provided, it will attempt to grab from configuration.'
  53. ),
  54. ))
  55. ->setHelp(<<<EOT
  56. Generates proxy classes for entity classes.
  57. EOT
  58. );
  59. }
  60. /**
  61. * @see Console\Command\Command
  62. */
  63. protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
  64. {
  65. $em = $this->getHelper('em')->getEntityManager();
  66. $metadatas = $em->getMetadataFactory()->getAllMetadata();
  67. $metadatas = MetadataFilter::filter($metadatas, $input->getOption('filter'));
  68. // Process destination directory
  69. if (($destPath = $input->getArgument('dest-path')) === null) {
  70. $destPath = $em->getConfiguration()->getProxyDir();
  71. }
  72. if ( ! is_dir($destPath)) {
  73. mkdir($destPath, 0777, true);
  74. }
  75. $destPath = realpath($destPath);
  76. if ( ! file_exists($destPath)) {
  77. throw new \InvalidArgumentException(
  78. sprintf("Proxies destination directory '<info>%s</info>' does not exist.", $em->getConfiguration()->getProxyDir())
  79. );
  80. } else if ( ! is_writable($destPath)) {
  81. throw new \InvalidArgumentException(
  82. sprintf("Proxies destination directory '<info>%s</info>' does not have write permissions.", $destPath)
  83. );
  84. }
  85. if ( count($metadatas)) {
  86. foreach ($metadatas as $metadata) {
  87. $output->write(
  88. sprintf('Processing entity "<info>%s</info>"', $metadata->name) . PHP_EOL
  89. );
  90. }
  91. // Generating Proxies
  92. $em->getProxyFactory()->generateProxyClasses($metadatas, $destPath);
  93. // Outputting information message
  94. $output->write(PHP_EOL . sprintf('Proxy classes generated to "<info>%s</INFO>"', $destPath) . PHP_EOL);
  95. } else {
  96. $output->write('No Metadata Classes to process.' . PHP_EOL);
  97. }
  98. }
  99. }