Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
443a2056
Commit
443a2056
authored
Jan 28, 2010
by
guilhermeblanco
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[2.0][DDC-281] Fixes for Mapping drivers
parent
14ec40e1
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
246 additions
and
175 deletions
+246
-175
AbstractDriver.php
lib/Doctrine/ORM/Mapping/Driver/AbstractDriver.php
+0
-97
AbstractFileDriver.php
lib/Doctrine/ORM/Mapping/Driver/AbstractFileDriver.php
+76
-25
AnnotationDriver.php
lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php
+63
-5
PhpDriver.php
lib/Doctrine/ORM/Mapping/Driver/PhpDriver.php
+73
-8
XmlDriver.php
lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php
+24
-24
YamlDriver.php
lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php
+1
-1
ClassMetadataExporter.php
lib/Doctrine/ORM/Tools/Export/ClassMetadataExporter.php
+6
-9
MappingDriverTest.php
tests/Doctrine/Tests/ORM/Mapping/MappingDriverTest.php
+3
-6
No files found.
lib/Doctrine/ORM/Mapping/Driver/AbstractDriver.php
deleted
100644 → 0
View file @
14ec40e1
<?php
/*
* $Id$
*
* 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\ORM\Mapping\Driver
;
/**
* Base driver for metadata drivers.
*
* A file driver operates in a mode where it loads the mapping files of individual
* classes on demand. This requires the user to adhere to the convention of 1 mapping
* file per class and the file names of the mapping files must correspond to the full
* class name, including namespace, with the namespace delimiters '\', replaced by dots '.'.
*
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.com
* @since 2.0
* @version $Revision$
* @author Benjamin Eberlei <kontakt@beberlei.de>
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Jonathan H. Wage <jonwage@gmail.com>
* @author Roman Borschel <roman@code-factory.org>
*/
abstract
class
AbstractDriver
{
/**
* The paths where to look for mapping files.
*
* @var array
*/
protected
$_paths
=
array
();
/**
* The file extension of mapping documents.
*
* @var string
*/
protected
$_fileExtension
=
'php'
;
/**
* Append lookup paths to metadata driver.
*
* @param array $paths
*/
public
function
addPaths
(
array
$paths
)
{
$this
->
_paths
=
array_unique
(
array_merge
(
$this
->
_paths
,
$paths
));
}
/**
* Retrieve the defined metadata lookup paths.
*
* @return array
*/
public
function
getPaths
()
{
return
$this
->
_paths
;
}
/**
* Get the file extension used to look for mapping files under
*
* @return void
*/
public
function
getFileExtension
()
{
return
$this
->
_fileExtension
;
}
/**
* Set the file extension used to look for mapping files under
*
* @param string $fileExtension The file extension to set
* @return void
*/
public
function
setFileExtension
(
$fileExtension
)
{
$this
->
_fileExtension
=
$fileExtension
;
}
}
\ No newline at end of file
lib/Doctrine/ORM/Mapping/Driver/AbstractFileDriver.php
View file @
443a2056
...
...
@@ -40,12 +40,73 @@ use Doctrine\ORM\Mapping\MappingException;
* @author Jonathan H. Wage <jonwage@gmail.com>
* @author Roman Borschel <roman@code-factory.org>
*/
abstract
class
AbstractFileDriver
extends
AbstractDriver
implements
Driver
abstract
class
AbstractFileDriver
implements
Driver
{
/**
* @var string Middle part file extension.
* The paths where to look for mapping files.
*
* @var array
*/
protected
$_paths
=
array
();
/**
* The file extension of mapping documents.
*
* @var string
*/
protected
$_fileExtension
=
'.php'
;
/**
* Initializes a new FileDriver that looks in the given path(s) for mapping
* documents and operates in the specified operating mode.
*
* @param string|array $paths One or multiple paths where mapping documents can be found.
*/
public
function
__construct
(
$paths
)
{
$this
->
addPaths
((
array
)
$paths
);
}
/**
* Append lookup paths to metadata driver.
*
* @param array $paths
*/
protected
$_middleFileExtension
=
'dcm'
;
public
function
addPaths
(
array
$paths
)
{
$this
->
_paths
=
array_unique
(
array_merge
(
$this
->
_paths
,
$paths
));
}
/**
* Retrieve the defined metadata lookup paths.
*
* @return array
*/
public
function
getPaths
()
{
return
$this
->
_paths
;
}
/**
* Get the file extension used to look for mapping files under
*
* @return void
*/
public
function
getFileExtension
()
{
return
$this
->
_fileExtension
;
}
/**
* Set the file extension used to look for mapping files under
*
* @param string $fileExtension The file extension to set
* @return void
*/
public
function
setFileExtension
(
$fileExtension
)
{
$this
->
_fileExtension
=
$fileExtension
;
}
/**
* Get the element of schema meta data for the class from the mapping file.
...
...
@@ -70,13 +131,16 @@ abstract class AbstractFileDriver extends AbstractDriver implements Driver
*/
public
function
isTransient
(
$className
)
{
try
{
$fileName
=
$this
->
_findMappingFile
(
$className
);
return
false
;
}
catch
(
\Exception
$e
)
{
return
true
;
$fileName
=
str_replace
(
'\\'
,
'.'
,
$className
)
.
$this
->
_fileExtension
;
// Check whether file exists
foreach
((
array
)
$this
->
_paths
as
$path
)
{
if
(
file_exists
(
$path
.
DIRECTORY_SEPARATOR
.
$fileName
))
{
return
false
;
}
}
return
true
;
}
/**
...
...
@@ -100,14 +164,12 @@ abstract class AbstractFileDriver extends AbstractDriver implements Driver
);
foreach
(
$iterator
as
$file
)
{
$info
=
pathinfo
(
$file
->
getPathName
());
if
(
!
isset
(
$info
[
'extension'
])
||
$info
[
'extension'
]
!=
$this
->
_fileExtension
)
{
if
((
$fileName
=
$file
->
getBasename
(
$this
->
_fileExtension
))
==
$file
->
getBasename
())
{
continue
;
}
// NOTE: All files found here means classes are not transient!
$classes
[]
=
str_replace
(
'.'
,
'\\'
,
$file
->
getBasename
(
'.'
.
$this
->
_getFileSuffix
())
);
$classes
[]
=
str_replace
(
'.'
,
'\\'
,
$file
Name
);
}
}
}
...
...
@@ -125,7 +187,7 @@ abstract class AbstractFileDriver extends AbstractDriver implements Driver
*/
protected
function
_findMappingFile
(
$className
)
{
$fileName
=
str_replace
(
'\\'
,
'.'
,
$className
)
.
'.'
.
$this
->
_getFileSuffix
()
;
$fileName
=
str_replace
(
'\\'
,
'.'
,
$className
)
.
$this
->
_fileExtension
;
// Check whether file exists
foreach
((
array
)
$this
->
_paths
as
$path
)
{
...
...
@@ -136,17 +198,6 @@ abstract class AbstractFileDriver extends AbstractDriver implements Driver
throw
MappingException
::
mappingFileNotFound
(
$className
);
}
/**
* Retrieves the mapping file name suffix.
*
* @return string File name suffix.
*/
protected
function
_getFileSuffix
()
{
return
(
$this
->
_middleFileExtension
!=
''
?
$this
->
_middleFileExtension
.
'.'
:
''
)
.
$this
->
_fileExtension
;
}
/**
* Loads a mapping file with the given name and returns a map
...
...
lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php
View file @
443a2056
...
...
@@ -41,7 +41,7 @@ require __DIR__ . '/DoctrineAnnotations.php';
* @author Jonathan H. Wage <jonwage@gmail.com>
* @author Roman Borschel <roman@code-factory.org>
*/
class
AnnotationDriver
extends
AbstractDriver
implements
Driver
class
AnnotationDriver
implements
Driver
{
/**
* The AnnotationReader.
...
...
@@ -50,15 +50,75 @@ class AnnotationDriver extends AbstractDriver implements Driver
*/
private
$_reader
;
/**
* The paths where to look for mapping files.
*
* @var array
*/
protected
$_paths
=
array
();
/**
* The file extension of mapping documents.
*
* @var string
*/
protected
$_fileExtension
=
'.php'
;
/**
* Initializes a new AnnotationDriver that uses the given AnnotationReader for reading
* docblock annotations.
*
* @param $reader The AnnotationReader to use.
* @param string|array $paths One or multiple paths where mapping classes can be found.
*/
public
function
__construct
(
AnnotationReader
$reader
)
public
function
__construct
(
AnnotationReader
$reader
,
$paths
=
null
)
{
$this
->
_reader
=
$reader
;
if
(
$paths
)
{
$this
->
addPaths
((
array
)
$paths
);
}
}
/**
* Append lookup paths to metadata driver.
*
* @param array $paths
*/
public
function
addPaths
(
array
$paths
)
{
$this
->
_paths
=
array_unique
(
array_merge
(
$this
->
_paths
,
$paths
));
}
/**
* Retrieve the defined metadata lookup paths.
*
* @return array
*/
public
function
getPaths
()
{
return
$this
->
_paths
;
}
/**
* Get the file extension used to look for mapping files under
*
* @return void
*/
public
function
getFileExtension
()
{
return
$this
->
_fileExtension
;
}
/**
* Set the file extension used to look for mapping files under
*
* @param string $fileExtension The file extension to set
* @return void
*/
public
function
setFileExtension
(
$fileExtension
)
{
$this
->
_fileExtension
=
$fileExtension
;
}
/**
...
...
@@ -359,9 +419,7 @@ class AnnotationDriver extends AbstractDriver implements Driver
);
foreach
(
$iterator
as
$file
)
{
$info
=
pathinfo
(
$file
->
getPathName
());
if
(
!
isset
(
$info
[
'extension'
])
||
$info
[
'extension'
]
!=
$this
->
_fileExtension
)
{
if
((
$fileName
=
$file
->
getBasename
(
$this
->
_fileExtension
))
==
$file
->
getBasename
())
{
continue
;
}
...
...
lib/Doctrine/ORM/Mapping/Driver/PhpDriver.php
View file @
443a2056
...
...
@@ -42,11 +42,79 @@ use Doctrine\Common\DoctrineException,
* @author Jonathan H. Wage <jonwage@gmail.com>
* @author Roman Borschel <roman@code-factory.org>
*/
class
PhpDriver
extends
AbstractDriver
implements
Driver
class
PhpDriver
implements
Driver
{
/** The array of class names found and the path to the file */
/**
* @var array The array of class names found and the path to the file
*/
private
$_classPaths
=
array
();
/**
* The paths where to look for mapping files.
*
* @var array
*/
protected
$_paths
=
array
();
/**
* The file extension of mapping documents.
*
* @var string
*/
protected
$_fileExtension
=
'.php'
;
/**
* Initializes a new PhpDriver that looks in the given path(s) for mapping
* documents and operates in the specified operating mode.
*
* @param string|array $paths One or multiple paths where mapping documents can be found.
*/
public
function
__construct
(
$paths
)
{
$this
->
addPaths
((
array
)
$paths
);
}
/**
* Append lookup paths to metadata driver.
*
* @param array $paths
*/
public
function
addPaths
(
array
$paths
)
{
$this
->
_paths
=
array_unique
(
array_merge
(
$this
->
_paths
,
$paths
));
}
/**
* Retrieve the defined metadata lookup paths.
*
* @return array
*/
public
function
getPaths
()
{
return
$this
->
_paths
;
}
/**
* Get the file extension used to look for mapping files under
*
* @return void
*/
public
function
getFileExtension
()
{
return
$this
->
_fileExtension
;
}
/**
* Set the file extension used to look for mapping files under
*
* @param string $fileExtension The file extension to set
* @return void
*/
public
function
setFileExtension
(
$fileExtension
)
{
$this
->
_fileExtension
=
$fileExtension
;
}
/**
* {@inheritdoc}
*/
...
...
@@ -84,15 +152,12 @@ class PhpDriver extends AbstractDriver implements Driver
);
foreach
(
$iterator
as
$file
)
{
$info
=
pathinfo
(
$file
->
getPathName
());
if
(
!
isset
(
$info
[
'extension'
])
||
$info
[
'extension'
]
!=
$this
->
_fileExtension
)
{
if
((
$fileName
=
$file
->
getBasename
(
$this
->
_fileExtension
))
==
$file
->
getBasename
())
{
continue
;
}
$className
=
$info
[
'filename'
];
$classes
[]
=
$className
;
$this
->
_classPaths
[
$className
]
=
$file
->
getPathName
();
$classes
[]
=
$fileName
;
$this
->
_classPaths
[
$fileName
]
=
$file
->
getPathName
();
}
}
}
...
...
lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php
View file @
443a2056
...
...
@@ -41,7 +41,7 @@ class XmlDriver extends AbstractFileDriver
/**
* {@inheritdoc}
*/
protected
$_fileExtension
=
'xml'
;
protected
$_fileExtension
=
'
.dcm.
xml'
;
/**
* {@inheritdoc}
...
...
@@ -369,29 +369,6 @@ class XmlDriver extends AbstractFileDriver
}
}
}
/**
* {@inheritdoc}
*/
protected
function
_loadMappingFile
(
$file
)
{
$result
=
array
();
$xmlElement
=
simplexml_load_file
(
$file
);
if
(
isset
(
$xmlElement
->
entity
))
{
foreach
(
$xmlElement
->
entity
as
$entityElement
)
{
$entityName
=
(
string
)
$entityElement
[
'name'
];
$result
[
$entityName
]
=
$entityElement
;
}
}
else
if
(
isset
(
$xmlElement
->
{
'mapped-superclass'
}))
{
foreach
(
$xmlElement
->
{
'mapped-superclass'
}
as
$mapperSuperClass
)
{
$className
=
(
string
)
$mappedSuperClass
[
'name'
];
$result
[
$className
]
=
$mappedSuperClass
;
}
}
return
$result
;
}
/**
* Constructs a joinColumn mapping array based on the information
...
...
@@ -445,4 +422,27 @@ class XmlDriver extends AbstractFileDriver
}
return
$cascades
;
}
/**
* {@inheritdoc}
*/
protected
function
_loadMappingFile
(
$file
)
{
$result
=
array
();
$xmlElement
=
simplexml_load_file
(
$file
);
if
(
isset
(
$xmlElement
->
entity
))
{
foreach
(
$xmlElement
->
entity
as
$entityElement
)
{
$entityName
=
(
string
)
$entityElement
[
'name'
];
$result
[
$entityName
]
=
$entityElement
;
}
}
else
if
(
isset
(
$xmlElement
->
{
'mapped-superclass'
}))
{
foreach
(
$xmlElement
->
{
'mapped-superclass'
}
as
$mapperSuperClass
)
{
$className
=
(
string
)
$mappedSuperClass
[
'name'
];
$result
[
$className
]
=
$mappedSuperClass
;
}
}
return
$result
;
}
}
\ No newline at end of file
lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php
View file @
443a2056
...
...
@@ -49,7 +49,7 @@ class YamlDriver extends AbstractFileDriver
/**
* {@inheritdoc}
*/
protected
$_fileExtension
=
'yml'
;
protected
$_fileExtension
=
'
.dcm.
yml'
;
/**
* {@inheritdoc}
...
...
lib/Doctrine/ORM/Tools/Export/ClassMetadataExporter.php
View file @
443a2056
...
...
@@ -111,20 +111,17 @@ class ClassMetadataExporter
$class
=
$this
->
_mappingDrivers
[
$type
];
if
(
is_subclass_of
(
$class
,
'Doctrine\ORM\Mapping\Driver\AbstractDriver'
))
{
if
(
is_subclass_of
(
$class
,
'Doctrine\ORM\Mapping\Driver\Abstract
File
Driver'
))
{
if
(
is_null
(
$source
))
{
throw
DoctrineException
::
fileMappingDriversRequireDirectoryPath
();
}
if
(
$class
==
'Doctrine\ORM\Mapping\Driver\AnnotationDriver'
)
{
$reader
=
new
\Doctrine\Common\Annotations\AnnotationReader
(
new
\Doctrine\Common\Cache\ArrayCache
);
$reader
->
setDefaultAnnotationNamespace
(
'Doctrine\ORM\Mapping\\'
);
$driver
=
new
\Doctrine\ORM\Mapping\Driver\AnnotationDriver
(
$reader
);
}
else
{
$driver
=
new
$class
();
}
$driver
=
new
$class
(
$source
);
}
else
if
(
$class
==
'Doctrine\ORM\Mapping\Driver\AnnotationDriver'
)
{
$reader
=
new
\Doctrine\Common\Annotations\AnnotationReader
(
new
\Doctrine\Common\Cache\ArrayCache
);
$reader
->
setDefaultAnnotationNamespace
(
'Doctrine\ORM\Mapping\\'
);
$driver
->
addPaths
((
array
)
$source
);
$driver
=
new
\Doctrine\ORM\Mapping\Driver\AnnotationDriver
(
$reader
,
$source
);
}
else
{
$driver
=
new
$class
(
$source
);
}
...
...
tests/Doctrine/Tests/ORM/Mapping/MappingDriverTest.php
View file @
443a2056
...
...
@@ -13,8 +13,7 @@ class MappingDriverTest extends \Doctrine\Tests\OrmTestCase
public
function
testXmlMapping
()
{
$className
=
'Doctrine\Tests\ORM\Mapping\User'
;
$xmlDriver
=
new
XmlDriver
();
$xmlDriver
->
addPaths
(
array
(
__DIR__
.
DIRECTORY_SEPARATOR
.
'xml'
));
$xmlDriver
=
new
XmlDriver
(
__DIR__
.
DIRECTORY_SEPARATOR
.
'xml'
);
$class
=
new
ClassMetadata
(
$className
);
...
...
@@ -28,8 +27,7 @@ class MappingDriverTest extends \Doctrine\Tests\OrmTestCase
public
function
testYamlMapping
()
{
$className
=
'Doctrine\Tests\ORM\Mapping\User'
;
$yamlDriver
=
new
YamlDriver
();
$yamlDriver
->
addPaths
(
array
(
__DIR__
.
DIRECTORY_SEPARATOR
.
'yaml'
));
$yamlDriver
=
new
YamlDriver
(
__DIR__
.
DIRECTORY_SEPARATOR
.
'yaml'
);
$class
=
new
ClassMetadata
(
$className
);
...
...
@@ -43,8 +41,7 @@ class MappingDriverTest extends \Doctrine\Tests\OrmTestCase
public
function
testXmlGetAllClassNames
()
{
$className
=
'Doctrine\Tests\ORM\Mapping\User'
;
$xmlDriver
=
new
XmlDriver
();
$xmlDriver
->
addPaths
(
array
(
__DIR__
.
DIRECTORY_SEPARATOR
.
'xml'
));
$xmlDriver
=
new
XmlDriver
(
__DIR__
.
DIRECTORY_SEPARATOR
.
'xml'
);
$class
=
new
ClassMetadata
(
$className
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment