Doctrine default cli-config.php location

2.1k views Asked by At

I would like to change the location of the doctrine cli-config.php file as well as possibly change it's name -- the first request is more important.

Any ideas???

2

There are 2 answers

0
Clamburger On BEST ANSWER

If you are using the doctrine CLI directly, this is not possible.

You can see this by having a look at the relevant source code:

$directories = array(getcwd(), getcwd() . DIRECTORY_SEPARATOR . 'config');
$configFile = null;
foreach ($directories as $directory) {
    $configFile = $directory . DIRECTORY_SEPARATOR . 'cli-config.php';
    if (file_exists($configFile)) {
        break;
    }
}

It only ever checks for cli-config.php and config/cli-config.php.


The alternative is to implement a CLI based on the Symfony Console component (which is what the Doctrine CLI is based on) yourself, and pull in the Doctrine commands. This allows you to avoid having cli-config.php altogether at the cost of having to put in a not-insignificant amount of work. You can find the details of this approach in this answer.

0
zey_ser On

Exists another one approach. You can add in custom location file, for example cli.php(with your own file name). Than add in this file something like that:

```

<?php
// cli.php
// where your entityManager is created
require_once "bootstrap.php";

$helperSet = new \Symfony\Component\Console\Helper\HelperSet(array(
    'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($entityManager)
));

\Doctrine\ORM\Tools\Console\ConsoleRunner::run($helperSet);

```

And you can run this file from where you want like php cli.php.