8000 [RFC][Bundles] Add a system to manage app & bundle resources · Issue #33293 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
[RFC][Bundles] Add a system to manage app & bundle resources #33293
Closed
@sukei

Description

@sukei

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 ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    RFCRFC = Request For Comments (proposals about features that you want to be discussed)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0