I'm in the very early stages of making an MVC web application. I want to try and do things composer style. Here is my directory structure so far:
public_html
|-vendor
| |-MyVendorName
| | |-DomainObjectClass.php
So that's where I am storing domain objects.
I'm also trying to do MVC as close as I can to the way it is done in the answer to this question
Where I am a bit stuck is where to put the Model, Controller, View, Services, DataMappers etc. Should I make subdirectories of MyVendorName (eg MyVendoreName/DomainObjects/DomainObjectClass.php and MyVendorName/Services/SomeServiceClass.php etc) or would it be wiser to make a directory separate from vendor called classes or src or something and do MVC stuff there?
Edit: Everyone is saying that vendor is for third party libs, I get that. But the way I am writing my domain objects is very decoupled from the MVC side of things. In fact, they do not even know they are part of an MVC app. They could very easily be reused in other projects (I intend to do this). So it seems illogical to me to put it in src/ or app/
This is an extremely debatable topic and there's no one right answer. However, I'd dispense the following hints:
vendor
directory is for third party dependencies, you should not be writing your own code in itsrc
or lib
directory, next to the vendor
directoryMyVendorName\Controller
, MyVendorName\Model
etc. makes senseMyVendorName\Model\DomainObjects\Foobar\Subclass
makes senseI would suggest this approach:
project_dir
|-vendor
| -(vendor directories, installed via composer)
|-public_html (images, javascript, css, html files/angular views)
|-app
Inside of your app
directory is where you put your PHP code. Inside of there you can organize your controllers, services, data mappers however you like, but this structure provides a strict separation between what should be accessible from the outside (public_html
) and what should only be executed by apache or cli (everything else).
As @deceze said, though, besides breaking out the vendor directory and the public directory, how you organize your application code is wholly up to you and should match whatever is most appropriate for the task you're attempting to accomplish.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With