HPCloud-PHP  1.2.0
PHP bindings for HPCloud and OpenStack services.
 All Classes Namespaces Files Functions Variables Pages
oo-tutorial-code.php
Go to the documentation of this file.
1 <?php
2 require_once __DIR__ . '/../src/HPCloud/Bootstrap.php';
3 
4 use \HPCloud\Bootstrap;
5 use \HPCloud\Services\IdentityServices;
6 use \HPCloud\Storage\ObjectStorage;
7 use \HPCloud\Storage\ObjectStorage\Object;
8 
9 Bootstrap::useAutoloader();
10 
11 // Load these from an ini file.
12 $ini = parse_ini_file(getenv('HOME') . '/.hpcloud.ini');
13 $account = $ini['account'];
14 $key = $ini['secret'];
15 $tenantId = $ini['tenantId'];
16 $endpoint = $ini['url'];
17 
19 $token = $idService->authenticateAsAccount($account, $key, $tenantId);
20 
21 $catalog = $idService->serviceCatalog();
22 
23 $store = ObjectStorage::newFromServiceCatalog($catalog, $token);
24 
25 $store->createContainer('Example');
26 $container = $store->container('Example');
27 
28 $name = 'hello.txt';
29 $content = 'Hello World';
30 $mime = 'text/plain';
31 
34 
35 $object = $container->object('hello.txt');
36 printf("Name: %s \n", $object->name());
37 printf("Size: %d \n", $object->contentLength());
38 printf("Type: %s \n", $object->contentType());
39 print $object->content() . PHP_EOL;
40 
41 
42