vendor/doctrine/orm/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/CreateCommand.php line 38

Open in your IDE?
  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\SchemaTool;
  20. use Doctrine\ORM\Tools\SchemaTool;
  21. use Symfony\Component\Console\Input\InputInterface;
  22. use Symfony\Component\Console\Input\InputOption;
  23. use Symfony\Component\Console\Output\OutputInterface;
  24. use Symfony\Component\Console\Style\SymfonyStyle;
  25. /**
  26.  * Command to create the database schema for a set of classes based on their mappings.
  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 CreateCommand extends AbstractCommand
  36. {
  37.     /**
  38.      * {@inheritdoc}
  39.      */
  40.     protected function configure()
  41.     {
  42.         $this->setName('orm:schema-tool:create')
  43.              ->setDescription('Processes the schema and either create it directly on EntityManager Storage Connection or generate the SQL output')
  44.              ->addOption('dump-sql'nullInputOption::VALUE_NONE'Instead of trying to apply generated SQLs into EntityManager Storage Connection, output them.')
  45.              ->setHelp(<<<EOT
  46. Processes the schema and either create it directly on EntityManager Storage Connection or generate the SQL output.
  47. <comment>Hint:</comment> If you have a database with tables that should not be managed
  48. by the ORM, you can use a DBAL functionality to filter the tables and sequences down
  49. on a global level:
  50.     \$config->setFilterSchemaAssetsExpression(\$regexp);
  51. EOT
  52.              );
  53.     }
  54.     /**
  55.      * {@inheritdoc}
  56.      */
  57.     protected function executeSchemaCommand(InputInterface $inputOutputInterface $outputSchemaTool $schemaTool, array $metadatasSymfonyStyle $ui)
  58.     {
  59.         $dumpSql true === $input->getOption('dump-sql');
  60.         if ($dumpSql) {
  61.             $sqls $schemaTool->getCreateSchemaSql($metadatas);
  62.             $ui->text('The following SQL statements will be executed:');
  63.             $ui->newLine();
  64.             foreach ($sqls as $sql) {
  65.                 $ui->text(sprintf('    %s;'$sql));
  66.             }
  67.             return 0;
  68.         }
  69.         $ui->caution('This operation should not be executed in a production environment!');
  70.         $ui->text('Creating database schema...');
  71.         $ui->newLine();
  72.         $schemaTool->createSchema($metadatas);
  73.         $ui->success('Database schema created successfully!');
  74.         return 0;
  75.     }
  76. }