6 Commits

Author SHA1 Message Date
Benjamin Eberlei
4c11672f09 Different error message formats 2012-06-18 09:06:25 +02:00
Benjamin Eberlei
46ce7624ae Add Storage and HttpStoragEException 2012-06-04 18:55:31 +02:00
Benjamin Eberlei
1f4af1e4f9 Fix WindowsAzureStorage and some bugs in RangeQuery 2012-06-04 18:51:21 +02:00
Benjamin Eberlei
a1cddb84ce Internal changes for Common 2.1 compatibility 2012-06-04 09:56:24 +02:00
Benjamin Eberlei
d16cefb478 Fix typo in variable 2012-06-04 09:50:19 +02:00
Benjamin Eberlei
0d50672268 Port parts of the Persistence namespace back for a Doctrine Common 2.1 compatible version. 2012-06-04 09:39:27 +02:00
18 changed files with 848 additions and 24 deletions

View File

@@ -1,7 +1,7 @@
{
"name": "doctrine/key-value-store",
"require": {
"doctrine/common": "*"
"doctrine/common": "2.1.*"
},
"description": "Simple Key-Value Store Abstraction Layer that maps to PHP objects, allowing for many backends.",
"license": "MIT",

17
composer.lock generated
View File

@@ -1,9 +1,18 @@
{
"hash": "09b80610c08784c764e1df9edca9b53f",
"hash": "1423c223b88271745223ad54dac71bfc",
"packages": [
{
"package": "doctrine\/common",
"version": "master-dev"
"package": "doctrine/common",
"version": "2.1.x-dev",
"source-reference": "41794945e795e108060eddb3342c9e13524b9b3e"
}
],
"packages-dev": null,
"aliases": [
],
"minimum-stability": "dev",
"stability-flags": [
]
}
}

View File

@@ -19,9 +19,10 @@
namespace Doctrine\KeyValueStore;
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver;
use Doctrine\Common\Cache\Cache;
use Doctrine\Common\Cache\ArrayCache;
use Doctrine\KeyValueStore\Persistence\Mapping\Driver\MappingDriver;
use Doctrine\KeyValueStore\Id\NullIdConverter;
/**
@@ -39,7 +40,7 @@ class Configuration
/**
* Get mapping driver implementation used with this configuration.
*
* @return \Doctrine\Common\Persistence\Mapping\Driver\MappingDriver
* @return \Doctrine\KeyValueStore\Persistence\Mapping\Driver\MappingDriver
*/
public function getMappingDriverImpl()
{
@@ -53,7 +54,7 @@ class Configuration
/**
* Set the mapping driver implementation.
*
* @param \Doctrine\Common\Persistence\Mapping\Driver\MappingDriver $driver
* @param \Doctrine\KeyValueStore\Persistence\Mapping\Driver\MappingDriver $driver
* @return \Doctrine\KeyValueStore\Configuration
*/
public function setMappingDriverImpl(MappingDriver $driver)

View File

@@ -22,7 +22,6 @@ namespace Doctrine\KeyValueStore;
use Doctrine\KeyValueStore\Storage\Storage;
use Doctrine\KeyValueStore\Mapping\ClassMetadataFactory;
use Doctrine\KeyValueStore\Query\RangeQuery;
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver;
use Doctrine\Common\Cache\Cache;
/**
@@ -145,7 +144,7 @@ class EntityManager
*/
public function getClassMetadata($className)
{
return $this->unitOfwork->getClassMetadata($className);
return $this->unitOfWork->getClassMetadata($className);
}
}

View File

@@ -20,7 +20,7 @@
namespace Doctrine\KeyValueStore\Mapping;
use Doctrine\Common\Persistence\Mapping\ClassMetadata;
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver;
use Doctrine\KeyValueStore\Persistence\Mapping\Driver\MappingDriver;
class AnnotationDriver implements MappingDriver
{

View File

@@ -28,5 +28,12 @@ class Entity
* @var string
*/
public $storageName;
public function __construct($values)
{
if (isset($values['storageName'])) {
$this->storageName = $values['storageName'];
}
}
}

View File

