php - 升级后 FOSUser Bundle Login 无法使用 Ramsey UUID
问题描述
我将 symfony 应用程序从 4.0 更新到 4.4 一切正常,除了登录到 ma 仪表板时,Could not convert database value "11ea3053-6c85-df5a-a..." to Doctrine Type uuid_binary_ordered_time. Expected format: UuidV1
如果我降级ramsey/uuid-doctrine
版本一切正常,我会收到此错误。
当前 Symfony 版本4.4
同一用户可以使用带有基本身份验证的 rest API 登录。这是我User.php
使用 UUID 的 id 参数。提前致谢。
/**
* @var Uuid
*
* @ORM\Id
* @ORM\Column(type="uuid_binary_ordered_time", unique=true)
* @ORM\GeneratedValue(strategy="CUSTOM")
* @ORM\CustomIdGenerator(class="Ramsey\Uuid\Doctrine\UuidOrderedTimeGenerator")
*/
protected $id;
/**
* @return string
*/
public function getId()
{
return $this->id->getHex();
}
解决方案
所以我找到了上述问题的解决方案。实际上,问题在于 symfony 序列化和反序列化。一切正常,除了使用会话存储用户数据的管理面板登录覆盖了安全性的序列化和反序列化方法,User Class User.php
一切正常。
主要的是,在序列化过程中,我必须将我的 uuid 转换为字符串,而在反序列化过程中,我必须将字符串 uuid 转换回。这是我的User.php
实体类中的代码。
public function serialize()
{
return serialize(array(
$this->password,
$this->salt,
$this->usernameCanonical,
$this->username,
$this->enabled,
$this->id->toString(),
$this->email,
$this->emailCanonical,
));
}
public function unserialize($serialized)
{
$data = unserialize($serialized);
if (13 === count($data)) {
// Unserializing a User object from 1.3.x
unset($data[4], $data[5], $data[6], $data[9], $data[10]);
$data = array_values($data);
} elseif (11 === count($data)) {
// Unserializing a User from a dev version somewhere between 2.0-alpha3 and 2.0-beta1
unset($data[4], $data[7], $data[8]);
$data = array_values($data);
}
$data[5] = UuidV1::fromString($data[5]);
list(
$this->password,
$this->salt,
$this->usernameCanonical,
$this->username,
$this->enabled,
$this->id,
$this->email,
$this->emailCanonical
) = $data;
}
推荐阅读
- python - yum 安装后找不到 mod_wsgi.so
- c# - Apache Ignite Group By Linq 查询问题
- reporting-services - 如何解决 SSRS 图表轴问题
- python - 如何在df中的日期之间附加月份名称并为每个月添加行?
- html - 如何同时隐藏@Html.TextBox 和日期类型?
- wordpress - 按变化的产品过滤器显示错误的产品
- javascript - 试图创建一个大的表情命令
- json - 调用 API 的 VBA 代码返回 XML 而不是 JSON
- r - 使用 if else 语句 R 创建一个新字段
- python - 为模拟 assert_call_once_with() 指定“类 Foo 的任何实例”?