Skip to content

Fix route name resolving with subresources#1110

Merged
dunglas merged 1 commit into
api-platform:masterfrom
soyuka:fix/1107
May 22, 2017
Merged

Fix route name resolving with subresources#1110
dunglas merged 1 commit into
api-platform:masterfrom
soyuka:fix/1107

Conversation

@soyuka

@soyuka soyuka commented May 10, 2017

Copy link
Copy Markdown
Member

Also resolves conflicts with existing subresources on a property having
the same name

Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? behat is okay, unit tests are nogo
Fixed tickets #1107
License MIT
Doc PR ma

Unit tests don't pass for now, waiting for an answer to the below comment.

* @return string
*/
public function getRouteName(string $resourceClass, $operationType): string;
public function getRouteName(string $resourceClass, $operationType, array $context = []): string;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think that this is a breaking change. Should I avoid changing this interface? I need more informations when retrieving the route name for a subresource because multiple routes may find a wrong match on the same resource class. It has to take into consideration the subresource tree. See isSameSubresource in RouteNameResolver.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yes, this is a BC break.

@soyuka
soyuka requested a review from teohhanhui May 10, 2017 09:35
* @ApiResource
* @ORM\Entity
*/
class DummyTour

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I suggest renaming this to DummyProduct (Tour is from my own project), since the offers property is defined by https://schema.org/offers

@soyuka
soyuka force-pushed the fix/1107 branch 2 times, most recently from e962113 to df0c44d Compare May 11, 2017 10:19
@soyuka

soyuka commented May 11, 2017

Copy link
Copy Markdown
Member Author

I've done some dirty fix to avoid breaking, let me know your thoughts or if you have another idea on how to do this.
Obviously, phpstan won't be happy with this:

 ------ ----------------------------------------------------------------------------------
  Line   tests/Bridge/Symfony/Routing/RouteNameResolverTest.php
 ------ ----------------------------------------------------------------------------------
  135    Method ApiPlatform\Core\Bridge\Symfony\Routing\RouteNameResolver::getRouteName()
         invoked with 3 parameters, 2 required.
 ------ ----------------------------------------------------------------------------------

@soyuka soyuka added the bug label May 15, 2017
@teohhanhui

Copy link
Copy Markdown
Contributor

Hehe... We can ignore the PHPstan error for now. 😄

@soyuka

soyuka commented May 22, 2017

Copy link
Copy Markdown
Member Author

ping @dunglas is also good to merge if you agree with the routename patch!

}

$routeName = $this->decorated->getRouteName($resourceClass, $operationType);
$routeName = $this->decorated->getRouteName($resourceClass, $operationType, @func_get_arg(2));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

public function getRouteName(string $resourceClass, $operationType): string
public function getRouteName(string $resourceClass, $operationType /**, array $context = [] **/): string
{
$context = @func_get_arg(2);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same here

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

done thanks

Also resolves conflicts with existing subresources on a property having
the same name
@dunglas
dunglas merged commit 183b0a5 into api-platform:master May 22, 2017
@dunglas

dunglas commented May 22, 2017

Copy link
Copy Markdown
Member

Thanks @soyuka

@soyuka
soyuka deleted the fix/1107 branch May 22, 2017 12:51
hoangnd25 pushed a commit to hoangnd25/core that referenced this pull request Feb 23, 2018
Fix route name resolving with subresources
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.

3 participants