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
c4e330e5
Commit
c4e330e5
authored
Jul 15, 2009
by
jwage
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[2.0] Placing loadClassMetadata() event so users can manipulate class meta data through events
parent
6c1690d3
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
115 additions
and
8 deletions
+115
-8
EntityManager.php
lib/Doctrine/ORM/EntityManager.php
+1
-3
LoadClassMetadataEventArgs.php
lib/Doctrine/ORM/Event/LoadClassMetadataEventArgs.php
+27
-0
Events.php
lib/Doctrine/ORM/Events.php
+1
-0
ClassMetadataFactory.php
lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php
+14
-3
MetadataDriverMock.php
tests/Doctrine/Tests/Mocks/MetadataDriverMock.php
+5
-0
AllTests.php
tests/Doctrine/Tests/ORM/Mapping/AllTests.php
+1
-0
ClassMetadataFactoryTest.php
...s/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php
+14
-2
ClassMetadataLoadEventTest.php
...Doctrine/Tests/ORM/Mapping/ClassMetadataLoadEventTest.php
+51
-0
ClassMetadataTest.php
tests/Doctrine/Tests/ORM/Mapping/ClassMetadataTest.php
+1
-0
No files found.
lib/Doctrine/ORM/EntityManager.php
View file @
c4e330e5
...
@@ -141,9 +141,7 @@ class EntityManager
...
@@ -141,9 +141,7 @@ class EntityManager
$this
->
_conn
=
$conn
;
$this
->
_conn
=
$conn
;
$this
->
_config
=
$config
;
$this
->
_config
=
$config
;
$this
->
_eventManager
=
$eventManager
;
$this
->
_eventManager
=
$eventManager
;
$this
->
_metadataFactory
=
new
ClassMetadataFactory
(
$this
->
_metadataFactory
=
new
ClassMetadataFactory
(
$this
);
$this
->
_config
->
getMetadataDriverImpl
(),
$this
->
_conn
->
getDatabasePlatform
());
$this
->
_metadataFactory
->
setCacheDriver
(
$this
->
_config
->
getMetadataCacheImpl
());
$this
->
_metadataFactory
->
setCacheDriver
(
$this
->
_config
->
getMetadataCacheImpl
());
$this
->
_unitOfWork
=
new
UnitOfWork
(
$this
);
$this
->
_unitOfWork
=
new
UnitOfWork
(
$this
);
$this
->
_proxyGenerator
=
new
DynamicProxyGenerator
(
$this
,
$this
->
_config
->
getCacheDir
());
$this
->
_proxyGenerator
=
new
DynamicProxyGenerator
(
$this
,
$this
->
_config
->
getCacheDir
());
...
...
lib/Doctrine/ORM/Event/LoadClassMetadataEventArgs.php
0 → 100644
View file @
c4e330e5
<?php
namespace
Doctrine\ORM\Event
;
use
Doctrine\Common\EventArgs
;
/**
* Class that holds event arguments for a loadMetadata event.
*
* @author Jonathan H. Wage <jonwage@gmail.com>
* @since 2.0
*/
class
LoadClassMetadataEventArgs
extends
EventArgs
{
private
$_classMetadata
;
public
function
__construct
(
\Doctrine\ORM\Mapping\ClassMetadata
$classMetadata
)
{
$this
->
_classMetadata
=
$classMetadata
;
}
public
function
getClassMetadata
()
{
return
$this
->
_classMetadata
;
}
}
lib/Doctrine/ORM/Events.php
View file @
c4e330e5
...
@@ -40,4 +40,5 @@ final class Events
...
@@ -40,4 +40,5 @@ final class Events
const
preUpdate
=
'preUpdate'
;
const
preUpdate
=
'preUpdate'
;
const
postUpdate
=
'postUpdate'
;
const
postUpdate
=
'postUpdate'
;
const
load
=
'load'
;
const
load
=
'load'
;
const
loadClassMetadata
=
'loadClassMetadata'
;
}
}
\ No newline at end of file
lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php
View file @
c4e330e5
...
@@ -23,6 +23,7 @@ namespace Doctrine\ORM\Mapping;
...
@@ -23,6 +23,7 @@ namespace Doctrine\ORM\Mapping;
use
Doctrine\Common\DoctrineException
;
use
Doctrine\Common\DoctrineException
;
use
Doctrine\DBAL\Platforms\AbstractPlatform
;
use
Doctrine\DBAL\Platforms\AbstractPlatform
;
use
Doctrine\ORM\Events
;
/**
/**
* The metadata factory is used to create ClassMetadata objects that contain all the
* The metadata factory is used to create ClassMetadata objects that contain all the
...
@@ -38,10 +39,13 @@ use Doctrine\DBAL\Platforms\AbstractPlatform;
...
@@ -38,10 +39,13 @@ use Doctrine\DBAL\Platforms\AbstractPlatform;
*/
*/
class
ClassMetadataFactory
class
ClassMetadataFactory
{
{
private
$_em
;
/** The targeted database platform. */
/** The targeted database platform. */
private
$_targetPlatform
;
private
$_targetPlatform
;
/** The used metadata driver. */
/** The used metadata driver. */
private
$_driver
;
private
$_driver
;
/** The event manager instance */
private
$_evm
;
/** The used cache driver. */
/** The used cache driver. */
private
$_cacheDriver
;
private
$_cacheDriver
;
private
$_loadedMetadata
=
array
();
private
$_loadedMetadata
=
array
();
...
@@ -51,10 +55,12 @@ class ClassMetadataFactory
...
@@ -51,10 +55,12 @@ class ClassMetadataFactory
*
*
* @param $driver The metadata driver to use.
* @param $driver The metadata driver to use.
*/
*/
public
function
__construct
(
$driver
,
AbstractPlatform
$targetPlatfor
m
)
public
function
__construct
(
\Doctrine\ORM\EntityManager
$e
m
)
{
{
$this
->
_driver
=
$driver
;
$this
->
_em
=
$em
;
$this
->
_targetPlatform
=
$targetPlatform
;
$this
->
_driver
=
$em
->
getConfiguration
()
->
getMetadataDriverImpl
();
$this
->
_targetPlatform
=
$em
->
getConnection
()
->
getDatabasePlatform
();
$this
->
_evm
=
$em
->
getEventManager
();
}
}
/**
/**
...
@@ -183,6 +189,11 @@ class ClassMetadataFactory
...
@@ -183,6 +189,11 @@ class ClassMetadataFactory
$class
->
setParentClasses
(
$visited
);
$class
->
setParentClasses
(
$visited
);
if
(
$this
->
_evm
->
hasListeners
(
Events
::
loadClassMetadata
))
{
$eventArgs
=
new
\Doctrine\ORM\Event\LoadClassMetadataEventArgs
(
$class
);
$this
->
_evm
->
dispatchEvent
(
Events
::
loadClassMetadata
,
$eventArgs
);
}
$this
->
_generateStaticSql
(
$class
);
$this
->
_generateStaticSql
(
$class
);
$this
->
_loadedMetadata
[
$className
]
=
$class
;
$this
->
_loadedMetadata
[
$className
]
=
$class
;
...
...
tests/Doctrine/Tests/Mocks/MetadataDriverMock.php
View file @
c4e330e5
...
@@ -13,4 +13,9 @@ class MetadataDriverMock
...
@@ -13,4 +13,9 @@ class MetadataDriverMock
{
{
return
false
;
return
false
;
}
}
public
function
preload
()
{
return
array
();
}
}
}
\ No newline at end of file
tests/Doctrine/Tests/ORM/Mapping/AllTests.php
View file @
c4e330e5
...
@@ -23,6 +23,7 @@ class AllTests
...
@@ -23,6 +23,7 @@ class AllTests
$suite
->
addTestSuite
(
'Doctrine\Tests\ORM\Mapping\XmlDriverTest'
);
$suite
->
addTestSuite
(
'Doctrine\Tests\ORM\Mapping\XmlDriverTest'
);
$suite
->
addTestSuite
(
'Doctrine\Tests\ORM\Mapping\YamlDriverTest'
);
$suite
->
addTestSuite
(
'Doctrine\Tests\ORM\Mapping\YamlDriverTest'
);
$suite
->
addTestSuite
(
'Doctrine\Tests\ORM\Mapping\ClassMetadataFactoryTest'
);
$suite
->
addTestSuite
(
'Doctrine\Tests\ORM\Mapping\ClassMetadataFactoryTest'
);
$suite
->
addTestSuite
(
'Doctrine\Tests\ORM\Mapping\ClassMetadataLoadEventTest'
);
return
$suite
;
return
$suite
;
}
}
...
...
tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php
View file @
c4e330e5
...
@@ -4,7 +4,11 @@ namespace Doctrine\Tests\ORM\Mapping;
...
@@ -4,7 +4,11 @@ namespace Doctrine\Tests\ORM\Mapping;
use
Doctrine\Tests\Mocks\MetadataDriverMock
;
use
Doctrine\Tests\Mocks\MetadataDriverMock
;
use
Doctrine\Tests\Mocks\DatabasePlatformMock
;
use
Doctrine\Tests\Mocks\DatabasePlatformMock
;
use
Doctrine\Tests\Mocks\EntityManagerMock
;
use
Doctrine\Tests\Mocks\ConnectionMock
;
use
Doctrine\Tests\Mocks\DriverMock
;
use
Doctrine\ORM\Mapping\ClassMetadata
;
use
Doctrine\ORM\Mapping\ClassMetadata
;
use
Doctrine\Common\EventManager
;
require_once
__DIR__
.
'/../../TestInit.php'
;
require_once
__DIR__
.
'/../../TestInit.php'
;
...
@@ -13,8 +17,16 @@ class ClassMetadataFactoryTest extends \Doctrine\Tests\OrmTestCase
...
@@ -13,8 +17,16 @@ class ClassMetadataFactoryTest extends \Doctrine\Tests\OrmTestCase
public
function
testGetMetadataForSingleClass
()
public
function
testGetMetadataForSingleClass
()
{
{
$mockPlatform
=
new
DatabasePlatformMock
();
$driverMock
=
new
DriverMock
();
$config
=
new
\Doctrine\ORM\Configuration
();
$eventManager
=
new
EventManager
();
$conn
=
new
ConnectionMock
(
array
(),
$driverMock
,
$config
,
$eventManager
);
$mockDriver
=
new
MetadataDriverMock
();
$mockDriver
=
new
MetadataDriverMock
();
$config
->
setMetadataDriverImpl
(
$mockDriver
);
$entityManager
=
EntityManagerMock
::
create
(
$conn
,
$config
,
$eventManager
);
$mockPlatform
=
$conn
->
getDatabasePlatform
();
$mockPlatform
->
setPrefersSequences
(
true
);
$mockPlatform
->
setPrefersSequences
(
true
);
$mockPlatform
->
setPrefersIdentityColumns
(
false
);
$mockPlatform
->
setPrefersIdentityColumns
(
false
);
...
@@ -30,7 +42,7 @@ class ClassMetadataFactoryTest extends \Doctrine\Tests\OrmTestCase
...
@@ -30,7 +42,7 @@ class ClassMetadataFactoryTest extends \Doctrine\Tests\OrmTestCase
$cm1
->
setIdGeneratorType
(
ClassMetadata
::
GENERATOR_TYPE_AUTO
);
$cm1
->
setIdGeneratorType
(
ClassMetadata
::
GENERATOR_TYPE_AUTO
);
// SUT
// SUT
$cmf
=
new
ClassMetadataFactoryTestSubject
(
$
mockDriver
,
$mockPlatform
);
$cmf
=
new
ClassMetadataFactoryTestSubject
(
$
entityManager
);
$cmf
->
setMetadataForClass
(
'Doctrine\Tests\ORM\Mapping\TestEntity1'
,
$cm1
);
$cmf
->
setMetadataForClass
(
'Doctrine\Tests\ORM\Mapping\TestEntity1'
,
$cm1
);
// Prechecks
// Prechecks
...
...
tests/Doctrine/Tests/ORM/Mapping/ClassMetadataLoadEventTest.php
0 → 100644
View file @
c4e330e5
<?php
namespace
Doctrine\Tests\ORM\Mapping
;
use
Doctrine\ORM\Mapping\ClassMetadata
;
use
Doctrine\ORM\Events
;
require_once
__DIR__
.
'/../../TestInit.php'
;
class
ClassMetadataLoadEventTest
extends
\Doctrine\Tests\OrmTestCase
{
public
function
testEvent
()
{
$em
=
$this
->
_getTestEntityManager
();
$metadataFactory
=
$em
->
getMetadataFactory
();
$evm
=
$em
->
getEventManager
();
$evm
->
addEventListener
(
Events
::
loadClassMetadata
,
$this
);
$classMetadata
=
$metadataFactory
->
getMetadataFor
(
'Doctrine\Tests\ORM\Mapping\LoadEventTestEntity'
);
$this
->
assertTrue
(
$classMetadata
->
hasField
(
'about'
));
}
public
function
loadClassMetadata
(
\Doctrine\ORM\Event\LoadClassMetadataEventArgs
$eventArgs
)
{
$classMetadata
=
$eventArgs
->
getClassMetadata
();
$field
=
array
(
'fieldName'
=>
'about'
,
'type'
=>
'string'
,
'length'
=>
255
);
$classMetadata
->
mapField
(
$field
);
}
}
/**
* @Entity
* @Table(name="load_event_test_entity")
*/
class
LoadEventTestEntity
{
/**
* @Id @Column(type="integer")
* @GeneratedValue(strategy="AUTO")
*/
private
$id
;
/**
* @Column(type="string", length=255)
*/
private
$name
;
private
$about
;
}
\ No newline at end of file
tests/Doctrine/Tests/ORM/Mapping/ClassMetadataTest.php
View file @
c4e330e5
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
namespace
Doctrine\Tests\ORM\Mapping
;
namespace
Doctrine\Tests\ORM\Mapping
;
use
Doctrine\ORM\Mapping\ClassMetadata
;
use
Doctrine\ORM\Mapping\ClassMetadata
;
use
Doctrine\ORM\Events
;
require_once
__DIR__
.
'/../../TestInit.php'
;
require_once
__DIR__
.
'/../../TestInit.php'
;
...
...
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