/** * Given an IdentityService instance, create an ObjectStorage instance. * * This constructs a new ObjectStorage from an authenticated instance * of an \OpenStack\Identity\v2\IdentityService object. * * @param \OpenStack\Identity\v2\IdentityService $identity An identity services object that already * has a valid token and a service catalog. * @param string $region The Object Storage region * @param \OpenStack\Common\Transport\ClientInterface $client The HTTP client * * @return \OpenStack\ObjectStore\v1\ObjectStorage A new ObjectStorage instance. */ public static function newFromIdentity($identity, $region, \OpenStack\Common\Transport\ClientInterface $client = null) { $cat = $identity->serviceCatalog(); $tok = $identity->token(); return self::newFromServiceCatalog($cat, $tok, $region, $client); }
<?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']; $idService = new IdentityService($endpoint); $token = $idService->authenticateAsUser($username, $password, $tenantId); $catalog = $idService->serviceCatalog(); $store = ObjectStorage::newFromServiceCatalog($catalog, $token); $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;