@@ -19,11 +19,12 @@
namespace Doctrine\KeyValueStore\Mapping;
use Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory;
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver;
use Doctrine\Common\Persistence\Mapping\ClassMetadata;
use Doctrine\KeyValueStore\Persistence\Mapping\Driver\MappingDriver;
use Doctrine\KeyValueStore\Persistence\Mapping\ReflectionService;
use Doctrine\KeyValueStore\Mapping\ClassMetadata as KeyValueMetadata;
use Doctrine\Common\Persistence\Mapping\ReflectionService;
use Doctrine\KeyValueStore\Persistence\Mapping\AbstractClassMetadataFactory;
/**
* Load Metadata of an entity.

View File

@@ -0,0 +1,364 @@
<?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 MIT license. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\KeyValueStore\Persistence\Mapping;
use Doctrine\Common\Cache\Cache;
use Doctrine\Common\Persistence\Mapping\ClassMetadataFactory;
use Doctrine\Common\Persistence\Mapping\ClassMetadata;
use Doctrine\KeyValueStore\Persistence\Mapping\ReflectionService;
/**
* The ClassMetadataFactory is used to create ClassMetadata objects that contain all the
* metadata mapping informations of a class which describes how a class should be mapped
* to a relational database.
*
* This class was abstracted from the ORM ClassMetadataFactory
*
* @since 2.2
* @author Benjamin Eberlei <kontakt@beberlei.de>
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Jonathan Wage <jonwage@gmail.com>
* @author Roman Borschel <roman@code-factory.org>
*/
abstract class AbstractClassMetadataFactory implements ClassMetadataFactory
{
/**
* Salt used by specific Object Manager implementation.
*
* @var string
*/
protected $cacheSalt = "\$CLASSMETADATA";
/**
* @var \Doctrine\Common\Cache\Cache
*/
private $cacheDriver;
/**
* @var array
*/
private $loadedMetadata = array();
/**
* @var bool
*/
protected $initialized = false;
/**
* @var ReflectionService
*/
private $reflectionService;
/**
* Sets the cache driver used by the factory to cache ClassMetadata instances.
*
* @param Doctrine\Common\Cache\Cache $cacheDriver
*/
public function setCacheDriver(Cache $cacheDriver = null)
{
$this->cacheDriver = $cacheDriver;
}
/**
* Gets the cache driver used by the factory to cache ClassMetadata instances.
*
* @return Doctrine\Common\Cache\Cache
*/
public function getCacheDriver()
{
return $this->cacheDriver;
}
/**
* Return an array of all the loaded metadata currently in memory.
*
* @return array
*/
public function getLoadedMetadata()
{
return $this->loadedMetadata;
}
/**
* Forces the factory to load the metadata of all classes known to the underlying
* mapping driver.
*
* @return array The ClassMetadata instances of all mapped classes.
*/
public function getAllMetadata()
{
if ( ! $this->initialized) {
$this->initialize();
}
$driver = $this->getDriver();
$metadata = array();
foreach ($driver->getAllClassNames() as $className) {
$metadata[] = $this->getMetadataFor($className);
}
return $metadata;
}
/**
* Lazy initialization of this stuff, especially the metadata driver,
* since these are not needed at all when a metadata cache is active.
*
* @return void
*/
abstract protected function initialize();
/**
* Get the fully qualified class-name from the namespace alias.
*
* @param string $namespaceAlias
* @param string $simpleClassName
* @return string
*/
abstract protected function getFqcnFromAlias($namespaceAlias, $simpleClassName);
/**
* Return the mapping driver implementation.
*
* @return \Doctrine\Common\Persistence\Mapping\Driver\MappingDriver
*/
abstract protected function getDriver();
/**
* Wakeup reflection after ClassMetadata gets unserialized from cache.
*
* @param ClassMetadata $class
* @param ReflectionService $reflService
* @return void
*/
abstract protected function wakeupReflection(ClassMetadata $class, ReflectionService $reflService);
/**
* Initialize Reflection after ClassMetadata was constructed.
*
* @param ClassMetadata $class
* @param ReflectionService $reflService
* @return void
*/
abstract protected function initializeReflection(ClassMetadata $class, ReflectionService $reflService);
/**
* Gets the class metadata descriptor for a class.
*
* @param string $className The name of the class.
* @return \Doctrine\Common\Persistence\Mapping\ClassMetadata
*/
public function getMetadataFor($className)
{
if ( ! isset($this->loadedMetadata[$className])) {
$realClassName = $className;
// Check for namespace alias
if (strpos($className, ':') !== false) {
list($namespaceAlias, $simpleClassName) = explode(':', $className);
$realClassName = $this->getFqcnFromAlias($namespaceAlias, $simpleClassName);
if (isset($this->loadedMetadata[$realClassName])) {
// We do not have the alias name in the map, include it
$this->loadedMetadata[$className] = $this->loadedMetadata[$realClassName];
return $this->loadedMetadata[$realClassName];
}
}
if ($this->cacheDriver) {
if (($cached = $this->cacheDriver->fetch($realClassName . $this->cacheSalt)) !== false) {
$this->loadedMetadata[$realClassName] = $cached;
$this->wakeupReflection($cached, $this->getReflectionService());
} else {
foreach ($this->loadMetadata($realClassName) as $loadedClassName) {
$this->cacheDriver->save(
$loadedClassName . $this->cacheSalt, $this->loadedMetadata[$loadedClassName], null
);
}
}
} else {
$this->loadMetadata($realClassName);
}
if ($className != $realClassName) {
// We do not have the alias name in the map, include it
$this->loadedMetadata[$className] = $this->loadedMetadata[$realClassName];
}
}
return $this->loadedMetadata[$className];
}
/**
* Checks whether the factory has the metadata for a class loaded already.
*
* @param string $className
* @return boolean TRUE if the metadata of the class in question is already loaded, FALSE otherwise.
*/
public function hasMetadataFor($className)
{
return isset($this->loadedMetadata[$className]);
}
/**
* Sets the metadata descriptor for a specific class.
*
* NOTE: This is only useful in very special cases, like when generating proxy classes.
*
* @param string $className
* @param ClassMetadata $class
*/
public function setMetadataFor($className, $class)
{
$this->loadedMetadata[$className] = $class;
}
/**
* Get array of parent classes for the given entity class
*
* @param string $name
* @return array $parentClasses
*/
protected function getParentClasses($name)
{
// Collect parent classes, ignoring transient (not-mapped) classes.
$parentClasses = array();
foreach (array_reverse($this->getReflectionService()->getParentClasses($name)) as $parentClass) {
if ( ! $this->getDriver()->isTransient($parentClass)) {
$parentClasses[] = $parentClass;
}
}
return $parentClasses;
}
/**
* Loads the metadata of the class in question and all it's ancestors whose metadata
* is still not loaded.
*
* @param string $name The name of the class for which the metadata should get loaded.
*
* @return array
*/
protected function loadMetadata($name)
{
if ( ! $this->initialized) {
$this->initialize();
}
$loaded = array();
$parentClasses = $this->getParentClasses($name);
$parentClasses[] = $name;
// Move down the hierarchy of parent classes, starting from the topmost class
$parent = null;
$rootEntityFound = false;
$visited = array();
$reflService = $this->getReflectionService();
foreach ($parentClasses as $className) {
if (isset($this->loadedMetadata[$className])) {
$parent = $this->loadedMetadata[$className];
if (isset($parent->isMappedSuperclass) && $parent->isMappedSuperclass === false) {
$rootEntityFound = true;
array_unshift($visited, $className);
}
continue;
}
$class = $this->newClassMetadataInstance($className);
$this->initializeReflection($class, $reflService);
$this->doLoadMetadata($class, $parent, $rootEntityFound);
$this->loadedMetadata[$className] = $class;
$parent = $class;
if (isset($parent->isMappedSuperclass) && $class->isMappedSuperclass === false) {
$rootEntityFound = true;
array_unshift($visited, $className);
}
$this->wakeupReflection($class, $reflService);
$loaded[] = $className;
}
return $loaded;
}
/**
* Actually load the metadata from the underlying metadata
*
* @param ClassMetadata $class
* @param ClassMetadata $parent
* @param bool $rootEntityFound
* @return void
*/
abstract protected function doLoadMetadata($class, $parent, $rootEntityFound);
/**
* Creates a new ClassMetadata instance for the given class name.
*
* @param string $className
* @return ClassMetadata
*/
abstract protected function newClassMetadataInstance($className);
/**
* Check if this class is mapped by this Object Manager + ClassMetadata configuration
*
* @param $class
* @return bool
*/
public function isTransient($class)
{
if ( ! $this->initialized) {
$this->initialize();
}
return $this->getDriver()->isTransient($class);
}
/**
* Set reflectionService.
*
* @param ReflectionService $reflectionService
*/
public function setReflectionService(ReflectionService $reflectionService)
{
$this->reflectionService = $reflectionService;
}
/**
* Get the reflection service associated with this metadata factory.
*
* @return ReflectionService
*/
public function getReflectionService()
{
if ($this->reflectionService === null) {
$this->reflectionService = new RuntimeReflectionService();
}
return $this->reflectionService;
}
}

View File

@@ -0,0 +1,56 @@
<?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 MIT license. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\KeyValueStore\Persistence\Mapping\Driver;
use Doctrine\Common\Persistence\Mapping\ClassMetadata;
/**
* Contract for metadata drivers.
*
* @since 2.2
* @author Jonathan H. Wage <jonwage@gmail.com>
*/
interface MappingDriver
{
/**
* Loads the metadata for the specified class into the provided container.
*
* @param string $className
* @param ClassMetadata $metadata
*/
function loadMetadataForClass($className, ClassMetadata $metadata);
/**
* Gets the names of all mapped classes known to this driver.
*
* @return array The names of all mapped classes known to this driver.
*/
function getAllClassNames();
/**
* Whether the class with the specified name should have its metadata loaded.
* This is only the case if it is either mapped as an Entity or a
* MappedSuperclass.
*
* @param string $className
* @return boolean
*/
function isTransient($className);
}

View File

@@ -0,0 +1,80 @@
<?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 MIT license. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\KeyValueStore\Persistence\Mapping;
/**
* Very simple reflection service abstraction.
*
* This is required inside metadata layers that may require either
* static or runtime reflection.
*
* @author Benjamin Eberlei <kontakt@beberlei.de>
*/
interface ReflectionService
{
/**
* Return an array of the parent classes (not interfaces) for the given class.
*
* @param string $class
* @return array
*/
function getParentClasses($class);
/**
* Return the shortname of a class.
*
* @param string $class
* @return string
*/
function getClassShortName($class);
/**
* @param string $class
* @return string
*/
function getClassNamespace($class);
/**
* Return a reflection class instance or null
*
* @param string $class
* @return \ReflectionClass|null
*/
function getClass($class);
/**
* Return an accessible property (setAccessible(true)) or null.
*
* @param string $class
* @param string $property
* @return \ReflectionProperty|null
*/
function getAccessibleProperty($class, $property);
/**
* Check if the class have a public method with the given name.
*
* @param mixed $class
* @param mixed $method
* @return bool
*/
function hasPublicMethod($class, $method);
}

