Search code examples
phpobjectguzzlerackspace-cloudrackspace

How to get the public objects


I'm working on PHP with Rackspace API, this is what I have used here:

$file->setContent(fopen('sites/default/files/rackspace/' . $end_element, 'r+'));
$cdnUrl = $file->getPublicUrl();
print_r($cdnUrl);

And its returning me the below mentioned structure.

Guzzle\Http\Url Object
(
    [scheme:protected] => http
    [host:protected] => something.r2.cf3.rackcdn.com
    [port:protected] => 
    [username:protected] => 
    [password:protected] => 
    [path:protected] => /something-abc.jpg
    [fragment:protected] => 
    [query:protected] => Guzzle\Http\QueryString Object
        (
            [fieldSeparator:protected] => &
            [valueSeparator:protected] => =
            [urlEncode:protected] => RFC 3986
            [aggregator:protected] => 
            [data:protected] => Array
                (
                )

        )

)

What I need here is something like this:

Guzzle\Http\Url Object
(
    [scheme] => http
    [host] => something.r2.cf3.rackcdn.com
    [port] => 
    [username] => 
    [password] => 
    [path] => /something-abc.jpg
    [fragment] => 
    [query] => Guzzle\Http\QueryString Object
        (
            [fieldSeparator] => &
            [valueSeparator] => =
            [urlEncode] => RFC 3986
            [aggregator] => 
            [data] => Array
                (
                )

        )

)

So that at least I can use those objects, any suggestions?


Solution

  • It is a Guzzle\Http\Url object, and you will not be able to access its protected or private properties. The class is defined here, so you can use any of the public methods to access its state.

    You can also cast it to a string like so:

    $stringUrl = (string) $url;
    

    Or access other stuff:

    $host   = $url->getHost();   // something.r2.cf3.rackcdn.com
    $scheme = $url->getScheme(); // http
    $port   = $url->getPort();
    $path   = $url->getPath();   // something-abc.jpg
    

    The query is represented by another object, Guzzle\Http\QueryString:

    $query = $url->getQuery();
    

    For more info on object visibility, please consult the official docs.