-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[PropertyAccess] Allow custom methods on property accesses #18016
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
Changes from all commits
af3a824
5b82237
00a26eb
e4aaac9
e46df98
5f206e6
94e6157
09707ad
d02d93a
748b894
688cbda
003efdb
dc5cacb
1a35d45
1e29523
7c6a79c
d0bd777
6b7eeff
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 |
---|---|---|
|
@@ -41,5 +41,6 @@ | |
<framework:validation enabled="true" cache="validator.mapping.cache.doctrine.apc" /> | ||
<framework:annotations cache="file" debug="true" file-cache-dir="%kernel.cache_dir%/annotations" /> | ||
<framework:serializer enabled="true" enable-annotations="true" name-converter="serializer.name_converter.camel_case_to_snake_case" /> | ||
<framework:property-access cache="property_access.mapping.cache.doctrine.apc" enable-annotations="true" magic-call="false" throw-exception-on-invalid-index="false" /> | ||
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. Should be removed and use the new cache component instead. 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. Right. |
||
</framework:config> | ||
</container> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ framework: | |
property_access: | ||
magic_call: true | ||
throw_exception_on_invalid_index: true | ||
enable_annotations: false |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\PropertyAccess\Annotation; | ||
|
||
/** | ||
* Property accessor configuration annotation. | ||
* | ||
* @Annotation | ||
* @Target({"PROPERTY"}) | ||
* | ||
* @author Luis Ramón López <lrlopez@gmail.com> | ||
*/ | ||
class Property | ||
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 annotation duplicates the other annotations. I don't think we should add multiple ways to add the same thing:
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. There are also some advantages of using property annotations:
Property annotations are implemented with just 19 lines of code (not taking into account the empty annotation class). In fact, all new annotations are loaded from the same method About being harder to understand for newcomers, we could just give them some initial guidelines (i.e. method annotations for virtual properties and property annotations for everything else) and let them use whatever they want, just like the YAML vs XML vs Annotation debate. Anyway, if you feel that only method annotations must be kept, I'll do that, of course! 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 agree with @webmozart, it's weird to have different way to do the same thing. What about having only a 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. @dunglas @webmozart 👍 for having only one annotation. |
||
{ | ||
/** | ||
* Custom setter method for the property. | ||
* | ||
* @var string | ||
*/ | ||
public $setter; | ||
|
||
/** | ||
* Custom getter method for the property. | ||
* | ||
* @var string | ||
*/ | ||
public $getter; | ||
|
||
/** | ||
* Custom adder method for the property. | ||
* | ||
* @var string | ||
*/ | ||
public $adder; | ||
|
||
/** | ||
* Custom remover method for the property. | ||
* | ||
* @var string | ||
*/ | ||
public $remover; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\PropertyAccess\Annotation; | ||
|
||
/** | ||
* Property accessor adder configuration annotation. | ||
* | ||
* @Annotation | ||
* @Target({"METHOD"}) | ||
* | ||
* @author Luis Ramón López <lrlopez@gmail.com> | ||
*/ | ||
class PropertyAdder | ||
{ | ||
/** | ||
* Associates this method to the adder of this property. | ||
* | ||
* @var string | ||
*/ | ||
public $property; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\PropertyAccess\Annotation; | ||
|
||
/** | ||
* Property accessor getter configuration annotation. | ||
* | ||
* @Annotation | ||
* @Target({"METHOD"}) | ||
* | ||
* @author Luis Ramón López <lrlopez@gmail.com> | ||
*/ | ||
class PropertyGetter | ||
{ | ||
/** | ||
* Associates this method to the getter of this property. | ||
* | ||
* @var string | ||
*/ | ||
public $property; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\PropertyAccess\Annotation; | ||
|
||
/** | ||
* Property accessor remover configuration annotation. | ||
* | ||
* @Annotation | ||
* @Target({"METHOD"}) | ||
* | ||
* @author Luis Ramón López <lrlopez@gmail.com> | ||
*/ | ||
class PropertyRemover | ||
{ | ||
/** | ||
* Associates this method to the remover of this property. | ||
* | ||
* @var string | ||
*/ | ||
public $property; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\PropertyAccess\Annotation; | ||
|
||
/** | ||
* Property accessor setter configuration annotation. | ||
* | ||
* @Annotation | ||
* @Target({"METHOD"}) | ||
* | ||
* @author Luis Ramón López <lrlopez@gmail.com> | ||
*/ | ||
class PropertySetter | ||
{ | ||
/** | ||
* Associates this method to the setter of this property. | ||
* | ||
* @var string | ||
*/ | ||
public $property; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
CHANGELOG | ||
========= | ||
|
||
3.2.0 | ||
------ | ||
* added custom method calling for properties. | ||
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 is unclear. 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. Ok, I'll add a more thoughtful explanation |
||
|
||
2.7.0 | ||
------ | ||
|
||
|
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.
It should be delayed until #17868 is merged.
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.
Sure, it makes sense
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.
I'm not sure #17868 will be merged before the 3.1 feature freeze. Could we skip this and work on it after the new Cache component is ready?
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.
It should use the new
system.cache
infrastructure: http://symfony.com/blog/new-in-symfony-3-1-cache-component