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

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