迄今为止,我没有见到过太多用PHP写的MVC框架。事实上我仅仅知道一个-Solar,是完全用PHP5写的。另外一个是Cake,一个试图成为PHP的RoR(Ruby on Rails-一个Ruby语言开源网络框架)。我自己对这两个框架都有一些不满意的地方:它们都没有利用到PEAR,Smarty等所包含的现有代码;现在的Cake还比较紊乱;最后,Solar是一个绝大部分由一个人写的作品(我无意说其作者Paul不是一个好人或者好程序员)。这些问题可能并不会让你否认它们,而且很有可能你根本不关心这些问题。但是正因为如此,我请各位尽可能地审视它们。
/**
* FR_Object
*
* The base object class for most of the classes that we use in our framework.
* Provides basic logging and set/get functionality.
*
* @author Joe Stump <joe@joestump.net>
* @package Framework
*/
abstract class FR_Object
{
/**
* $log
*
* @var mixed $log Instance of PEAR Log
*/
<?PHP
abstract class FR_Auth extends FR_Module
{
// {{{ __construct()
function __construct()
{
parent::__construct();
}
// }}}
// {{{ authenticate()
abstract function authenticate();
// }}}
// {{{ __destruct()
function __destruct()
{
parent::__destruct();
}
// }}}
}
?>
module.PHP-所有模块的心脏
<?PHP
abstract class FR_Module extends FR_Object_Web
{
// {{{ properties
/**
* $presenter
*
* Used in FR_Presenter::factory() to determine which presentation (view)
* class should be used for the module.
*
* @author Joe Stump <joe@joestump.net>
* @var string $presenter
* @see FR_Presenter, FR_Presenter_common, FR_Presenter_smarty
*/
public $presenter = 'smarty';
/**
* $data
*
* Data set by the module that will eventually be passed to the view.
*
* @author Joe Stump <joe@joestump.net>
* @var mixed $data Module data
* @see FR_Module::set(), FR_Module::getData()
*/
protected $data = array();
/**
* $name
*
* @author Joe Stump <joe@joestump.net>
* @var string $name Name of module class
*/
public $name;
/**
* $tplFile
*
* @author Joe Stump <joe@joestump.net>
* @var string $tplFile Name of template file
* @see FR_Presenter_smarty
*/
public $tplFile;
/**
* $moduleName
*
* @author Joe Stump <joe@joestump.net>
* @var string $moduleName Name of requested module
* @see FR_Presenter_smarty
*/
public $moduleName = null;
/**
* $pageTemplateFile
*
* @author Joe Stump <joe@joestump.net>
* @var string $pageTemplateFile Name of outer page template
*/
public function __construct()
{
parent::__construct();
$this->name = $this->me->getName();
$this->tplFile = $this->name.'.tpl';
}
// }}}
// {{{ __default()
/**
* __default
*
* This function is ran by the controller if an event is not specified
* in the user's request.
*
* @author Joe Stump <joe@joestump.net>
*/
abstract public function __default();
// }}}
// {{{ set( $var, $val)
/**
* set
*
* Set data for your module. This will eventually be passed toe the
* presenter class via FR_Module::getData().
*
* @author Joe Stump <joe@joestump.net>
* @param string $var Name of variable
* @param mixed $val Value of variable
* @return void
* @see FR_Module::getData()
*/
public function getData()
{
return $this->data;
}
// }}}
// {{{ isValid( $module)
/**
* isValid
*
* Determines if $module is a valid framework module. This is used by
* the controller to determine if the module fits into our framework's
* mold. If it extends from both FR_Module and FR_Auth then it should be
* good to run.
*
* @author Joe Stump <joe@joestump.net>
* @static
* @param mixed $module
* @return bool
*/