Doctrine 2 Console Tool says: You are missing a "cli-config.php" or "config/cli-config.php"
The Easy Way
Use Doctrine Module:
vendor/bin/doctrine-module orm:schema-tool:create --dump-sql
Note: this answer may be specific to these frameworks:
- Zend Framework
- Zend Expressive
- Laminas
- Mezzio
The Hard Way
Put this into your config/cli-config.php
:
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Tools\Console\ConsoleRunner;
use DoctrineConnector\EntityManagerFactory;
include 'vendor/autoload.php'
global $container;
$container = require 'config/container.php';
$factory = new EntityManagerFactory();
$entityManager = $factory($container);
return ConsoleRunner::createHelperSet($entityManager);
Put this into your config/autoload/database.local.php
:
return [
'doctrine' => [
/*
* Paths for Doctrine to find Entities
*/
'paths' => array(
"src/Blah/src/Entity",
),
/*
* Doctrine configuration parameters
*/
'db_params' => array(
'driver' => 'pdo_mysql',
'user' => 'user',
'password' => 'password',
'dbname' => 'dbname',
'driverOptions' => array(
1002 => 'SET NAMES UTF8MB4'
)
),
/*
* Tells Doctrine what mode we want
* For Production environment set to \Doctrine\Common\Proxy\AbstractProxyFactory::AUTOGENERATE_NEVER;
*/
'is_dev_mode' => false
]
];
Create this class: EntityManagerFactory
class EntityManagerFactory
{
/**
* Set Up & return Doctrine connection
*
* @param ContainerInterface $container
* @throws \RuntimeException
* @return EntityManager
*/
public function __invoke(ContainerInterface $container): EntityManager
{
$config = $container->get('config');
Assert::that($config)->keyExists('doctrine', "No Doctrine ORM Configuration Specified, check your 'config/autoload/database.local.php'");
$paths = $config['doctrine']['paths'];
$dbParams = $config['doctrine']['db_params'];
$isDevMode = $config['doctrine']['is_dev_mode'];
$config = Setup::createAnnotationMetadataConfiguration($paths, $isDevMode);
$config->setProxyDir("temp/proxies");
$entityManager = EntityManager::create($dbParams, $config);
/*
* Enable native prepared statements
*/
$pdo = $entityManager->getConnection()->getWrappedConnection();
$pdo->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false);
/*
* Allow Doctrine to persist boolean types
*/
Type::overrideType('boolean', BooleanToIntType::class);
return $entityManager;
}
}
After that, things should work splendidly