symfony-docs icon indicating copy to clipboard operation
symfony-docs copied to clipboard

Inconsistent documentation regarding bundle directory structure

Open tacman opened this issue 3 years ago • 12 comments

There is an inconsistency between best practices and bundles documentation regarding the directory structure

https://symfony.com/doc/5.4/bundles/best_practices.html#directory-structure

<your-bundle>/
├── config/
├── docs/
│   └─ index.md
├── public/
├── src/
│   ├── Controller/
│   ├── DependencyInjection/
│   └── AcmeBlogBundle.php
├── templates/
├── tests/
├── translations/
├── LICENSE
└── README.md

https://symfony.com/doc/current/bundles.html#bundle-directory-structure

image

I would LOVE to use the new directory structure, get rid of the Resources level directory and use config, templates and public, just like the main application. But I've never been able to get that to work. If there's a setting somewhere to use the Best Practices directory structure (skip the /Resources), can that be documented?

tacman avatar Oct 01 '21 15:10 tacman

I think we need to update the second article to match the structure of the best practices article.

xabbuh avatar Oct 04 '21 10:10 xabbuh

I would LOVE to use the new directory structure, get rid of the Resources level directory and use config, templates and public, just like the main application. But I've never been able to get that to work. If there's a setting somewhere to use the Best Practices directory structure (skip the /Resources), can that be documented?

You need Symfony 5 for the new structure to work. Also, you need to edit Bundle::getPath() and probably also the path in Extension::load(). https://github.com/symfony/symfony/blob/5.4/UPGRADE-5.0.md#httpkernel

wouterj avatar Oct 04 '21 10:10 wouterj

Thanks, this is almost working for me now. I'm not sure how to reference the bundles when loading routes, though, as it fails with the new structure.

# /config/routes/my_bundle_base.yaml
my_company_base_bundle_oauth:
    resource: '@MyCompanyBaseBundle/Controller/OAuthController.php'
    prefix: /
    type: annotation

Curiously, the src/Controller directory didn't move (unlike views=>templates and config). Services seem normal (and work with the "traditional" bundle structure.

        <service id="MyCompany\BaseBundle\Controller\OAuthController" public="true" autowire="true">
            <tag name="container.service_subscriber" />
            <tag name="controller.service_arguments" />
        </service>

Is there a way to list the path resources? I'm trying to follow the FileLoader and YamlFileLoader, but having trouble figuring out where the map comes from to get from @whatever to an realPath.

tacman avatar Oct 05 '21 13:10 tacman

Can anyone point me to a bundle that uses the best practices and the new directory structure? I'm really having a hard time trying to figure out how to reference the controller path. @weaverryan , do you think you'll update your excellent SymfonyCast tutorial on how to make a reusable bundle? Especially now that recipes are now much easier to publish since Flex is serverless. (At least that's how I'm readying it.)

Thx.

tacman avatar Oct 10 '21 19:10 tacman

@tacman Most of Symfony bundle use this structure.

But some "offical" bundles use a mixed directory structure :

  • https://github.com/EasyCorp/EasyAdminBundle
  • https://github.com/symfony/panther

There is a src/ and assets/ folder but config, templates and translations are in src/Resourcesfolder.

I my repository, there is 2 bundles that uses the best practises structure.

acantepie avatar Oct 29 '21 18:10 acantepie

What is the consensus for new bundles structure? I like the way https://github.com/symfony/panther is structured.

https://github.com/symfony/mercure-bundle or https://github.com/symfony/webpack-encore-bundle also use "src/", I feel it's the new convention, it would be great to have the documentation reflect it.

BafS avatar Dec 22 '21 12:12 BafS

Hello, I'm trying to figure out the right directory structure of a bundle (for 5.4).

Is there finally a consensus, the PR is still not merged ? Thanks

Trismegiste avatar Apr 05 '22 08:04 Trismegiste

Unfortunately it didn't move, I personally went for https://symfony.com/doc/current/bundles/best_practices.html#directory-structure because I prefer to have my sources in src/ and configs/readme/etc. outside

BafS avatar Apr 05 '22 09:04 BafS

I agree with you about src/ & config/ folders.

Thank you for your reply :+1:

Trismegiste avatar Apr 06 '22 14:04 Trismegiste

Some new UX bundles are also using the src/ folder (eg. https://github.com/symfony/ux/tree/2.x/src/Autocomplete) and some not (eg. https://github.com/symfony/ux/tree/2.x/src/Chartjs). I'm not sure why it's not consistent across the same repo.

BafS avatar Sep 14 '22 05:09 BafS

Yea, we should normalize that - someone else started with some packages NOT using src/, but I HAVE used src/ for the packages that I've created.

weaverryan avatar Sep 14 '22 13:09 weaverryan

I created an issue to track this @weaverryan. And I didn't realized but the docs got updated 4 months ago in https://github.com/symfony/symfony-docs/pull/16801, both pages now use src/ for the logic! We can probably close this issue.

BafS avatar Sep 16 '22 03:09 BafS

I also think we can close this issue

alamirault avatar Apr 16 '23 11:04 alamirault