Description
For a project of mine, I moved app/Resources
into resources
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.yml
app:
resource: '../../src/Infrastructure/Action'
type: 'annotation'
In a regular application, this relative path is being located from app/Resources
so it should result in app/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. with realpath()
will fail.
One could get around that by using the @AppBundle
notation, but this notation is not usable with ..
so if AppBundle
is not place at a higher level than src/Infrastructure/Action
, e.g. when you have src/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 a app/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 the file_locator
service:
# resources/services.yml
services:
file_locator:
class: Symfony\Component\HttpKernel\Config\FileLocator
arguments:
- '@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.php
class AppKernel
{
//...
/**
* @inheritdoc
*/
public function locateResource($name, $dir = null, $first = true)
{
if (__DIR__.'/Resources' === $dir) {
$dir = realpath(__DIR__.'/../resources');
}
return parent::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.