Conversation
| if ($node->hasProperty('phpcr:class')) { | ||
| $nodeClassName = $node->getProperty('phpcr:class')->getString(); | ||
| if ($node->hasProperty(self::CLASS_PROPERTY)) { | ||
| $nodeClassName = $node->getProperty(self::CLASS_PROPERTY)->getString(); |
There was a problem hiding this comment.
Grep to see if phpcr:class is referenced anywhere else.
There was a problem hiding this comment.
Actually this is too risky (adding class constants to places that might be untested) and unrequired for this PR, reverting.
There was a problem hiding this comment.
|
Would need to add XML and YAML drivers. |
a2481f6 to
1e084bf
Compare
|
interesting proposal! indeed the outside tree definition we currently have is awkward and weak. and i always forget to add my new classes to it. i wonder if we should do this on the class level or on Child / Children mappings and then merge all Child / Children mappings to know the allowed children. or maybe keep what you propose, but add that when the annotation / attribute is present the child and children types are merged into the allowed list automatically. then i can potentially limit my model by having children explicitly mapped and just set an empty annotation / attribute to trigger restriction. i guess restricting by default is not that user friendly (and a huge BC break that can be annoying even when upgrading to 2.0 at some point) i think i prefer the separate annotation, given that we could have options. it could be something like |
I did think about doing it on the I think its correct to say "this document can have these children" rather than "this document which has a property mapped as children wiith these types can have those children".
If we add an extra annotation then I suggest that the Metadata has an enum So the annotation would be fully expressed: If |
|
i prefer to have the explicit lists (see the example i created) as it allows you to allow everything of a base class but exclude some exceptions. like the sonata admin extensions do. an empty and i would merge types from Child / Children mappings into the allowed children. otherwise you need to duplicate that. there can be several Children annotations, btw. you can restrict them to prefixes and use a naming pattern to separate children. avoids you to have Child with a container object. |
ok thats makes sense.
I don't think you can set type for Child / Children? only a node-name filter? |
|
I don't think you can set type for Child / Children? only a node-name
filter?
ups, you are right. i guess the feature would make sense, but we don't
have to mix it into this PR. maybe we could have the minimal sanity
check that when you forbid all children but have a Child / Children
mapping, we raise an error that this makes no sense?
|
| * READ-ONLY: Child class restrictions. | ||
| * | ||
| * @var array | ||
| */ |
There was a problem hiding this comment.
child or children? not sure which is the correct way. its the restriction on each child...
There was a problem hiding this comment.
if we were to follow from PHPCR we could just have requiredClasses as with NodeDefinition::getRequiredPrimaryTypes
There was a problem hiding this comment.
Also interesting that they do not permit blacklisting (afaict)
There was a problem hiding this comment.
But maybe this is an argument to keep it as a whitelist - as if we do allow mapping by phpcr_type in the future, this feature would not map to it.
There was a problem hiding this comment.
There was a problem hiding this comment.
Shall we go with a requiredClasses attribute or a separate annotation?
There was a problem hiding this comment.
|
what if i edit a document that is in an illegal place already, but is neither moved nor created? i think it would make sense to allow that - a user otherwise could have a hard time saving their changes and understanding what is happening. and the situation was illegal before the edit already... |
Not sure .. if their tree is in an illegal state, then its broken, so I would expect an \Exception when editing an illegal child - otherwise nobody knows that it is broken until part of the system that relies on chldren being of a specific type recieves a class of the wrong type and throws an error at a critical moment. But it does raise the issue of migration when restrictions are added to an existing model - but I would say that that excerise could be left to the user with the |
|
what is the current code doing?
i guess we definitely don't want to throw errors on loading. but on
saving an edit i don't know which is better, error or not. i tend to say
no error if its just property changes, but maybe its too difficult to
separate from adding another child or a child to the illegal child or
whatever, so an error sounds ok.
we could do a command to validate the validity of the current tree, to
help figure out if the migration worked as expected...
|
yeah that crossed my mind too.. I would say that could be another PR. |
yes, for sure. there are other things to check, like missing required |
|
@dbu have added the XML and YAML drivers and tests. So it looks like this: Annotation: XML: <document ...>
<required-class>stdClass</required-class>
<!-- ... -->
</document>YAML: MyMapping:
required_classes: [ "stdClass" ]There remains the case where the user wants to explicitly declare that they want no children, which is not possible the XML or YAML drivers, we could add a "allow_children" boolean flag? MyMapping:
allow_children: false |
229c628 to
ad0f215
Compare
|
Made the benchmark, no noticable difference: It uses a bit more memory however. |
|
i don't like in jackrabbit cnd the child types are defined on the child / children names. i think we have the same here. on an |
|
and thanks for the benchmark, looks like its not a noticable performance decrease. and its for write only, not for read so it should be pretty safe. |
|
regarding forbidding all children: what if we allow to just have one entry with |
:) but also fine to change it, its just for the sake of copying PHPCR. |
|
I think I prefer the explcit option, will update. |
ad0f215 to
75e9f84
Compare
c6f4c41 to
a13b30b
Compare
| @@ -1,9 +1,12 @@ | |||
| <phpunit colors="true" bootstrap="bootstrap.php" backupGlobals="false" cacheTokens="true"> | |||
| <php> | |||
| <env name="SYMFONY_DEPRECATIONS_HELPER" value="disabled"/> | |||
There was a problem hiding this comment.
May as well remove this
217299b to
3cde352
Compare
|
can you please rebase on master and then bump the branch-alias for master to 1.4? i think apart from that we are pretty much ready. |
7390b49 to
ad381e0
Compare
|
Rebased and bumped the branch alias for this branch to |
| } | ||
|
|
||
| $childClasses = $this->getChildClasses(); | ||
|
|
There was a problem hiding this comment.
if (0 === count($childClasses)) { ?
dac5d49 to
9329d4b
Compare
|
@dbu good to merge? |
| $cm->setChildClasses(array('stdClass')); | ||
| $childCm = new ClassMetadata('stdClass'); | ||
| $childCm->initializeReflection(new RuntimeReflectionService()); | ||
| $result = $cm->assertValidChildClass($childCm); |
There was a problem hiding this comment.
i'd even remove the assignment here and just have $cm->assertValidChildClass($childCm);
|
i'd prefer to clean up that assertNull in the tests. apart from that its ready, yes. great job! |
9329d4b to
aeaf6a8
Compare
|
ok, well if it could cause a compiler to crash then its not good :) removed the |
|
yay! |
|
\o/ On Mon, Jun 20, 2016 at 05:12:43AM -0700, David Buchmann wrote:
|
TODO
Doc PR: doctrine/phpcr-odm-documentation#81
This PR allows the restriction of child document types:
childRestrictions = null)Why?
Alternatives
We could also implement this as a separate annotation:
Where
restrictis an enum ofnone,includeandexclude.