symfony 赞助的项目 \Doctrine\ORM\Mapping\Driver\SimplifiedYamlDriver 在我的项目中非常有用,可以保持实体文件名干净简单。然而,JMSSerialize 假定每个实体的命名约定是完全限定的命名空间。在 Doctrine2 配置中使用 \Doctrine\ORM\Mapping\Driver\SimplifiedYamlDriver 时,情况并非如此。
(http://docs.doctrine-project.org/en/latest/reference/yaml-mapping.html http://docs.doctrine-project.org/en/latest/reference/yaml-mapping.html)
<?php
$namespaces = array(
'/path/to/files1' => 'MyProject\Entities',
'/path/to/files2' => 'OtherProject\Entities'
);
$driver = new \Doctrine\ORM\Mapping\Driver\SimplifiedYamlDriver($namespaces);
根据文档:文件名被缩短,“MyProject\Entities\User”将变为 User.orm.yml
但 JMSSerialzer 正在 $myDir 查找 YAML 文件。 '/MyProject.Entities.User.yml'
(see: http://jmsyst.com/libs/serializer/master/configuration#configuring-metadata-locations http://jmsyst.com/libs/serializer/master/configuration#configuring-metadata-locations)
问题:有没有办法覆盖 JMSSerialize 查找的元数据文件名?我已经使用 addMetadataDir() 来指定其位置
注意:这不是 Symfony2 项目
您是否使用了第二个参数addMetadataDir
?
From JMS\Serializer\SerializerBuilder.php
:
/**
* Adds a directory where the serializer will look for class metadata.
*
* The namespace prefix will make the names of the actual metadata files a bit shorter. For example, let's assume
* that you have a directory where you only store metadata files for the ``MyApplication\Entity`` namespace.
*
* If you use an empty prefix, your metadata files would need to look like:
*
* ``my-dir/MyApplication.Entity.SomeObject.yml``
* ``my-dir/MyApplication.Entity.OtherObject.xml``
*
* If you use ``MyApplication\Entity`` as prefix, your metadata files would need to look like:
*
* ``my-dir/SomeObject.yml``
* ``my-dir/OtherObject.yml``
*
* Please keep in mind that you currently may only have one directory per namespace prefix.
*
* @param string $dir The directory where metadata files are located.
* @param string $namespacePrefix An optional prefix if you only store metadata for specific namespaces in this directory.
*
* @return SerializerBuilder
*
* @throws InvalidArgumentException When a directory does not exist
* @throws InvalidArgumentException When a directory has already been registered
*/
public function addMetadataDir($dir, $namespacePrefix = '')
{
// ...
}
看来如果您指定第二个参数,您就可以实现您正在寻找的目标。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)