Source for file HandlerChain.inc

Documentation is available at HandlerChain.inc

  1. <?php
  2. /**
  3. * Generic HandlerChain
  4. *
  5. * This file is part of CompInaBox.
  6. * @copyright CompInaBox Copyright 2001-2005. Eric D. Nielsen, All rights reserverd.
  7. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  8. *
  9. * @author Eric D. Nielsen <nielsene@alum.mit.edu>
  10. * @package InputControllers
  11. */
  12. /**
  13. * The Generic HandlerChain
  14. *
  15. * @package InputControllers
  16. */
  17. require_once("conf/tools/defines.inc");
  18. class HandlerChain {
  19.  
  20. var $_handlers;
  21. function HandlerChain($filename="") {
  22. $this->_handlers=array();
  23. if ($filename!="")
  24. $this->initHandlers(file(CIB_BASE."include/conf/handlers/$filename.setup"));
  25. }
  26. function addHandler(&$handler) {
  27. $this->_handlers[]=&$handler;
  28. }
  29.  
  30. function invoke(&$con, $req) {
  31. $numHandlers=count($this->_handlers);
  32. $view="";
  33. for ($i=0;$i<$numHandlers;$i++) {
  34. $aHandler=&$this->_handlers[$i];
  35. if ($aHandler->canHandle($con,$req)) {
  36. $view=$aHandler->execute($con,$req);
  37. break;
  38. }
  39. }
  40. return $view;
  41.  
  42. }
  43.  
  44. function initHandlers($config) {
  45. foreach ($config as $aLine) {
  46. if ($aLine=="") continue;
  47. $components = explode(" ",$aLine);
  48. $type = $components[0];
  49. switch ($type) {
  50. case "AccessControl":
  51. $authRequired = in_array("AuthenticationRequired",$components);
  52. $levelIndex = array_search("Levels",$components);
  53. if ($levelIndex!==FALSE) {
  54. $permissions=& new Permissions($components[$levelIndex+1]);
  55. $handler = &new AccessDeniedHandler($authRequired,$permissions);
  56. } else {
  57. $handler =& new AccessDeniedHandler($authRequired);
  58. }
  59. $this->addHandler($handler); break;
  60. }
  61. }
  62. return;
  63. }
  64. }
  65. ?>

Documentation generated on Tue, 25 Apr 2006 13:01:48 -0400 by phpDocumentor 1.3.0RC3