8000 [PropertyAccess] Allow custom methods on property accesses by lrlopez · Pull Request #18016 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[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

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added 'Property' prefix to method annotations
  • Loading branch information
lrlopez committed Jul 3, 2016
commit 003efdb2aec1a91d57d9c248883f7d50eef5c366
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
*
* @author Luis Ramón López <lrlopez@gmail.com>
*/
class Adder
class PropertyAdder
{
/**
* Associates this method to the setter of this property.
* Associates this method to the adder of this property.
*
* @var string
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*
* @author Luis Ramón López <lrlopez@gmail.com>
*/
class Getter
class PropertyGetter
{
/**
* Associates this method to the getter of this property.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
*
* @author Luis Ramón López <lrlopez@gmail.com>
*/
class Remover
class PropertyRemover
{
/**
* Associates this method to the setter of this property.
* Associates this method to the remover of this property.
*
* @var string
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*
* @author Luis Ramón López <lrlopez@gmail.com>
*/
class Setter
class PropertySetter
{
/**
* Associates this method to the setter of this property.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
namespace Symfony\Component\PropertyAccess\Mapping\Loader;

use Doctrine\Common\Annotations\Reader;
use Symfony\Component\PropertyAccess\Annotation\Adder;
use Symfony\Component\PropertyAccess\Annotation\Getter;
use Symfony\Component\PropertyAccess\Annotation\PropertyAdder;
use Symfony\Component\PropertyAccess\Annotation\PropertyGetter;
use Symfony\Component\PropertyAccess\Annotation\Property;
use Symfony\Component\PropertyAccess\Annotation\Remover;
use Symfony\Component\PropertyAccess\Annotation\Setter;
use Symfony\Component\PropertyAccess\Annotation\PropertyRemover;
use Symfony\Component\PropertyAccess\Annotation\PropertySetter;
use Symfony\Component\PropertyAccess\Mapping\PropertyMetadata;
use Symfony\Component\PropertyAccess\Mapping\ClassMetadata;

Expand Down Expand Up @@ -76,28 +76,28 @@ public function loadClassMetadata(ClassMetadata $classMetadata)
if ($method->getDeclaringClass()->name === $className) {

foreach ($this->reader->getMethodAnnotations($method) as $annotation) {
if ($annotation instanceof Getter) {
if ($annotation instanceof PropertyGetter) {
if (!isset($propertiesMetadata[$annotation->property])) {
$propertiesMetadata[$annotation->property] = new PropertyMetadata($annotation->property);
$classMetadata->addPropertyMetadata($propertiesMetadata[$annotation->property]);
}
$propertiesMetadata[$annotation->property]->setGetter($method->getName());
}
if ($annotation instanceof Setter) {
if ($annotation instanceof PropertySetter) {
if (!isset($propertiesMetadata[$annotation->property])) {
$propertiesMetadata[$annotation->property] = new PropertyMetadata($annotation->property);
$classMetadata->addPropertyMetadata($propertiesMetadata[$annotation->property]);
}
$propertiesMetadata[$annotation->property]->setSetter($method->getName());
}
if ($annotation instanceof Adder) {
if ($annotation instanceof PropertyAdder) {
if (!isset($propertiesMetadata[$annotation->property])) {
$propertiesMetadata[$annotation->property] = new PropertyMetadata($annotation->property);
$classMetadata->addPropertyMetadata($propertiesMetadata[$annotation->property]);
}
$propertiesMetadata[$annotation->property]->setAdder($method->getName());
}
if ($annotation instanceof Remover) {
if ($annotation instanceof PropertyRemover) {
if (!isset($propertiesMetadata[$annotation->property])) {
$propertiesMetadata[$annotation->property] = new PropertyMetadata($annotation->property);
$classMetadata->addPropertyMetadata($propertiesMetadata[$annotation->property]);
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/PropertyAccess/Tests/Fixtures/Dummy.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace Symfony\Component\PropertyAccess\Tests\Fixtures;

use Symfony\Component\PropertyAccess\Annotation\Property;
use Symfony\Component\PropertyAccess\Annotation\Getter;
use Symfony\Component\PropertyAccess\Annotation\PropertyGetter;

/**
* Fixtures for testing metadata.
Expand Down Expand Up @@ -62,7 +62,7 @@ public function setBar($bar)
}

/**
* @Getter(property="test")
* @PropertyGetter(property="test")
*/
public function testChild()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@

namespace Symfony\Component\PropertyAccess\Tests\Fixtures;

use Symfony\Component\PropertyAccess\Annotation\Getter;
use Symfony\Component\PropertyAccess\Annotation\PropertyGetter;

/**
* Fixtures for testing metadata.
*/
class DummyParent
{
/**
* @Getter(property="test")
* @PropertyGetter(property="test")
*/
public function testParent()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
namespace Symfony\Component\PropertyAccess\Tests\Fixtures;

use Symfony\Component\PropertyAccess\Annotation\Property;
use Symfony\Component\PropertyAccess\Annotation\Getter;
use Symfony\Component\PropertyAccess\Annotation\Setter;
use Symfony\Component\PropertyAccess\Annotation\PropertyGetter;
use Symfony\Component\PropertyAccess\Annotation\PropertySetter;

class TestClass
{
Expand Down Expand Up @@ -217,15 +217,15 @@ public function getQuantity()
}

/**
* @Getter(property="total")
* @PropertyGetter(property="total")
*/
public function getTotal()
{
return $this->quantity * $this->pricePerUnit;
}

/**
* @Setter(property="total")
* @PropertySetter(property="total")
*
* @param mixed $total
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\Annotations\AnnotationRegistry;
use Symfony\Component\PropertyAccess\Annotation\Adder;
use Symfony\Component\PropertyAccess\Annotation\Getter;
use Symfony\Component\PropertyAccess\Annotation\Remover;
use Symfony\Component\PropertyAccess\Annotation\PropertyAdder;
use Symfony\Component\PropertyAccess\Annotation\PropertyGetter;
use Symfony\Component\PropertyAccess\Annotation\PropertyRemover;
use Symfony\Component\PropertyAccess\Mapping\Factory\LazyLoadingMetadataFactory;
use Symfony\Component\PropertyAccess\Mapping\Loader\AnnotationLoader;
use Symfony\Component\PropertyAccess\PropertyAccessor;
Expand Down Expand Up @@ -43,7 +43,7 @@ public function addAxis($axis)

// In the test, use a name that StringUtil can't uniquely singularify
/**
* @Adder(property="customVirtualAxes")
* @PropertyAdder(property="customVirtualAxes")
* @param $axis
*/
public function addAxisTest($axis)
Expand All @@ -63,7 +63,7 @@ public function removeAxis($axis)
}

/**
* @Remover(property="customVirtualAxes")
* @PropertyRemover(property="customVirtualAxes")
* @param $axis
*/
public function removeAxisTest($axis)
Expand All @@ -83,7 +83,7 @@ public function getAxes()
}

/**
* @Getter(property="customVirtualAxes")
* @PropertyGetter(property="customVirtualAxes")
* @return null
*/
public function getCustomAxes()
Expand Down
0