-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Value objects (Based on #634) #835
Changes from 15 commits
b4b9709
02d34bb
32988b3
0204a8b
011776f
879ab6e
9613f1d
38b041d
c67ac8a
30897c3
41c937b
fd8b5bd
20fb827
4f6c150
f86abd8
97836ef
d4e6618
ece62d6
5586ddd
0cd6061
2b2f489
17e0a7b
9ad376c
fb3a06b
2a73a6f
0ee7b68
e5cab1d
928c32d
fbb7b5a
f7f7c46
4f585a3
9464194
7020f41
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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("CLASS") | ||
*/ | ||
final class Embeddable implements Annotation | ||
{ | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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("PROPERTY") | ||
*/ | ||
final class Embedded implements Annotation | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
public $class; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?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; | ||
|
||
/** | ||
* Acts as a proxy to a nested Property structure, making it look like | ||
* just a single scalar property. | ||
* | ||
* This way value objects "just work" without UnitOfWork, Persisters or Hydrators | ||
* needing any changes. | ||
* | ||
* TODO: Move this class into Common\Reflection | ||
*/ | ||
class ReflectionEmbeddedProperty | ||
{ | ||
private $parentProperty; | ||
private $childProperty; | ||
private $class; | ||
|
||
public function __construct($parentProperty, $childProperty, $class) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aren't these parameters missing some typehint ? As it is used as (possibly ?) ReflectionProperty afterwards... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Taluu see standing |
||
{ | ||
$this->parentProperty = $parentProperty; | ||
$this->childProperty = $childProperty; | ||
$this->class = $class; | ||
} | ||
|
||
public function getValue($object) | ||
{ | ||
$embeddedObject = $this->parentProperty->getValue($object); | ||
|
||
if ($embeddedObject === null) { | ||
return null; | ||
} | ||
|
||
return $this->childProperty->getValue($embeddedObject); | ||
} | ||
|
||
public function setValue($object, $value) | ||
{ | ||
$embeddedObject = $this->parentProperty->getValue($object); | ||
|
||
if ($embeddedObject === null) { | ||
$embeddedObject = new $this->class; // TODO | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about changing this to use the |
||
$this->parentProperty->setValue($object, $embeddedObject); | ||
} | ||
|
||
$this->childProperty->setValue($embeddedObject, $value); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1049,7 +1049,7 @@ public function JoinAssociationPathExpression() | |
* Parses an arbitrary path expression and defers semantical validation | ||
* based on expected types. | ||
* | ||
* PathExpression ::= IdentificationVariable "." identifier | ||
* PathExpression ::= IdentificationVariable "." identifier [ ("." identifier)* ] | ||
* | ||
* @param integer $expectedTypes | ||
* | ||
|
@@ -1065,6 +1065,12 @@ public function PathExpression($expectedTypes) | |
$this->match(Lexer::T_IDENTIFIER); | ||
|
||
$field = $this->lexer->token['value']; | ||
|
||
while ($this->lexer->isNextToken(Lexer::T_DOT)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this loop need validation of sorts? Or are there sane failures for it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the field does not exist, there is a QueryException at some later point. I don't think that we need to add more validation here, or did you have anything specific in mind? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. query exception is perfect, i was afraid it might notice out or something ugly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems incomplete. We're relying on a breakage somewhere as a Query Exception else instead of properly throwing a Semantical or Parser exception properly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this fields are saved as "foo.bar" in fieldMappings this is passed to deferred path expressions etc. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The beauty of this implementation really is that almost all parts except the metadata drivers can be left completely unaware of embeddables. We now just allow field names to contain dots. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @beberlei but it's not properly validated. Is it "foo" or "bar" that is wrong? I describe some of my concerns below. @schmittjoh I see a problem with this. There's no way to differ a field from an embedded (and this is a huge problem IMHO). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can address some of these concerns at least:
I cannot address the other things. I really don't know whether this feature will cause headaches in the future. At this point, I don't see why, but I'm not a fortune teller :) however, the internal implementation could be changed for a Doctrine 3 release without breaking BC with the end-user facing part. |
||
$this->match(Lexer::T_DOT); | ||
$this->match(Lexer::T_IDENTIFIER); | ||
$field .= '.'.$this->lexer->token['value']; | ||
} | ||
} | ||
|
||
// Creating AST node | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo