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 configurable naming strategy #547

Merged
merged 1 commit into from
May 31, 2016
Merged

Add configurable naming strategy #547

merged 1 commit into from
May 31, 2016

Conversation

polc
Copy link
Contributor

@polc polc commented May 17, 2016

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? maybe
Fixed tickets #165 , #534
License MIT

So here is a simple naming strategy PR. I couldn't check if the tests pass because I have a weird issue on my computer so wait until I resolve all test

Some things I'm not sure:

  • Is the folder src/NamingStrategy good, or I would be better to use src/Routing/NamingStrategy or something else.
  • Should I add an option for pluralization (pluralize or not)

If this PR is merged, I would like to change the default strategy (in an other PR) to dashs strategy maybe

@teohhanhui
Copy link
Contributor

teohhanhui commented May 17, 2016

We have to be clear what this naming strategy is for, and normalizeShortName? That makes little sense when taken out of the existing context...

@polc
Copy link
Contributor Author

polc commented May 17, 2016

naming strategy is just about naming routes?, and what about normalizeResourceShortName ?

@teohhanhui
Copy link
Contributor

I don't think we should restrict it to just naming routes URL paths. And I'm not sure what "normalize" is supposed to mean in the context of a "naming strategy" (it was fine for the original local variable / private method, but we need better method names for an interface).

@polc
Copy link
Contributor Author

polc commented May 18, 2016

Are there others usages you think of ?

For naming, I have not much idea.. Its a method transforming a camel case name to an url segment so transformResourceNameToUrl() maybe ?

@teohhanhui
Copy link
Contributor

I suggest this method signature:

public function namePath(string $resourceShortName) : string;

@teohhanhui
Copy link
Contributor

Are there others usages you think of ?

Not at the moment. Actually, I take back what I said. It's better to have smaller interfaces that only do one thing. We could make this ApiPlatform\Core\Naming\PathNamerInterface.

@polc
Copy link
Contributor Author

polc commented May 18, 2016

I've updated with your comments

{
private $pathNamer;

public function __construct(
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be kept as one line (Symfony CS).

@polc
Copy link
Contributor Author

polc commented May 19, 2016

I've updated with your comments

$resourceShortName = $resourceMetadata->getShortName();

if (null === $resourceShortName) {
throw new InvalidResourceException(sprintf('Resource "%s" have a null short name.', $resourceClass));
Copy link
Member

Choose a reason for hiding this comment

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

"Resource %s has no short name defined."

@polc
Copy link
Contributor Author

polc commented May 27, 2016

Done

@soyuka
Copy link
Member

soyuka commented May 27, 2016

LGTM 👍 rebase needed though

@Simperfit
Copy link
Contributor

👍

@teohhanhui
Copy link
Contributor

Needs rebase.

ping @api-platform/core-team

*/
public function testNoShortNameApiLoader()
{
$resourceMetadata = new ResourceMetadata();
Copy link
Member

@dunglas dunglas May 28, 2016

Choose a reason for hiding this comment

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

You can inline this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you mean?
$this->getApiLoaderWithResourceMetadata(new ResourceMetadata())->load(null); ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Why should it be inlined? It will be less readable...

Copy link
Member

@dunglas dunglas May 30, 2016

Choose a reason for hiding this comment

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

Let me be more precise. The variable assignation is useless. It can be on 2 lines for readability, but without the assignation :)

@dunglas
Copy link
Member

dunglas commented May 28, 2016

👍

@polc
Copy link
Contributor Author

polc commented May 30, 2016

Updated I think it good now :)

@dunglas dunglas merged commit f7fb780 into api-platform:master May 31, 2016
@dunglas
Copy link
Member

dunglas commented May 31, 2016

Thank you @polc!

Can you open a doc PR now please? https://github.com/api-platform/doc

@polc
Copy link
Contributor Author

polc commented May 31, 2016

@dunglas Sure

magarzon pushed a commit to magarzon/core that referenced this pull request Feb 12, 2017
Add configurable naming strategy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants