扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:Joe Stump 来源:PHP5研究室 2007年10月21日
关键字: Linux
/ config.php index.php includes/ Auth.php Auth/ No.php User.php Module.php Object.php Object/ DB.php Presenter.php Presenter/ common.php debug.php smarty.php Smarty/ modules/ example/ config.php example.php tpl/ example.tpl tpl/ default/ cache/ config/ templates/ templates_c/ |
<?php require_once('Log.php'); /** * 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 */ protected $log; /** * $me * * @var mixed $me Instance of ReflectionClass */ protected $me; /** * __construct * * @author Joe Stump <joe@joestump.net> * @access public */ public function __construct() { $this->log = Log::factory('file',FR_LOG_FILE); $this->me = new ReflectionClass($this); } /** * setFrom * * @author Joe Stump <joe@joestump.net> * @access public * @param mixed $data Array of variables to assign to instance * @return void */ public function setFrom($data) { if (is_array($data) && count($data)) { $valid = get_class_vars(get_class($this)); foreach ($valid as $var => $val) { if (isset($data[$var])) { $this->$var = $data[$var]; } } } } /** * toArray * * @author Joe Stump <joe@joestump.net> * @access public * @return mixed Array of member variables keyed by variable name */ public function toArray() { $defaults = $this->me->getDefaultProperties(); $return = array(); foreach ($defaults as $var => $val) { if ($this->$var instanceof FR_Object) { $return[$var] = $this->$var->toArray(); } else { $return[$var] = $this->$var; } } return $return; } /** * __destruct * * @author Joe Stump <joe@joestump.net> * @access public * @return void */ public function __destruct() { if ($this->log instanceof Log) { $this->log->close(); } } } ?> |
<?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 $pageTemplateFile = null; // }}} // {{{ __construct() /** * __construct * * @author Joe Stump <joe@joestump.net> */ 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() */ protected function set($var,$val) { $this->data[$var] = $val; } // }}} // {{{ getData() /** * getData * * Returns module's data. * * @author Joe Stump <joe@joestump.net> * @return mixed * @see FR_Presenter_common */ 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 */ public static function isValid($module) { return (is_object($module) && $module instanceof FR_Module && $module instanceof FR_Auth); } // }}} // {{{ __destruct() public function __destruct() { parent::__destruct(); } // }}} } ?> presenter.php-表述层的核心。 <?php class FR_Presenter { // {{{ factory($type,FR_Module $module) /** * factory * * @author Joe Stump <joe@joestump.net> * @access public * @param string $type Presentation type (our view) * @param mixed $module Our module, which the presenter will display * @return mixed PEAR_Error on failure or a valid presenter * @static */ static public function factory($type,FR_Module $module) { $file = FR_BASE_PATH.'/includes/Presenter/'.$type.'.php'; if (include($file)) { $class = 'FR_Presenter_'.$type; if (class_exists($class)) { $presenter = new $class($module); if ($presenter instanceof FR_Presenter_common) { return $presenter; } return PEAR::raiseError('Invalid presentation class: '.$type); } return PEAR::raiseError('Presentation class not found: '.$type); } return PEAR::raiseError('Presenter file not found: '.$type); } // }}} } ?> |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者