问题
I am working on a Silex project which requires some custom service providers and their related classes to be written.
I am aware of the preferred file structure of silex projects but cannot anywhere find information on where custom classes should fit into this structure. All composer supplied libraries are naturally in the vendor folder, where do custom ones go?
At the moment (trimmed down for space) my directory structure follows:
.
├── composer.json
├── composer.lock
├── composer.phar
├── src
│ └── Dashboard
│ ├── Controller
│ │ ├── indexController.php
│ │ └── viewController.php
│ └── Model
│ └── Users.php
├── vendor
│ ├── autoload.php
│ ├── composer
├── views
│ ├── index.twig
│ ├── layout.twig
│ ├── logout.twig
│ └── view.twig
└── web
├── css
│ ├── bootstrap.min.css
│ └── style.css
├── index.php
├── js
│ ├── bootstrap.min.js
│ ├── jquery-2.0.3.min.js
│ ├── jquery-ui-1.10.3.min.js
└── twiglib.php
Where in this do custom service providers go and custom non composer included libraries? In src under a specific namespace? Or in the vendor folder?
I can see from Where to put 3rd party service providers in my Silex app than the vendor folder is suggested, but then Creating new service providers in Silex, contradicts this and advises against editing the vendor folder and putting it in the src folder.
Is there an official standard?
回答1:
Vendor folder is supposed to contain only composer dependencies, so it is for sure a bad design to add some specific classes there manually. You can put your custom Service providers into separate git repositories and use them in your project via composer. Or, if this way too hard to come, you could put them into your src folder, in this case it either could be a separate folder Services or, if you prefer domain driven design, you can put every service provider into your domain specific folders (i.e. in your case it could be smth like /src/Dashboard/DashboardService.php). Not sure if any common standard exists.
来源:https://stackoverflow.com/questions/30239962/silex-file-structure-for-custom-service-providers