PageRenderTime 39ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/backwpup/libs/rackspace/cloudfiles.php

https://bitbucket.org/ssellek/saywhatnation.bitbucket
PHP | 2592 lines | 962 code | 114 blank | 1516 comment | 219 complexity | 1c42a73a72528717dc605d0fa7aa4faf MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1, GPL-2.0, GPL-3.0

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

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