Overview

Namespaces

  • None
  • OpenCloud
    • Autoscale
      • Resource
    • CloudMonitoring
      • Exception
      • Resource
    • Common
      • Exceptions
      • Log
      • Request
        • Response
    • Compute
    • Database
    • DNS
    • LoadBalancer
      • Resources
    • ObjectStore
      • Resource
    • Orchestration
    • Volume
  • PHP

Classes

  • AbstractService
  • CDNService
  • Service
  • Overview
  • Namespace
  • Class
  • Tree
  • Download
  1: <?php
  2: /**
  3:  * PHP OpenCloud library.
  4:  * 
  5:  * @copyright Copyright 2013 Rackspace US, Inc. See COPYING for licensing information.
  6:  * @license   https://www.apache.org/licenses/LICENSE-2.0 Apache 2.0
  7:  * @version   1.6.0
  8:  * @author    Glen Campbell <glen.campbell@rackspace.com>
  9:  * @author    Jamie Hannaford <jamie.hannaford@rackspace.com>
 10:  */
 11: 
 12: namespace OpenCloud\ObjectStore;
 13: 
 14: use OpenCloud\OpenStack;
 15: use OpenCloud\Common\Exceptions;
 16: use OpenCloud\Common\Lang;
 17: 
 18: /**
 19:  * The ObjectStore (Cloud Files) service.
 20:  */
 21: class Service extends AbstractService 
 22: {
 23:     
 24:     /**
 25:      * This holds the associated CDN service (for Rackspace public cloud)
 26:      * or is NULL otherwise. The existence of an object here is
 27:      * indicative that the CDN service is available.
 28:      */
 29:     private $cdn;
 30: 
 31:     /**
 32:      * Creates a new ObjectStore service object.
 33:      *
 34:      * @param OpenCloud\OpenStack $connection    The connection object
 35:      * @param string              $serviceName   The name of the service
 36:      * @param string              $serviceRegion The service's region
 37:      * @param string              $urlType       The type of URL (normally 'publicURL')
 38:      */
 39:     public function __construct(
 40:         OpenStack $connection,
 41:         $serviceName = RAXSDK_OBJSTORE_NAME,
 42:         $serviceRegion = RAXSDK_OBJSTORE_REGION,
 43:         $urltype = RAXSDK_OBJSTORE_URLTYPE
 44:     ) {
 45:         $this->getLogger()->info('Initializing Container Service...');
 46: 
 47:         parent::__construct(
 48:             $connection,
 49:             'object-store',
 50:             $serviceName,
 51:             $serviceRegion,
 52:             $urltype
 53:         );
 54: 
 55:         // establish the CDN container, if available
 56:         try {
 57:             $this->cdn = new CDNService(
 58:                 $connection,
 59:                 $serviceName . 'CDN',
 60:                 $serviceRegion,
 61:                 $urltype
 62:             );
 63:         } catch (Exceptions\EndpointError $e) {
 64:              // If we have an endpoint error, then the CDN functionality is not 
 65:              // available. In this case, we silently ignore  it.
 66:         }
 67:     }
 68: 
 69:     /** 
 70:      * Sets the shared secret value for the TEMP_URL
 71:      *
 72:      * @param string $secret the shared secret
 73:      * @return HttpResponse
 74:      */
 75:     public function setTempUrlSecret($secret) 
 76:     {
 77:         $response = $this->request(
 78:             $this->url(), 
 79:             'POST',
 80:             array('X-Account-Meta-Temp-Url-Key' => $secret)
 81:         );
 82:         
 83:         // @codeCoverageIgnoreStart
 84:         if ($response->httpStatus() > 204) {
 85:             throw new Exceptions\HttpError(sprintf(
 86:                 Lang::translate('Error in request, status [%d] for URL [%s] [%s]'),
 87:                 $response->httpStatus(),
 88:                 $this->url(),
 89:                 $response->httpBody()
 90:             ));
 91:         }
 92:         // @codeCoverageIgnoreEnd
 93: 
 94:         return $response;
 95:     }
 96: 
 97:     /**
 98:      * Get the CDN service.
 99:      * 
100:      * @return null|CDNService
101:      */
102:     public function getCDNService() 
103:     {
104:         return $this->cdn;
105:     }
106:     
107:     /**
108:      * Backwards compability.
109:      */
110:     public function CDN()
111:     {
112:         return $this->getCDNService();
113:     }
114:     
115: }
116: 
PHP OpenCloud API API documentation generated by ApiGen 2.8.0