Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Inconsistent documentation regarding bundle directory structure #15881

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
tacman opened this issue Oct 1, 2021 · 13 comments
Closed

Inconsistent documentation regarding bundle directory structure #15881

tacman opened this issue Oct 1, 2021 · 13 comments

Comments

@tacman
Copy link
Contributor

tacman commented Oct 1, 2021

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?

@xabbuh
Copy link
Member

xabbuh commented Oct 4, 2021

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

@wouterj
Copy link
Member

wouterj commented Oct 4, 2021

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

@tacman
Copy link
Contributor Author

tacman commented Oct 5, 2021

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
Copy link
Contributor Author

tacman commented Oct 10, 2021

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.

@acantepie
Copy link

@tacman
Most of Symfony bundle use this structure.

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

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.

@BafS
Copy link
Contributor

BafS commented Dec 22, 2021

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 added a commit to BafS/symfony-docs that referenced this issue Jan 12, 2022
BafS added a commit to BafS/symfony-docs that referenced this issue Jan 12, 2022
BafS added a commit to BafS/symfony-docs that referenced this issue Jan 12, 2022
@Trismegiste
Copy link

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

@BafS
Copy link
Contributor

BafS commented Apr 5, 2022

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

@Trismegiste
Copy link

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

Thank you for your reply 👍

@BafS
Copy link
Contributor

BafS commented Sep 14, 2022

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.

@weaverryan
Copy link
Member

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.

@BafS
Copy link
Contributor

BafS commented Sep 16, 2022

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

@alamirault
Copy link
Contributor

I also think we can close this issue

@xabbuh xabbuh closed this as completed Apr 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants