This repository has been archived by the owner on Feb 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored Configuration into its own class, integrated IdConverterSt…
…rategies.
- Loading branch information
Showing
9 changed files
with
249 additions
and
19 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 |
---|---|---|
@@ -0,0 +1,117 @@ | ||
<?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; | ||
|
||
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver; | ||
use Doctrine\Common\Cache\Cache; | ||
use Doctrine\Common\Cache\ArrayCache; | ||
use Doctrine\KeyValueStore\Id\NullIdConverter; | ||
|
||
/** | ||
* Configure the behavior of the EntityManager | ||
* | ||
* @author Benjamin Eberlei <[email protected]> | ||
*/ | ||
class Configuration | ||
{ | ||
/** | ||
* @param array | ||
*/ | ||
private $config; | ||
|
||
/** | ||
* Get mapping driver implementation used with this configuration. | ||
* | ||
* @return \Doctrine\Common\Persistence\Mapping\Driver\MappingDriver | ||
*/ | ||
public function getMappingDriverImpl() | ||
{ | ||
if ( ! isset($this->config['mappingDriver'])) { | ||
throw KeyValueStoreException::mappingDriverMissing(); | ||
} | ||
|
||
return $this->config['mappingDriver']; | ||
} | ||
|
||
/** | ||
* Set the mapping driver implementation. | ||
* | ||
* @param \Doctrine\Common\Persistence\Mapping\Driver\MappingDriver $driver | ||
* @return \Doctrine\KeyValueStore\Configuration | ||
*/ | ||
public function setMappingDriverImpl(MappingDriver $driver) | ||
{ | ||
$this->config['mappingDriver'] = $driver; | ||
return $this; | ||
} | ||
|
||
/** | ||
* Set the Metadata Mapping cache used with this configuration. | ||
* | ||
* @param \Doctrine\Common\Cache\Cache $cache | ||
* @return \Doctrine\KeyValueStore\Configuration | ||
*/ | ||
public function setMetadataCache(Cache $cache) | ||
{ | ||
$this->config['metadataCache'] = $cache; | ||
return $this; | ||
} | ||
|
||
/** | ||
* Get the metadata mapping cache used with this configuration. | ||
* | ||
* @return \Doctrine\Common\Cache\Cache $cache | ||
*/ | ||
public function getMetadataCache() | ||
{ | ||
if ( ! isset($this->config['metadataCache'])) { | ||
$this->config['metadataCache'] = new ArrayCache(); | ||
} | ||
|
||
return $this->config['metadataCache']; | ||
} | ||
|
||
/** | ||
* Set the ID Converter Strategy | ||
* | ||
* @param \Doctrine\KeyValueStore\Id\IdConverterStrategy | ||
* @return \Doctrine\KeyValueStore\Configuration | ||
*/ | ||
public function setIdConverterStrategy(IdConverterStrategy $strategy) | ||
{ | ||
$this->config['idConverter'] = $strategy; | ||
return $this; | ||
} | ||
|
||
/** | ||
* Get the Id Converter strategy | ||
* | ||
* @return \Doctrine\KeyValueStore\Id\IdConverterStrategy | ||
*/ | ||
public function getIdConverterStrategy() | ||
{ | ||
if ( ! isset($this->config['idConverter'])) { | ||
$this->config['idConverter'] = new NullIdConverter(); | ||
} | ||
|
||
return $this->config['idConverter']; | ||
} | ||
} | ||
|
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
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
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
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,29 @@ | ||
<?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; | ||
|
||
class KeyValueStoreException extends \Exception | ||
{ | ||
static public function mappingDriverMissing() | ||
{ | ||
return new self("No mapping driver was assigned to the configuration. Use \$config->setMappingDriverImpl()"); | ||
} | ||
} | ||
|
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
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
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,32 @@ | ||
<?php | ||
namespace Doctrine\Tests\KeyValueStore; | ||
|
||
use Doctrine\KeyValueStore\Configuration; | ||
|
||
class ConfigurationTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testNoMappingDriver() | ||
{ | ||
$config = new Configuration(); | ||
|
||
$this->setExpectedException('Doctrine\KeyValueStore\KeyValueStoreException', 'No mapping driver was assigned to the configuration. Use $config->setMappingDriverImpl()'); | ||
$config->getMappingDriverImpl(); | ||
} | ||
|
||
public function testDefaultCacheDriver() | ||
{ | ||
$config = new Configuration(); | ||
$cache = $config->getMetadataCache(); | ||
|
||
$this->assertInstanceOf('Doctrine\Common\Cache\Cache', $cache); | ||
} | ||
|
||
public function testDefaultIdConverterStrategy() | ||
{ | ||
$config = new Configuration(); | ||
$strategy = $config->getIdConverterStrategy(); | ||
|
||
$this->assertInstanceOf('Doctrine\KeyValueStore\Id\NullIdConverter', $strategy); | ||
} | ||
} | ||
|
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