orm: Error thrown when setting up Doctrine ORM
On a freshly installed Doctrine ORM I tried to setup the EntityManager like so:
use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;
require_once __DIR__ . '/../../vendor/autoload.php';
$isDevMode = true;
$proxyDir = null;
$cache = null;
$useSimpleAnnotationReader = false;
$config = Setup::createAnnotationMetadataConfiguration(array(__DIR__ . "/entities"), $isDevMode, $proxyDir, $cache, $useSimpleAnnotationReader);
// or if you prefer yaml or XML
// $config = Setup::createXMLMetadataConfiguration(array(__DIR__."/config/xml"), $isDevMode);
// $config = Setup::createYAMLMetadataConfiguration(array(__DIR__."/config/yaml"), $isDevMode);
// database configuration parameters
$conn = array(
'driver' => 'mysql',
'user' => 'something',
'passwords' => 'other',
'dbname' => 'itsadb',
'host' => 'localhost'
);
$em = EntityManager::create($conn, $config);
Only to get the following error:
[02-Jul-2021 16:07:30 Europe/Berlin] PHP Fatal error: Uncaught RuntimeException: Setup tool cannot configure caches without doctrine/cache 1.11 or symfony/cache. Please add an explicit dependency to either library. in C:\xampp\htdocs\iPoint\vendor\doctrine\orm\lib\Doctrine\ORM\Tools\Setup.php:184
Stack trace:
#0 C:\xampp\htdocs\iPoint\vendor\doctrine\orm\lib\Doctrine\ORM\Tools\Setup.php(160): Doctrine\ORM\Tools\Setup::createCacheInstance(true, NULL)
#1 C:\xampp\htdocs\iPoint\vendor\doctrine\orm\lib\Doctrine\ORM\Tools\Setup.php(139): Doctrine\ORM\Tools\Setup::createCacheConfiguration(true, 'C:\\Users\\FILIP~...', NULL)
#2 C:\xampp\htdocs\iPoint\vendor\doctrine\orm\lib\Doctrine\ORM\Tools\Setup.php(87): Doctrine\ORM\Tools\Setup::createConfiguration(true, 'C:\\Users\\FILIP~...', NULL)
#3 C:\xampp\htdocs\iPoint\php\doctrine\bootstrap.php(16): Doctrine\ORM\Tools\Setup::createAnnotationMetadataConfiguration(Array, true, NULL, NULL, false)
#4 C:\xampp\htdocs\iPoint\php\test.php(5): getEntityManager()
#5 {main}
thrown in C:\xampp\htdocs\iPoint\vendor\doctrine\orm\lib\Doctrine\ORM\Tools\Setup.php on line 184
My composer.json:
{
"require": {
"stripe/stripe-php": "^7.86",
"facebook/graph-sdk": "^5.7",
"google/apiclient": "2.10",
"symfony/yaml": "2.*",
"doctrine/orm": "^2.9"
}
}
I also tried installing the symfony/cache
and doctrine/cache
packages separately with composer require
but I got the same error.
I’m running PHP version 7.3.28
This should be the piece of code throwing the exception:
if (! class_exists(ArrayCache::class) && ! class_exists(ArrayAdapter::class)) {
throw new RuntimeException('Setup tool cannot configure caches without doctrine/cache 1.11 or symfony/cache. Please add an explicit dependency to either library.');
}
My IDE also highlights those classes and some others as missing.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 24 (16 by maintainers)
To be fair, a new developer starting a new project with doctrine/orm from scratch does not deserve that.
Please note that the code in my repo was a copy/paste from the getting started docs located here, no more than that. The current Getting Started example from the documentation doesn’t work, and instead requires the developer to read an error message and fix it manually by including an extra package (or downgrading one). I don’t believe that’s a good introduction to an excellent project that doctrine/orm is.
I understand you are trying to stay away of being dependent on a cache dependency, while one is still needed for setting up. So I don’t have any other suggestion to fix this, except for applying your proposed PR against the getting started docs instead (https://github.com/doctrine/orm/pull/8883).
It works for me!
The error is already explained when you have typed a command E.g:
bash ./vendor/bin/doctrine list
Fatal error: Uncaught RuntimeException: Setup tool cannot configure caches without doctrine/cache 1.11In your composer.json, add the following:
"doctrine/cache": "~1.11.3",
Ok so I tried your example repository. I’m getting the following crash
I have read the error message. Now, let’s compare it with what’s installed.
Indeed, I have
doctrine/cache
, but v2, and I don’t havesymfony/cache
. I deserve this error message.The next steps are clear to me: I should either downgrade to
doctrine/cache
, or, and that’s better, installsymfony/cache
(withcomposer require symfony/cache
)After doing so, there is no crash anymore.
Is any of this unclear to anyone here?
In case you want to experience the absence of crash for yourself, I made a PR at https://github.com/dopeh/doctrine-orm-example/pull/1
👍 That might be possible without explicitly recommending
symfony/cache
, by requiringpsr/cache-implementation
fromdoctrine/cache
. Let me do a PR with that.