From: Jason S. <jsw...@ya...> - 2003-03-15 05:58:28
|
Hello all, Had some time tonight to work with some ideas I have had recently. I wanted to modify Phrame to a) not have to include all the models/ actions/ forms/ and views/ directories (to improve application performance) b) create a view factory (each of my views is a separate class that has a Render method that accepts a smarty object) c) create a default action to be process if no other action was specified (in my case, ShowViewAction) Seems to be up and working. Here are some of the changes I have been working with: to ActionController.php: 134c134 < function _processMapping($mappings, $request) --- > function &_processMapping($mappings, $request) 138c138,143 < $actionMapping = $this->_actionMappings->get($name); --- > if ($this->_actionMappings->containsKey($name)) { > $actionMapping = $this->_actionMappings->get($name); > } else { > $name = $this->_options[_DEFAULT_ACTION]; > $actionMapping = $this->_actionMappings->get($name); > } 155c160 < function _processForm($mappings, $request) --- > function &_processForm($mappings, $request) 164a170,171 > //JES > require_once "forms/$type.php"; 189c196 < function _processValidate($actionMapping, $actionForm) --- > function _processValidate(&$actionMapping, &$actionForm) 210c217 < function _processAction($actionMapping, $actionForm) --- > function &_processAction(&$actionMapping, &$actionForm) 215a223,224 > //JES > require_once "actions/$type.php"; 236c245 < function _processForward($actionForward) --- > function _processForward(&$actionForward) 246a256 > exit; to Constants.php (changed the whole file to avoid E_ALL notices): <?php //request contant(s) define('_ACTION', 'action'); define('_VIEW', 'view'); //session constant(s) define('_CONTROLLER', '_controller'); define('_ERRORS', '_errors'); define('_FORM', '_form'); //mappings constant(s) define('_ACTION_FORMS', '_actionForms'); define('_ACTION_MAPPINGS', '_actionMappings'); define('_TYPE', '_type'); define('_NAME', '_name'); define('_INPUT', '_input'); define('_VALIDATE', '_validate'); define('_ACTION_FORWARDS', '_actionForwards'); define('_PATH', '_path'); define('_REDIRECT', '_redirect'); //options constant(s) define('_CACHE', '_cache'); define('_ERROR_REPORTING', '_errorReporting'); define('_ERROR_HANDLER', '_errorHandler'); //JES define('_DEFAULT_ACTION', '_defaultAction'); ?> to include.php: <?php require_once 'util/Object.php'; require_once 'util/ArrayList.php'; require_once 'util/HashMap.php'; require_once 'util/Stack.php'; require_once 'util/ListIterator.php'; //require_once 'ext/Xml.php'; require_once 'Constants.php'; require_once 'Action.php'; require_once 'ActionController.php'; require_once 'ActionForm.php'; require_once 'ActionForward.php'; require_once 'ActionMapping.php'; require_once 'MappingManager.php'; require_once 'ViewFactory.php'; ?> MappingManager.php was posted to the list earlier. The new ViewFactory.php is: <?php /** * view class directory */ define('PHRAME_VIEW_CLASS_DIR', 'views/'); /** * class to create Phrame Mapping arrays * * @author Jason E. Sweat * @since 2003-01-13 */ class ViewFactory extends Object { /** * constructor * * @return void */ function ViewFactory() { trigger_error("ViewFactory is a virtual class, please extend for your application"); return false; } /** * abstract function to return class based on view * * Must be overridden in the application, should always return a valid class file. * * @return void */ function _GetViewClass($psView) { $s_error = 'ViewFactory::_GetViewClass is a virtual method, please extend for your application'; trigger_error($s_error); die($s_error); } /** * factory function * * @return object the view object */ function &Build($psView) { $s_view_class = $this->_GetViewClass($psView); require_once PHRAME_VIEW_CLASS_DIR.$s_view_class.'.php'; $o_view = new $s_view_class; return $o_view; } } When defining the applicaiton options, I added ,_DEFAULT_ACTION => 'ShowView' and my ShowViewAction is: class ShowViewAction extends Action { /** * perform the action of showing a view * * @param object $poActionMapping the action mapping object * @param object $poActionForm the form object * @return object ActionForward */ function Perform(&$poActionMapping, &$poActionForm) { $o_view_factory = new SeiViewFactory; $o_view = $o_view_factory->Build($poActionForm->Get('view')); $o_smarty = new Smarty; //any default assignments //render the template $o_view->Render($o_smarty); //$o_action_forward = &$poActionMapping->Get('debug'); //return $o_action_forward; } I hope you find some of these changes of interest. Regards, Jason __________________________________________________ Do you Yahoo!? Yahoo! Web Hosting - establish your business online http://webhosting.yahoo.com |