HPCloud-PHP  1.2.0
PHP bindings for HPCloud and OpenStack services.
 All Classes Namespaces Files Functions Variables Pages
Transport.php
Go to the documentation of this file.
1 <?php
2 /* ============================================================================
3 (c) Copyright 2012 Hewlett-Packard Development Company, L.P.
4 Permission is hereby granted, free of charge, to any person obtaining a copy
5 of this software and associated documentation files (the "Software"), to deal
6 in the Software without restriction, including without limitation the rights to
7 use, copy, modify, merge,publish, distribute, sublicense, and/or sell copies of
8 the Software, and to permit persons to whom the Software is furnished to do so,
9 subject to the following conditions:
10 
11 The above copyright notice and this permission notice shall be included in all
12 copies or substantial portions of the Software.
13 
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 SOFTWARE.
21 ============================================================================ */
22 /**
23  * @file
24  * The Transport class.
25  */
26 namespace HPCloud;
27 /**
28  * Provide an HTTP client (Transporter) for interaction with HPCloud.
29  *
30  * Interaction with the OpenStack/HPCloud services is handled via
31  * HTTPS/REST requests. This class provides transport for requests.
32  *
33  * <b>Usage</b>
34  *
35  * @code
36  * <?php
37  * // Create a new transport.
38  * $client = Transport::instance();
39  *
40  * // Send a request.
41  * $response = $client->doRequest($uri, $method, $headerArray, $body);
42  *
43  * print $response->content();
44  * ?>
45  * @endcode
46  *
47  */
48 class Transport {
49 
50  protected static $inst = NULL;
51 
52  /**
53  * Get an instance of a Transporter.
54  *
55  * See HPCloud::Transport::CURLTransport and HPCloud::Transport::PHPStreamTransport
56  * for implementations of an HPCloud::Transport::Transporter.
57  *
58  * To set the transport, the suggested method is this:
59  *
60  * @code
61  * <?php
62  * // Set the 'transport' config option.
63  * $settings = array(
64  * // Make sure you use the entire namespace, and that
65  * // your classloader can find this namespace.
66  * 'transport' => '\HPCloud\Transport\CURLTransport',
67  * );
68  *
69  * // Merge $settings into existing configuration.
70  * \HPCloud\Bootstrap::setConfiguration($settings);
71  * ?>
72  * @endcode
73  *
74  * @retval HPCloud::Transport::Transporter
75  * @return \HPCloud\Transport\Transporter
76  * An initialized transporter.
77  */
78  public static function instance() {
79 
80  if (empty(self::$inst)) {
81  $klass = \HPCloud\Bootstrap::config('transport');
82  self::$inst = new $klass();
83  }
84  return self::$inst;
85  }
86 
87  /**
88  * Rebuild the transporter.
89  *
90  * This will rebuild the client transporter,
91  * re-reading any configuration data in the process.
92  */
93  public static function reset() {
94  self::$inst = NULL;
95  }
96 }