Skip to content

Commit

Permalink
[DDC-93] Parse @Embedded and @embeddable during SchemaTool processing…
Browse files Browse the repository at this point in the history
… to make parsing work.
  • Loading branch information
beberlei committed Mar 26, 2013
1 parent 02d34bb commit 32988b3
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 3 deletions.
13 changes: 12 additions & 1 deletion lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php
Expand Up @@ -246,6 +246,13 @@ class ClassMetadataInfo implements ClassMetadata
*/
public $isMappedSuperclass = false;

/**
* READ-ONLY: Wheather this class describes the mapping of an embeddable class.
*
* @var boolean
*/
public $isEmbeddedClass = false;

/**
* READ-ONLY: The names of the parent classes (ancestors).
*
Expand Down Expand Up @@ -921,8 +928,12 @@ public function initializeReflection($reflService)
*/
public function validateIdentifier()
{
if ($this->isMappedSuperclass || $this->isEmbeddedClass) {
return;
}

// Verify & complete identifier mapping
if ( ! $this->identifier && ! $this->isMappedSuperclass) {
if ( ! $this->identifier) {
throw MappingException::identifierRequired($this->name);
}

Expand Down
2 changes: 2 additions & 0 deletions lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php
Expand Up @@ -85,6 +85,8 @@ public function loadMetadataForClass($className, ClassMetadata $metadata)
$mappedSuperclassAnnot = $classAnnotations['Doctrine\ORM\Mapping\MappedSuperclass'];
$metadata->setCustomRepositoryClass($mappedSuperclassAnnot->repositoryClass);
$metadata->isMappedSuperclass = true;
} else if (isset($classAnnotations['Doctrine\ORM\Mapping\Embeddable'])) {
$metadata->isEmbeddedClass = true;
} else {
throw MappingException::classIsNotAValidEntityOrMappedSuperClass($className);
}
Expand Down
4 changes: 3 additions & 1 deletion lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php
Expand Up @@ -19,6 +19,8 @@

require_once __DIR__.'/../Annotation.php';
require_once __DIR__.'/../Entity.php';
require_once __DIR__.'/../Embeddable.php';
require_once __DIR__.'/../Embedded.php';
require_once __DIR__.'/../MappedSuperclass.php';
require_once __DIR__.'/../InheritanceType.php';
require_once __DIR__.'/../DiscriminatorColumn.php';
Expand Down Expand Up @@ -64,4 +66,4 @@
require_once __DIR__.'/../AssociationOverrides.php';
require_once __DIR__.'/../AttributeOverride.php';
require_once __DIR__.'/../AttributeOverrides.php';
require_once __DIR__.'/../EntityListeners.php';
require_once __DIR__.'/../EntityListeners.php';
28 changes: 28 additions & 0 deletions lib/Doctrine/ORM/Mapping/Embeddable.php
@@ -0,0 +1,28 @@
<?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 MIT license. For more information, see
* <http://www.doctrine-project.org>.
*/

namespace Doctrine\ORM\Mapping;

/**
* @Annotation
* @Target("PROPERTY")
*/
final class Embeddable implements Annotation
{
}
32 changes: 32 additions & 0 deletions lib/Doctrine/ORM/Mapping/Embedded.php
@@ -0,0 +1,32 @@
<?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 MIT license. For more information, see
* <http://www.doctrine-project.org>.
*/

namespace Doctrine\ORM\Mapping;

/**
* @Annotation
* @Target("CLASS")
*/
final class Embedded implements Annotation
{
/**
* @var string
*/
public $class;
}
1 change: 1 addition & 0 deletions lib/Doctrine/ORM/Tools/SchemaTool.php
Expand Up @@ -126,6 +126,7 @@ private function processingNotRequired($class, array $processedClasses)
return (
isset($processedClasses[$class->name]) ||
$class->isMappedSuperclass ||
$class->isEmbeddedClass ||
($class->isInheritanceTypeSingleTable() && $class->name != $class->rootEntityName)
);
}
Expand Down
53 changes: 52 additions & 1 deletion tests/Doctrine/Tests/ORM/Functional/ValueObjectsTest.php
Expand Up @@ -2,10 +2,37 @@

namespace Doctrine\Tests\ORM\Functional;

/**
* @group DDC-93
*/
class ValueObjectsTest extends \Doctrine\Tests\OrmFunctionalTestCase
{
public function setUp()
{
parent::setUp();

$this->_schemaTool->createSchema(array(
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC93Person'),
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC93Address'),
));
}

public function testMetadata()
{
$person = new DDC93Person();
$person->name = "Tara";
$person->address = new DDC93Address();
$person->address->street = "United States of Tara Street";
$person->address->zip = "12345";
$person->address->city = "funkytown";

$this->_em->persist($person);
$this->_em->flush();

$this->_em->clear();

$person = $this->_em->find(DDC93Person::CLASSNAME, $person->id);
$this->assertInstanceOf(DDC93Address::CLASSNAME, $person->address);
}
}

Expand All @@ -14,12 +41,36 @@ public function setUp()
*/
class DDC93Person
{
const CLASSNAME = __CLASS__;

/** @Id @GeneratedValue @Column(type="integer") */
public $id;

/** @Column(type="string") */
public $name;

/** @Embedded */
/** @Embedded(class="DDC93Address") */
public $address;
}

/**
* @Embeddable
*/
class DDC93Address
{
const CLASSNAME = __CLASS__;

This comment has been minimized.

Copy link
@mvrhov

mvrhov Mar 27, 2013

Why don't we raise the requirements and also drive up the php 5.5 adaption?

This comment has been minimized.

Copy link
@stof

stof Mar 27, 2013

Member

@mvrhov bumping the requirement to 5.5 would be a BC break (what about people which cannot use 5.5 yet ?).
And doing this bump only to make the testsuite a bit more convenient would be weird IMO

This comment has been minimized.

Copy link
@mvrhov

mvrhov Mar 27, 2013

If this is required just for the test, then I don't care. However if I need to provide this additionally in each of my classes, then it's a shame.
I've also listed my reasoning behind why it should be a good idea.

This comment has been minimized.

Copy link
@stof

stof Mar 27, 2013

Member

This is just a convenience for tests to avoid writing the class name as a string when doing a $em->find call, making it easier to move fixture classes. See line 34.


/**
* @Column(type="string")
*/
public $street;
/**
* @Column(type="string")
*/
public $zip;
/**
* @Column(type="string")
*/
public $city;
}

0 comments on commit 32988b3

Please sign in to comment.