View File

@@ -0,0 +1,102 @@
<?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 MIT license. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\KeyValueStore\Persistence\Mapping;
use ReflectionClass;
use ReflectionProperty;
/**
* PHP Runtime Reflection Service
*
* @author Benjamin Eberlei <kontakt@beberlei.de>
*/
class RuntimeReflectionService implements ReflectionService
{
/**
* Return an array of the parent classes (not interfaces) for the given class.
*
* @param string $class
* @return array
*/
public function getParentClasses($class)
{
return class_parents($class);
}
/**
* Return the shortname of a class.
*
* @param string $class
* @return string
*/
public function getClassShortName($class)
{
$r = new ReflectionClass($class);
return $r->getShortName();
}
/**
* @param string $class
* @return string
*/
public function getClassNamespace($class)
{
$r = new ReflectionClass($class);
return $r->getNamespaceName();
}
/**
* Return a reflection class instance or null
*
* @param string $class
* @return ReflectionClass|null
*/
public function getClass($class)
{
return new ReflectionClass($class);
}
/**
* Return an accessible property (setAccessible(true)) or null.
*
* @param string $class
* @param string $property
* @return ReflectionProperty|null
*/
public function getAccessibleProperty($class, $property)
{
$property = new ReflectionProperty($class, $property);
$property->setAccessible(true);
return $property;
}
/**
* Check if the class have a public method with the given name.
*
* @param mixed $class
* @param mixed $method
* @return bool
*/
public function hasPublicMethod($class, $method)
{
return method_exists($class, $method) && is_callable(array($class, $method));
}
}

