1
0
mirror of synced 2025-01-31 04:21:44 +03:00

Removing API that should be moved to common

This commit is contained in:
Marco Pivetta 2012-01-17 14:31:27 +01:00
parent 82cfda3dec
commit 03fb734de8
5 changed files with 24 additions and 56 deletions

View File

@ -21,6 +21,7 @@ namespace Doctrine\ORM\Mapping\Driver;
use Doctrine\ORM\Mapping\MappingException;
use Doctrine\Common\Persistence\Mapping\Driver\FileDriver;
use Doctrine\Common\Persistence\Mapping\Driver\FileLocator;
/**
* Base driver for file-based metadata drivers.
@ -40,26 +41,6 @@ use Doctrine\Common\Persistence\Mapping\Driver\FileDriver;
*/
abstract class AbstractFileDriver extends FileDriver implements Driver
{
/**
* Append lookup paths to metadata driver.
*
* @param array $paths
*/
public function addPaths(array $paths)
{
$this->locator->addPaths($paths);
}
/**
* Retrieve the defined metadata lookup paths.
*
* @return array
*/
public function getPaths()
{
return $this->locator->getPaths();
}
/**
* Get the element of schema meta data for the class from the mapping file.
* This will lazily load the mapping file if it is not loaded yet
@ -76,17 +57,4 @@ abstract class AbstractFileDriver extends FileDriver implements Driver
}
return $result;
}
/**
* Finds the mapping file for the class with the given name by searching
* through the configured paths.
*
* @param $className
* @return string The (absolute) file name.
* @throws MappingException
*/
protected function findMappingFile($className)
{
return $this->locator->findMappingFile($className);
}
}

View File

@ -19,12 +19,7 @@
namespace Doctrine\ORM\Mapping\Driver;
use Doctrine\Common\Cache\ArrayCache,
Doctrine\Common\Annotations\AnnotationReader,
Doctrine\DBAL\Schema\AbstractSchemaManager,
Doctrine\Common\Persistence\Mapping\ClassMetadata,
Doctrine\ORM\Mapping\MappingException,
Doctrine\Common\Util\Inflector,
use Doctrine\Common\Persistence\Mapping\ClassMetadata,
Doctrine\ORM\Mapping\Driver\AbstractFileDriver;
/**
@ -46,11 +41,11 @@ class PHPDriver extends AbstractFileDriver
const DEFAULT_FILE_EXTENSION = '.php';
/**
* {@inheritdoc}
*
* @var ClassMetadata
*/
protected $_fileExtension = '.php';
protected $_metadata;
/**
* {@inheritdoc}
*/
@ -65,7 +60,7 @@ class PHPDriver extends AbstractFileDriver
public function loadMetadataForClass($className, ClassMetadata $metadata)
{
$this->_metadata = $metadata;
$this->loadMappingFile($this->findMappingFile($className));
$this->getElement($className);
}
/**
@ -73,7 +68,12 @@ class PHPDriver extends AbstractFileDriver
*/
protected function loadMappingFile($file)
{
$result = array();
$metadata = $this->_metadata;
include $file;
// @todo cannot assume that the only loaded metadata is $metadata. Some
// decision about the preferred approach should be taken
$result[$metadata->getName()] = $metadata;
return $result;
}
}
}

View File

@ -59,7 +59,7 @@ class SimplifiedXmlDriver extends XmlDriver
public function addNamespacePrefixes($prefixes)
{
$this->_prefixes = array_merge($this->_prefixes, $prefixes);
$this->addPaths(array_flip($prefixes));
$this->locator->addPaths(array_flip($prefixes));
}
public function getNamespacePrefixes()
@ -95,8 +95,8 @@ class SimplifiedXmlDriver extends XmlDriver
$classes = array();
if ($this->_paths) {
foreach ((array) $this->_paths as $path) {
if ($this->locator->getPaths()) {
foreach ($this->locator->getPaths() as $path) {
if (!is_dir($path)) {
throw MappingException::fileMappingDriversRequireConfiguredDirectoryPath($path);
}
@ -143,7 +143,7 @@ class SimplifiedXmlDriver extends XmlDriver
{
$this->_classCache = array();
if (null !== $this->_globalBasename) {
foreach ($this->_paths as $path) {
foreach ($this->locator->getPaths() as $path) {
if (is_file($file = $path.'/'.$this->_globalBasename.$this->_fileExtension)) {
$this->_classCache = array_merge($this->_classCache, $this->loadMappingFile($file));
}
@ -154,7 +154,7 @@ class SimplifiedXmlDriver extends XmlDriver
protected function findMappingFile($className)
{
$defaultFileName = str_replace('\\', '.', $className).$this->_fileExtension;
foreach ($this->_paths as $path) {
foreach ($this->locator->getPaths() as $path) {
if (!isset($this->_prefixes[$path])) {
if (is_file($path.DIRECTORY_SEPARATOR.$defaultFileName)) {
return $path.DIRECTORY_SEPARATOR.$defaultFileName;

View File

@ -30,7 +30,7 @@ use Doctrine\ORM\Mapping\MappingException;
*/
class SimplifiedYamlDriver extends YamlDriver
{
const DEFAULT_FILE_EXTENSION = '.orm.xml';
const DEFAULT_FILE_EXTENSION = '.orm.yml';
protected $_prefixes = array();
protected $_globalBasename;
@ -59,7 +59,7 @@ class SimplifiedYamlDriver extends YamlDriver
public function addNamespacePrefixes($prefixes)
{
$this->_prefixes = array_merge($this->_prefixes, $prefixes);
$this->addPaths(array_flip($prefixes));
$this->locator->addPaths(array_flip($prefixes));
}
public function addNamespacePrefix($prefix, $path)
@ -100,8 +100,8 @@ class SimplifiedYamlDriver extends YamlDriver
$classes = array();
if ($this->_paths) {
foreach ((array) $this->_paths as $path) {
if ($this->locator->getPaths()) {
foreach ($this->locator->getPaths() as $path) {
if (!is_dir($path)) {
throw MappingException::fileMappingDriversRequireConfiguredDirectoryPath($path);
}
@ -148,7 +148,7 @@ class SimplifiedYamlDriver extends YamlDriver
{
$this->_classCache = array();
if (null !== $this->_globalBasename) {
foreach ($this->_paths as $path) {
foreach ($this->locator->getPaths() as $path) {
if (is_file($file = $path.'/'.$this->_globalBasename.$this->_fileExtension)) {
$this->_classCache = array_merge($this->_classCache, $this->loadMappingFile($file));
}
@ -159,7 +159,7 @@ class SimplifiedYamlDriver extends YamlDriver
protected function findMappingFile($className)
{
$defaultFileName = str_replace('\\', '.', $className).$this->_fileExtension;
foreach ($this->_paths as $path) {
foreach ($this->locator->getPaths() as $path) {
if (!isset($this->_prefixes[$path])) {
if (is_file($path.DIRECTORY_SEPARATOR.$defaultFileName)) {
return $path.DIRECTORY_SEPARATOR.$defaultFileName;

View File

@ -27,7 +27,7 @@ class YamlMappingDriverTest extends AbstractMappingDriverTest
public function testJoinTablesWithMappedSuperclassForYamlDriver()
{
$yamlDriver = $this->_loadDriver();
$yamlDriver->addPaths(array(__DIR__ . DIRECTORY_SEPARATOR . 'yaml'));
$yamlDriver->getLocator()->addPaths(array(__DIR__ . DIRECTORY_SEPARATOR . 'yaml'));
$em = $this->_getTestEntityManager();
$em->getConfiguration()->setMetadataDriverImpl($yamlDriver);