      1: <?php
      2: /**
      3:  * Copyright 2012-2014 Rackspace US, Inc.
      4:  *
      5:  * Licensed under the Apache License, Version 2.0 (the "License");
      6:  * you may not use this file except in compliance with the License.
      7:  * You may obtain a copy of the License at
      8:  *
      9:  * http://www.apache.org/licenses/LICENSE-2.0
     10:  *
     11:  * Unless required by applicable law or agreed to in writing, software
     12:  * distributed under the License is distributed on an "AS IS" BASIS,
     13:  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14:  * See the License for the specific language governing permissions and
     15:  * limitations under the License.
     16:  */
     17:
     18: namespace OpenCloud\Common\Service;
     19:
     20: use Guzzle\Http\Url;
     21:
     22: /**
     23:  * An endpoint serves as a location which receives and emits API interactions. It will therefore also host
     24:  * particular API resources. Each endpoint object has different access methods - one receives network connections over
     25:  * the public Internet, another receives traffic through an internal network. You will be able to access the latter
     26:  * from a Server, for example, in the same Region - which will incur no bandwidth charges, and be quicker.
     27:  */
     28: class Endpoint
     29: {
     30:     /**
     31:      * @var \Guzzle\Http\Url
     32:      */
     33:     private $publicUrl;
     34:
     35:     /**
     36:      * @var \Guzzle\Http\Url
     37:      */
     38:     private $privateUrl;
     39:
     40:     /**
     41:      * @var string
     42:      */
     43:     private $region;
     44:
     45:     /**
     46:      * @param $object
     47:      * @return Endpoint
     48:      */
     49:     public static function factory($object)
     50:     {
     51:         $endpoint = new self();
     52:
     53:         if (isset($object->publicURL)) {
     54:             $endpoint->setPublicUrl($object->publicURL);
     55:         }
     56:         if (isset($object->internalURL)) {
     57:             $endpoint->setPrivateUrl($object->internalURL);
     58:         }
     59:         if (isset($object->region)) {
     60:             $endpoint->setRegion($object->region);
     61:         }
     62:
     63:         return $endpoint;
     64:     }
     65:
     66:     /**
     67:      * @param $publicUrl
     68:      * @return $this
     69:      */
     70:     public function setPublicUrl($publicUrl)
     71:     {
     72:         $this->publicUrl = Url::factory($publicUrl);
     73:
     74:         return $this;
     75:     }
     76:
     77:     /**
     78:      * @return Url
     79:      */
     80:     public function getPublicUrl()
     81:     {
     82:         return $this->publicUrl;
     83:     }
     84:
     85:     /**
     86:      * @param $privateUrl
     87:      * @return $this
     88:      */
     89:     public function setPrivateUrl($privateUrl)
     90:     {
     91:         $this->privateUrl = Url::factory($privateUrl);
     92:
     93:         return $this;
     94:     }
     95:
     96:     /**
     97:      * @return Url
     98:      */
     99:     public function getPrivateUrl()
    100:     {
    101:         return $this->privateUrl;
    102:     }
    103:
    104:     /**
    105:      * @param $region
    106:      * @return $this
    107:      */
    108:     public function setRegion($region)
    109:     {
    110:         $this->region = $region;
    111:
    112:         return $this;
    113:     }
    114:
    115:     /**
    116:      * @return string
    117:      */
    118:     public function getRegion()
    119:     {
    120:         return $this->region;
    121:     }
    122: }
    123: