到目前为止,从以下几行$records = $this->entityManager->getRepository(Translation::class)->findBy([], ['id' => 'DESC'], 1, 0);$uuid = $records[0]->getId();我可以得到以下几行。Ramsey\Uuid\Uuid {#131 #codec: Ramsey\Uuid\Codec\StringCodec {#86 -builder: Ramsey\Uuid\Builder\DefaultUuidBuilder {#383 -converter: Ramsey\Uuid\Converter\Number\DegradedNumberConverter {#390} } } #fields: array:6 [ "time_low" => "1483fc71" "time_mid" => "66e9" "time_hi_and_version" => "4e21" "clock_seq_hi_and_reserved" => "b9" "clock_seq_low" => "50" "node" => "c6e9e6405428" ] #converter: Ramsey\Uuid\Converter\Number\DegradedNumberConverter {#390} uuid: "1483fc71-66e9"}我怎样才能提取uuid?
2 回答
跃然一笑
TA贡献1826条经验 获得超6个赞
您可以通过Ramsey\Uuid\Uuid多种方式将 UUID 提取为字符串。基本方法是Ramsey\Uuid\Uuid::toString(),所以对于您的代码示例如下:
$uuid = $records[0]->getId()->toString();
对于命名约定,存在一些全部调用的包装方法Ramsey\Uuid\Uuid::toString():
Ramsey\Uuid\Uuid::serialize()
Ramsey\Uuid\Uuid::jsonSerialize()
但是当然你可以将整个对象转换为字符串。
梵蒂冈之花
TA贡献1900条经验 获得超5个赞
该类实现了 PHP 的__toString
方法,因此您可以将对象转换为字符串:
$uuid = (string) $records[0]->getId();
- 2 回答
- 0 关注
- 127 浏览
添加回答
举报
0/150
提交
取消