[DDC-93] Parse @Embedded and @Embeddable during SchemaTool processing to make parsing work.
This commit is contained in:
parent
02d34bbba6
commit
32988b3cdf
@ -246,6 +246,13 @@ class ClassMetadataInfo implements ClassMetadata
|
|||||||
*/
|
*/
|
||||||
public $isMappedSuperclass = false;
|
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).
|
* READ-ONLY: The names of the parent classes (ancestors).
|
||||||
*
|
*
|
||||||
@ -921,8 +928,12 @@ class ClassMetadataInfo implements ClassMetadata
|
|||||||
*/
|
*/
|
||||||
public function validateIdentifier()
|
public function validateIdentifier()
|
||||||
{
|
{
|
||||||
|
if ($this->isMappedSuperclass || $this->isEmbeddedClass) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Verify & complete identifier mapping
|
// Verify & complete identifier mapping
|
||||||
if ( ! $this->identifier && ! $this->isMappedSuperclass) {
|
if ( ! $this->identifier) {
|
||||||
throw MappingException::identifierRequired($this->name);
|
throw MappingException::identifierRequired($this->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,6 +85,8 @@ class AnnotationDriver extends AbstractAnnotationDriver
|
|||||||
$mappedSuperclassAnnot = $classAnnotations['Doctrine\ORM\Mapping\MappedSuperclass'];
|
$mappedSuperclassAnnot = $classAnnotations['Doctrine\ORM\Mapping\MappedSuperclass'];
|
||||||
$metadata->setCustomRepositoryClass($mappedSuperclassAnnot->repositoryClass);
|
$metadata->setCustomRepositoryClass($mappedSuperclassAnnot->repositoryClass);
|
||||||
$metadata->isMappedSuperclass = true;
|
$metadata->isMappedSuperclass = true;
|
||||||
|
} else if (isset($classAnnotations['Doctrine\ORM\Mapping\Embeddable'])) {
|
||||||
|
$metadata->isEmbeddedClass = true;
|
||||||
} else {
|
} else {
|
||||||
throw MappingException::classIsNotAValidEntityOrMappedSuperClass($className);
|
throw MappingException::classIsNotAValidEntityOrMappedSuperClass($className);
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,8 @@
|
|||||||
|
|
||||||
require_once __DIR__.'/../Annotation.php';
|
require_once __DIR__.'/../Annotation.php';
|
||||||
require_once __DIR__.'/../Entity.php';
|
require_once __DIR__.'/../Entity.php';
|
||||||
|
require_once __DIR__.'/../Embeddable.php';
|
||||||
|
require_once __DIR__.'/../Embedded.php';
|
||||||
require_once __DIR__.'/../MappedSuperclass.php';
|
require_once __DIR__.'/../MappedSuperclass.php';
|
||||||
require_once __DIR__.'/../InheritanceType.php';
|
require_once __DIR__.'/../InheritanceType.php';
|
||||||
require_once __DIR__.'/../DiscriminatorColumn.php';
|
require_once __DIR__.'/../DiscriminatorColumn.php';
|
||||||
@ -64,4 +66,4 @@ require_once __DIR__.'/../AssociationOverride.php';
|
|||||||
require_once __DIR__.'/../AssociationOverrides.php';
|
require_once __DIR__.'/../AssociationOverrides.php';
|
||||||
require_once __DIR__.'/../AttributeOverride.php';
|
require_once __DIR__.'/../AttributeOverride.php';
|
||||||
require_once __DIR__.'/../AttributeOverrides.php';
|
require_once __DIR__.'/../AttributeOverrides.php';
|
||||||
require_once __DIR__.'/../EntityListeners.php';
|
require_once __DIR__.'/../EntityListeners.php';
|
||||||
|
28
lib/Doctrine/ORM/Mapping/Embeddable.php
Normal file
28
lib/Doctrine/ORM/Mapping/Embeddable.php
Normal file
@ -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
lib/Doctrine/ORM/Mapping/Embedded.php
Normal file
32
lib/Doctrine/ORM/Mapping/Embedded.php
Normal file
@ -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;
|
||||||
|
}
|
@ -126,6 +126,7 @@ class SchemaTool
|
|||||||
return (
|
return (
|
||||||
isset($processedClasses[$class->name]) ||
|
isset($processedClasses[$class->name]) ||
|
||||||
$class->isMappedSuperclass ||
|
$class->isMappedSuperclass ||
|
||||||
|
$class->isEmbeddedClass ||
|
||||||
($class->isInheritanceTypeSingleTable() && $class->name != $class->rootEntityName)
|
($class->isInheritanceTypeSingleTable() && $class->name != $class->rootEntityName)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -2,10 +2,37 @@
|
|||||||
|
|
||||||
namespace Doctrine\Tests\ORM\Functional;
|
namespace Doctrine\Tests\ORM\Functional;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group DDC-93
|
||||||
|
*/
|
||||||
class ValueObjectsTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
class ValueObjectsTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||||
{
|
{
|
||||||
public function setUp()
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -14,12 +41,36 @@ class ValueObjectsTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
|||||||
*/
|
*/
|
||||||
class DDC93Person
|
class DDC93Person
|
||||||
{
|
{
|
||||||
|
const CLASSNAME = __CLASS__;
|
||||||
|
|
||||||
/** @Id @GeneratedValue @Column(type="integer") */
|
/** @Id @GeneratedValue @Column(type="integer") */
|
||||||
public $id;
|
public $id;
|
||||||
|
|
||||||
/** @Column(type="string") */
|
/** @Column(type="string") */
|
||||||
public $name;
|
public $name;
|
||||||
|
|
||||||
/** @Embedded */
|
/** @Embedded(class="DDC93Address") */
|
||||||
public $address;
|
public $address;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Embeddable
|
||||||
|
*/
|
||||||
|
class DDC93Address
|
||||||
|
{
|
||||||
|
const CLASSNAME = __CLASS__;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Column(type="string")
|
||||||
|
*/
|
||||||
|
public $street;
|
||||||
|
/**
|
||||||
|
* @Column(type="string")
|
||||||
|
*/
|
||||||
|
public $zip;
|
||||||
|
/**
|
||||||
|
* @Column(type="string")
|
||||||
|
*/
|
||||||
|
public $city;
|
||||||
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user