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
4ac39f0c
Commit
4ac39f0c
authored
Mar 03, 2010
by
guilhermeblanco
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[2.0][DDC-379][DDC-384] Implemented Entity namespace alias support.
parent
9427a85e
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
95 additions
and
37 deletions
+95
-37
Configuration.php
lib/Doctrine/ORM/Configuration.php
+20
-16
ClassMetadataFactory.php
lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php
+27
-10
ORMException.php
lib/Doctrine/ORM/ORMException.php
+26
-2
Lexer.php
lib/Doctrine/ORM/Query/Lexer.php
+1
-1
Parser.php
lib/Doctrine/ORM/Query/Parser.php
+6
-4
EntityRepositoryTest.php
tests/Doctrine/Tests/ORM/Functional/EntityRepositoryTest.php
+11
-0
QueryTest.php
tests/Doctrine/Tests/ORM/Functional/QueryTest.php
+4
-4
No files found.
lib/Doctrine/ORM/Configuration.php
View file @
4ac39f0c
...
...
@@ -21,8 +21,6 @@
namespace
Doctrine\ORM
;
use
Doctrine\Common\DoctrineException
;
/**
* Configuration container for all configuration options of Doctrine.
* It combines all configuration options from DBAL & ORM.
...
...
@@ -52,7 +50,7 @@ class Configuration extends \Doctrine\DBAL\Configuration
'namedNativeQueries'
=>
array
(),
'autoGenerateProxyClasses'
=>
true
,
'proxyNamespace'
=>
null
,
'entity
AliasMap
'
=>
array
()
'entity
Namespaces
'
=>
array
()
));
}
...
...
@@ -121,24 +119,30 @@ class Configuration extends \Doctrine\DBAL\Configuration
}
/**
* Add a
n alias for an entity
.
* Add a
namespace alias for entities
.
*
* @param string $className
* @param string $alias
* @param string $namespace
*/
public
function
addEntity
Alias
(
$className
,
$alias
)
public
function
addEntity
Namespace
(
$alias
,
$namespace
)
{
$this
->
_attributes
[
'entity
AliasMap'
][
$alias
]
=
$classNam
e
;
$this
->
_attributes
[
'entity
Namespaces'
][
$alias
]
=
$namespac
e
;
}
/**
*
get the array of entity aliases
*
Get the namespace of a given entity namespace
*
* @return array $aliasMap
* @param string $entityNamespaceAlias
* @return string
* @throws MappingException
*/
public
function
getEntity
AliasMap
(
)
public
function
getEntity
Namespace
(
$entityNamespaceAlias
)
{
return
$this
->
_attributes
[
'entityAliasMap'
];
if
(
isset
(
$this
->
_attributes
[
'entityNamespaces'
][
$entityNamespaceAlias
]))
{
return
trim
(
$this
->
_attributes
[
'entityNamespaces'
][
$entityNamespaceAlias
],
'\\'
);
}
throw
ORMException
::
unknownEntityNamespace
(
$entityNamespaceAlias
);
}
/**
...
...
@@ -147,9 +151,9 @@ class Configuration extends \Doctrine\DBAL\Configuration
* @param array $entityAliasMap
* @return void
*/
public
function
setEntity
AliasMap
(
array
$entityAliasMap
)
public
function
setEntity
Namespaces
(
array
$entityNamespaces
)
{
$this
->
_attributes
[
'entity
AliasMap'
]
=
$entityAliasMap
;
$this
->
_attributes
[
'entity
Namespaces'
]
=
$entityNamespaces
;
}
/**
...
...
@@ -306,13 +310,13 @@ class Configuration extends \Doctrine\DBAL\Configuration
public
function
ensureProductionSettings
()
{
if
(
!
$this
->
_attributes
[
'queryCacheImpl'
])
{
throw
Doctrine
Exception
::
queryCacheNotConfigured
();
throw
ORM
Exception
::
queryCacheNotConfigured
();
}
if
(
!
$this
->
_attributes
[
'metadataCacheImpl'
])
{
throw
Doctrine
Exception
::
metadataCacheNotConfigured
();
throw
ORM
Exception
::
metadataCacheNotConfigured
();
}
if
(
$this
->
_attributes
[
'autoGenerateProxyClasses'
])
{
throw
Doctrine
Exception
::
proxyClassesAlwaysRegenerating
();
throw
ORM
Exception
::
proxyClassesAlwaysRegenerating
();
}
}
}
\ No newline at end of file
lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php
View file @
4ac39f0c
...
...
@@ -128,27 +128,44 @@ class ClassMetadataFactory
public
function
getMetadataFor
(
$className
)
{
if
(
!
isset
(
$this
->
_loadedMetadata
[
$className
]))
{
$aliasMap
=
$this
->
_em
->
getConfiguration
()
->
getEntityAliasMap
();
if
(
isset
(
$aliasMap
[
$className
]))
{
$className
=
$aliasMap
[
$className
];
$realClassName
=
$className
;
if
(
strpos
(
$className
,
':'
)
!==
false
)
{
list
(
$namespaceAlias
,
$simpleClassName
)
=
explode
(
':'
,
$className
);
$realClassName
=
$this
->
_em
->
getConfiguration
()
->
getEntityNamespace
(
$namespaceAlias
)
.
'\\'
.
$simpleClassName
;
if
(
isset
(
$this
->
_loadedMetadata
[
$realClassName
]))
{
// We do not have the alias reference, include it
$this
->
_loadedMetadata
[
$className
]
=
$this
->
_loadedMetadata
[
$realClassName
];
return
$this
->
_loadedMetadata
[
$realClassName
];
}
}
$cacheKey
=
"
$className
\$
CLASSMETADATA"
;
$cacheKey
=
"
$realClassName
\$
CLASSMETADATA"
;
if
(
$this
->
_cacheDriver
)
{
if
((
$cached
=
$this
->
_cacheDriver
->
fetch
(
$cacheKey
))
!==
false
)
{
$this
->
_loadedMetadata
[
$
c
lassName
]
=
$cached
;
$this
->
_loadedMetadata
[
$
realC
lassName
]
=
$cached
;
}
else
{
foreach
(
$this
->
_loadMetadata
(
$
c
lassName
)
as
$loadedClassName
)
{
$this
->
_cacheDriver
->
save
(
$cacheKey
,
$this
->
_loadedMetadata
[
$
c
lassName
],
null
);
foreach
(
$this
->
_loadMetadata
(
$
realC
lassName
)
as
$loadedClassName
)
{
$this
->
_cacheDriver
->
save
(
$cacheKey
,
$this
->
_loadedMetadata
[
$
realC
lassName
],
null
);
}
}
}
else
{
$this
->
_loadMetadata
(
$className
);
$this
->
_loadMetadata
(
$realClassName
);
}
// Include the alias of this situation:
// CMS:CmsUser => Doctrine\Tests\ORM\Models\CMS\CmsUser
if
(
$className
!=
$realClassName
)
{
$this
->
_loadedMetadata
[
$className
]
=
$this
->
_loadedMetadata
[
$realClassName
];
}
}
return
$this
->
_loadedMetadata
[
$className
];
}
/**
* Checks whether the factory has the metadata for a class loaded already.
*
...
...
lib/Doctrine/ORM/ORMException.php
View file @
4ac39f0c
...
...
@@ -57,14 +57,38 @@ class ORMException extends \Exception
return
new
self
(
"Cannot use different EventManager instances for EntityManager and Connection."
);
}
public
static
function
findByRequiresParameter
(
$methodName
)
{
public
static
function
findByRequiresParameter
(
$methodName
)
{
return
new
self
(
"You need to pass a parameter to '"
.
$methodName
.
"'"
);
}
public
static
function
invalidFindByCall
(
$entityName
,
$fieldName
,
$method
)
{
public
static
function
invalidFindByCall
(
$entityName
,
$fieldName
,
$method
)
{
return
new
self
(
"Entity '"
.
$entityName
.
"' has no field '"
.
$fieldName
.
"'. "
.
"You can therefore not call '"
.
$method
.
"' on the entities' repository"
);
}
public
static
function
queryCacheNotConfigured
()
{
return
new
self
(
'Query Cache is not configured.'
);
}
public
static
function
metadataCacheNotConfigured
()
{
return
new
self
(
'Class Metadata Cache is not configured.'
);
}
public
static
function
proxyClassesAlwaysRegenerating
()
{
return
new
self
(
'Proxy Classes are always regenerating.'
);
}
public
static
function
unknownEntityNamespace
(
$entityNamespaceAlias
)
{
return
new
self
(
"Unknown Entity namespace alias '
$entityNamespaceAlias
'."
);
}
}
lib/Doctrine/ORM/Query/Lexer.php
View file @
4ac39f0c
...
...
@@ -123,7 +123,7 @@ class Lexer extends \Doctrine\Common\Lexer
protected
function
getCatchablePatterns
()
{
return
array
(
'[a-z_][a-z0-9_\
\\]*
'
,
'[a-z_][a-z0-9_\
:\\\]*[a-z0-9_]{1}
'
,
'(?:[0-9]+(?:[,\.][0-9]+)*)(?:e[+-]?[0-9]+)?'
,
"'(?:[^']|'')*'"
,
'\?[1-9]+|:[a-z][a-z0-9_]+'
...
...
lib/Doctrine/ORM/Query/Parser.php
View file @
4ac39f0c
...
...
@@ -867,12 +867,14 @@ class Parser
$this
->
match
(
Lexer
::
T_IDENTIFIER
);
$schemaName
=
$this
->
_lexer
->
token
[
'value'
];
$aliasMap
=
$this
->
_em
->
getConfiguration
()
->
getEntityAliasMap
();
if
(
isset
(
$aliasMap
[
$schemaName
]))
{
$schemaName
=
$aliasMap
[
$schemaName
];
if
(
strrpos
(
$schemaName
,
':'
)
!==
false
)
{
list
(
$namespaceAlias
,
$simpleClassName
)
=
explode
(
':'
,
$schemaName
);
$schemaName
=
$this
->
_em
->
getConfiguration
()
->
getEntityNamespace
(
$namespaceAlias
)
.
'\\'
.
$simpleClassName
;
}
$exists
=
class_exists
(
$schemaName
,
true
);
if
(
!
$exists
)
{
$this
->
semanticalError
(
"Class '
$schemaName
' is not defined."
,
$this
->
_lexer
->
token
);
}
...
...
tests/Doctrine/Tests/ORM/Functional/EntityRepositoryTest.php
View file @
4ac39f0c
...
...
@@ -65,6 +65,17 @@ class EntityRepositoryTest extends \Doctrine\Tests\OrmFunctionalTestCase
$users
=
$repos
->
findAll
();
$this
->
assertEquals
(
2
,
count
(
$users
));
$this
->
_em
->
clear
();
$this
->
_em
->
getConfiguration
()
->
addEntityNamespace
(
'CMS'
,
'Doctrine\Tests\Models\CMS'
);
$repos
=
$this
->
_em
->
getRepository
(
'CMS:CmsUser'
);
$users
=
$repos
->
findAll
();
$this
->
assertEquals
(
2
,
count
(
$users
));
$this
->
_em
->
getConfiguration
()
->
setEntityNamespaces
(
array
());
}
/**
...
...
tests/Doctrine/Tests/ORM/Functional/QueryTest.php
View file @
4ac39f0c
...
...
@@ -227,18 +227,18 @@ class QueryTest extends \Doctrine\Tests\OrmFunctionalTestCase
->
getSingleResult
();
}
public
function
testSupportsQueriesWithEntity
Alias
es
()
public
function
testSupportsQueriesWithEntity
Namespac
es
()
{
$this
->
_em
->
getConfiguration
()
->
addEntity
Alias
(
'Doctrine\Tests\Models\CMS\CmsUser'
,
'TestAlias
'
);
$this
->
_em
->
getConfiguration
()
->
addEntity
Namespace
(
'CMS'
,
'Doctrine\Tests\Models\CMS
'
);
try
{
$query
=
$this
->
_em
->
createQuery
(
'UPDATE
TestAlias
u SET u.name = ?1'
);
$query
=
$this
->
_em
->
createQuery
(
'UPDATE
CMS:CmsUser
u SET u.name = ?1'
);
$this
->
assertEquals
(
'UPDATE cms_users SET name = ?'
,
$query
->
getSql
());
$query
->
free
();
}
catch
(
\Exception
$e
)
{
$this
->
fail
(
$e
->
getMessage
());
}
$this
->
_em
->
getConfiguration
()
->
setEntity
AliasMap
(
array
());
$this
->
_em
->
getConfiguration
()
->
setEntity
Namespaces
(
array
());
}
}
\ No newline at end of file
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