我将一个项目从 Zend Framework 3 迁移到 Laminas。
因为我的 Doctrine 和 DoctrineModule\Cache\LaminasStorageCache 出现错误。
消息说: 无法创建名为“DoctrineModule\Cache\LaminasStorageCache”的服务。原因:无法解析 DoctrineModule\Cache\LaminasStorageCache 类中 Laminas\Cache\Storage\StorageInterface 类型的参数“storage”的值(作为 DoctrineModule\Cache\LaminasStorageCache 请求)
我没有在任何地方定义任何“存储”参数。
当我尝试访问数据库时发生此错误
$this->getServiceLocator()->get('Doctrine\ORM\EntityManager');
我可以获取ServiceLocator,它返回一个对象,但无法到达EntityManager。 此 EntityManager 多次子调用服务定位器以创建大量不同 Laminas 模块的实例,并且在 LaminasStorageCache 上失败,如错误消息所述。
我在本地主机中有一个简单的 MySQL 以及关于 Doctrine 的简单配置:
'doctrine' => array(
'connection' => array(
'orm_default' => array(
'driverClass' => \Doctrine\DBAL\Driver\PDO\MySQL\Driver::class,
'params' => array(
'host' => 'localhost',
'port' => '3306',
'user' => 'root',
'password' => '',
'dbname' => 'mybase',
'charset' => 'utf8'
)
)
),
我不明白这个错误,它没有链接到我的应用程序代码,它来自 Laminas 深 ^^ 这应该是一个糟糕的配置,但我不知道是什么:' 我深入代码并尝试配置 Doctrine 缓存,但没有任何区别。
如果有人可以帮助我或解释我错过了什么。
顺便说一句,我想补充一点,我有其他项目,已成功迁移到Laminas,我没有看到配置文件有任何差异,并且它们运行良好。
编辑: 我深入到 Laminas\Di\Resolver\DependencyResolver 并看到
public function resolveParameters(string $requestedType, array $callTimeParameters = []): array
{
$definition = $this->getClassDefinition($requestedType);
$params = $definition->getParameters();
$result = [];
[... and here $params is an array and contain storage...]
foreach ($params as $paramInfo) {
[...]
// The parameter is required, but we can't find anything that is suitable
if ($paramInfo->isRequired()) {
$isAlias = $this->config->isAlias($requestedType);
$class = $isAlias ? $this->config->getClassForAlias($requestedType) : $requestedType;
assert(is_string($class));
throw new Exception\MissingPropertyException(sprintf(
'Could not resolve value for parameter "%s" of type %s in class %s (requested as %s)',
$name,
$type ?: 'any',
$class,
$requestedType
));
}
$result[$name] = new ValueInjection($paramInfo->getDefault());
这就是显示的消息,是的,我配置错误了一些东西,但无法确切知道是什么。 它查找“存储”参数,我没有定义它。帮助:)
好的,我通过比较我的项目发现了这个问题。
在迁移过程中,laminas-di 会自动添加为依赖项。 教义加上层层有点太多了。
我删除了 laminas-di,这部分现在可以工作了!
希望这可以帮助将来的其他人
“laminas-di 有点太多了”是什么意思?