<?php

require_once __DIR__ . '/../src/HPCloud/Bootstrap.php';
use HPCloud\Bootstrap;
Bootstrap::useAutoloader();
Bootstrap::useStreamWrappers();
$ini = parse_ini_file(getenv('HOME') . '/.hpcloud.ini');
$settings = array('username' => $ini['username'], 'password' => $ini['password'], 'tenantid' => $ini['tenantId'], 'endpoint' => $ini['url']);
Bootstrap::setConfiguration($settings);
// Create a new file and write it to the object store.
$newfile = fopen('swift://Example/my_file.txt', 'w');
fwrite($newfile, "Good Morning!");
fclose($newfile);
// Check for an object:
if (file_exists('swift://Example/my_file.txt')) {
    print "Found my_file.txt." . PHP_EOL;
}
// Get an entire object at once:
$file = file_get_contents('swift://Example/my_file.txt');
print 'File: ' . $file . PHP_EOL;
$cxt = stream_context_create(array('swift' => array('account' => $ini['account'], 'key' => $ini['secret'], 'tenantid' => $ini['tenantId'], 'endpoint' => $ini['url'])));
print file_get_contents('swift://Example/my_file.txt', FALSE, $cxt);
Example #2
0
 * A commandline demonstration of the PHP API.
 */
// Name of the container to test. It must have
// CDN enabled. Using the one you use for standard
// tests is ill advised.
define('TEST_CONTAINER', 'mycontainer');
$base = __DIR__ . '/../src';
require_once $base . '/HPCloud/Bootstrap.php';
\HPCloud\Bootstrap::useAutoloader();
$inifile = __DIR__ . '/settings.ini';
if (!is_readable($inifile)) {
    die('Could not find ' . $inifile);
}
$ini = parse_ini_file($inifile, FALSE);
\HPCloud\Bootstrap::setConfiguration($ini);
\HPCloud\Bootstrap::useStreamWrappers();
$id = new \HPCloud\Services\IdentityServices($ini['hpcloud.identity.url']);
//$token = $id->authenticateAsAccount($ini['hpcloud.identity.account'], $ini['hpcloud.identity.secret'], $ini['hpcloud.identity.tenantId']);
$token = $id->authenticateAsUser($ini['hpcloud.identity.username'], $ini['hpcloud.identity.password'], $ini['hpcloud.identity.tenantId']);
$objstore = \HPCloud\Storage\ObjectStorage::newFromServiceCatalog($id->serviceCatalog(), $token);
$cdn = \HPCloud\Storage\CDN::newFromServiceCatalog($id->serviceCatalog(), $token);
$objstore->useCDN($cdn);
//var_dump($cdn->containers());
// Check that the container has CDN.
$cname = TEST_CONTAINER;
//$ini['hpcloud.swift.container'];
$isEnabled = FALSE;
$cdnData = $cdn->container($cname);
print "***** TESTING CDN ENABLED" . PHP_EOL;
if ($cdnData['cdn_enabled'] != 1) {
    die('Cannot test CDN: You must enable CDN on ' . $cname);