Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork5.3k
Description
For a project of mine, I movedapp/Resources intoresources to keep more in line with the company project structure. On the way I had a few quirks, namely with the routing.
When having the following:
# resources/config/routing.ymlapp:resource:'../../src/Infrastructure/Action'type:'annotation'
In a regular application, this relative path is being located fromapp/Resources so it should result inapp/Resources/../../src/Infrastructure/Action. Whilst the path does make sense (src/Infrastructure/Action exists),app/Resources does not exist so resolving this path e.g. withrealpath() will fail.
One could get around that by using the@AppBundle notation, but this notation is not usable with.. so ifAppBundle is not place at a higher level thansrc/Infrastructure/Action, e.g. when you havesrc/Infrastructure/Bundle/AppBundle.php, this trick cannot work.
When you get at that point, you either take the path of the least resistance and just create aapp/Resources/.gitkeep file and don't care or you are a stubborn sore loser and try to keep going.
So here's how I eventually got around that: First override thefile_locator service:
# resources/services.ymlservices:file_locator:class:Symfony\Component\HttpKernel\Config\FileLocatorarguments: -'@kernel' -'%kernel.root_dir%/../resources'
I don't know exactly where in the application this service is really used, but I do know it's used very early in the bootstrapping process so this in any case is not enough. Not finding a better solution, I changed:
// app/AppKernel.phpclass AppKernel{//.../** * @inheritdoc */publicfunctionlocateResource($name,$dir =null,$first =true) {if (__DIR__.'/Resources' ===$dir) {$dir =realpath(__DIR__.'/../resources'); }returnparent::locateResource($name,$dir,$first); }}
I'm not sure is there something more elegant that could be done neither if this should be documented. If it should let me know where I'll be happy to do a PR about it, if you feel it's not worth it just close the issue.