Skip to content

[Routing] Allow to set name prefixes from the configuration #25178

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

Conversation

sroze
Copy link
Contributor

@sroze sroze commented Nov 27, 2017

Q A
Branch? master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #19612
License MIT
Doc PR ø

This allows setting name prefixes to routes while importing them. Typically, we can then import multiple times a similar file. This was originally requested by 🎸 @chrisguitarguy in #19612

app:
    resource: ../controller/routing.yml

api:
    resource: ../controller/routing.yml
    name_prefix: api_
    prefix: /api
<?xml version="1.0" encoding="UTF-8" ?>
<routes xmlns="http://symfony.com/schema/routing"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://symfony.com/schema/routing
        http://symfony.com/schema/routing/routing-1.0.xsd">

    <import resource="../controller/routing.xml" />
    <import resource="../controller/routing.xml" prefix="/api" name-prefix="api_" />

</routes>

@sroze sroze force-pushed the feature/19612-add-name-prefix-to-routes branch from 0875723 to e0a8690 Compare November 27, 2017 17:20
@stof stof added this to the 4.1 milestone Nov 27, 2017
public function testAddNamePrefix()
{
$collection = new RouteCollection();
$collection->add('foo', $foo = new Route('/foo'));
Copy link
Member

Choose a reason for hiding this comment

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

please also add an existing api_foo route, to be sure that the prefixing does not delete this route due to overriding.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, added.

@stof
Copy link
Member

stof commented Nov 27, 2017

Does the PHP DSL also need this feature, or is it already available in it ?

@sroze sroze force-pushed the feature/19612-add-name-prefix-to-routes branch 2 times, most recently from 841d5ee to a4c836c Compare November 28, 2017 05:14
@sroze
Copy link
Contributor Author

sroze commented Nov 28, 2017

@stof it was't. I've added it to the trait.

@sroze
Copy link
Contributor Author

sroze commented Nov 30, 2017

Status: Needs review

@@ -124,4 +124,18 @@

return $this;
}

/**
* Add a prefix to the name of all the routes within the collection.
Copy link
Member

Choose a reason for hiding this comment

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

Adds

@@ -153,6 +153,22 @@ public function addPrefix($prefix, array $defaults = array(), array $requirement
}
}

/**
* Add a prefix to the name of all the routes within in the collection.
Copy link
Member

Choose a reason for hiding this comment

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

Adds

/**
* Add a prefix to the name of all the routes within in the collection.
*
* @param string $prefix
Copy link
Member

Choose a reason for hiding this comment

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

Should be removed

/**
* Add a prefix to the name of all the routes within the collection.
*
* @param string $prefix
Copy link
Member

Choose a reason for hiding this comment

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

Should be removed

*
* @return $this
*/
final public function addNamePrefix(string $prefix)
Copy link
Member

Choose a reason for hiding this comment

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

: self to fully get rid of the phpdoc?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, we still need the description I'd say, as it's meant to be used by developers

Copy link
Member

Choose a reason for hiding this comment

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

Getting rid of @return $this would be nice though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

but... on the trait I'm not sure if this makes sense... as (at least in my mind) self refers to the trait here, not the class useing the trait.

Copy link
Member

Choose a reason for hiding this comment

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

There is no such thing as referring to a trait. PHP merges traits into the class, so self will always point to the correct class.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was talking conceptually, by reading this. But if you two believe it's better just to put self within the trait, I'm happy with it as I don't mind that much tbh. Changed 👍

@sroze sroze force-pushed the feature/19612-add-name-prefix-to-routes branch from a4c836c to 9f7c4e7 Compare December 1, 2017 15:26
Copy link
Contributor Author

@sroze sroze left a comment

Choose a reason for hiding this comment

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

Updated based on @fabpot's comments.

*
* @return $this
*/
final public function addNamePrefix(string $prefix)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, we still need the description I'd say, as it's meant to be used by developers

@sroze sroze force-pushed the feature/19612-add-name-prefix-to-routes branch from 9f7c4e7 to dd15433 Compare December 1, 2017 16:01
Add the `addNamePrefix` method to the PHP trait
@sroze sroze force-pushed the feature/19612-add-name-prefix-to-routes branch from dd15433 to e895402 Compare December 1, 2017 16:02
@fabpot
Copy link
Member

fabpot commented Dec 2, 2017

Thank you @sroze.

@fabpot fabpot closed this Dec 2, 2017
fabpot added a commit that referenced this pull request Dec 2, 2017
…ation (sroze)

This PR was squashed before being merged into the 4.1-dev branch (closes #25178).

Discussion
----------

[Routing] Allow to set name prefixes from the configuration

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #19612
| License       | MIT
| Doc PR        | ø

This allows setting name prefixes to routes while importing them. Typically, we can then import multiple times a similar file. This was originally requested by 🎸 @chrisguitarguy in #19612

```yaml
app:
    resource: ../controller/routing.yml

api:
    resource: ../controller/routing.yml
    name_prefix: api_
    prefix: /api
```

```xml
<?xml version="1.0" encoding="UTF-8" ?>
<routes xmlns="http://symfony.com/schema/routing"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://symfony.com/schema/routing
        http://symfony.com/schema/routing/routing-1.0.xsd">

    <import resource="../controller/routing.xml" />
    <import resource="../controller/routing.xml" prefix="/api" name-prefix="api_" />

</routes>
```

Commits
-------

880d7e7 [Routing] Allow to set name prefixes from the configuration
@sroze sroze deleted the feature/19612-add-name-prefix-to-routes branch December 2, 2017 17:38
nicolas-grekas added a commit that referenced this pull request Mar 19, 2018
…rekas)

This PR was merged into the 4.1-dev branch.

Discussion
----------

[Routing] Fix name-prefixing when using PHP DSL

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

Fixes bad implem merged in #25178

Commits
-------

0053eee [Routing] Fix name-prefixing when using PHP DSL
@fabpot fabpot mentioned this pull request May 7, 2018
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.

6 participants