Skip to content
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

Merged

Conversation

raskyer
Copy link
Contributor

@raskyer 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

Copy link
Collaborator

@goetas goetas left a 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,
Copy link
Collaborator

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()
Copy link
Collaborator

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()) {
Copy link
Collaborator

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()) {
Copy link
Collaborator

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()) {
Copy link
Collaborator

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,
Copy link
Collaborator

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()) {
Copy link
Collaborator

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;
Copy link
Collaborator

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(
Copy link
Collaborator

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(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and this

@raskyer
Copy link
Contributor Author

raskyer commented Jan 18, 2018

@goetas Fix for your first request

Copy link
Collaborator

@goetas goetas left a 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);
Copy link
Collaborator

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)

@raskyer
Copy link
Contributor Author

raskyer commented Jan 18, 2018

@goetas Should be ok right now

@goetas goetas self-requested a review January 18, 2018 15:09
Copy link
Collaborator

@goetas goetas left a 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

@goetas goetas self-assigned this Jan 18, 2018
@goetas goetas added this to the 1.11 milestone Feb 3, 2018
@goetas goetas merged commit 6faeb47 into schmittjoh:master Feb 4, 2018
@goetas
Copy link
Collaborator

goetas commented Feb 4, 2018

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants