Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add simpleyaml and simplexml driver support
- Loading branch information
Showing
7 changed files
with
325 additions
and
1 deletion.
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
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
43 changes: 43 additions & 0 deletions
43
lib/Doctrine/ODM/MongoDB/Mapping/Driver/SimplifiedXmlDriver.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?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\ODM\MongoDB\Mapping\Driver; | ||
|
||
use Doctrine\Common\Persistence\Mapping\Driver\SymfonyFileLocator; | ||
|
||
/** | ||
* XmlDriver that additionally looks for mapping information in a global file. | ||
* | ||
* @author Fabien Potencier <fabien@symfony.com> | ||
* @author Benjamin Eberlei <kontakt@beberlei.de> | ||
* @license MIT | ||
*/ | ||
class SimplifiedXmlDriver extends XmlDriver | ||
{ | ||
const DEFAULT_FILE_EXTENSION = '.mongodb-odm.xml'; | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function __construct($prefixes, $fileExtension = self::DEFAULT_FILE_EXTENSION) | ||
{ | ||
$locator = new SymfonyFileLocator((array) $prefixes, $fileExtension); | ||
parent::__construct($locator, $fileExtension); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
lib/Doctrine/ODM/MongoDB/Mapping/Driver/SimplifiedYamlDriver.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?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\ODM\MongoDB\Mapping\Driver; | ||
|
||
use Doctrine\Common\Persistence\Mapping\Driver\SymfonyFileLocator; | ||
|
||
/** | ||
* YamlDriver that additionally looks for mapping information in a global file. | ||
* | ||
* @author Fabien Potencier <fabien@symfony.com> | ||
* @author Benjamin Eberlei <kontakt@beberlei.de> | ||
* @license MIT | ||
*/ | ||
class SimplifiedYamlDriver extends YamlDriver | ||
{ | ||
const DEFAULT_FILE_EXTENSION = '.mongodb-odm.yml'; | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function __construct($prefixes, $fileExtension = self::DEFAULT_FILE_EXTENSION) | ||
{ | ||
$locator = new SymfonyFileLocator((array) $prefixes, $fileExtension); | ||
parent::__construct($locator, $fileExtension); | ||
} | ||
} |
114 changes: 114 additions & 0 deletions
114
tests/Doctrine/ODM/MongoDB/Tests/Mapping/Symfony/AbstractDriverTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
<?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\ODM\MongoDB\Tests\Mapping\Symfony; | ||
|
||
/** | ||
* @group DDC-1418 | ||
*/ | ||
abstract class AbstractDriverTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testFindMappingFile() | ||
{ | ||
$driver = $this->getDriver(array( | ||
'MyNamespace\MySubnamespace\DocumentFoo' => 'foo', | ||
'MyNamespace\MySubnamespace\Document' => $this->dir, | ||
)); | ||
|
||
touch($filename = $this->dir.'/Foo'.$this->getFileExtension()); | ||
$this->assertEquals($filename, $driver->getLocator()->findMappingFile('MyNamespace\MySubnamespace\Document\Foo')); | ||
} | ||
|
||
public function testFindMappingFileInSubnamespace() | ||
{ | ||
$driver = $this->getDriver(array( | ||
'MyNamespace\MySubnamespace\Document' => $this->dir, | ||
)); | ||
|
||
touch($filename = $this->dir.'/Foo.Bar'.$this->getFileExtension()); | ||
$this->assertEquals($filename, $driver->getLocator()->findMappingFile('MyNamespace\MySubnamespace\Document\Foo\Bar')); | ||
} | ||
|
||
public function testFindMappingFileNamespacedFoundFileNotFound() | ||
{ | ||
$this->setExpectedException( | ||
'Doctrine\Common\Persistence\Mapping\MappingException', | ||
"No mapping file found named '".$this->dir."/Foo".$this->getFileExtension()."' for class 'MyNamespace\MySubnamespace\Document\Foo'." | ||
); | ||
|
||
$driver = $this->getDriver(array( | ||
'MyNamespace\MySubnamespace\Document' => $this->dir, | ||
)); | ||
|
||
$driver->getLocator()->findMappingFile('MyNamespace\MySubnamespace\Document\Foo'); | ||
} | ||
|
||
public function testFindMappingNamespaceNotFound() | ||
{ | ||
$this->setExpectedException( | ||
'Doctrine\Common\Persistence\Mapping\MappingException', | ||
"No mapping file found named 'Foo".$this->getFileExtension()."' for class 'MyOtherNamespace\MySubnamespace\Document\Foo'." | ||
); | ||
|
||
$driver = $this->getDriver(array( | ||
'MyNamespace\MySubnamespace\Document' => $this->dir, | ||
)); | ||
|
||
$driver->getLocator()->findMappingFile('MyOtherNamespace\MySubnamespace\Document\Foo'); | ||
} | ||
|
||
protected function setUp() | ||
{ | ||
$this->dir = sys_get_temp_dir().'/abstract_driver_test'; | ||
@mkdir($this->dir, 0777, true); | ||
} | ||
|
||
protected function tearDown() | ||
{ | ||
$iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->dir), \RecursiveIteratorIterator::CHILD_FIRST); | ||
|
||
foreach ($iterator as $path) { | ||
if ($path->isDir()) { | ||
@rmdir($path); | ||
} else { | ||
@unlink($path); | ||
} | ||
} | ||
|
||
@rmdir($this->dir); | ||
} | ||
|
||
abstract protected function getFileExtension(); | ||
abstract protected function getDriver(array $paths = array()); | ||
|
||
private function setField($obj, $field, $value) | ||
{ | ||
$ref = new \ReflectionProperty($obj, $field); | ||
$ref->setAccessible(true); | ||
$ref->setValue($obj, $value); | ||
} | ||
|
||
private function invoke($obj, $method, array $args = array()) | ||
{ | ||
$ref = new \ReflectionMethod($obj, $method); | ||
$ref->setAccessible(true); | ||
|
||
return $ref->invokeArgs($obj, $args); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
tests/Doctrine/ODM/MongoDB/Tests/Mapping/Symfony/XmlDriverTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?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\ODM\MongoDB\Tests\Mapping\Symfony; | ||
|
||
use Doctrine\ODM\MongoDB\Mapping\Driver\SimplifiedXmlDriver; | ||
|
||
/** | ||
* @group DDC-1418 | ||
*/ | ||
class XmlDriverTest extends AbstractDriverTest | ||
{ | ||
protected function getFileExtension() | ||
{ | ||
return '.mongodb-odm.xml'; | ||
} | ||
|
||
protected function getDriver(array $paths = array()) | ||
{ | ||
$driver = new SimplifiedXmlDriver(array_flip($paths)); | ||
|
||
return $driver; | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
tests/Doctrine/ODM/MongoDB/Tests/Mapping/Symfony/YamlDriverTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?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\ODM\MongoDB\Tests\Mapping\Symfony; | ||
|
||
use Doctrine\ODM\MongoDB\Mapping\Driver\SimplifiedYamlDriver; | ||
|
||
/** | ||
* @group DDC-1418 | ||
*/ | ||
class YamlDriverTest extends AbstractDriverTest | ||
{ | ||
protected function getFileExtension() | ||
{ | ||
return '.mongodb-odm.yml'; | ||
} | ||
|
||
protected function getDriver(array $paths = array()) | ||
{ | ||
$driver = new SimplifiedYamlDriver(array_flip($paths)); | ||
|
||
return $driver; | ||
} | ||
} |