1 Commits

Author SHA1 Message Date
Benjamin Eberlei
2d1dcf6c20 Initial References Commit 2012-04-07 00:08:48 +02:00
44 changed files with 418 additions and 1205 deletions

View File

@@ -1,10 +1,8 @@
{
"name": "doctrine/key-value-store",
"require": {
"doctrine/common": "2.1.*"
"doctrine/common": "*"
},
"description": "Simple Key-Value Store Abstraction Layer that maps to PHP objects, allowing for many backends.",
"license": "MIT",
"autoload": {
"psr-0": {
"Doctrine\\KeyValueStore\\": "lib/"

17
composer.lock generated
View File

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

View File

@@ -13,16 +13,15 @@
* 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
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/
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;
/**
@@ -40,7 +39,7 @@ class Configuration
/**
* Get mapping driver implementation used with this configuration.
*
* @return \Doctrine\KeyValueStore\Persistence\Mapping\Driver\MappingDriver
* @return \Doctrine\Common\Persistence\Mapping\Driver\MappingDriver
*/
public function getMappingDriverImpl()
{
@@ -54,7 +53,7 @@ class Configuration
/**
* Set the mapping driver implementation.
*
* @param \Doctrine\KeyValueStore\Persistence\Mapping\Driver\MappingDriver $driver
* @param \Doctrine\Common\Persistence\Mapping\Driver\MappingDriver $driver
* @return \Doctrine\KeyValueStore\Configuration
*/
public function setMappingDriverImpl(MappingDriver $driver)

View File

@@ -13,7 +13,7 @@
* 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
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/
@@ -22,6 +22,7 @@ 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;
/**
@@ -144,7 +145,7 @@ class EntityManager
*/
public function getClassMetadata($className)
{
return $this->unitOfWork->getClassMetadata($className);
return $this->unitOfwork->getClassMetadata($className);
}
}

View File

@@ -13,7 +13,7 @@
* 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
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/

View File

@@ -13,7 +13,7 @@
* 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
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\KeyValueStore\Http;

View File

@@ -13,7 +13,7 @@
* 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
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/

View File

@@ -13,7 +13,7 @@
* 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
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/

View File

@@ -13,7 +13,7 @@
* 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
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/

View File

@@ -13,7 +13,7 @@
* 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
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/

View File

@@ -13,7 +13,7 @@
* 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
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/

View File

@@ -13,7 +13,7 @@
* 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
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/

View File

@@ -13,7 +13,7 @@
* 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
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/

View File

@@ -13,14 +13,14 @@
* 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
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\KeyValueStore\Mapping;
use Doctrine\Common\Persistence\Mapping\ClassMetadata;
use Doctrine\KeyValueStore\Persistence\Mapping\Driver\MappingDriver;
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver;
class AnnotationDriver implements MappingDriver
{

View File

@@ -13,7 +13,7 @@
* 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
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/
@@ -28,12 +28,5 @@ class Entity
* @var string
*/
public $storageName;
public function __construct($values)
{
if (isset($values['storageName'])) {
$this->storageName = $values['storageName'];
}
}
}

View File

@@ -13,7 +13,7 @@
* 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
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/

View File

@@ -13,7 +13,7 @@
* 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
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/

View File

@@ -13,7 +13,7 @@
* 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
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/

View File

@@ -13,18 +13,17 @@
* 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
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/
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\KeyValueStore\Persistence\Mapping\AbstractClassMetadataFactory;
use Doctrine\Common\Persistence\Mapping\ReflectionService;
/**
* Load Metadata of an entity.

View File

@@ -1,364 +0,0 @@
<?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

@@ -1,56 +0,0 @@
<?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

@@ -1,80 +0,0 @@
<?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

@@ -1,102 +0,0 @@
<?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

@@ -1,107 +0,0 @@
<?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

@@ -13,7 +13,7 @@
* 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
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/
@@ -51,7 +51,7 @@ class RangeQuery
/**
* @var array
*/
protected $conditions = array();
protected $rangeConditions = array();
/**
* Limit result to only a set of entities.
@@ -205,16 +205,11 @@ class RangeQuery
throw new \RuntimeException("The storage backend " . $this->storage->getName() . " does not support range queries.");
}
$uow = $this->em->getUnitOfWork();
$uow = $em->getUnitOfWork();
$class = $this->em->getClassMetadata($this->className);
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);
return $storage>executeRangeQuery($this, $class->storageName, $class->identifiers, function ($row) use($uow, $class) {
return $uow->createEntity($class, $data);
});
}
}

View File

@@ -13,7 +13,7 @@
* 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
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/

View File

@@ -0,0 +1,98 @@
<?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\References;
use Doctrine\Common\Persistence\Mapping\ClassMetadata;
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver;
/**
* AnnotationDriver for References
*
* @author Benjamin Eberlei <kontakt@beberlei.de>
*/
class AnnotationDriver implements Driver
{
private $reader;
public function __construct($reader)
{
$this->reader = $reader;
}
/**
* Loads the metadata for the specified class into the provided container.
*
* @param string $className
* @param ClassMetadata $metadata
*/
function loadMetadataForClass($className, ClassMetadata $metadata)
{
$class = $metadata->getReflectionClass();
if (!$class) {
// this happens when running annotation driver in combination with
// static reflection services. This is not the nicest fix
$class = new \ReflectionClass($metadata->name);
}
// Evaluate annotations on properties/fields
foreach ($class->getProperties() as $property) {
$referenceOneAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\KeyValueStore\References\Annotations\ReferenceOne');
if ($referenceOneAnnot) {
$metadata->addReferenceOne(
$property->getName(),
$referenceOneAnnot->targetEntity
);
}
$referenceManyAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\KeyValueStore\References\Annotations\ReferenceMany');
if ($referenceManyAnnot) {
$metadata->addReferenceMany(
$property->getName(),
$referenceManyAnnot->targetEntity,
$referenceManyAnnot->parentField,
$referenceManyAnnot->rangeField,
);
}
}
}
/**
* 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)
{
return false;
}
}

View File

@@ -13,14 +13,45 @@
* 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
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\KeyValueStore;
namespace Doctrine\KeyValueStore\Integration;
class NotFoundException extends KeyValueStoreException
use Doctrine\KeyValueStore\EntityManager;
/**
* Non-transaction save listener to synchronize association with to-one or
* to-many sets of key-value store entities into the storage.
*
* @author Benjamin Eberlei <kontakt@beberlei.de>
*/
class ReferenceListener
{
/**
* @var EntityManager
*/
private $kvsManager;
public function __construct(EntityManager $manager)
{
$this->kvsManager = $manager;
}
public function postLoad($eventArgs)
{
}
public function postUpdate($eventArgs)
{
}
public function postInsert($eventArgs)
{
}
}

View File

@@ -0,0 +1,76 @@
<?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\References;
/**
* Reference Metadata
*
* @author Benjamin Eberlei <kontakt@beberlei.de>
*/
class ReferenceMetadata
{
const REFERENCE_ONE = 1;
const REFERENCE_MANY = 2;
public $name;
public $namespace;
public $references = array();
public $reflFields = array();
public function __construct($name)
{
$this->name = $name;
if ($pos = strrpos($name, "\\")) {
$this->namespace = substr($name, 0, $pos);
}
}
public function addReferenceOne($fieldName, $targetEntity)
{
if ($this->namespace || strpos($targetEntity, "\\") === false) {
$targetEntity = $this->namespace . "\\" . $targetEntity;
}
$this->references[$fieldName] = array(
'type' => self::REFERENCE_ONE,
'targetEntity' => $targetEntity
);
}
public function addReferenceMany($fieldName, $targetEntity, $parentField, $rangeField)
{
if ($this->namespace || strpos($targetEntity, "\\") === false) {
$targetEntity = $this->namespace . "\\" . $targetEntity;
}
$this->references[$fieldName] = array(
'type' => self::REFERENCE_MANY,
'targetEntity' => $targetEntity,
'parentField' => $parentField,
'rangeField' => $rangeField,
);
}
public function __sleep()
{
return array('name', 'namespace', 'references');
}
}

View File

@@ -0,0 +1,92 @@
<?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\Integration;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\Common\Persistence\Mapping\ClassMetadataFactory;
use Doctrine\Common\Persistence\Mapping\ClassMetadata;
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver;
use Doctrine\Common\Persistence\Mapping\ReflectionService;
/**
* Metadata factory for Reference Mapping Metadata
*
* @author Benjamin Eberlei <kontakt@beberlei.de>
*/
class ReferenceMetadataFactory extends AbstractClassMetadataFactory
{
/**
* @var ObjectManager
*/
private $parentManager;
/**
* @var MappingDriver
*/
private $mappingDriver;
public function __construct(ObjectManager $parentManager, MappingDriver $driver)
{
$this->mappingDriver = $driver;
$this->parentManager = $parentManager;
}
protected function initialize()
{
}
protected function getFqcnFromAlias($namespaceAlias, $simpleClassName)
{
throw new \InvalidArgumentException("aliasing is not supported.");
}
protected function doLoadMetadata($class, $parent, $rootEntityFound)
{
$this->getDriver()->loadMetadataForClass($class->name, $class);
}
protected function newClassMetadataInstance($className)
{
return new ReferenceMetadata($className);
}
protected function getDriver()
{
return $this->mappingDriver;
}
protected function wakeupReflection(ClassMetadata $class, ReflectionService $reflService)
{
$class->reflClass = $reflService->getClass($class->name);
foreach ($class->references as $fieldName => $mapping) {
$class->reflFields[$fieldName] = $reflService->getAccessibleProperty($class->name, $fieldName);
}
}
protected function initializeReflection(ClassMetadata $class, ReflectionService $reflService)
{
$reflClass = $reflService->getClass($class->name);
if ($reflClass) {
foreach ($class->references as $fieldName => $mapping) {
$class->reflFields[$fieldName] = $reflService->getAccessibleProperty($class->name, $fieldName);
}
}
}
}

View File

@@ -13,14 +13,12 @@
* 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
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\KeyValueStore\Storage;
use Doctrine\KeyValueStore\NotFoundException;
/**
* Relational databased backed system.
*
@@ -132,7 +130,7 @@ class DBALStorage implements Storage
$stmt = $this->conn->executeQuery($sql, array($key));
$data = $stmt->fetchColumn();
if (!$data) {
throw new NotFoundException();
return null;
}
return unserialize($data);

View File

@@ -13,7 +13,7 @@
* 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
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/

View File

@@ -1,171 +0,0 @@
<?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\Storage;
use Doctrine\KeyValueStore\NotFoundException;
/**
* MongoDb storage
*
* @author Markus Bachmann <markus.bachmann@bachi.biz>
*/
class MongoDbStorage implements Storage
{
/**
* @var \Mongo
*/
protected $mongo;
/**
* @var array
*/
protected $dbOptions;
/**
* @var \MongoCollection
*/
protected $collection;
/**
* Constructor
*
* @param \Mongo $mongo
* @param array $dbOptions
*/
public function __construct(\Mongo $mongo, array $dbOptions = array())
{
$this->mongo = $mongo;
$this->dbOptions = array_merge(array(
'database' => '',
'collection' => '',
), $dbOptions);
}
/**
* Initialize the mongodb collection
*
* @throws \RuntimeException
*/
public function initialize()
{
if (null !== $this->collection) {
return;
}
if (empty($this->dbOptions['database'])) {
throw new \RuntimeException('The option "database" must be set');
}
if (empty($this->dbOptions['collection'])) {
throw new \RuntimeException('The option "collection" must be set');
}
$this->collection = $this->mongo->selectDB($this->dbOptions['database'])->selectCollection($this->dbOptions['collection']);
}
/**
* {@inheritDoc}
*/
public function supportsPartialUpdates()
{
return false;
}
/**
* {@inheritDoc}
*/
public function supportsCompositePrimaryKeys()
{
return false;
}
/**
* {@inheritDoc}
*/
public function requiresCompositePrimaryKeys()
{
return false;
}
/**
* {@inheritDoc}
*/
public function insert($storageName, $key, array $data)
{
$this->initialize();
$value = array(
'key' => $key,
'value' => $data,
);
$this->collection->insert($value);
}
/**
* {@inheritDoc}
*/
public function update($storageName, $key, array $data)
{
$this->initialize();
$value = array(
'key' => $key,
'value' => $data,
);
$this->collection->update(array('key' => $key), $value);
}
/**
* {@inheritDoc}
*/
public function delete($storageName, $key)
{
$this->initialize();
$this->collection->remove(array('key' => $key));
}
/**
* {@inheritDoc}
*/
public function find($storageName, $key)
{
$this->initialize();
$value = $this->collection->findOne(array('key' => $key), array('value'));
if ($value) {
return $value['value'];
}
throw new NotFoundException();
}
/**
* Return a name of the underlying storage.
*
* @return string
*/
public function getName()
{
return 'mongodb';
}
}

View File

@@ -13,7 +13,7 @@
* 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
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/
@@ -97,8 +97,6 @@ interface Storage
*
* Important note: The returned array does contain the identifier (again)!
*
* @throws Doctrine\KeyValueStore\NotFoundException When data with key is not found.
*
* @param string $storageName
* @param array|string $key
* @return array

View File

@@ -1,21 +0,0 @@
<?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

@@ -13,7 +13,7 @@
* 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
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\KeyValueStore\Storage\WindowsAzureTable;

View File

@@ -1,22 +0,0 @@
<?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

@@ -13,7 +13,7 @@
* 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
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/

View File

@@ -13,7 +13,7 @@
* 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
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/

View File

@@ -13,7 +13,7 @@
* 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
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/
@@ -21,10 +21,8 @@ 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;
/**
* Storage implementation for Microsoft Windows Azure Table.
@@ -150,36 +148,11 @@ 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(
@@ -194,10 +167,6 @@ 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;
}
@@ -228,10 +197,6 @@ 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)
@@ -248,11 +213,7 @@ class WindowsAzureTableStorage implements Storage, RangeQueryStorage
$keys = array_values($key);
$url = $this->baseUrl . '/' . $tableName . rawurlencode("(PartitionKey='" . $keys[0] . "', RowKey='" . $keys[1] . "')");
$response = $this->request('DELETE', $url, '', $headers);
if ($response->getStatusCode() >= 400) {
$this->convertResponseToException($response);
}
$this->request('DELETE', $url, '', $headers);
}
public function find($storageName, $key)
@@ -270,12 +231,8 @@ class WindowsAzureTableStorage implements Storage, RangeQueryStorage
$response = $this->request('GET', $url, '', $headers);
if ($response->getStatusCode() == 404) {
throw new NotFoundException();
}
if ($response->getStatusCode() >= 400) {
$this->convertResponseToException($response);
if ($response->getStatusCode() != 200) {
// Todo: do stuff
}
$dom = new \DomDocument('1.0', 'UTF-8');
@@ -353,8 +310,8 @@ class WindowsAzureTableStorage implements Storage, RangeQueryStorage
$response = $this->request('GET', $url, '', $headers);
if ($response->getStatusCode() >= 400) {
$this->convertResponseToException($response);
if ($response->getStatusCode() != 200) {
// Todo: do stuff
}
$dom = new \DomDocument('1.0', 'UTF-8');

View File

@@ -13,7 +13,7 @@
* 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
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/
@@ -59,11 +59,6 @@ class UnitOfWork
new Id\SingleIdHandler();
}
public function getClassMetadata($name)
{
return $this->cmf->getMetadataFor($name);
}
private function tryGetById($id)
{
$idHash = $this->idHandler->hash($id);
@@ -79,10 +74,6 @@ class UnitOfWork
$id = $this->idHandler->normalizeId($class, $key);
$data = $this->storageDriver->find($class->storageName, $id);
if (!$data) {
throw new NotFoundException();
}
return $this->createEntity($class, $id, $data);
}

View File

@@ -55,9 +55,8 @@ class WindowsAzureTableTest extends KeyValueStoreTestCase
$this->assertEquals('baz', $data['bar']);
$storage->delete("test", $key);
$this->setExpectedException("Doctrine\KeyValueStore\NotFoundException");
$storage->find("test", $key);
$data = $storage->find("test", $key);
$this->assertEquals(array(), $data);
}
public function testQueryRange()

View File

@@ -0,0 +1,64 @@
<?php
namespace Doctrine\Tests\KeyValueStore\References;
use Doctrine\KeyValueStore\References\ReferenceMetadata;
class ReferenceMetadataTest extends \PHPUnit_Framework_TestCase
{
public function testCreate()
{
$class = new ReferenceMetadata('Foo\Bar');
$this->assertEquals('Foo', $class->namespace);
$this->assertEquals('Foo\Bar', $class->name);
}
public function testAddReferenceOne()
{
$class = new ReferenceMetadata('Foo\Bar');
$class->addReferenceOne('baz', 'Baz');
$this->assertEquals(array(
'type' => ReferenceMetadata::REFERENCE_ONE,
'targetEntity' => 'Foo\Baz',
), $class->references['baz']);
}
public function testAddReferenceMany()
{
$class = new ReferenceMetadata('Foo\Bar');
$class->addReferenceMany('baz', 'Baz', 'bar', 'range');
$this->assertEquals(array(
'type' => ReferenceMetadata::REFERENCE_MANY,
'targetEntity' => 'Foo\Baz',
'parentField' => 'bar',
'rangeField' => 'range',
), $class->references['baz']);
}
public function testSerialize()
{
$class = new ReferenceMetadata('Foo\Bar');
$class->addReferenceOne('baz1', 'Baz');
$class->addReferenceMany('baz2', 'Baz', 'bar', 'range');
$class = unserialize(serialize($class));
$this->assertEquals('Foo', $class->namespace);
$this->assertEquals('Foo\Bar', $class->name);
$this->assertEquals(array(
'type' => ReferenceMetadata::REFERENCE_ONE,
'targetEntity' => 'Foo\Baz',
), $class->references['baz1']);
$this->assertEquals(array(
'type' => ReferenceMetadata::REFERENCE_MANY,
'targetEntity' => 'Foo\Baz',
'parentField' => 'bar',
'rangeField' => 'range',
), $class->references['baz2']);
}
}

View File

@@ -1,144 +0,0 @@
<?php
namespace Doctrine\Tests\KeyValueStore\Storage;
use Doctrine\KeyValueStore\Storage\MongoDbStorage;
/**
* MongoDb storage testcase
*
* @author Markus Bachmann <markus.bachmann@bachi.biz>
*/
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();
$this->mongo->expects($this->any())
->method('selectDB')
->will($this->returnValue($this->mongodb));
$this->collection = $this->getMockBuilder('MongoCollection')->disableOriginalConstructor()->getMock();
$this->mongodb->expects($this->once())
->method('selectCollection')
->will($this->returnValue($this->collection));
$this->storage = new MongoDbStorage($this->mongo, array(
'collection' => 'test',
'database' => 'test'
));
}
public function testInsert()
{
$data = array(
'author' => 'John Doe',
'title' => 'example book',
);
$dbDataset = array();
$this->collection->expects($this->once())
->method('insert')
->will($this->returnCallback(function($data) use (&$dbDataset) {
$dbDataset[] = $data;
}));
$this->storage->insert('mongodb', '1', $data);
$this->assertCount(1, $dbDataset);
$this->assertEquals(array(array('key' => '1', 'value' => $data)), $dbDataset);
}
public function testUpdate()
{
$data = array(
'author' => 'John Doe',
'title' => 'example book',
);
$dbDataset = array();
$this->collection->expects($this->once())
->method('update')
->will($this->returnCallback(function($citeria, $data) use (&$dbDataset) {
$dbDataset = array($citeria, $data);
}));
$this->storage->update('mongodb', '1', $data);
$this->assertEquals(array('key' => '1'), $dbDataset[0]);
$this->assertEquals(array('key' => '1', 'value' => $data), $dbDataset[1]);
}
public function testDelete()
{
$dataset = array(
array(
'key' => 'foobar',
'value' => array(
'author' => 'John Doe',
'title' => 'example book',
),
),
);
$this->collection->expects($this->once())
->method('remove')
->will($this->returnCallback(function($citeria) use (&$dataset) {
foreach ($dataset as $key => $row) {
if ($row['key'] === $citeria['key']) {
unset($dataset[$key]);
}
}
}
));
$this->storage->delete('test', 'foobar');
$this->assertCount(0, $dataset);
}
public function testFind()
{
$dataset = array(
array(
'key' => 'foobar',
'value' => array(
'author' => 'John Doe',
'title' => 'example book',
),
),
);
$this->collection->expects($this->once())
->method('findOne')
->will($this->returnCallback(function($citeria, $fields) use (&$dataset) {
foreach ($dataset as $key => $row) {
if ($row['key'] === $citeria['key']) {
return $row;
}
}
}
));
$data = $this->storage->find('test', 'foobar');
$this->assertEquals($dataset[0]['value'], $data);
}
public function testGetName()
{
$this->storage->initialize();
$this->assertEquals('mongodb', $this->storage->getName());
}
}