1

I have this variable: $token = $resource->getToken();

This represent a 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
                                )

                        )

                )

        )

)

I need to convert this object to and php array like this output:

{
    "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"
            }
        }
    }
}

I tried to use: (array)$token but it does not do the conversion correctly, any help is appreciated.

u_mulder
  • 54,101
  • 5
  • 48
  • 64
Jonathan Nuñez
  • 432
  • 6
  • 19

1 Answers1

1

Solved using: https://gist.github.com/TwanoO67/50049affa4d0307d54dcdc527533269c

object_to_array($token);
Jonathan Nuñez
  • 432
  • 6
  • 19