How to use the Doctrine command line developing a Symfony Bundle
Adamo Crespi

Adamo Crespi @aerendir

Location:
NOCERA Inferiore (Between Naples and Salerno)
Joined:
Jun 29, 2020

How to use the Doctrine command line developing a Symfony Bundle

Publish Date: Mar 16 '24
0 0

Maybe you need to use the Doctrine’s command line while you are developing a Symfony Bundle (or anything else).

This will make you able, for example, to validate the schema or to convert an annotated schema to its XML counterpart.

Here is how to use Doctrine command line outside of a Symfony Application.

You have to simply create a cli-config.php file and put it into the root directory of your developing bundle.

<?php 

use Doctrine\ORM\Tools\Console\ConsoleRunner;
use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;

$paths = [getcwd() . "/Model"];
$isDevMode = true;

// the connection configuration
$dbParams = array( 'driver' => 'pdo_mysql',
    'user' => 'root',
    'password' => 'root',
    'dbname' => 'test_your_bundle',
);

// @see http://stackoverflow.com/a/19129147/1399706
$config = Setup::createAnnotationMetadataConfiguration($paths, $isDevMode, null, null, false);

$entityManager = EntityManager::create($dbParams, $config);

return ConsoleRunner::createHelperSet($entityManager);
Enter fullscreen mode Exit fullscreen mode

Now you can use vendor/bin/doctrine your:command to perform the task you need.

Very simple! 🙂

Remember to “Make. Ideas. Happen.”.

I wish you flocking users, see you soon!

L'articolo How to use the Doctrine command line developing a Symfony Bundle proviene da ÐΞV Experiences by Serendipity HQ.

Comments 0 total

    Add comment