Description
Description
Add a system to let third-party bundles to declare its needed resources and "conventional" path to them. While reading the thread of #32845, I was thinking about a way to abstract this.
We are OK to say that bundles are opinionated in theirs structures. We stated that *.twig
templates should be in templates/
and translations files in translations/
, but every bundle may add its own conventions over it.
What about adding a way to let bundles declare the "conventional" path for its needed resources and give it tools to locate them across the app and the registered bundles ?
Example
<?php
namespace My\Bundle\DBALBundle;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use My\Bundle\DBALBundle\DependencyInjection\CompilerPass\SqlResourcesCompilerPass;
class MyDBALBundle extends Bundle
{
public function build(ContainerBuilder $container);
{
$container->defineResourcesPaths('sql', 'res/sql/**/*.sql');
$container->addCompilerPass(new SqlResourcesCompilerPass());
}
}
When declared, the framework expects to finds the sql
resources in the res/sql
folders of the app and bundles.
config/
src/
tests/
res/
└─ sql/
└─ ...everything here
vendor/
└─ organization/
└─ lib/
├─ src/
├─ tests/
└─ res/
└─ sql/
└─ ...everything here
<?php
namespace My\Bundle\DBALBundle\DependencyInjection\CompilerPass;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
class SqlResourcesCompilerPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
/** @var SplFileInfo[] $list */
$list = $container->locateResources('sql');
// do something useful with the list of resources located in `res/sql`
// of app and registered bundles (like building a locator/loader for your
// libs, etc.)
}
}
On the other hand, I suggest to add a new directory called res
to share user defined resources and to avoid the overload of the project root.
config/
src/
tests/
vendor/
templates/
translations/
sql/
...
gql/
VS
config/
src/
tests/
vendor/
res/
├─ templates/
├─ translations/
├─ sql/
├─ ...
└─ gql/
Every bit of this RFC is subject to discussion, but you get the idea.
WDYT ?