|
Project Information
Featured
Links
|
PMVC - PHP FrameworkObject oriented PHP framework that borrows heavily from The Spring Framework for java. PMVC requires PHP 5.3 or better. PMVC provides a number of utilities and APIs that go far beyond a simple web mvc framework. In fact, most of the framework is completely web independent and everything is built to be as standalone as possible. PMVC is 100% Object oriented. PMVC is currently in very active development and as a result it's trunk is constantly changing. An official release will soon come. Basic UsagePMVC is designed to be very easy to use. To get started merely extract the PMVC archive to a directory and initialize it: <?php
require("path/to/pmvc.php");
// or if using the phar: require("path/to/pmvc.phar");
?>This will initialize PMVC with it's default system class path so that autoloading of the framework classes is possible. If you'd like to add to the class path you can pass additional paths to the ClassUtil::addClassLoadersForPaths method as follows: <?php
require("path/to/pmvc.php");
// or if using the phar: require("path/to/pmvc.phar");
pmvc\util\ClassUtil::addClassLoadersForPaths(Array(
"/var/lib/myLib",
"./WEB-INF/classes"
));
?>Class Loading APIAt the heart of the PMVC class loading framework lies the ClassLoader interface. It provides functions for "requiring" files and loading classes by their class name. As a default implementation there exists FileSystemClassLoader. It provides a basic yet robust way of finding and loading classes. The FileSystemClassLoader is instantiated by passing an array of strings to it's constructor each string being a path to be added to it's class path. These are folders that the FileSystemClassLoader will search when a class is to be loaded. Imagine a FileSystemClassLoader created in the following way: $cl = new FileSystemClassLoader(Array("./classes", "./lib"));Upon calling: $cl->loadClass("pmvc\mvc\Dispatcher");it does the follwing:
It is expected that a class named Dispatcher in the pmvc\mvc namespace will be declared, ie: namespace pmvc\mvc;
class Dispatcher {
... code ...
}
Also, files known to exist in the class path can be required: $cl->requireFile("some/nonConformingClass.php");This does the following:
When a call to loadClass is successful the class can then be used as normal: $classLoader->loadClass("pmvc\mvc\Dispatcher");
use pmvc\mvc\Dispatcher;
$dispatcher = new Dispatcher();Of course, the call to loadClass is not needed as long as the ClassLoader's loadClass has been registered with spl_autoload_register or with one of the methods on the ClassUtil class for adding ClassLoaders to the class path. Class loading and the SPL (aka: autoload)PMVC provides some convenient was of using ClassLoaders within the SPL autoloading framework as described here. To use this one must call ClassUtil::addClassLoader and the ClassLoader will be registered via spl_autoload_register: $cl = new FileSystemClassLoader(Array("./classes", "./lib"));
ClassUtil::addClassLoader($cl);
use pmvc\mvc\Dispatcher;
$dispatcher = new Dispatcher(); // automatically calls loadClassMost users will never need to call ClassUtil::addClassLoader. Instead they will merely initialize the framework as described above. Inversion Of Control (IoC) APIPMVC offers a very powerful Inversion Of Control (IoC) container for PHP very similar to that of The Spring Framework for Java. Object "glue" or relationships can be defined in an XML configuration file and the IoC container maintains their life cycle and is responsible for injecting dependent objects into one another. At the heart of the IoC container is the ObjectFactory interface. It provides methods for accessing objects within the container. The IoC container comes complete with various life cycle interfaces and other features that enabled things like AOP and object Proxying. For instance, caching method calls can be done completely in configuration and no code needs to be implemented - same for logging method execution times and other useful things. PMVC provides two implementations of the ObjectFactory: DescriptorObjectFactory - Object descriptors are added to the DescriptorObjectFactory describing the relationships between Objects. This is a more low level approach and mainly exists to provide a convenient way to create implementations of the ObjectFactory interface that can load Object definitions from variations locations like a database or xml configuration file. XmlObjectFactory - An extension of the DescriptorObjectFactory that allows the defining of Objects in an XML document. Check out the IoCContainer document for more information on how to work with the IoC. Web Model View Controller Framework (MVC)TODO: document Cache APITODO: document Data APITODO: document I/O APITODO: document Logging APITODO: document Sample ApplicationA lot of the framework is used in the sample application. The sample application can by found in the trunk (or any branch/tag) under the "sample" folder. |