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
35fa81db
Commit
35fa81db
authored
Jun 16, 2008
by
romanb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Removed static EntityManager lookup from productions. Entity refactorings.
parent
7206b1dd
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
192 additions
and
42 deletions
+192
-42
Entity.php
lib/Doctrine/Entity.php
+13
-17
EntityManager.php
lib/Doctrine/EntityManager.php
+17
-1
Abstract.php
lib/Doctrine/EntityPersister/Abstract.php
+4
-5
Parser.php
lib/Doctrine/Query/Parser.php
+19
-2
Production.php
lib/Doctrine/Query/Production.php
+8
-1
PathExpression.php
lib/Doctrine/Query/Production/PathExpression.php
+1
-2
PathExpressionEndingWithAsterisk.php
...ine/Query/Production/PathExpressionEndingWithAsterisk.php
+1
-2
RangeVariableDeclaration.php
lib/Doctrine/Query/Production/RangeVariableDeclaration.php
+3
-5
SelectExpression.php
lib/Doctrine/Query/Production/SelectExpression.php
+1
-2
VariableDeclaration.php
lib/Doctrine/Query/Production/VariableDeclaration.php
+3
-5
AllTests.php
tests/Orm/Entity/AllTests.php
+32
-0
ConstructorTest.php
tests/Orm/Entity/ConstructorTest.php
+31
-0
UnitOfWorkTest.php
tests/Orm/UnitOfWorkTest.php
+59
-0
No files found.
lib/Doctrine/Entity.php
View file @
35fa81db
...
...
@@ -66,7 +66,7 @@ abstract class Doctrine_Entity extends Doctrine_Access implements Serializable
* PROXY STATE
* An Entity is in proxy state when its properties are not fully loaded.
*/
const
STATE_PROXY
=
4
;
//
const STATE_PROXY = 4;
/**
* NEW TCLEAN
...
...
@@ -963,9 +963,8 @@ abstract class Doctrine_Entity extends Doctrine_Access implements Serializable
return
$this
->
$setter
(
$value
);
}
$class
=
$this
->
_class
;
if
(
$class
->
hasField
(
$fieldName
))
{
if
(
$value
instanceof
Doctrine_Entity
)
{
if
(
$this
->
_class
->
hasField
(
$fieldName
))
{
/*if ($value instanceof Doctrine_Entity) {
$type = $class->getTypeOf($fieldName);
// FIXME: composite key support
$ids = $value->identifier();
...
...
@@ -973,17 +972,15 @@ abstract class Doctrine_Entity extends Doctrine_Access implements Serializable
if ($id !== null && $type !== 'object') {
$value = $id;
}
}
}
*/
$old
=
isset
(
$this
->
_data
[
$fieldName
])
?
$this
->
_data
[
$fieldName
]
:
null
;
if
(
$old
!=
=
$value
)
{
if
(
$old
!=
$value
)
{
$this
->
_data
[
$fieldName
]
=
$value
;
$this
->
_modified
[]
=
$fieldName
;
/* We can't do this currently because there are tests that change
* the primary key of already persisted entities (ugh). */
if
(
$this
->
isTransient
()
&&
$class
->
isIdentifier
(
$fieldName
))
{
if
(
$this
->
isTransient
()
&&
$this
->
_class
->
isIdentifier
(
$fieldName
))
{
$this
->
_id
[
$fieldName
]
=
$value
;
}
...
...
@@ -996,7 +993,7 @@ abstract class Doctrine_Entity extends Doctrine_Access implements Serializable
break
;
}
}
}
else
if
(
$class
->
hasRelation
(
$fieldName
))
{
}
else
if
(
$
this
->
_
class
->
hasRelation
(
$fieldName
))
{
$this
->
_rawSetReference
(
$fieldName
,
$value
);
}
else
{
throw
Doctrine_Entity_Exception
::
invalidField
(
$fieldName
);
...
...
@@ -1141,12 +1138,12 @@ abstract class Doctrine_Entity extends Doctrine_Access implements Serializable
$dataSet
[
$field
]
=
$this
->
_class
->
enumIndex
(
$field
,
$this
->
_data
[
$field
]);
break
;
default
:
if
(
$this
->
_data
[
$field
]
instanceof
Doctrine_Entity
)
{
/*
if ($this->_data[$field] instanceof Doctrine_Entity) {
// FIXME: composite key support
$ids = $this->_data[$field]->identifier();
$id = count($ids) > 0 ? array_pop($ids) : null;
$this->_data[$field] = $id;
}
}
*/
/** TODO:
if ($this->_data[$v] === null) {
throw new Doctrine_Record_Exception('Unexpected null value.');
...
...
@@ -1159,11 +1156,10 @@ abstract class Doctrine_Entity extends Doctrine_Access implements Serializable
// @todo cleanup
// populates the discriminator field in Single & Class Table Inheritance
$class
=
$this
->
_class
;
if
(
$class
->
getInheritanceType
()
==
Doctrine
::
INHERITANCE_TYPE_JOINED
||
$class
->
getInheritanceType
()
==
Doctrine
::
INHERITANCE_TYPE_SINGLE_TABLE
)
{
$discCol
=
$class
->
getInheritanceOption
(
'discriminatorColumn'
);
$discMap
=
$class
->
getInheritanceOption
(
'discriminatorMap'
);
if
(
$this
->
_class
->
getInheritanceType
()
==
Doctrine
::
INHERITANCE_TYPE_JOINED
||
$this
->
_class
->
getInheritanceType
()
==
Doctrine
::
INHERITANCE_TYPE_SINGLE_TABLE
)
{
$discCol
=
$this
->
_class
->
getInheritanceOption
(
'discriminatorColumn'
);
$discMap
=
$this
->
_class
->
getInheritanceOption
(
'discriminatorMap'
);
$old
=
$this
->
get
(
$discCol
,
false
);
$discValue
=
array_search
(
$this
->
_entityName
,
$discMap
);
if
((
string
)
$old
!==
(
string
)
$discValue
||
$old
===
null
)
{
...
...
lib/Doctrine/EntityManager.php
View file @
35fa81db
...
...
@@ -59,7 +59,6 @@ class Doctrine_EntityManager
*/
private
$_config
;
/**
* The database connection used by the EntityManager.
*
...
...
@@ -409,7 +408,24 @@ class Doctrine_EntityManager
*/
public
function
save
(
Doctrine_Entity
$entity
)
{
$state
=
$entity
->
_state
();
if
(
$state
==
Doctrine_Entity
::
STATE_CLEAN
||
$state
==
Doctrine_Entity
::
STATE_LOCKED
)
{
return
;
}
//...
//$this->_unitOfWork->
switch
(
$entity
->
_state
())
{
case
Doctrine_Entity
::
STATE_CLEAN
:
//nothing to do
break
;
case
Doctrine_Entity
::
STATE_DIRTY
:
$this
->
_unitOfWork
->
registerDirty
(
$entity
);
break
;
case
Doctrine_Entity
::
STATE_TCLEAN
:
case
Doctrine_Entity
::
STATE_TDIRTY
:
//...
}
}
/**
...
...
lib/Doctrine/EntityPersister/Abstract.php
View file @
35fa81db
...
...
@@ -248,14 +248,13 @@ abstract class Doctrine_EntityPersister_Abstract
}
/**
* Saves an entity
and all it's related entities
.
* Saves an entity.
*
* @param Doctrine_Entity $record The entity to save.
* @param Doctrine_Connection $conn The connection to use. Will default to the mapper's
* connection.
* @throws Doctrine_Mapper_Exception If the mapper is unable to save the given entity.
*/
public
function
save
(
Doctrine_Entity
$record
,
Doctrine_Connection
$conn
=
null
)
public
function
save
(
Doctrine_Entity
$record
)
{
if
(
!
(
$record
instanceof
$this
->
_domainClassName
))
{
throw
new
Doctrine_Mapper_Exception
(
"Mapper of type "
.
$this
->
_domainClassName
.
"
...
...
@@ -282,7 +281,7 @@ abstract class Doctrine_EntityPersister_Abstract
if
(
$record
->
isValid
())
{
$this
->
_insertOrUpdate
(
$record
);
}
else
{
$conn
->
transaction
->
addInvalid
(
$record
);
$conn
->
getTransaction
()
->
addInvalid
(
$record
);
}
$state
=
$record
->
_state
();
...
...
@@ -375,7 +374,7 @@ abstract class Doctrine_EntityPersister_Abstract
// Protection against infinite function recursion before attempting to save
if
(
$obj
instanceof
Doctrine_Entity
&&
$obj
->
isModified
())
{
$obj
->
save
(
$this
->
_conn
);
$obj
->
save
();
/** Can this be removed?
$id = array_values($obj->identifier());
...
...
lib/Doctrine/Query/Parser.php
View file @
35fa81db
...
...
@@ -101,6 +101,13 @@ class Doctrine_Query_Parser
* @var int The number of tokens read since last error in the input string.
*/
protected
$_errorDistance
;
/**
* The EntityManager.
*
* @var EnityManager
*/
protected
$_em
;
// End of Error management stuff
...
...
@@ -113,8 +120,9 @@ class Doctrine_Query_Parser
*/
public
function
__construct
(
Doctrine_Query
$query
)
{
$this
->
_em
=
$query
->
getEntityManager
();
$this
->
_scanner
=
new
Doctrine_Query_Scanner
(
$query
->
getDql
());
$this
->
_sqlBuilder
=
Doctrine_Query_SqlBuilder
::
fromConnection
(
$
query
->
getEntityManager
()
);
$this
->
_sqlBuilder
=
Doctrine_Query_SqlBuilder
::
fromConnection
(
$
this
->
_em
);
$this
->
_keywordTable
=
new
Doctrine_Query_Token
();
$this
->
_parserResult
=
new
Doctrine_Query_ParserResult
(
...
...
@@ -333,5 +341,14 @@ class Doctrine_Query_Parser
$this
->
_errorDistance
=
0
;
}
/**
* Gets the EntityManager used by the parser.
*
* @return EntityManager
*/
public
function
getEntityManager
()
{
return
$this
->
_em
;
}
}
lib/Doctrine/Query/Production.php
View file @
35fa81db
<?php
/*
* $Id$
*
...
...
@@ -53,6 +52,13 @@ abstract class Doctrine_Query_Production
* @var Doctrine_Query_Parser
*/
protected
$_parser
;
/**
* The EntityManager.
*
* @var EntityManager
*/
protected
$_em
;
/**
...
...
@@ -63,6 +69,7 @@ abstract class Doctrine_Query_Production
public
function
__construct
(
Doctrine_Query_Parser
$parser
)
{
$this
->
_parser
=
$parser
;
$this
->
_em
=
$this
->
_parser
->
getEntityManager
();
}
...
...
lib/Doctrine/Query/Production/PathExpression.php
View file @
35fa81db
...
...
@@ -130,8 +130,7 @@ class Doctrine_Query_Production_PathExpression extends Doctrine_Query_Production
$parserResult
=
$this
->
_parser
->
getParserResult
();
// Retrieving connection
$manager
=
Doctrine_EntityManagerFactory
::
getManager
();
$conn
=
$manager
->
getConnection
();
$conn
=
$this
->
_em
->
getConnection
();
// Looking for queryComponent to fetch
$queryComponent
=
$parserResult
->
getQueryComponent
(
$this
->
_componentAlias
);
...
...
lib/Doctrine/Query/Production/PathExpressionEndingWithAsterisk.php
View file @
35fa81db
...
...
@@ -119,8 +119,7 @@ class Doctrine_Query_Production_PathExpressionEndingWithAsterisk extends Doctrin
$parserResult
=
$this
->
_parser
->
getParserResult
();
// Retrieving connection
$manager
=
Doctrine_EntityManagerFactory
::
getManager
();
$conn
=
$manager
->
getConnection
();
$conn
=
$this
->
_em
->
getConnection
();
// Looking for componentAlias to fetch
$componentAlias
=
implode
(
'.'
,
$this
->
_identifiers
);
...
...
lib/Doctrine/Query/Production/RangeVariableDeclaration.php
View file @
35fa81db
...
...
@@ -115,13 +115,12 @@ class Doctrine_Query_Production_RangeVariableDeclaration extends Doctrine_Query_
$parserResult
=
$this
->
_parser
->
getParserResult
();
// Get the connection for the component
$conn
=
$this
->
_parser
->
getSqlBuilder
()
->
getConnection
();
$manager
=
Doctrine_EntityManagerFactory
::
getManager
();
$conn
=
$this
->
_em
->
getConnection
();
$componentName
=
$this
->
_identifiers
[
0
];
// Retrieving ClassMetadata and Mapper
try
{
$classMetadata
=
$
manager
->
getClassMetadata
(
$componentName
);
$classMetadata
=
$
this
->
_em
->
getClassMetadata
(
$componentName
);
// Building queryComponent
$queryComponent
=
array
(
...
...
@@ -155,8 +154,7 @@ class Doctrine_Query_Production_RangeVariableDeclaration extends Doctrine_Query_
$parserResult
=
$this
->
_parser
->
getParserResult
();
// Get the connection for the component
$conn
=
$this
->
_parser
->
getSqlBuilder
()
->
getConnection
();
$manager
=
Doctrine_EntityManagerFactory
::
getManager
();
$conn
=
$this
->
_em
->
getConnection
();
// Retrieve the base component
try
{
...
...
lib/Doctrine/Query/Production/SelectExpression.php
View file @
35fa81db
...
...
@@ -136,8 +136,7 @@ class Doctrine_Query_Production_SelectExpression extends Doctrine_Query_Producti
$parserResult
=
$this
->
_parser
->
getParserResult
();
// Retrieving connection
$manager
=
Doctrine_EntityManagerFactory
::
getManager
();
$conn
=
$manager
->
getConnection
();
$conn
=
$this
->
_em
->
getConnection
();
switch
(
get_class
(
$this
->
_leftExpression
))
{
case
'Doctrine_Query_Production_PathExpressionEndingWithAsterisk'
:
...
...
lib/Doctrine/Query/Production/VariableDeclaration.php
View file @
35fa81db
...
...
@@ -83,12 +83,11 @@ class Doctrine_Query_Production_VariableDeclaration extends Doctrine_Query_Produ
// No queryComponent was found. We will have to build it for the first time
// Get the connection for the component
$conn
=
$this
->
_parser
->
getSqlBuilder
()
->
getConnection
();
$manager
=
Doctrine_EntityManagerFactory
::
getManager
();
$conn
=
$this
->
_em
->
getConnection
();
// Retrieving ClassMetadata and Mapper
try
{
$classMetadata
=
$
manager
->
getMetadata
(
$this
->
_componentName
);
$classMetadata
=
$
this
->
_em
->
getMetadata
(
$this
->
_componentName
);
// Building queryComponent
$queryComponent
=
array
(
...
...
@@ -124,8 +123,7 @@ class Doctrine_Query_Production_VariableDeclaration extends Doctrine_Query_Produ
$queryComponent
=
$parserResult
->
getQueryComponent
(
$this
->
_componentAlias
);
// Retrieving connection
$manager
=
Doctrine_EntityManagerFactory
::
getManager
();
$conn
=
$manager
->
getConnection
();
$conn
=
$this
->
_em
->
getConnection
();
return
$conn
->
quoteIdentifier
(
$queryComponent
[
'metadata'
]
->
getTableName
())
.
' '
.
$conn
->
quoteIdentifier
(
$parserResult
->
getTableAliasFromComponentAlias
(
$this
->
_componentAlias
));
...
...
tests/Orm/Entity/AllTests.php
0 → 100644
View file @
35fa81db
<?php
if
(
!
defined
(
'PHPUnit_MAIN_METHOD'
))
{
define
(
'PHPUnit_MAIN_METHOD'
,
'Orm_Entity_AllTests::main'
);
}
require_once
'lib/DoctrineTestInit.php'
;
// Tests
require_once
'Orm/Entity/AccessorTestCase.php'
;
require_once
'Orm/Entity/ConstructorTest.php'
;
class
Orm_Entity_AllTests
{
public
static
function
main
()
{
PHPUnit_TextUI_TestRunner
::
run
(
self
::
suite
());
}
public
static
function
suite
()
{
$suite
=
new
Doctrine_TestSuite
(
'Doctrine Orm Entity Tests'
);
$suite
->
addTestSuite
(
'Orm_Entity_AccessorTestCase'
);
$suite
->
addTestSuite
(
'Orm_Entity_ConstructorTest'
);
return
$suite
;
}
}
if
(
PHPUnit_MAIN_METHOD
==
'Orm_Entity_AllTests::main'
)
{
Orm_Entity_AllTests
::
main
();
}
\ No newline at end of file
tests/Orm/Entity/ConstructorTest.php
0 → 100644
View file @
35fa81db
<?php
require_once
'lib/DoctrineTestInit.php'
;
class
Orm_Entity_ConstructorTest
extends
Doctrine_OrmTestCase
{
public
function
testFieldInitializationInConstructor
()
{
$entity
=
new
ConstructorTestEntity1
(
"romanb"
);
$this
->
assertTrue
(
$entity
->
isTransient
());
$this
->
assertEquals
(
"romanb"
,
$entity
->
username
);
}
}
class
ConstructorTestEntity1
extends
Doctrine_Entity
{
public
function
__construct
(
$username
=
null
)
{
parent
::
__construct
();
if
(
$this
->
isTransient
())
{
$this
->
username
=
$username
;
}
}
/* The mapping definition */
public
static
function
initMetadata
(
$class
)
{
$class
->
mapColumn
(
'username'
,
'string'
,
50
,
array
());
}
}
?>
\ No newline at end of file
tests/Orm/UnitOfWorkTest.php
0 → 100644
View file @
35fa81db
<?php
require_once
'lib/DoctrineTestInit.php'
;
class
Orm_UnitOfWorkTest
extends
Doctrine_OrmTestCase
{
private
$_unitOfWork
;
private
$_user
;
protected
function
setUp
()
{
parent
::
setUp
();
$this
->
_user
=
new
ForumUser
();
$this
->
_unitOfWork
=
$this
->
_em
->
getUnitOfWork
();
}
protected
function
tearDown
()
{
$this
->
_user
->
free
();
}
public
function
testRegisterNew
()
{
$this
->
_user
->
username
=
'romanb'
;
$this
->
_user
->
id
=
1
;
// registerNew() is normally called in save()/persist()
$this
->
_unitOfWork
->
registerNew
(
$this
->
_user
);
$this
->
assertTrue
(
$this
->
_unitOfWork
->
isRegisteredNew
(
$this
->
_user
));
$this
->
assertTrue
(
$this
->
_unitOfWork
->
contains
(
$this
->
_user
));
$this
->
assertFalse
(
$this
->
_unitOfWork
->
isRegisteredDirty
(
$this
->
_user
));
$this
->
assertFalse
(
$this
->
_unitOfWork
->
isRegisteredRemoved
(
$this
->
_user
));
}
public
function
testRegisterDirty
()
{
$this
->
_user
->
username
=
'romanb'
;
$this
->
_user
->
id
=
1
;
$this
->
assertEquals
(
Doctrine_Entity
::
STATE_TDIRTY
,
$this
->
_user
->
_state
());
$this
->
assertFalse
(
$this
->
_unitOfWork
->
contains
(
$this
->
_user
));
$this
->
_unitOfWork
->
registerDirty
(
$this
->
_user
);
$this
->
assertTrue
(
$this
->
_unitOfWork
->
isRegisteredDirty
(
$this
->
_user
));
$this
->
assertFalse
(
$this
->
_unitOfWork
->
isRegisteredNew
(
$this
->
_user
));
$this
->
assertFalse
(
$this
->
_unitOfWork
->
isRegisteredRemoved
(
$this
->
_user
));
}
public
function
testRegisterRemovedOnTransientEntityIsIgnored
()
{
$this
->
_user
->
username
=
'romanb'
;
$this
->
_user
->
id
=
1
;
$this
->
assertFalse
(
$this
->
_unitOfWork
->
isRegisteredRemoved
(
$this
->
_user
));
$this
->
_unitOfWork
->
registerRemoved
(
$this
->
_user
);
$this
->
assertFalse
(
$this
->
_unitOfWork
->
isRegisteredRemoved
(
$this
->
_user
));
}
/*public function testSavedEntityHasIdentityAndIsManaged()
{
$this->_user->username = 'romanb';
$this->_user->save();
$this->assertTrue($this->_unitOfWork->hasIdentity($this->_user));
$this->assertTrue($this->_unitOfWork->isManaged($this->_user));
}*/
}
\ 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