Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[DDC-93] Parse @Embedded and @Embeddable during SchemaTool processing…

… to make parsing work.
  • Loading branch information...
commit 32988b3cdf050f2531c4d4f6d85971f896cd8303 1 parent 02d34bb
@beberlei beberlei authored
View
13 lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php
@@ -247,6 +247,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).
*
* @var array
@@ -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);
}
View
2  lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php
@@ -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);
}
View
4 lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php
@@ -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';
@@ -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';
View
28 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
+{
+}
View
32 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;
+}
View
1  lib/Doctrine/ORM/Tools/SchemaTool.php
@@ -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)
);
}
View
53 tests/Doctrine/Tests/ORM/Functional/ValueObjectsTest.php
@@ -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);
}
}
@@ -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__;
@mvrhov
mvrhov added a note

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

@stof
stof added a note

@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

@mvrhov
mvrhov added a note

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.

@stof
stof added a note

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+
+ /**
+ * @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.
Something went wrong with that request. Please try again.