forked from doctrine/KeyValueStore
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial commit for Windows Azure Table support.
- Loading branch information
Showing
6 changed files
with
212 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
vendor | ||
*phpunit.xml |
39 changes: 39 additions & 0 deletions
39
lib/Doctrine/KeyValueStore/Storage/WindowsAzureTable/AuthorizationSchema.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
|
99 changes: 99 additions & 0 deletions
99
lib/Doctrine/KeyValueStore/Storage/WindowsAzureTableStorage.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
tests/Doctrine/Tests/KeyValueStore/Storage/AbstractStorageTestCase.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} | ||
|
31 changes: 31 additions & 0 deletions
31
tests/Doctrine/Tests/KeyValueStore/Storage/WindowsAzureTableStorageTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} | ||
|