Configuring Doctrine command-line tools
The Doctrine library is bundled with some useful command line tools. They provide many helpful features, including, but not limited to the ability to create database schema from entity mappings.
Composer has installed Doctrine's command line tools in the vendor/bin/
directory. But before being able to use them, a bit of configuration must be done. Command line tools internally use an Entity Manager. We need to tell them how to retrieve it.
Here, we just need to create one more file called cli-config.php
in the config/
directory as follows:
<?php // Doctrine CLI configuration file use Doctrine\ORM\Tools\Console\ConsoleRunner; require_once __DIR__.'/../src/bootstrap.php'; return ConsoleRunner::createHelperSet($entityManager);
Thanks to the Doctrine's conventions, the file will be automatically detected and used by the Doctrine CLI.
Note
Command line tools will look for a file called cli-config.php
in the current directory and in the config/
directory.
This file just gets a new Entity Manager using the utility class we've created earlier and configures the Doctrine CLI to use it.
Type the following command to get a list of available Doctrine commands:
php vendor/bin/doctrine.php