Skip to content

Commit

Permalink
DCOM-93 - Seperate builder from metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
beberlei committed Dec 29, 2011
1 parent d92156b commit de7a3f3
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -261,12 +261,12 @@ protected function loadMetadata($name)
continue;
}

$class = $this->newClassMetadataInstance($className);
$class->initializeReflection($reflService);
$builder = $this->newClassMetadataBuilderInstance($className);
$builder->initializeReflection($reflService);
$this->doLoadMetadata($builder, $parent, $rootEntityFound);
$builder->wakeupReflection($reflService);

$this->doLoadMetadata($class, $parent, $rootEntityFound);

$this->loadedMetadata[$className] = $class;
$this->loadedMetadata[$className] = $class = $builder->getWrappedClassMetadata();

$parent = $class;

Expand All @@ -275,7 +275,6 @@ protected function loadMetadata($name)
array_unshift($visited, $className);
}

$class->wakeupReflection($reflService);

$loaded[] = $className;
}
Expand All @@ -286,20 +285,20 @@ protected function loadMetadata($name)
/**
* Actually load the metadata from the underlying metadata
*
* @param ClassMetadata $class
* @param ClassMetadataBuilder $builder
* @param ClassMetadata $parent
* @param bool $rootEntityFound
* @return void
*/
abstract protected function doLoadMetadata($class, $parent, $rootEntityFound);
abstract protected function doLoadMetadata($builder, $parent, $rootEntityFound);

/**
* Creates a new ClassMetadata instance for the given class name.
*
* @param string $className
* @return ClassMetadata
* @return ClassMetadataBuilder
*/
abstract protected function newClassMetadataInstance($className);
abstract protected function newClassMetadataBuilderInstance($className);

/**
* Check if this class is mapped by this Object Manager + ClassMetadata configuration
Expand Down
23 changes: 0 additions & 23 deletions lib/Doctrine/Common/Persistence/Mapping/ClassMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,27 +162,4 @@ function getAssociationMappedByTargetField($assocName);
* @return array
*/
function getIdentifierValues($object);

/**
* Initialize Reflection services
*
* This method is called from a metadata factory after an uncached
* initialization. Data set in this method should be serialized and
* reconstituted on wakeup.
*
* @param ReflectionService $reflService
* @return void
*/
function initializeReflection(ReflectionService $reflService);

/**
* Wakeup Reflection
*
* Method is called when the metadata instance is reconstituted from the
* cache and also after initialization.
*
* @param ReflectionService $reflService
* @return void
*/
function wakeupReflection(ReflectionService $reflService);
}
59 changes: 59 additions & 0 deletions lib/Doctrine/Common/Persistence/Mapping/ClassMetadataBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php
/*
* 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\Common\Persistence\Mapping;

/**
* Builder interface for class metadata instances used for constructing
* metadata.
*
* @author Benjamin Eberlei <kontakt@beberlei.de>
*/
interface ClassMetadataBuilder
{
/**
* Initialize Reflection based parameters of the underlying metadata.
*
* Method is only called on non-cache construction of a new metadata
* instance. The data set here should be serialized.
*
* @param ReflectionService $reflService
* @return void
*/
function initializeReflection(ReflectionService $reflService);

/**
* Wakeup Reflection parameters after reconstituting the metdata from cache

This comment has been minimized.

Copy link
@henrikbjorn

henrikbjorn Dec 29, 2011

typo "metadata"

*
* @param ReflectionService $reflService
* @return void
*/
function wakeupReflection(ReflectionService $reflService);

/**
* Get the metadata class that belongs to this builder.
*
* If the builder and metadata are implemented on the same class this
* method has to just return $this.
*
* @return ClassMetadata
*/
function getWrappedClassMetadata();
}

Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ class ClassMetadataFactoryTest extends DoctrineTestCase
public function setUp()
{
$driver = $this->getMock('Doctrine\Common\Persistence\Mapping\Driver\MappingDriver');
$builder = $this->getMock('Doctrine\Common\Persistence\Mapping\ClassMetadataBuilder');
$metadata = $this->getMock('Doctrine\Common\Persistence\Mapping\ClassMetadata');
$this->cmf = new TestClassMetadataFactory($driver, $metadata);
$builder->expects($this->any())->method('getWrappedClassMetadata')->will($this->returnValue($metadata));
$this->cmf = new TestClassMetadataFactory($driver, $builder);
}

public function testGetCacheDriver()
Expand Down Expand Up @@ -48,7 +50,7 @@ public function testGetParentMetadata()

public function testGetCachedMetadata()
{
$metadata = $this->getMock('Doctrine\Common\Persistence\Mapping\ClassMetadata');
$metadata = $this->getMock('Doctrine\Common\Persistence\Mapping\ClassMetadataBuilder');
$cache = new ArrayCache();
$cache->save(__NAMESPACE__. '\ChildEntity$CLASSMETADATA', $metadata);

Expand Down Expand Up @@ -103,7 +105,7 @@ protected function initialize()

}

protected function newClassMetadataInstance($className)
protected function newClassMetadataBuilderInstance($className)
{
return $this->metadata;
}
Expand All @@ -122,4 +124,4 @@ class RootEntity
class ChildEntity extends RootEntity
{

}
}

0 comments on commit de7a3f3

Please sign in to comment.