我有这个变量:$token = $resource->getToken();
这代表一个Dingo \ OAuth2 \ Entity \ Token Object:
Dingo\OAuth2\Entity\Token Object
(
[attributes:protected] => Array
(
[token] => 4w8kCzaxUeqPC4bt1vIqcyea7cnOwkXMRljnrTLZ
[type] => access
[client_id] => gozfly-support-wvjausbh
[user_id] => 2
[expires] => 1513305079
[scopes] => Array
(
[accounts.profile.basic] => Dingo\OAuth2\Entity\Scope Object
(
[attributes:protected] => Array
(
[scope] => accounts.profile.basic
[name] => View profile basic information
[description] => GOZFLY Accounts: View basic profile information
)
)
[accounts.profile.emailaddress] => Dingo\OAuth2\Entity\Scope Object
(
[attributes:protected] => Array
(
[scope] => accounts.profile.emailaddress
[name] => View profile email address information
[description] => GOZFLY Accounts: View email address profile information
)
)
)
)
)
我需要将此对象转换为php数组,如此输出:
{
"attributes": {
"token": "4w8kCzaxUeqPC4bt1vIqcyea7cnOwkXMRljnrTLZ",
"type": "access",
"client_id": "gozfly-support-wvjausbh",
"user_id": "2",
"expires": 1513301754,
"scopes": {
"accounts.profile.basic": {
"scope": "accounts.profile.basic",
"name": "View profile basic information",
"description": "GOZFLY Accounts: View basic profile information"
},
"accounts.profile.emailaddress": {
"scope": "accounts.profile.emailaddress",
"name": "View profile email address information",
"description": "GOZFLY Accounts: View email address profile information"
}
}
}
}
我尝试使用:(array)$ token但它没有正确进行转换,感谢任何帮助。
答案 0 :(得分:1)
解决使用:https://gist.github.com/TwanoO67/50049affa4d0307d54dcdc527533269c
object_to_array($token);