PageRenderTime 54ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/backupbuddy/destinations/rackspace/lib/rackspace/cloudfiles.php

https://bitbucket.org/betaimages/chakalos
PHP | 2385 lines | 885 code | 112 blank | 1388 comment | 183 complexity | 9259ef112adb606f3e9adc06420ae538 MD5 | raw file
Possible License(s): BSD-3-Clause

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. * This is the PHP Cloud Files API.
  4. *
  5. * <code>
  6. * # Authenticate to Cloud Files. The default is to automatically try
  7. * # to re-authenticate if an authentication token expires.
  8. * #
  9. * # NOTE: Some versions of cURL include an outdated certificate authority (CA)
  10. * # file. This API ships with a newer version obtained directly from
  11. * # cURL's web site (http://curl.haxx.se). To use the newer CA bundle,
  12. * # call the CF_Authentication instance's 'ssl_use_cabundle()' method.
  13. * #
  14. * $auth = new CF_Authentication($username, $api_key);
  15. * # $auth->ssl_use_cabundle(); # bypass cURL's old CA bundle
  16. * $auth->authenticate();
  17. *
  18. * # Establish a connection to the storage system
  19. * #
  20. * # NOTE: Some versions of cURL include an outdated certificate authority (CA)
  21. * # file. This API ships with a newer version obtained directly from
  22. * # cURL's web site (http://curl.haxx.se). To use the newer CA bundle,
  23. * # call the CF_Connection instance's 'ssl_use_cabundle()' method.
  24. * #
  25. * $conn = new CF_Connection($auth);
  26. * # $conn->ssl_use_cabundle(); # bypass cURL's old CA bundle
  27. *
  28. * # Create a remote Container and storage Object
  29. * #
  30. * $images = $conn->create_container("photos");
  31. * $bday = $images->create_object("first_birthday.jpg");
  32. *
  33. * # Upload content from a local file by streaming it. Note that we use
  34. * # a "float" for the file size to overcome PHP's 32-bit integer limit for
  35. * # very large files.
  36. * #
  37. * $fname = "/home/user/photos/birthdays/birthday1.jpg"; # filename to upload
  38. * $size = (float) sprintf("%u", filesize($fname));
  39. * $fp = open($fname, "r");
  40. * $bday->write($fp, $size);
  41. *
  42. * # Or... use a convenience function instead
  43. * #
  44. * $bday->load_from_filename("/home/user/photos/birthdays/birthday1.jpg");
  45. *
  46. * # Now, publish the "photos" container to serve the images by CDN.
  47. * # Use the "$uri" value to put in your web pages or send the link in an
  48. * # email message, etc.
  49. * #
  50. * $uri = $images->make_public();
  51. *
  52. * # Or... print out the Object's public URI
  53. * #
  54. * print $bday->public_uri();
  55. * </code>
  56. *
  57. * See the included tests directory for additional sample code.
  58. *
  59. * Requres PHP 5.x (for Exceptions and OO syntax) and PHP's cURL module.
  60. *
  61. * It uses the supporting "cloudfiles_http.php" module for HTTP(s) support and
  62. * allows for connection re-use and streaming of content into/out of Cloud Files
  63. * via PHP's cURL module.
  64. *
  65. * See COPYING for license information.
  66. *
  67. * @author Eric "EJ" Johnson <ej@racklabs.com>
  68. * @copyright Copyright (c) 2008, Rackspace US, Inc.
  69. * @package php-cloudfiles
  70. */
  71. /**
  72. */
  73. require_once("cloudfiles_exceptions.php");
  74. require("cloudfiles_http.php");
  75. define("DEFAULT_CF_API_VERSION", 1);
  76. define("MAX_CONTAINER_NAME_LEN", 256);
  77. define("MAX_OBJECT_NAME_LEN", 1024);
  78. define("MAX_OBJECT_SIZE", 5*1024*1024*1024+1);
  79. define("US_AUTHURL", "https://auth.api.rackspacecloud.com");
  80. define("UK_AUTHURL", "https://lon.auth.api.rackspacecloud.com");
  81. /**
  82. * Class for handling Cloud Files Authentication, call it's {@link authenticate()}
  83. * method to obtain authorized service urls and an authentication token.
  84. *
  85. * Example:
  86. * <code>
  87. * # Create the authentication instance
  88. * #
  89. * $auth = new CF_Authentication("username", "api_key");
  90. *
  91. * # NOTE: For UK Customers please specify your AuthURL Manually
  92. * # There is a Predfined constant to use EX:
  93. * #
  94. * # $auth = new CF_Authentication("username, "api_key", NULL, UK_AUTHURL);
  95. * # Using the UK_AUTHURL keyword will force the api to use the UK AuthUrl.
  96. * # rather then the US one. The NULL Is passed for legacy purposes and must
  97. * # be passed to function correctly.
  98. *
  99. * # NOTE: Some versions of cURL include an outdated certificate authority (CA)
  100. * # file. This API ships with a newer version obtained directly from
  101. * # cURL's web site (http://curl.haxx.se). To use the newer CA bundle,
  102. * # call the CF_Authentication instance's 'ssl_use_cabundle()' method.
  103. * #
  104. * # $auth->ssl_use_cabundle(); # bypass cURL's old CA bundle
  105. *
  106. * # Perform authentication request
  107. * #
  108. * $auth->authenticate();
  109. * </code>
  110. *
  111. * @package php-cloudfiles
  112. */
  113. class CF_Authentication
  114. {
  115. public $dbug;
  116. public $username;
  117. public $api_key;
  118. public $auth_host;
  119. public $account;
  120. /**
  121. * Instance variables that are set after successful authentication
  122. */
  123. public $storage_url;
  124. public $cdnm_url;
  125. public $auth_token;
  126. /**
  127. * Class constructor (PHP 5 syntax)
  128. *
  129. * @param string $username Mosso username
  130. * @param string $api_key Mosso API Access Key
  131. * @param string $account <i>Account name</i>
  132. * @param string $auth_host <i>Authentication service URI</i>
  133. */
  134. function __construct($username=NULL, $api_key=NULL, $account=NULL, $auth_host=US_AUTHURL)
  135. {
  136. $this->dbug = False;
  137. $this->username = $username;
  138. $this->api_key = $api_key;
  139. $this->account_name = $account;
  140. $this->auth_host = $auth_host;
  141. $this->storage_url = NULL;
  142. $this->cdnm_url = NULL;
  143. $this->auth_token = NULL;
  144. $this->cfs_http = new CF_Http(DEFAULT_CF_API_VERSION);
  145. }
  146. /**
  147. * Use the Certificate Authority bundle included with this API
  148. *
  149. * Most versions of PHP with cURL support include an outdated Certificate
  150. * Authority (CA) bundle (the file that lists all valid certificate
  151. * signing authorities). The SSL certificates used by the Cloud Files
  152. * storage system are perfectly valid but have been created/signed by
  153. * a CA not listed in these outdated cURL distributions.
  154. *
  155. * As a work-around, we've included an updated CA bundle obtained
  156. * directly from cURL's web site (http://curl.haxx.se). You can direct
  157. * the API to use this CA bundle by calling this method prior to making
  158. * any remote calls. The best place to use this method is right after
  159. * the CF_Authentication instance has been instantiated.
  160. *
  161. * You can specify your own CA bundle by passing in the full pathname
  162. * to the bundle. You can use the included CA bundle by leaving the
  163. * argument blank.
  164. *
  165. * @param string $path Specify path to CA bundle (default to included)
  166. */
  167. function ssl_use_cabundle($path=NULL)
  168. {
  169. $this->cfs_http->ssl_use_cabundle($path);
  170. }
  171. /**
  172. * Attempt to validate Username/API Access Key
  173. *
  174. * Attempts to validate credentials with the authentication service. It
  175. * either returns <kbd>True</kbd> or throws an Exception. Accepts a single
  176. * (optional) argument for the storage system API version.
  177. *
  178. * Example:
  179. * <code>
  180. * # Create the authentication instance
  181. * #
  182. * $auth = new CF_Authentication("username", "api_key");
  183. *
  184. * # Perform authentication request
  185. * #
  186. * $auth->authenticate();
  187. * </code>
  188. *
  189. * @param string $version API version for Auth service (optional)
  190. * @return boolean <kbd>True</kbd> if successfully authenticated
  191. * @throws AuthenticationException invalid credentials
  192. * @throws InvalidResponseException invalid response
  193. */
  194. function authenticate($version=DEFAULT_CF_API_VERSION)
  195. {
  196. list($status,$reason,$surl,$curl,$atoken) =
  197. $this->cfs_http->authenticate($this->username, $this->api_key,
  198. $this->account_name, $this->auth_host);
  199. if ($status == 401) {
  200. //throw new AuthenticationException("Invalid username or access key.");
  201. return false;
  202. }
  203. if ($status != 204) {
  204. // throw new InvalidResponseException(
  205. // "Unexpected response (".$status."): ".$reason);
  206. return false;
  207. }
  208. if (!($surl || $curl) || !$atoken) {
  209. //throw new InvalidResponseException(
  210. // "Expected headers missing from auth service.");
  211. return false;
  212. }
  213. $this->storage_url = $surl;
  214. $this->cdnm_url = $curl;
  215. $this->auth_token = $atoken;
  216. return True;
  217. }
  218. /**
  219. * Use Cached Token and Storage URL's rather then grabbing from the Auth System
  220. *
  221. * Example:
  222. * <code>
  223. * #Create an Auth instance
  224. * $auth = new CF_Authentication();
  225. * #Pass Cached URL's and Token as Args
  226. * $auth->load_cached_credentials("auth_token", "storage_url", "cdn_management_url");
  227. * </code>
  228. *
  229. * @param string $auth_token A Cloud Files Auth Token (Required)
  230. * @param string $storage_url The Cloud Files Storage URL (Required)
  231. * @param string $cdnm_url CDN Management URL (Required)
  232. * @return boolean <kbd>True</kbd> if successful
  233. * @throws SyntaxException If any of the Required Arguments are missing
  234. */
  235. function load_cached_credentials($auth_token, $storage_url, $cdnm_url)
  236. {
  237. if(!$storage_url || !$cdnm_url)
  238. {
  239. throw new SyntaxException("Missing Required Interface URL's!");
  240. return False;
  241. }
  242. if(!$auth_token)
  243. {
  244. throw new SyntaxException("Missing Auth Token!");
  245. return False;
  246. }
  247. $this->storage_url = $storage_url;
  248. $this->cdnm_url = $cdnm_url;
  249. $this->auth_token = $auth_token;
  250. return True;
  251. }
  252. /**
  253. * Grab Cloud Files info to be Cached for later use with the load_cached_credentials method.
  254. *
  255. * Example:
  256. * <code>
  257. * #Create an Auth instance
  258. * $auth = new CF_Authentication("UserName","API_Key");
  259. * $auth->authenticate();
  260. * $array = $auth->export_credentials();
  261. * </code>
  262. *
  263. * @return array of url's and an auth token.
  264. */
  265. function export_credentials()
  266. {
  267. $arr = array();
  268. $arr['storage_url'] = $this->storage_url;
  269. $arr['cdnm_url'] = $this->cdnm_url;
  270. $arr['auth_token'] = $this->auth_token;
  271. return $arr;
  272. }
  273. /**
  274. * Make sure the CF_Authentication instance has authenticated.
  275. *
  276. * Ensures that the instance variables necessary to communicate with
  277. * Cloud Files have been set from a previous authenticate() call.
  278. *
  279. * @return boolean <kbd>True</kbd> if successfully authenticated
  280. */
  281. function authenticated()
  282. {
  283. if (!($this->storage_url || $this->cdnm_url) || !$this->auth_token) {
  284. return False;
  285. }
  286. return True;
  287. }
  288. /**
  289. * Toggle debugging - set cURL verbose flag
  290. */
  291. function setDebug($bool)
  292. {
  293. $this->dbug = $bool;
  294. $this->cfs_http->setDebug($bool);
  295. }
  296. }
  297. /**
  298. * Class for establishing connections to the Cloud Files storage system.
  299. * Connection instances are used to communicate with the storage system at
  300. * the account level; listing and deleting Containers and returning Container
  301. * instances.
  302. *
  303. * Example:
  304. * <code>
  305. * # Create the authentication instance
  306. * #
  307. * $auth = new CF_Authentication("username", "api_key");
  308. *
  309. * # Perform authentication request
  310. * #
  311. * $auth->authenticate();
  312. *
  313. * # Create a connection to the storage/cdn system(s) and pass in the
  314. * # validated CF_Authentication instance.
  315. * #
  316. * $conn = new CF_Connection($auth);
  317. *
  318. * # NOTE: Some versions of cURL include an outdated certificate authority (CA)
  319. * # file. This API ships with a newer version obtained directly from
  320. * # cURL's web site (http://curl.haxx.se). To use the newer CA bundle,
  321. * # call the CF_Authentication instance's 'ssl_use_cabundle()' method.
  322. * #
  323. * # $conn->ssl_use_cabundle(); # bypass cURL's old CA bundle
  324. * </code>
  325. *
  326. * @package php-cloudfiles
  327. */
  328. class CF_Connection
  329. {
  330. public $dbug;
  331. public $cfs_http;
  332. public $cfs_auth;
  333. /**
  334. * Pass in a previously authenticated CF_Authentication instance.
  335. *
  336. * Example:
  337. * <code>
  338. * # Create the authentication instance
  339. * #
  340. * $auth = new CF_Authentication("username", "api_key");
  341. *
  342. * # Perform authentication request
  343. * #
  344. * $auth->authenticate();
  345. *
  346. * # Create a connection to the storage/cdn system(s) and pass in the
  347. * # validated CF_Authentication instance.
  348. * #
  349. * $conn = new CF_Connection($auth);
  350. *
  351. * # If you are connecting via Rackspace servers and have access
  352. * # to the servicenet network you can set the $servicenet to True
  353. * # like this.
  354. *
  355. * $conn = new CF_Connection($auth, $servicenet=True);
  356. *
  357. * </code>
  358. *
  359. * If the environement variable RACKSPACE_SERVICENET is defined it will
  360. * force to connect via the servicenet.
  361. *
  362. * @param obj $cfs_auth previously authenticated CF_Authentication instance
  363. * @param boolean $servicenet enable/disable access via Rackspace servicenet.
  364. * @throws AuthenticationException not authenticated
  365. */
  366. function __construct($cfs_auth, $servicenet=False)
  367. {
  368. if (isset($_ENV['RACKSPACE_SERVICENET']))
  369. $servicenet=True;
  370. $this->cfs_http = new CF_Http(DEFAULT_CF_API_VERSION);
  371. $this->cfs_auth = $cfs_auth;
  372. if (!$this->cfs_auth->authenticated()) {
  373. $e = "Need to pass in a previously authenticated ";
  374. $e .= "CF_Authentication instance.";
  375. throw new AuthenticationException($e);
  376. }
  377. $this->cfs_http->setCFAuth($this->cfs_auth, $servicenet=$servicenet);
  378. $this->dbug = False;
  379. }
  380. /**
  381. * Toggle debugging of instance and back-end HTTP module
  382. *
  383. * @param boolean $bool enable/disable cURL debugging
  384. */
  385. function setDebug($bool)
  386. {
  387. $this->dbug = (boolean) $bool;
  388. $this->cfs_http->setDebug($this->dbug);
  389. }
  390. /**
  391. * Close a connection
  392. *
  393. * Example:
  394. * <code>
  395. *
  396. * $conn->close();
  397. *
  398. * </code>
  399. *
  400. * Will close all current cUrl active connections.
  401. *
  402. */
  403. public function close()
  404. {
  405. $this->cfs_http->close();
  406. }
  407. /**
  408. * Cloud Files account information
  409. *
  410. * Return an array of two floats (since PHP only supports 32-bit integers);
  411. * number of containers on the account and total bytes used for the account.
  412. *
  413. * Example:
  414. * <code>
  415. * # ... authentication code excluded (see previous examples) ...
  416. * #
  417. * $conn = new CF_Authentication($auth);
  418. *
  419. * list($quantity, $bytes) = $conn->get_info();
  420. * print "Number of containers: " . $quantity . "\n";
  421. * print "Bytes stored in container: " . $bytes . "\n";
  422. * </code>
  423. *
  424. * @return array (number of containers, total bytes stored)
  425. * @throws InvalidResponseException unexpected response
  426. */
  427. function get_info()
  428. {
  429. list($status, $reason, $container_count, $total_bytes) =
  430. $this->cfs_http->head_account();
  431. #if ($status == 401 && $this->_re_auth()) {
  432. # return $this->get_info();
  433. #}
  434. if ($status < 200 || $status > 299) {
  435. throw new InvalidResponseException(
  436. "Invalid response (".$status."): ".$this->cfs_http->get_error());
  437. }
  438. return array($container_count, $total_bytes);
  439. }
  440. /**
  441. * Create a Container
  442. *
  443. * Given a Container name, return a Container instance, creating a new
  444. * remote Container if it does not exit.
  445. *
  446. * Example:
  447. * <code>
  448. * # ... authentication code excluded (see previous examples) ...
  449. * #
  450. * $conn = new CF_Authentication($auth);
  451. *
  452. * $images = $conn->create_container("my photos");
  453. * </code>
  454. *
  455. * @param string $container_name container name
  456. * @return CF_Container
  457. * @throws SyntaxException invalid name
  458. * @throws InvalidResponseException unexpected response
  459. */
  460. function create_container($container_name=NULL)
  461. {
  462. if ($container_name != "0" and !isset($container_name))
  463. throw new SyntaxException("Container name not set.");
  464. if (!isset($container_name) or $container_name == "")
  465. throw new SyntaxException("Container name not set.");
  466. if (strpos($container_name, "/") !== False) {
  467. $r = "Container name '".$container_name;
  468. $r .= "' cannot contain a '/' character.";
  469. throw new SyntaxException($r);
  470. }
  471. if (strlen($container_name) > MAX_CONTAINER_NAME_LEN) {
  472. throw new SyntaxException(sprintf(
  473. "Container name exeeds %d bytes.",
  474. MAX_CONTAINER_NAME_LEN));
  475. }
  476. $return_code = $this->cfs_http->create_container($container_name);
  477. if (!$return_code) {
  478. throw new InvalidResponseException("Invalid response ("
  479. . $return_code. "): " . $this->cfs_http->get_error());
  480. }
  481. #if ($status == 401 && $this->_re_auth()) {
  482. # return $this->create_container($container_name);
  483. #}
  484. if ($return_code != 201 && $return_code != 202) {
  485. throw new InvalidResponseException(
  486. "Invalid response (".$return_code."): "
  487. . $this->cfs_http->get_error());
  488. }
  489. return new CF_Container($this->cfs_auth, $this->cfs_http, $container_name);
  490. }
  491. /**
  492. * Delete a Container
  493. *
  494. * Given either a Container instance or name, remove the remote Container.
  495. * The Container must be empty prior to removing it.
  496. *
  497. * Example:
  498. * <code>
  499. * # ... authentication code excluded (see previous examples) ...
  500. * #
  501. * $conn = new CF_Authentication($auth);
  502. *
  503. * $conn->delete_container("my photos");
  504. * </code>
  505. *
  506. * @param string|obj $container container name or instance
  507. * @return boolean <kbd>True</kbd> if successfully deleted
  508. * @throws SyntaxException missing proper argument
  509. * @throws InvalidResponseException invalid response
  510. * @throws NonEmptyContainerException container not empty
  511. * @throws NoSuchContainerException remote container does not exist
  512. */
  513. function delete_container($container=NULL)
  514. {
  515. $container_name = NULL;
  516. if (is_object($container)) {
  517. if (get_class($container) == "CF_Container") {
  518. $container_name = $container->name;
  519. }
  520. }
  521. if (is_string($container)) {
  522. $container_name = $container;
  523. }
  524. if ($container_name != "0" and !isset($container_name))
  525. throw new SyntaxException("Must specify container object or name.");
  526. $return_code = $this->cfs_http->delete_container($container_name);
  527. if (!$return_code) {
  528. throw new InvalidResponseException("Failed to obtain http response");
  529. }
  530. #if ($status == 401 && $this->_re_auth()) {
  531. # return $this->delete_container($container);
  532. #}
  533. if ($return_code == 409) {
  534. throw new NonEmptyContainerException(
  535. "Container must be empty prior to removing it.");
  536. }
  537. if ($return_code == 404) {
  538. throw new NoSuchContainerException(
  539. "Specified container did not exist to delete.");
  540. }
  541. if ($return_code != 204) {
  542. throw new InvalidResponseException(
  543. "Invalid response (".$return_code."): "
  544. . $this->cfs_http->get_error());
  545. }
  546. return True;
  547. }
  548. /**
  549. * Return a Container instance
  550. *
  551. * For the given name, return a Container instance if the remote Container
  552. * exists, otherwise throw a Not Found exception.
  553. *
  554. * Example:
  555. * <code>
  556. * # ... authentication code excluded (see previous examples) ...
  557. * #
  558. * $conn = new CF_Authentication($auth);
  559. *
  560. * $images = $conn->get_container("my photos");
  561. * print "Number of Objects: " . $images->count . "\n";
  562. * print "Bytes stored in container: " . $images->bytes . "\n";
  563. * </code>
  564. *
  565. * @param string $container_name name of the remote Container
  566. * @return object/string CF_Container instance object. On error returns a string of the error.
  567. * @throws NoSuchContainerException thrown if no remote Container
  568. * @throws InvalidResponseException unexpected response
  569. */
  570. function get_container($container_name=NULL)
  571. {
  572. list($status, $reason, $count, $bytes) =
  573. $this->cfs_http->head_container($container_name);
  574. #if ($status == 401 && $this->_re_auth()) {
  575. # return $this->get_container($container_name);
  576. #}
  577. if ($status == 404) {
  578. return 'Error: Container not found. You must create it first. Status: `' . $status . '`. Reason: `' . $reason . '`.';
  579. }
  580. if ($status < 200 || $status > 299) {
  581. return 'Error: Invalid container response. Status: `' . $status . '`. Reason: `' . $reason . '`. Message: `' . $this->cfs_http->get_error() . '`.';
  582. }
  583. return new CF_Container($this->cfs_auth, $this->cfs_http, $container_name, $count, $bytes);
  584. }
  585. /**
  586. * Return array of Container instances
  587. *
  588. * Return an array of CF_Container instances on the account. The instances
  589. * will be fully populated with Container attributes (bytes stored and
  590. * Object count)
  591. *
  592. * Example:
  593. * <code>
  594. * # ... authentication code excluded (see previous examples) ...
  595. * #
  596. * $conn = new CF_Authentication($auth);
  597. *
  598. * $clist = $conn->get_containers();
  599. * foreach ($clist as $cont) {
  600. * print "Container name: " . $cont->name . "\n";
  601. * print "Number of Objects: " . $cont->count . "\n";
  602. * print "Bytes stored in container: " . $cont->bytes . "\n";
  603. * }
  604. * </code>
  605. *
  606. * @return array An array of CF_Container instances
  607. * @throws InvalidResponseException unexpected response
  608. */
  609. function get_containers($limit=0, $marker=NULL)
  610. {
  611. list($status, $reason, $container_info) =
  612. $this->cfs_http->list_containers_info($limit, $marker);
  613. #if ($status == 401 && $this->_re_auth()) {
  614. # return $this->get_containers();
  615. #}
  616. if ($status < 200 || $status > 299) {
  617. throw new InvalidResponseException(
  618. "Invalid response: ".$this->cfs_http->get_error());
  619. }
  620. $containers = array();
  621. foreach ($container_info as $name => $info) {
  622. $containers[] = new CF_Container($this->cfs_auth, $this->cfs_http,
  623. $info['name'], $info["count"], $info["bytes"], False);
  624. }
  625. return $containers;
  626. }
  627. /**
  628. * Return list of remote Containers
  629. *
  630. * Return an array of strings containing the names of all remote Containers.
  631. *
  632. * Example:
  633. * <code>
  634. * # ... authentication code excluded (see previous examples) ...
  635. * #
  636. * $conn = new CF_Authentication($auth);
  637. *
  638. * $container_list = $conn->list_containers();
  639. * print_r($container_list);
  640. * Array
  641. * (
  642. * [0] => "my photos",
  643. * [1] => "my docs"
  644. * )
  645. * </code>
  646. *
  647. * @param integer $limit restrict results to $limit Containers
  648. * @param string $marker return results greater than $marker
  649. * @return array list of remote Containers
  650. * @throws InvalidResponseException unexpected response
  651. */
  652. function list_containers($limit=0, $marker=NULL)
  653. {
  654. list($status, $reason, $containers) =
  655. $this->cfs_http->list_containers($limit, $marker);
  656. #if ($status == 401 && $this->_re_auth()) {
  657. # return $this->list_containers($limit, $marker);
  658. #}
  659. if ($status < 200 || $status > 299) {
  660. throw new InvalidResponseException(
  661. "Invalid response (".$status."): ".$this->cfs_http->get_error());
  662. }
  663. return $containers;
  664. }
  665. /**
  666. * Return array of information about remote Containers
  667. *
  668. * Return a nested array structure of Container info.
  669. *
  670. * Example:
  671. * <code>
  672. * # ... authentication code excluded (see previous examples) ...
  673. * #
  674. *
  675. * $container_info = $conn->list_containers_info();
  676. * print_r($container_info);
  677. * Array
  678. * (
  679. * ["my photos"] =>
  680. * Array
  681. * (
  682. * ["bytes"] => 78,
  683. * ["count"] => 2
  684. * )
  685. * ["docs"] =>
  686. * Array
  687. * (
  688. * ["bytes"] => 37323,
  689. * ["count"] => 12
  690. * )
  691. * )
  692. * </code>
  693. *
  694. * @param integer $limit restrict results to $limit Containers
  695. * @param string $marker return results greater than $marker
  696. * @return array nested array structure of Container info
  697. * @throws InvalidResponseException unexpected response
  698. */
  699. function list_containers_info($limit=0, $marker=NULL)
  700. {
  701. list($status, $reason, $container_info) =
  702. $this->cfs_http->list_containers_info($limit, $marker);
  703. #if ($status == 401 && $this->_re_auth()) {
  704. # return $this->list_containers_info($limit, $marker);
  705. #}
  706. if ($status < 200 || $status > 299) {
  707. throw new InvalidResponseException(
  708. "Invalid response (".$status."): ".$this->cfs_http->get_error());
  709. }
  710. return $container_info;
  711. }
  712. /**
  713. * Return list of Containers that have been published to the CDN.
  714. *
  715. * Return an array of strings containing the names of published Containers.
  716. * Note that this function returns the list of any Container that has
  717. * ever been CDN-enabled regardless of it's existence in the storage
  718. * system.
  719. *
  720. * Example:
  721. * <code>
  722. * # ... authentication code excluded (see previous examples) ...
  723. * #
  724. * $conn = new CF_Authentication($auth);
  725. *
  726. * $public_containers = $conn->list_public_containers();
  727. * print_r($public_containers);
  728. * Array
  729. * (
  730. * [0] => "images",
  731. * [1] => "css",
  732. * [2] => "javascript"
  733. * )
  734. * </code>
  735. *
  736. * @param bool $enabled_only Will list all containers ever CDN enabled if * set to false or only currently enabled CDN containers if set to true. * Defaults to false.
  737. * @return array list of published Container names
  738. * @throws InvalidResponseException unexpected response
  739. */
  740. function list_public_containers($enabled_only=False)
  741. {
  742. list($status, $reason, $containers) =
  743. $this->cfs_http->list_cdn_containers($enabled_only);
  744. #if ($status == 401 && $this->_re_auth()) {
  745. # return $this->list_public_containers();
  746. #}
  747. if ($status < 200 || $status > 299) {
  748. throw new InvalidResponseException(
  749. "Invalid response (".$status."): ".$this->cfs_http->get_error());
  750. }
  751. return $containers;
  752. }
  753. /**
  754. * Set a user-supplied callback function to report download progress
  755. *
  756. * The callback function is used to report incremental progress of a data
  757. * download functions (e.g. $container->list_objects(), $obj->read(), etc).
  758. * The specified function will be periodically called with the number of
  759. * bytes transferred until the entire download is complete. This callback
  760. * function can be useful for implementing "progress bars" for large
  761. * downloads.
  762. *
  763. * The specified callback function should take a single integer parameter.
  764. *
  765. * <code>
  766. * function read_callback($bytes_transferred) {
  767. * print ">> downloaded " . $bytes_transferred . " bytes.\n";
  768. * # ... do other things ...
  769. * return;
  770. * }
  771. *
  772. * $conn = new CF_Connection($auth_obj);
  773. * $conn->set_read_progress_function("read_callback");
  774. * print_r($conn->list_containers());
  775. *
  776. * # output would look like this:
  777. * #
  778. * >> downloaded 10 bytes.
  779. * >> downloaded 11 bytes.
  780. * Array
  781. * (
  782. * [0] => fuzzy.txt
  783. * [1] => space name
  784. * )
  785. * </code>
  786. *
  787. * @param string $func_name the name of the user callback function
  788. */
  789. function set_read_progress_function($func_name)
  790. {
  791. $this->cfs_http->setReadProgressFunc($func_name);
  792. }
  793. /**
  794. * Set a user-supplied callback function to report upload progress
  795. *
  796. * The callback function is used to report incremental progress of a data
  797. * upload functions (e.g. $obj->write() call). The specified function will
  798. * be periodically called with the number of bytes transferred until the
  799. * entire upload is complete. This callback function can be useful
  800. * for implementing "progress bars" for large uploads/downloads.
  801. *
  802. * The specified callback function should take a single integer parameter.
  803. *
  804. * <code>
  805. * function write_callback($bytes_transferred) {
  806. * print ">> uploaded " . $bytes_transferred . " bytes.\n";
  807. * # ... do other things ...
  808. * return;
  809. * }
  810. *
  811. * $conn = new CF_Connection($auth_obj);
  812. * $conn->set_write_progress_function("write_callback");
  813. * $container = $conn->create_container("stuff");
  814. * $obj = $container->create_object("foo");
  815. * $obj->write("The callback function will be called during upload.");
  816. *
  817. * # output would look like this:
  818. * # >> uploaded 51 bytes.
  819. * #
  820. * </code>
  821. *
  822. * @param string $func_name the name of the user callback function
  823. */
  824. function set_write_progress_function($func_name)
  825. {
  826. $this->cfs_http->setWriteProgressFunc($func_name);
  827. }
  828. /**
  829. * Use the Certificate Authority bundle included with this API
  830. *
  831. * Most versions of PHP with cURL support include an outdated Certificate
  832. * Authority (CA) bundle (the file that lists all valid certificate
  833. * signing authorities). The SSL certificates used by the Cloud Files
  834. * storage system are perfectly valid but have been created/signed by
  835. * a CA not listed in these outdated cURL distributions.
  836. *
  837. * As a work-around, we've included an updated CA bundle obtained
  838. * directly from cURL's web site (http://curl.haxx.se). You can direct
  839. * the API to use this CA bundle by calling this method prior to making
  840. * any remote calls. The best place to use this method is right after
  841. * the CF_Authentication instance has been instantiated.
  842. *
  843. * You can specify your own CA bundle by passing in the full pathname
  844. * to the bundle. You can use the included CA bundle by leaving the
  845. * argument blank.
  846. *
  847. * @param string $path Specify path to CA bundle (default to included)
  848. */
  849. function ssl_use_cabundle($path=NULL)
  850. {
  851. $this->cfs_http->ssl_use_cabundle($path);
  852. }
  853. #private function _re_auth()
  854. #{
  855. # $new_auth = new CF_Authentication(
  856. # $this->cfs_auth->username,
  857. # $this->cfs_auth->api_key,
  858. # $this->cfs_auth->auth_host,
  859. # $this->cfs_auth->account);
  860. # $new_auth->authenticate();
  861. # $this->cfs_auth = $new_auth;
  862. # $this->cfs_http->setCFAuth($this->cfs_auth);
  863. # return True;
  864. #}
  865. }
  866. /**
  867. * Container operations
  868. *
  869. * Containers are storage compartments where you put your data (objects).
  870. * A container is similar to a directory or folder on a conventional filesystem
  871. * with the exception that they exist in a flat namespace, you can not create
  872. * containers inside of containers.
  873. *
  874. * You also have the option of marking a Container as "public" so that the
  875. * Objects stored in the Container are publicly available via the CDN.
  876. *
  877. * @package php-cloudfiles
  878. */
  879. class CF_Container
  880. {
  881. public $cfs_auth;
  882. public $cfs_http;
  883. public $name;
  884. public $object_count;
  885. public $bytes_used;
  886. public $cdn_enabled;
  887. public $cdn_ssl_uri;
  888. public $cdn_uri;
  889. public $cdn_ttl;
  890. public $cdn_log_retention;
  891. public $cdn_acl_user_agent;
  892. public $cdn_acl_referrer;
  893. /**
  894. * Class constructor
  895. *
  896. * Constructor for Container
  897. *
  898. * @param obj $cfs_auth CF_Authentication instance
  899. * @param obj $cfs_http HTTP connection manager
  900. * @param string $name name of Container
  901. * @param int $count number of Objects stored in this Container
  902. * @param int $bytes number of bytes stored in this Container
  903. * @throws SyntaxException invalid Container name
  904. */
  905. function __construct(&$cfs_auth, &$cfs_http, $name, $count=0,
  906. $bytes=0, $docdn=True)
  907. {
  908. if (strlen($name) > MAX_CONTAINER_NAME_LEN) {
  909. throw new SyntaxException("Container name exceeds "
  910. . "maximum allowed length.");
  911. }
  912. if (strpos($name, "/") !== False) {
  913. throw new SyntaxException(
  914. "Container names cannot contain a '/' character.");
  915. }
  916. $this->cfs_auth = $cfs_auth;
  917. $this->cfs_http = $cfs_http;
  918. $this->name = $name;
  919. $this->object_count = $count;
  920. $this->bytes_used = $bytes;
  921. $this->cdn_enabled = NULL;
  922. $this->cdn_uri = NULL;
  923. $this->cdn_ssl_uri = NULL;
  924. $this->cdn_ttl = NULL;
  925. $this->cdn_log_retention = NULL;
  926. $this->cdn_acl_user_agent = NULL;
  927. $this->cdn_acl_referrer = NULL;
  928. if ($this->cfs_http->getCDNMUrl() != NULL && $docdn) {
  929. $this->_cdn_initialize();
  930. }
  931. }
  932. /**
  933. * String representation of Container
  934. *
  935. * Pretty print the Container instance.
  936. *
  937. * @return string Container details
  938. */
  939. function __toString()
  940. {
  941. $me = sprintf("name: %s, count: %.0f, bytes: %.0f",
  942. $this->name, $this->object_count, $this->bytes_used);
  943. if ($this->cfs_http->getCDNMUrl() != NULL) {
  944. $me .= sprintf(", cdn: %s, cdn uri: %s, cdn ttl: %.0f, logs retention: %s",
  945. $this->is_public() ? "Yes" : "No",
  946. $this->cdn_uri, $this->cdn_ttl,
  947. $this->cdn_log_retention ? "Yes" : "No"
  948. );
  949. if ($this->cdn_acl_user_agent != NULL) {
  950. $me .= ", cdn acl user agent: " . $this->cdn_acl_user_agent;
  951. }
  952. if ($this->cdn_acl_referrer != NULL) {
  953. $me .= ", cdn acl referrer: " . $this->cdn_acl_referrer;
  954. }
  955. }
  956. return $me;
  957. }
  958. /**
  959. * Enable Container content to be served via CDN or modify CDN attributes
  960. *
  961. * Either enable this Container's content to be served via CDN or
  962. * adjust its CDN attributes. This Container will always return the
  963. * same CDN-enabled URI each time it is toggled public/private/public.
  964. *
  965. * Example:
  966. * <code>
  967. * # ... authentication code excluded (see previous examples) ...
  968. * #
  969. * $conn = new CF_Authentication($auth);
  970. *
  971. * $public_container = $conn->create_container("public");
  972. *
  973. * # CDN-enable the container and set it's TTL for a month
  974. * #
  975. * $public_container->make_public(86400/2); # 12 hours (86400 seconds/day)
  976. * </code>
  977. *
  978. * @param int $ttl the time in seconds content will be cached in the CDN
  979. * @returns string the CDN enabled Container's URI
  980. * @throws CDNNotEnabledException CDN functionality not returned during auth
  981. * @throws AuthenticationException if auth token is not valid/expired
  982. * @throws InvalidResponseException unexpected response
  983. */
  984. function make_public($ttl=86400)
  985. {
  986. if ($this->cfs_http->getCDNMUrl() == NULL) {
  987. throw new CDNNotEnabledException(
  988. "Authentication response did not indicate CDN availability");
  989. }
  990. if ($this->cdn_uri != NULL) {
  991. # previously published, assume we're setting new attributes
  992. list($status, $reason, $cdn_uri, $cdn_ssl_uri) =
  993. $this->cfs_http->update_cdn_container($this->name,$ttl,
  994. $this->cdn_log_retention,
  995. $this->cdn_acl_user_agent,
  996. $this->cdn_acl_referrer);
  997. #if ($status == 401 && $this->_re_auth()) {
  998. # return $this->make_public($ttl);
  999. #}
  1000. if ($status == 404) {
  1001. # this instance _thinks_ the container was published, but the
  1002. # cdn management system thinks otherwise - try again with a PUT
  1003. list($status, $reason, $cdn_uri, $cdn_ssl_uri) =
  1004. $this->cfs_http->add_cdn_container($this->name,$ttl);
  1005. }
  1006. } else {
  1007. # publish it for first time
  1008. list($status, $reason, $cdn_uri, $cdn_ssl_uri) =
  1009. $this->cfs_http->add_cdn_container($this->name,$ttl);
  1010. }
  1011. #if ($status == 401 && $this->_re_auth()) {
  1012. # return $this->make_public($ttl);
  1013. #}
  1014. if (!in_array($status, array(201,202))) {
  1015. throw new InvalidResponseException(
  1016. "Invalid response (".$status."): ".$this->cfs_http->get_error());
  1017. }
  1018. $this->cdn_enabled = True;
  1019. $this->cdn_ttl = $ttl;
  1020. $this->cdn_ssl_uri = $cdn_ssl_uri;
  1021. $this->cdn_uri = $cdn_uri;
  1022. $this->cdn_log_retention = False;
  1023. $this->cdn_acl_user_agent = "";
  1024. $this->cdn_acl_referrer = "";
  1025. return $this->cdn_uri;
  1026. }
  1027. /**
  1028. * Purge Containers objects from CDN Cache.
  1029. * Example:
  1030. * <code>
  1031. * # ... authentication code excluded (see previous examples) ...
  1032. * #
  1033. * $conn = new CF_Authentication($auth);
  1034. * $container = $conn->get_container("cdn_enabled");
  1035. * $container->purge_from_cdn("user@domain.com");
  1036. * # or
  1037. * $container->purge_from_cdn();
  1038. * # or
  1039. * $container->purge_from_cdn("user1@domain.com,user2@domain.com");
  1040. * @returns boolean True if successful
  1041. * @throws CDNNotEnabledException if CDN Is not enabled on this connection
  1042. * @throws InvalidResponseException if the response expected is not returned
  1043. */
  1044. function purge_from_cdn($email=null)
  1045. {
  1046. if (!$this->cfs_http->getCDNMUrl())
  1047. {
  1048. throw new CDNNotEnabledException(
  1049. "Authentication response did not indicate CDN availability");
  1050. }
  1051. $status = $this->cfs_http->purge_from_cdn($this->name, $email);
  1052. if ($status < 199 or $status > 299) {
  1053. throw new InvalidResponseException(
  1054. "Invalid response (".$status."): ".$this->cfs_http->get_error());
  1055. }
  1056. return True;
  1057. }
  1058. /**
  1059. * Enable ACL restriction by User Agent for this container.
  1060. *
  1061. * Example:
  1062. * <code>
  1063. * # ... authentication code excluded (see previous examples) ...
  1064. * #
  1065. * $conn = new CF_Authentication($auth);
  1066. *
  1067. * $public_container = $conn->get_container("public");
  1068. *
  1069. * # Enable ACL by Referrer
  1070. * $public_container->acl_referrer("Mozilla");
  1071. * </code>
  1072. *
  1073. * @returns boolean True if successful
  1074. * @throws CDNNotEnabledException CDN functionality not returned during auth
  1075. * @throws AuthenticationException if auth token is not valid/expired
  1076. * @throws InvalidResponseException unexpected response
  1077. */
  1078. function acl_user_agent($cdn_acl_user_agent="") {
  1079. if ($this->cfs_http->getCDNMUrl() == NULL) {
  1080. throw new CDNNotEnabledException(
  1081. "Authentication response did not indicate CDN availability");
  1082. }
  1083. list($status,$reason) =
  1084. $this->cfs_http->update_cdn_container($this->name,
  1085. $this->cdn_ttl,
  1086. $this->cdn_log_retention,
  1087. $cdn_acl_user_agent,
  1088. $this->cdn_acl_referrer
  1089. );
  1090. if (!in_array($status, array(202,404))) {
  1091. throw new InvalidResponseException(
  1092. "Invalid response (".$status."): ".$this->cfs_http->get_error());
  1093. }
  1094. $this->cdn_acl_user_agent = $cdn_acl_user_agent;
  1095. return True;
  1096. }
  1097. /**
  1098. * Enable ACL restriction by referer for this container.
  1099. *
  1100. * Example:
  1101. * <code>
  1102. * # ... authentication code excluded (see previous examples) ...
  1103. * #
  1104. * $conn = new CF_Authentication($auth);
  1105. *
  1106. * $public_container = $conn->get_container("public");
  1107. *
  1108. * # Enable Referrer
  1109. * $public_container->acl_referrer("http://www.example.com/gallery.php");
  1110. * </code>
  1111. *
  1112. * @returns boolean True if successful
  1113. * @throws CDNNotEnabledException CDN functionality not returned during auth
  1114. * @throws AuthenticationException if auth token is not valid/expired
  1115. * @throws InvalidResponseException unexpected response
  1116. */
  1117. function acl_referrer($cdn_acl_referrer="") {
  1118. if ($this->cfs_http->getCDNMUrl() == NULL) {
  1119. throw new CDNNotEnabledException(
  1120. "Authentication response did not indicate CDN availability");
  1121. }
  1122. list($status,$reason) =
  1123. $this->cfs_http->update_cdn_container($this->name,
  1124. $this->cdn_ttl,
  1125. $this->cdn_log_retention,
  1126. $this->cdn_acl_user_agent,
  1127. $cdn_acl_referrer
  1128. );
  1129. if (!in_array($status, array(202,404))) {
  1130. throw new InvalidResponseException(
  1131. "Invalid response (".$status."): ".$this->cfs_http->get_error());
  1132. }
  1133. $this->cdn_acl_referrer = $cdn_acl_referrer;
  1134. return True;
  1135. }
  1136. /**
  1137. * Enable log retention for this CDN container.
  1138. *
  1139. * Enable CDN log retention on the container. If enabled logs will
  1140. * be periodically (at unpredictable intervals) compressed and
  1141. * uploaded to a ".CDN_ACCESS_LOGS" container in the form of
  1142. * "container_name.YYYYMMDDHH-XXXX.gz". Requires CDN be enabled on
  1143. * the account.
  1144. *
  1145. * Example:
  1146. * <code>
  1147. * # ... authentication code excluded (see previous examples) ...
  1148. * #
  1149. * $conn = new CF_Authentication($auth);
  1150. *
  1151. * $public_container = $conn->get_container("public");
  1152. *
  1153. * # Enable logs retention.
  1154. * $public_container->log_retention(True);
  1155. * </code>
  1156. *
  1157. * @returns boolean True if successful
  1158. * @throws CDNNotEnabledException CDN functionality not returned during auth
  1159. * @throws AuthenticationException if auth token is not valid/expired
  1160. * @throws InvalidResponseException unexpected response
  1161. */
  1162. function log_retention($cdn_log_retention=False) {
  1163. if ($this->cfs_http->getCDNMUrl() == NULL) {
  1164. throw new CDNNotEnabledException(
  1165. "Authentication response did not indicate CDN availability");
  1166. }
  1167. list($status,$reason) =
  1168. $this->cfs_http->update_cdn_container($this->name,
  1169. $this->cdn_ttl,
  1170. $cdn_log_retention,
  1171. $this->cdn_acl_user_agent,
  1172. $this->cdn_acl_referrer
  1173. );
  1174. if (!in_array($status, array(202,404))) {
  1175. throw new InvalidResponseException(
  1176. "Invalid response (".$status."): ".$this->cfs_http->get_error());
  1177. }
  1178. $this->cdn_log_retention = $cdn_log_retention;
  1179. return True;
  1180. }
  1181. /**
  1182. * Disable the CDN sharing for this container
  1183. *
  1184. * Use this method to disallow distribution into the CDN of this Container's
  1185. * content.
  1186. *
  1187. * NOTE: Any content already cached in the CDN will continue to be served
  1188. * from its cache until the TTL expiration transpires. The default
  1189. * TTL is typically one day, so "privatizing" the Container will take
  1190. * up to 24 hours before the content is purged from the CDN cache.
  1191. *
  1192. * Example:
  1193. * <code>
  1194. * # ... authentication code excluded (see previous examples) ...
  1195. * #
  1196. * $conn = new CF_Authentication($auth);
  1197. *
  1198. * $public_container = $conn->get_container("public");
  1199. *
  1200. * # Disable CDN accessability
  1201. * # ... still cached up to a month based on previous example
  1202. * #
  1203. * $public_container->make_private();
  1204. * </code>
  1205. *
  1206. * @returns boolean True if successful
  1207. * @throws CDNNotEnabledException CDN functionality not returned during auth
  1208. * @throws AuthenticationException if auth token is not valid/expired
  1209. * @throws InvalidResponseException unexpected response
  1210. */
  1211. function make_private()
  1212. {
  1213. if ($this->cfs_http->getCDNMUrl() == NULL) {
  1214. throw new CDNNotEnabledException(
  1215. "Authentication response did not indicate CDN availability");
  1216. }
  1217. list($status,$reason) = $this->cfs_http->remove_cdn_container($this->name);
  1218. #if ($status == 401 && $this->_re_auth()) {
  1219. # return $this->make_private();
  1220. #}
  1221. if (!in_array($status, array(202,404))) {
  1222. throw new InvalidResponseException(
  1223. "Invalid response (".$status."): ".$this->cfs_http->get_error());
  1224. }
  1225. $this->cdn_enabled = False;
  1226. $this->cdn_ttl = NULL;
  1227. $this->cdn_uri = NULL;
  1228. $this->cdn_ssl_uri = NULL;
  1229. $this->cdn_log_retention = NULL;
  1230. $this->cdn_acl_user_agent = NULL;
  1231. $this->cdn_acl_referrer = NULL;
  1232. return True;
  1233. }
  1234. /**
  1235. * Check if this Container is being publicly served via CDN
  1236. *
  1237. * Use this method to determine if the Container's content is currently
  1238. * available through the CDN.
  1239. *
  1240. * Example:
  1241. * <code>
  1242. * # ... authentication code excluded (see previous examples) ...
  1243. * #
  1244. * $conn = new CF_Authentication($auth);
  1245. *
  1246. * $public_container = $conn->get_container("public");
  1247. *
  1248. * # Display CDN accessability
  1249. * #
  1250. * $public_container->is_public() ? print "Yes" : print "No";
  1251. * </code>
  1252. *
  1253. * @returns boolean True if enabled, False otherwise
  1254. */
  1255. function is_public()
  1256. {
  1257. return $this->cdn_enabled == True ? True : False;
  1258. }
  1259. /**
  1260. * Create a new remote storage Object
  1261. *
  1262. * Return a new Object instance. If the remote storage Object exists,
  1263. * the instance's attributes are populated.
  1264. *
  1265. * Example:
  1266. * <code>
  1267. * # ... authentication code excluded (see previous examples) ...
  1268. * #
  1269. * $conn = new CF_Authentication($auth);
  1270. *
  1271. * $public_container = $conn->get_container("public");
  1272. *
  1273. * # This creates a local instance of a storage object but only creates
  1274. * # it in the storage system when the object's write() method is called.
  1275. * #
  1276. * $pic = $public_container->create_object("baby.jpg");
  1277. * </code>
  1278. *
  1279. * @param string $obj_name name of storage Object
  1280. * @return obj CF_Object instance
  1281. */
  1282. function create_object($obj_name=NULL)
  1283. {
  1284. return new CF_Object($this, $obj_name);
  1285. }
  1286. /**
  1287. * Return an Object instance for the remote storage Object
  1288. *
  1289. * Given a name, return a Object instance representing the
  1290. * remote storage object.
  1291. *
  1292. * Example:
  1293. * <code>
  1294. * # ... authentication code excluded (see previous examples) ...
  1295. * #
  1296. * $conn = new CF_Authentication($auth);
  1297. *
  1298. * $public_container = $conn->get_container("public");
  1299. *
  1300. * # This call only fetches header information and not the content of
  1301. * # the storage object. Use the Object's read() or stream() methods
  1302. * # to obtain the object's data.
  1303. * #
  1304. * $pic = $public_container->get_object("baby.jpg");
  1305. * </code>
  1306. *
  1307. * @param string $obj_name name of storage Object
  1308. * @return obj CF_Object instance
  1309. */
  1310. function get_object($obj_name=NULL)
  1311. {
  1312. return new CF_Object($this, $obj_name, True);
  1313. }
  1314. /**
  1315. * Return a list of Objects
  1316. *
  1317. * Return an array of strings listing the Object names in this Container.
  1318. *
  1319. * Example:
  1320. * <code>
  1321. * # ... authentication code excluded (see previous examples) ...
  1322. * #
  1323. * $images = $conn->get_container("my photos");
  1324. *
  1325. * # Grab the list of all storage objects
  1326. * #
  1327. * $all_objects = $images->list_objects();
  1328. *
  1329. * # Grab subsets of all storage objects
  1330. * #
  1331. * $first_ten = $images->list_objects(10);
  1332. *
  1333. * # Note the use of the previous result's last object name being
  1334. * # used as the 'marker' parameter to fetch the next 10 objects
  1335. * #
  1336. * $next_ten = $images->list_objects(10, $first_ten[count($first_ten)-1]);
  1337. *
  1338. * # Grab images starting with "birthday_party" and default limit/marker
  1339. * # to match all photos with that prefix
  1340. * #
  1341. * $prefixed = $images->list_objects(0, NULL, "birthday");
  1342. *
  1343. * # Assuming you have created the appropriate directory marker Objects,
  1344. * # you can traverse your pseudo-hierarchical containers
  1345. * # with the "path" argument.
  1346. * #
  1347. * $animals = $images->list_objects(0,NULL,NULL,"pictures/animals");
  1348. * $dogs = $images->list_objects(0,NULL,NULL,"pictures/animals/dogs");
  1349. * </code>
  1350. *
  1351. * @param int $limit <i>optional</i> only return $limit names
  1352. * @param int $marker <i>optional</i> subset of names starting at $marker
  1353. * @param string $prefix <i>optional</i> Objects whose names begin with $prefix
  1354. * @param string $path <i>optional</i> only return results under "pathname"
  1355. * @return array array of strings
  1356. * @throws InvalidResponseEx…

Large files files are truncated, but you can click here to view the full file