Skip to content

[Config][Routing] Nicer config syntax for PSR-4 route loading #47943

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

Merged
merged 1 commit into from
Oct 22, 2022

Conversation

derrabus
Copy link
Member

Q A
Branch? 6.2
Bug fix? no
New feature? yes
Deprecations? no
Tickets Follow-up to #47916
License MIT
Doc PR symfony/symfony-docs#17373 (WIP)

This PR implements an alternative syntax for the PSR-4 route loader introduced in #47916.

controllers:
    resource:
        path: ./Controllers
        namespace: App\Controllers
    type: attribute
<routes>
    <import type="attribute">
        <resource path="./Controllers" namespace="App\Psr4Controllers" />
    </import>
</routes>

@carsonbot carsonbot changed the title Nicer config syntax for PSR-4 route loading [Config][Routing] Nicer config syntax for PSR-4 route loading Oct 21, 2022
@carsonbot carsonbot added this to the 6.2 milestone Oct 21, 2022
@javiereguiluz
Copy link
Member

@derrabus thanks for taking the time to update the config syntax of this feature 🙏

@derrabus derrabus force-pushed the improvement/psr-4-routing-syntax branch from 6ae58f7 to 94f0b72 Compare October 21, 2022 13:24
@derrabus derrabus force-pushed the improvement/psr-4-routing-syntax branch 3 times, most recently from 5328cf2 to 82b3b74 Compare October 21, 2022 14:54
@derrabus derrabus force-pushed the improvement/psr-4-routing-syntax branch from 82b3b74 to d7df3be Compare October 21, 2022 14:55
@fabpot
Copy link
Member

fabpot commented Oct 22, 2022

Thank you @derrabus.

@fabpot
Copy link
Member

fabpot commented Oct 22, 2022

symfony/recipes#1138 for the recipe update.

@@ -136,7 +136,11 @@ private function doImport(mixed $resource, string $type = null, bool $ignoreErro
try {
$loader = $this->resolve($resource, $type);

if ($loader instanceof self && null !== $this->currentDir) {
if (!$loader instanceof self) {
return $loader->load($resource, $type);
Copy link
Member

Choose a reason for hiding this comment

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

@derrabus That does not work as the PSR-4 loader uses the locator but without the current dir, so the resource cannot be found. Or am I missing something?

@derrabus derrabus deleted the improvement/psr-4-routing-syntax branch October 22, 2022 10:40
fabpot added a commit that referenced this pull request Oct 23, 2022
…irectory (derrabus)

This PR was merged into the 6.2 branch.

Discussion
----------

[Config][Routing] Fix delegating to PSR-4 loader from subdirectory

| Q             | A
| ------------- | ---
| Branch?       | 6.2
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | #47943 (comment)
| License       | MIT
| Doc PR        | N/A

Commits
-------

c1f0ccb Fix delegating to PSR-4 loader from subdirectory
@fabpot fabpot mentioned this pull request Oct 24, 2022
fabpot added a commit that referenced this pull request Oct 27, 2022
…iles (derrabus)

This PR was merged into the 6.2 branch.

Discussion
----------

[Routing] Add tests for loading PSR-4 classes from PHP files

| Q             | A
| ------------- | ---
| Branch?       | 6.2
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | N/A
| License       | MIT
| Doc PR        | N/A

Follow-up to #47916, #47943

This PR adds more tests, demonstrating how to trigger the new PSR-4 loader from a PHP config file.

Commits
-------

416639c Add tests for loading PSR-4 classes from PHP files
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.

5 participants