Files
openstack-sdk-php/doc/oo-tutorial-code.php
alexandre-butynski a65650cc81 Update ObjectStorage documentation
ObjectStorage::newFromServiceCatalog() needs three parameters
but $region was missing in the documentation.

Change-Id: Id6d3ebd25e0f925b5416d866f3fb251052967e39
2015-01-16 10:22:09 +01:00

38 lines
1.1 KiB
PHP

<?php
require_once __DIR__ . '/../vendor/autoload.php';
use \OpenStack\Identity\v2\IdentityService;
use \OpenStack\ObjectStore\v1\ObjectStorage;
use \OpenStack\ObjectStore\v1\ObjectStorage\Object;
// Load these from an ini file.
$ini = parse_ini_file(getenv('HOME') . '/.OpenStack.ini');
$username = $ini['username'];
$password = $ini['password'];
$tenantId = $ini['tenantId'];
$endpoint = $ini['url'];
$region = $ini['region'];
$idService = new IdentityService($endpoint);
$token = $idService->authenticateAsUser($username, $password, $tenantId);
$catalog = $idService->serviceCatalog();
$store = ObjectStorage::newFromServiceCatalog($catalog, $token, $region);
$store->createContainer('Example');
$container = $store->container('Example');
$name = 'hello.txt';
$content = 'Hello World';
$mime = 'text/plain';
$localObject = new Object($name, $content, $mime);
$container->save($localObject);
$object = $container->object('hello.txt');
printf("Name: %s \n", $object->name());
printf("Size: %d \n", $object->contentLength());
printf("Type: %s \n", $object->contentType());
print $object->content() . PHP_EOL;