如何获取公共对象

时间:2015-06-18 07:19:49

标签: php object guzzle rackspace-cloud rackspace

我正在使用Rackspace API处理PHP,这是我在这里使用的:

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

它给我回复了下面提到的结构。

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
                (
                )

        )

)

我需要的是这样的事情:

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
                (
                )

        )

)

所以至少我可以使用那些对象,任何建议?

1 个答案:

答案 0 :(得分:3)

它是Guzzle\Http\Url对象,您将无法访问其受保护或私有属性。该类为defined here,因此您可以使用任何公共方法来访问其状态。

您也可以将其强制转换为字符串:

$stringUrl = (string) $url;

或访问其他内容:

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

查询由另一个对象Guzzle\Http\QueryString表示:

$query = $url->getQuery();

有关对象可见性的更多信息,请参阅official docs