コード例 #1
0
ファイル: CDNTest.php プロジェクト: hpcloud/hpcloud-php
 /**
  * @depends testConstructor
  */
 public function testNewFromIdentity()
 {
     $ident = $this->identity();
     $cdn = CDN::newFromIdentity($ident, $this->conf('hpcloud.swift.region'));
     $this->assertInstanceOf('\\HPCloud\\Storage\\CDN', $cdn);
     return $cdn;
 }
コード例 #2
0
 /**
  * @depends testOpen
  */
 public function testOpenWithCDN()
 {
     // Unfortunately we cannot test with CDN directly, because CDN requires ten
     // minutes to an our to configure itself. Use the `php test/CDNTest.php` program
     // to directly test CDN on an already-prepared container.
     $this->containerFixture();
     // Simple write test.
     $oUrl = $this->newUrl('foo→/test.csv');
     // Now we test the same, but re-using the auth token:
     $cxt = $this->authSwiftContext(array('use_cdn' => TRUE));
     $res = fopen($oUrl, 'nope', FALSE, $cxt);
     $this->assertTrue(is_resource($res));
     // For this to work, we need to re-use auth tokens.
     $md = stream_get_meta_data($res);
     $wrapper = $md['wrapper_data'];
     fclose($res);
     // Test with auth token.
     $cxt = $this->basicSwiftContext(array('token' => $wrapper->token(), 'use_cdn' => TRUE));
     $res = fopen($oUrl, 'nope', FALSE, $cxt);
     $this->assertTrue(is_resource($res));
     fclose($res);
     // Test with CDN object
     $region = self::conf('hpcloud.swift.region');
     $cdn = \HPCloud\Storage\CDN::newFromServiceCatalog($wrapper->serviceCatalog(), $wrapper->token(), $region);
     $cxt = $this->basicSwiftContext(array('use_cdn' => $cdn));
     $res = fopen($oUrl, 'nope', FALSE, $cxt);
     $this->assertTrue(is_resource($res));
     fclose($res);
 }
コード例 #3
0
ファイル: CDNTest.php プロジェクト: hpcloud/hpcloud-php
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);
}
$container = $objstore->container($cname);
print "***** TESTING CDN URL" . PHP_EOL;
$cdnSsl = $objstore->cdnUrl($cname);
$cdnPlain = $objstore->cdnUrl($cname, FALSE);
コード例 #4
0
ファイル: StreamWrapper.php プロジェクト: biggtfish/cms
 /**
  * Initialize CDN service.
  *
  * When the `use_cdn` parameter is passed into the context, we try
  * to use a CDN service wherever possible.
  *
  * If `use_cdn` is set to TRUE, we try to create a new CDN object.
  * This will require a service catalog.
  *
  * When use_cdn is set to TRUE, the wrapper tries to use CDN service.
  * In such cases, we need a handle to the CDN object. This initializes
  * that handle, which can later be used to get other information.
  *
  * Also note that CDN's default behavior is to fetch over SSL CDN.
  * To disable this, set 'cdn_require_ssl' to FALSE.
  */
 protected function initializeCDN($token, $catalog)
 {
     $cdn = $this->cxt('use_cdn', FALSE);
     // No CDN should be enabled.
     if (empty($cdn)) {
         return FALSE;
     } elseif ($cdn instanceof \HPCloud\Storage\CDN) {
         $this->cdn = $cdn;
     } else {
         if (empty($catalog)) {
             $ident = $this->authenticate();
             $catalog = $ident->serviceCatalog();
             $token = $ident->token();
         }
         $this->cdn = \HPCloud\Storage\CDN::newFromServiceCatalog($catalog, $token);
     }
     if (!empty($this->cdn)) {
         $this->store->useCDN($this->cdn);
     }
     return TRUE;
 }