View File

@@ -0,0 +1,107 @@
<?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 MIT license. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\KeyValueStore\Persistence\Mapping;
use ReflectionClass;
use ReflectionProperty;
/**
* PHP Runtime Reflection Service
*
* @author Benjamin Eberlei <kontakt@beberlei.de>
*/
class StaticReflectionService implements ReflectionService
{
/**
* Return an array of the parent classes (not interfaces) for the given class.
*
* @param string $class
* @return array
*/
public function getParentClasses($class)
{
return array();
}
/**
* Return the shortname of a class.
*
* @param string $className
* @return string
*/
public function getClassShortName($className)
{
if (strpos($className, '\\') !== false) {
$className = substr($className, strrpos($className, "\\")+1);
}
return $className;
}
/**
* Return the namespace of a class.
*
* @param string $className
* @return string
*/
public function getClassNamespace($className)
{
$namespace = '';
if (strpos($className, '\\') !== false) {
$namespace = strrev(substr( strrev($className), strpos(strrev($className), '\\')+1 ));
}
return $namespace;
}
/**
* Return a reflection class instance or null
*
* @param string $class
* @return ReflectionClass|null
*/
public function getClass($class)
{
return null;
}
/**
* Return an accessible property (setAccessible(true)) or null.
*
* @param string $class
* @param string $property
* @return ReflectionProperty|null
*/
public function getAccessibleProperty($class, $property)
{
return null;
}
/**
* Check if the class have a public method with the given name.
*
* @param mixed $class
* @param mixed $method
* @return bool
*/
public function hasPublicMethod($class, $method)
{
return method_exists($class, $method) && is_callable(array($class, $method));
}
}

View File

@@ -51,7 +51,7 @@ class RangeQuery
/**
* @var array
*/
protected $rangeConditions = array();
protected $conditions = array();
/**
* Limit result to only a set of entities.
@@ -205,11 +205,16 @@ class RangeQuery
throw new \RuntimeException("The storage backend " . $this->storage->getName() . " does not support range queries.");
}
$uow = $em->getUnitOfWork();
$uow = $this->em->getUnitOfWork();
$class = $this->em->getClassMetadata($this->className);
return $storage>executeRangeQuery($this, $class->storageName, $class->identifiers, function ($row) use($uow, $class) {
return $uow->createEntity($class, $data);
return $storage->executeRangeQuery($this, $class->storageName, $class->identifier, function ($row) use($uow, $class) {
$key = array();
foreach ($class->identifier as $id) {
$key[$id] = $row[$id];
}
return $uow->createEntity($class, $key, $row);
});
}
}

View File

@@ -0,0 +1,21 @@
<?php
/**
* Doctrine KeyValueStore
*
* LICENSE
*
* This source file is subject to the MIT license that is bundled
* with this package in the file LICENSE.txt.
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to kontakt@beberlei.de so I can send you a copy immediately.
*/
namespace Doctrine\KeyValueStore\Storage;
use Doctrine\KeyValueStore\KeyValueStoreException;
class StorageException extends KeyValueStoreException
{
}

View File

@@ -0,0 +1,22 @@
<?php
/**
* Doctrine Key Value Store
*
* LICENSE
*
* This source file is subject to the MIT license that is bundled
* with this package in the file LICENSE.txt.
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to kontakt@beberlei.de so I can send you a copy immediately.
*/
namespace Doctrine\KeyValueStore\Storage\WindowsAzureTable;
use Doctrine\KeyValueStore\Storage\StorageException;
class HttpStorageException extends StorageException
{
}

View File

@@ -21,6 +21,7 @@ namespace Doctrine\KeyValueStore\Storage;
use Doctrine\KeyValueStore\Http\Client;
use Doctrine\KeyValueStore\Storage\WindowsAzureTable\AuthorizationSchema;
use Doctrine\KeyValueStore\Storage\WindowsAzureTable\HttpStorageException;
use Doctrine\KeyValueStore\Query\RangeQuery;
use Doctrine\KeyValueStore\Query\RangeQueryStorage;
use Doctrine\KeyValueStore\NotFoundException;
@@ -149,11 +150,36 @@ class WindowsAzureTableStorage implements Storage, RangeQueryStorage
$response = $this->request('POST', $url, $xml, $headers);
if ($response->getStatusCode() == 404) {
$this->createTable($tableName);
$this->insert($storageName, $key, $data);
} else if ($response->getStatusCode() >= 400) {
$this->convertResponseToException($response);
}
}
private function convertResponseToException($response)
{
$dom = new \DomDocument('1.0', 'UTF-8');
$dom->loadXML($response->getBody());
$message = "";
$nodeList = $dom->getElementsByTagName('Message');
if ($nodeList->length > 0) {
$message = $nodeList->item(0)->nodeValue;
throw new HttpStorageException($message);
}
$nodeList = $dom->getElementsByTagName('message');
if ($nodeList->length > 0) {
$message = $nodeList->item(0)->nodeValue;
throw new HttpStorageException($message);
}
throw new HttpStorageException($response->getBody());
}
public function createTable($tableName)
{
$headers = array(
@@ -168,6 +194,10 @@ class WindowsAzureTableStorage implements Storage, RangeQueryStorage
$url = $this->baseUrl . '/Tables';
$response = $this->request('POST', $url, $xml, $headers);
if ($response->getStatusCode() != 201) {
$this->convertResponseToException($response);
}
return $response;
}
@@ -198,6 +228,10 @@ class WindowsAzureTableStorage implements Storage, RangeQueryStorage
$xml = $dom->saveXML();
$response = $this->request('PUT', $url, $xml, $headers);
if ($response->getStatusCode() >= 400) {
$this->convertResponseToException($response);
}
}
public function delete($storageName, $key)
@@ -214,7 +248,11 @@ class WindowsAzureTableStorage implements Storage, RangeQueryStorage
$keys = array_values($key);
$url = $this->baseUrl . '/' . $tableName . rawurlencode("(PartitionKey='" . $keys[0] . "', RowKey='" . $keys[1] . "')");
$this->request('DELETE', $url, '', $headers);
$response = $this->request('DELETE', $url, '', $headers);
if ($response->getStatusCode() >= 400) {
$this->convertResponseToException($response);
}
}
public function find($storageName, $key)
@@ -232,9 +270,12 @@ class WindowsAzureTableStorage implements Storage, RangeQueryStorage
$response = $this->request('GET', $url, '', $headers);
switch ($response->getStatusCode()) {
case 404:
throw new NotFoundException();
if ($response->getStatusCode() == 404) {
throw new NotFoundException();
}
if ($response->getStatusCode() >= 400) {
$this->convertResponseToException($response);
}
$dom = new \DomDocument('1.0', 'UTF-8');
@@ -312,8 +353,8 @@ class WindowsAzureTableStorage implements Storage, RangeQueryStorage
$response = $this->request('GET', $url, '', $headers);
if ($response->getStatusCode() != 200) {
// Todo: do stuff
if ($response->getStatusCode() >= 400) {
$this->convertResponseToException($response);
}
$dom = new \DomDocument('1.0', 'UTF-8');

View File

@@ -59,6 +59,11 @@ class UnitOfWork
new Id\SingleIdHandler();
}
public function getClassMetadata($name)
{
return $this->cmf->getMetadataFor($name);
}
private function tryGetById($id)
{
$idHash = $this->idHandler->hash($id);

View File

@@ -13,6 +13,10 @@ class MongoDbStorageTest extends \PHPUnit_Framework_TestCase
{
protected function setUp()
{
if ( ! class_exists('Mongo')) {
$this->markTestSkipped('Mongo needs to be installed');
}
$this->mongo = $this->getMock('\Mongo');
$this->mongodb = $this->getMockBuilder('\MongoDB')->disableOriginalConstructor()->getMock();