Actually i'm using this project directory structure http://framework.zend.com/manual/1.12/en/project-structure.project.html
But recently i started using namespaces in all my php-classes like:
Myapp\Configuration\
Myapp\Controller\
Myapp\Persistence\Entities\
Myapp\Persistence\Dao\
Myapp\Validation
....
and now I'm a little bit confused on where should i put all this directories in order to maintain a correct folder structure.
In the old project directory structure i also wrote directory names in lowercase, but now with namespaces i saw that most frameworks use camelcase
like in the example above.
Any help would be appreciated.
Best Answer
Most modern PHP projects are structured much like a Java package; ie a top level source folder, with subdirectories for each vendor, containing subdirectories for individual packages and so on.
However, because PHP doesn't have the same kind of loading of classes as a language like Java, it loads its classes using an autoload function. This means that files must be in a predictable location, or else be missed by the loader.
The PSR-0 and PSR-4 specifications from the PHP Framework Interop Group (PHP-FIG) are intended to standardise the stucture of packages. These specifications are adopted and implemented by pretty much all 1 modern (see: last few years) PHP libraries, packages and applications; aidedin no small part, I'm sure, by Composer.
In short, the PSR-0 specification requires that, under a given directory, files be structured and named according to the namespace of the single class they contain. For example, if the source directory is
src
and you have a classMy\Simple\Class
, then your class could be found at1 I can't think of a single project off the top of my head, but I'm sure there are some out there.