PHP SDK for Windows Azure

PHP SDK for Windows Azure
http://phpazure.codeplex.com/
PHPからAzureにアクセスするためのライブラリ。
Zend_Azureからこっちに移動ってことかしら(・ω・)?


とりあえず使いかた(・∀・)
ちなみに、トランスポートにcURLを使っているので、有効にするのを忘れないように。

<?php
define('STORAGE_ACCOUNT', "xxxxxxxx");
define('STORAGE_KEY'    , "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX==");

define('BLOB_CONTAINERNAME', 'phpazuretest');

require_once 'Microsoft/Azure/Storage/Blob.php';


// ストレージクライアント作成
$storageClient = new Microsoft_Azure_Storage_Blob( Microsoft_Azure_Storage::URL_CLOUD_BLOB, STORAGE_ACCOUNT, STORAGE_KEY );

// コンテナ作成
try { $result = $storageClient->createContainer( BLOB_CONTAINERNAME ); } catch (Exception $ex) { }

// コンテナ数取得
$result = $storageClient->listContainers();
$count = count( $result );


$blobName = 'images/Test.png';

// ファイル「D:/Test.png」をコンテナに'images/Test.png'でPut
$result = $storageClient->putBlob( BLOB_CONTAINERNAME, $blobName, 'D:/Test.png' );
var_dump( $result );

// Blob数取得
$result = $storageClient->listBlobs( BLOB_CONTAINERNAME );
$count = count( $result );

// コンテナから'images/Test.png'をファイル「D:/Test2.png」にGet
$storageClient->getBlob( BLOB_CONTAINERNAME, $blobName, 'D:/Test2.png' );

// Blob削除
$storageClient->deleteBlob( BLOB_CONTAINERNAME, $blobName );


// コンテナ削除
try { $storageClient->deleteContainer( BLOB_CONTAINERNAME ); } catch (Exception $ex) { }
?>

っで、putBlob()の結果はこんな感じ。

object(Microsoft_Azure_Storage_BlobInstance)#4 (1) {
  ["_data:protected"]=>
  array(11) {
    ["container"]=>
    string(12) "phpazuretest"
    ["name"]=>
    string(15) "images/Test.png"
    ["etag"]=>
    NULL
    ["lastmodified"]=>
    NULL
    ["url"]=>
    string(72) "http://xxxxxxxx.blob.core.windows.net/phpazuretest/images/Test.png"
    ["size"]=>
    int(37779)
    ["contenttype"]=>
    string(0) ""
    ["contentencoding"]=>
    string(0) ""
    ["contentlanguage"]=>
    string(0) ""
    ["isprefix"]=>
    bool(false)
    ["metadata"]=>
    array(0) {
    }
  }
}

Milestone 2でTable Storageの操作がサポート、Milestone 3でQueue Storageのサポート予定っと(・∀・)