There are many different ways you can build your system with regard to class names, automatic loading, interfaces, etc. what you should remember is that if other people use the code while developing on it, you want to make it simple and easy in development, otherwise it will be difficult for developers to code it.
There are many ways, as mentioned above, one of them is PSR-0 , which looks for class names, namespaces and directory structure, it is a simple concept that is used by many major developers such as Zend and many others
Im working on the system at the moment and although it does not have a PSR-0 structure, it is still pretty simple:
You can visit the source here and take a review: https://github.com/AdminSpot/ASFramework
Also, I'm not sure that you will apply the convention to libraries, I mean that the file name has nothing to do with the actual code, so combining the class name with the parent and interfaces is pointless, since you will never include this file through the class name, which he is expanding.
If these are basically the dependencies that you are interested in, an automatic solution to load class dependencies, then I would make a PSR-0 decision.
You basically do the following:
function autoload($className) { $className = ltrim($className, '\\'); $fileName = ''; $namespace = ''; if ($lastNsPos = strripos($className, '\\')) { $namespace = substr($className, 0, $lastNsPos); $className = substr($className, $lastNsPos + 1); $fileName = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR; } $fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php'; require $fileName; } spl_autoload_register('autoload');
Create your classes as follows:
class HTTP_Input extends HTTP_Protocol implements Interface_Readable_Context{}
and then you donโt need to enable it before hand, as new HTTP_Input will automatically download the following:
- HTTP / Input.php
- HTTP / Protocol.php
- Interface / Read / Context.php