我正在使用symfony组件在Silex中进行一些编程,我想我发现了它symfony/serializer和symfony/validator组件的错误.
首先让我解释一下我要实现的目标,然后让我们去看看代码.我的目标是使用序列化指令和验证指令等信息来注释类.由于读取这些注释可能需要花费很少的cpu,我喜欢将它们缓存在内存中.为此,我在Doctrine/Common/Cache包中使用了memcache包装器.
我面临的问题是,使用类名作为键symfony/serializer,symfony/validator将元数据写入缓存.当他们稍后尝试检索元数据时,会抛出异常,因为缓存具有无效的元数据,或者是Symfony\Component\Validator\Mapping\ClassMetadata或的实例Symfony\Component\Serializer\Mapping\ClassMetadataInterface.
以下是一个可重复的例子(对不起,如果它的大,我试图做尽可能小):
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
class Foo
{
/**
* @var int
* @Assert\NotBlank(message="This field cannot be empty")
*/
private $someProperty;
/**
* @return int
* @Groups({"some_group"})
*/
public function getSomeProperty() {
return $this->someProperty;
}
}
use Doctrine\Common\Annotations\AnnotationReader;
use \Memcache as MemcachePHP;
use Doctrine\Common\Cache\MemcacheCache as MemcacheWrapper;
$loader = require_once __DIR__ . '/../vendor/autoload.php';
\Doctrine\Common\Annotations\AnnotationRegistry::registerLoader([$loader, 'loadClass']);
$memcache = new MemcachePHP();
if (! $memcache->connect('localhost', …Run Code Online (Sandbox Code Playgroud)