-
-
Notifications
You must be signed in to change notification settings - Fork 585
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
Add AdvancedNamingStrategyInterface #859
Add AdvancedNamingStrategyInterface #859
Conversation
raskyer
commented
Jan 18, 2018
Q | A |
---|---|
Bug fix? | no |
New feature? | yes |
Doc updated | no |
BC breaks? | no |
Deprecations? | no |
Tests pass? | yes |
Fixed tickets | #857 |
License | Apache-2.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.
Here is my review. The main change is that you can change the signature of the constructor
protected $advancedNamingStrategy; | ||
|
||
public function __construct( | ||
PropertyNamingStrategyInterface $namingStrategy, |
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.
instead of adding a new parameter, you can remove the signature from the current
/** | ||
* @return bool | ||
*/ | ||
protected function hasAdvancedNamingStrategy() |
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.
you do not need this
@@ -161,6 +161,9 @@ public function startVisitingObject(ClassMetadata $metadata, $object, array $typ | |||
public function visitProperty(PropertyMetadata $metadata, $data, Context $context) | |||
{ | |||
$name = $this->namingStrategy->translateName($metadata); | |||
if ($this->hasAdvancedNamingStrategy()) { |
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.
better do do if ( instanceof ...) then "new strategy" else "old strategy" endif
instead of computing each time the name
twice
@@ -158,6 +158,9 @@ public function visitProperty(PropertyMetadata $metadata, $data, Context $contex | |||
} | |||
|
|||
$k = $this->namingStrategy->translateName($metadata); | |||
if ($this->hasAdvancedNamingStrategy()) { |
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.
as said on other comment
@@ -165,6 +165,9 @@ public function visitProperty(PropertyMetadata $metadata, $data, Context $contex | |||
} | |||
|
|||
$k = $this->namingStrategy->translateName($metadata); | |||
if ($this->hasAdvancedNamingStrategy()) { |
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.
as said on other comment
{ | ||
parent::__construct($namingStrategy, $accessorStrategy); | ||
public function __construct( | ||
PropertyNamingStrategyInterface $namingStrategy, |
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.
as said on other comment
@@ -166,6 +170,9 @@ public function visitProperty(PropertyMetadata $metadata, $data, Context $contex | |||
} | |||
|
|||
$name = $this->namingStrategy->translateName($metadata); | |||
if ($this->hasAdvancedNamingStrategy()) { |
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.
as said on other comment
@@ -205,6 +207,13 @@ public function setPropertyNamingStrategy(PropertyNamingStrategyInterface $prope | |||
return $this; | |||
} | |||
|
|||
public function setAdvancedNamingStrategy(AdvancedNamingStrategyInterface $advancedNamingStrategy) | |||
{ | |||
$this->advancedNamingStrategy = $advancedNamingStrategy; |
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.
here you might overwrite $this->propertyNamingStrategy
'xml' => new XmlSerializationVisitor($this->propertyNamingStrategy, $this->getAccessorStrategy()), | ||
'yml' => new YamlSerializationVisitor($this->propertyNamingStrategy, $this->getAccessorStrategy()), | ||
'json' => new JsonSerializationVisitor($this->propertyNamingStrategy, $this->getAccessorStrategy()), | ||
'xml' => new XmlSerializationVisitor( |
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.
so no need to change this code
@@ -241,8 +262,16 @@ public function addDefaultDeserializationVisitors() | |||
|
|||
$this->visitorsAdded = true; | |||
$this->deserializationVisitors->setAll(array( | |||
'xml' => new XmlDeserializationVisitor($this->propertyNamingStrategy), | |||
'json' => new JsonDeserializationVisitor($this->propertyNamingStrategy), | |||
'xml' => new XmlDeserializationVisitor( |
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.
and this
@goetas Fix for your first request |
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.
Looks much better now.
Please add also some tests.
The current naming strategies might implement both
* | ||
* @return string | ||
*/ | ||
public function translateName(PropertyMetadata $property, Context $context); |
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.
ah, my bad, please use a different name (as example getPropertyName
, so people can implement both interfaces (for compatibility)
@goetas Should be ok right now |
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.
looks good to me for now. will check when can be merged this
Thanks! |