Permalink
Browse files

Initial commit for Windows Azure Table support.

  • Loading branch information...
1 parent 2aae182 commit feef6cb775064e17d0f25323750df16b77286936 @beberlei beberlei committed Mar 26, 2012
View
@@ -1 +1,2 @@
vendor
+*phpunit.xml
@@ -0,0 +1,39 @@
+<?php
+/*
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * and is licensed under the LGPL. For more information, see
+ * <http://www.doctrine-project.org>.
+ */
+namespace Doctrine\KeyValueStore\Storage\WindowsAzureTable;
+
+/**
+ * Abstraction for WindowsAzure Authorization Schemes
+ *
+ * @link http://msdn.microsoft.com/en-us/library/windowsazure/dd179428.aspx
+ * @author Benjamin Eberlei <kontakt@beberlei.de>
+ */
+interface AuthorizationSchema
+{
+ /**
+ * Sign a request by returning a new header to be appended to headers.
+ *
+ * @param string $method
+ * @param string $body
+ * @param array $headers
+ * @return string
+ */
+ function signRequest($method, $body, array $headers);
+}
+
@@ -0,0 +1,99 @@
+<?php
+/*
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * and is licensed under the LGPL. For more information, see
+ * <http://www.doctrine-project.org>.
+ */
+
+namespace Doctrine\KeyValueStore\Storage;
+
+use Doctrine\KeyValueStore\HTTP\HttpClient;
+
+/**
+ * Storage implementation for Microsoft Windows Azure Table.
+ *
+ * Using a HTTP client to communicate with the REST API of Azure Table.
+ *
+ * @author Benjamin Eberlei <kontakt@beberlei.de>
+ */
+class WindowsAzureTableStorage implements Storage
+{
+ const WINDOWS_AZURE_TABLE_BASEURL = 'https://%s.table.core.windows.net';
+ /**
+ * @var \Doctrine\KeyValueStore\HTTP\HttpClient
+ */
+ private $client;
+
+ /**
+ * @var \Doctrine\KeyValueStore\Storage\WindowsAzureTable\AuthorizationSchema
+ */
+ private $authorization;
+
+ /**
+ * @var string
+ */
+ private $baseUrl;
+
+ /**
+ * @param HttpClient $client
+ * @param AuthorizationSchema $authorization
+ */
+ public function __construct(HttpClient $client, $accountName, AuthorizationSchema $authorization)
+ {
+ $this->client = $client;
+ $this->authorization = $authorization;
+ $this->baseUrl = sprintf(self::WINDOWS_AZURE_TABLE_BASEURL, $accountName);
+ }
+
+ public function supportsPartialUpdates()
+ {
+ return false;
+ }
+
+ public function supportsCompositePrimaryKeys()
+ {
+ return true;
+ }
+
+ public function requiresCompositePrimaryKeys()
+ {
+ return true;
+ }
+
+ public function insert($key, array $data)
+ {
+
+ }
+
+ public function update($key, array $data)
+ {
+
+ }
+
+ public function delete($key)
+ {
+ }
+
+ public function find($key)
+ {
+
+ }
+
+ public function getName()
+ {
+ return 'azure_table';
+ }
+}
+
View
@@ -11,4 +11,10 @@
<directory>lib/Doctrine/KeyValueStore</directory>
</whitelist>
</filter>
+
+ <php>
+ <var name="DOCTRINE_KEYVALUE_AZURE_AUTHSCHEMA" value="shared" />
+ <var name="DOCTRINE_KEYVALUE_AZURE_NAME" value="" />
+ <var name="DOCTRINE_KEYVALUE_AZURE_KEY" value="" />
+ </php>
</phpunit>
@@ -0,0 +1,36 @@
+<?php
+namespace Doctrine\Tests\KeyValueStore\Storage;
+
+abstract class AbstractStorageTestCase extends \PHPUnit_Framework_TestCase
+{
+ /**
+ * @var Storage
+ */
+ protected $storage;
+
+ /**
+ * @return \Doctrine\KeyValueStore\Storage\Storage
+ */
+ abstract protected function createStorage();
+
+ public function setUp()
+ {
+ $this->storage = $this->createStorage();
+ }
+
+ public function testInsertThenFindCompositeKey()
+ {
+ if ( ! $this->storage->supportsCompositeKeys()) {
+ $this->markTestSkipped("Composite keys need to be supported for this test to run.");
+ }
+
+ $key = array('dist' => 'foo', 'range' => 100);
+ $data = array('dist' => 'foo', 'range' => 100, 'name' => 'Test', 'value' => 'val', 'date' => new \DateTime("2012-03-26 12:12:12"));
+
+ $this->storage->insert($key, $data);
+ $foundData = $this->storage->find($key);
+
+ $this->assertEquals($data, $foundData);
+ }
+}
+
@@ -0,0 +1,31 @@
+<?php
+
+namespace Doctrine\Tests\KeyValueStore\Storage;
+
+class WindowsAzureTableStorageTest extends AbstractStorageTestCase
+{
+ protected function createStorage()
+ {
+ if ( empty($GLOBALS['DOCTRINE_KEYVALUE_AZURE_NAME']) || empty($GLOBALS['DOCTRINE_KEYVALUE_AZURE_KEY'])) {
+ $this->markTestSkipped("No Azure information provided.");
+ }
+
+ switch ($GLOBALS['DOCTRINE_KEYVALUE_AZURE_AUTHSCHEMA']) {
+ case 'shared':
+ $auth = new SharedKeyAuthorization();
+ break;
+ case 'sharedlite':
+ $auth = new SharedKeyLiteAuthorization();
+ break;
+ default:
+ $this->markTestSkipped("Unknown auth schema " . $GLOBALS['DOCTRINE_KEYVALUE_AZURE_AUTHSCHEMA']);
+ }
+
+ $storage = new WindowsAzureTableStorage(
+ $client, $GLOBALS['DOCTRINE_KEYVALUE_AZURE_NAME'], $auth
+ );
+
+ return $storage;
+ }
+}
+

0 comments on commit feef6cb

Please sign in to comment.