Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony Folder Structure Standard

Tags:

symfony

Is there someone who can explain in detail the standard used by Symfony* to name folders and files in the directory structure?

MyBundle
├─ Controller/                 <-- 1) why singular?
├─ Model/                      <-- 2) why singular?
├─ Resources/                  <-- 3) why plural?
│  ├─ config/                  <-- 4) why the "c" is lowercase?
│  ├─ translations/
│  ├─ views/                   <-- 5) why the "v" is lowercase and views is plural?
│  │  └─ Default/              <-- 6) Why uppercase?
│  │     └─ my_view.html.twig  <-- 7) Why lowercase and snake case?
│  └─ public/
├─ Service/                    <-- 8) why singular?
└─ Tests/

This leads to another question: if I want to create a folder which contains ArchiveSection classes inside the Model folder, how should I name it?

  • Model/ArchiveSections/
  • Model/ArchiveSection/
  • Model/archive_sections/

* I am using Symfony 2.3.

like image 681
StockBreak Avatar asked Nov 09 '22 17:11

StockBreak


1 Answers

See the docs talking about bundle directory structure.

I would say just keep in mind that the Resources directory structure must follow the standards to get some automatic registration of view paths and translations files in the kernel. The same applies to the Command directory.

For the rest it's how you want it to be, just know that the directory structure should repeat the symfony components structure to keep logic and readability (a Twig directory for creating twig extensions or functions, a Serializer directory to hold custom normalizers...).

This is relevant to have a good directory structure as it defines your classes namespace structure.

like image 125
Heah Avatar answered Nov 15 '22 08:11

Heah