Commit 30b8038
committed
minor #59189 [Routing] Validate "namespace" (when using
This PR was merged into the 7.3 branch.
Discussion
----------
[Routing] Validate "namespace" (when using `Psr4DirectoryLoader`)
| Q | A
| ------------- | ---
| Branch? | 7.3
| Bug fix? | no
| New feature? | yes <!-- please update src/**/CHANGELOG.md files -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Issues | Fix #... <!-- prefix each issue number with "Fix #", no need to create an issue if none exists, explain below instead -->
| License | MIT
<!--
Replace this notice by a description of your feature/bugfix.
This will help reviewers and should be a good start for the documentation.
Additionally (see https://symfony.com/releases):
- Always add tests and ensure they pass.
- Bug fixes must be submitted against the lowest maintained branch where they apply
(lowest branches are regularly merged to upper ones so they get the fixes too).
- Features and deprecations must be submitted against the latest branch.
- For new features, provide some code snippets to help understand usage.
- Changelog entry should follow https://symfony.com/doc/current/contributing/code/conventions.html#writing-a-changelog-entry
- Never break backward compatibility (see https://symfony.com/bc).
-->
I spend a small amount of time to understand why my controller was inaccessible:
<img width="496" alt="image" src="https://github.com/user-attachments/assets/959188fc-75d3-43db-a4e8-78fc4d140a74" />
With the following configuration:
```yaml
controllers:
resource:
path: ../src/Application/Controller/
namespace: App\Application/Controller
type: attribute
```
You may have seen that the namespace `App\Application/Controller` is invalid because the presence of `/` instead of `\`. If I correct it, then my controller is accessible.
It means that invalid namespaces are simply ignored without any hints for the user, and I think it can be improved and be more user-friendly :)
This PR add namespace validation, it checks if `/` is found, and if namespace is composed of valid PHP identifiers:
<img width="759" alt="image" src="https://github.com/user-attachments/assets/ae8d1dc8-f250-4faf-bc07-22aaefc363fd" />
<img width="1011" alt="image" src="https://github.com/user-attachments/assets/7fe97b1e-77be-45ab-b875-b2a67b7501dd" />
Commits
-------
3d807c1 [Routing] Validate "namespace" (when using `Psr4DirectoryLoader`)Psr4DirectoryLoader) (Kocal)File tree
2 files changed
+34
-0
lines changed- src/Symfony/Component/Routing
- Loader
- Tests/Loader
2 files changed
+34
-0
lines changedLines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
43 | 44 | | |
44 | 45 | | |
45 | 46 | | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
46 | 51 | | |
47 | 52 | | |
48 | 53 | | |
| |||
Lines changed: 29 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
90 | 91 | | |
91 | 92 | | |
92 | 93 | | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
93 | 122 | | |
94 | 123 | | |
95 | 124 | | |
| |||
0 commit comments