phpDocumentor ZNF
[ class tree: ZNF ] [ index: ZNF ] [ all elements ]

Source for file ZNF.php

Documentation is available at ZNF.php

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  3. /**
  4.  * PHP version 5
  5.  *
  6.  * This source file is subject to version 2.1 of the GNU Lesser General Public
  7.  * License, that is bundled with this package in the file COPYING, available
  8.  * through the world wide web at the following URI:
  9.  * http://www.gnu.org/copyleft/lesser.html.
  10.  *
  11.  * @package    ZNF
  12.  * @author     Alessandro Rossini <http://www.alessandrorossini.org>
  13.  * @author     Graziano Liberati <http://www.liberati.org>
  14.  * @author     Tomasz Kuter <evolic@interia.pl>
  15.  * @copyright  2004-2007 The ZNF Development Team
  16.  * @license    LGPL License 2.1 <http://www.gnu.org/copyleft/lesser.html>
  17.  * @version    SVN $Id: ZNF.php 44 2007-07-22 23:55:30Z evolic $
  18.  * @since      Release 0.6.1
  19.  * @link       http://www.zeronotice.org
  20.  */
  21.  
  22. require_once('ZNF/Action/RequestProcessor.php');
  23. require_once('ZNF/Config/AppConfig.php');
  24. require_once('ZNF/Config/ModulesConfig.php');
  25. require_once('ZNF/Presentation/Translation.php');
  26.  
  27. /**
  28.  * <i>ZNF</i> provides the controller in the Model-View-Controller (MVC) design pattern for web applications that is commonly known as Model 2.
  29.  *
  30.  * @access     public
  31.  * @package    ZNF
  32.  * @author     Alessandro Rossini <http://www.alessandrorossini.org>
  33.  * @author     Graziano Liberati <http://www.liberati.org>
  34.  * @author     Tomasz Kuter <evolic@interia.pl>
  35.  * @copyright  2004-2007 The ZNF Development Team
  36.  * @license    LGPL License 2.1 <http://www.gnu.org/copyleft/lesser.html>
  37.  * @version    SVN $Id: ZNF.php 44 2007-07-22 23:55:30Z evolic $
  38.  * @since      Release 0.6.1
  39.  * @link       http://www.zeronotice.org
  40.  */
  41. class ZNF
  42. {
  43.  
  44.     /**
  45.      * Version of the framework.
  46.      */
  47.     const VERSION '0.7.10';
  48.  
  49.     /**
  50.      * Name of the GET attribute used to select the action to execute.
  51.      */
  52.     const ACTION_INDEX 'znfAction';
  53.  
  54.     /**
  55.      * Name of the GET attribute used to select the module configuration.
  56.      */
  57.     const MODULE_INDEX 'znfModule';
  58.  
  59.     /**
  60.      * Name of the GET attribute used to select persistently the module configuration.
  61.      */
  62.     const CHANGE_MODULE_INDEX 'znfChangeModule';
  63.  
  64.     /**
  65.      * Name of the cache directory.
  66.      */
  67.     const CACHE_DIR 'cache';
  68.  
  69.     /**
  70.      * Name of the config directory.
  71.      */
  72.     const CONFIG_DIR 'config';
  73.  
  74.     /**
  75.      * Name of the language directory.
  76.      */
  77.     const LANG_DIR 'lang';
  78.  
  79.     /**
  80.      * Name of the libraries directory.
  81.      */
  82.     const LIB_DIR 'lib';
  83.  
  84.     /**
  85.      * Name of the modules directory.
  86.      */
  87.     const MODULES_DIR 'modules';
  88.  
  89.     /**
  90.      * Name of the package templates directory.
  91.      */
  92.     const TEMPLATE_DIR 'templates';
  93.  
  94.     /**
  95.      * Name of the package templates overlay directory.
  96.      */
  97.     const TEMPLATE_OVERLAY_DIR 'packages';
  98.  
  99.     /**
  100.      * Name of the theme directory.
  101.      */
  102.     const THEME_DIR 'themes';
  103.  
  104.     /**
  105.      * Debugging mode, set to true if you want to debug the application.
  106.      */
  107.     const DEBUG false;
  108.  
  109.     /**
  110.      * ZNF credits, don't modify the line below.
  111.      */
  112.     const CREDITS 'Powered by <a target="_blank" href="http://www.zeronotice.org">ZNF</a> &raquo; &copy; 2004-2007 The ZNF Development Team &raquo; Released under the <a target="_blank" href="http://www.gnu.org/copyleft/lesser.html">GNU/LGPL</a> license';
  113.  
  114.     /**
  115.      * Constructs a new <i>ZNF</i> object.
  116.      *
  117.      * @access public
  118.      */
  119.     public function __construct()
  120.     {
  121.         set_include_path(get_include_path(PATH_SEPARATOR self::LIB_DIR '/');
  122.         $this->_startSession();
  123.     }
  124.  
  125.     /**
  126.      * Processes the action requested with the correct <i>ZNF_Action_RequestProcessor</i>.
  127.      *
  128.      * @access public
  129.      * @return boolean 
  130.      */
  131.     public function process()
  132.     {
  133.         $path $this->_processPath();
  134.         $module $this->_processModule();
  135.  
  136.         $appConfig ZNF_Config_AppConfig::getInstance();
  137.  
  138.         // get the app module config
  139.         $appModuleConfig $appConfig->findModule($module);
  140.  
  141.         // custom request processor selected
  142.         if ($appModuleConfig['processor']{
  143.             $file preg_replace('/_/''/'$appModuleConfig['processor']'.php';
  144.  
  145.             // selected custom request processor not found
  146.             if (!file_exists($file)) {
  147.                 $translation new ZNF_Presentation_Translation('ZNF'$_SESSION['znf']['lang']);
  148.                 throw new ZNF_Action_RequestProcessorException($translation->get('errorLoadRequestProcessor'));
  149.             }
  150.  
  151.             // requires the file of the of the custom request processor
  152.             require_once($file);
  153.             $processor new $appModuleConfig['processor']($module);
  154.         else {
  155.             $processor new ZNF_Action_RequestProcessor($module);
  156.         }
  157.  
  158.         $processor->preProcess($path);
  159.         $processor->process($path);
  160.         $processor->postProcess($path);
  161.  
  162.         return true;
  163.     }
  164.  
  165.     /**
  166.      * Starts or reloads the session, setting the proper framework attributes for language, locale, theme and sessionId.
  167.      *
  168.      * @access protected
  169.      * @return boolean 
  170.      */
  171.     protected function _startSession()
  172.     {
  173.         $appConfig ZNF_Config_AppConfig::getInstance();
  174.  
  175.         // get defaults from the configuration file
  176.         $sessionId $appConfig->getSessionId();
  177.         $sessionPrevId session_name($sessionId);
  178.  
  179.         // starts a new session if new session name is not equal previous
  180.         if ($sessionPrevId != $sessionId{
  181.             session_start();
  182.         }
  183.         // starts a new session if not set
  184.         if (!isset($_SESSION['znf']['id'])) {
  185.             $lang   $appConfig->getLang();
  186.             $locale $appConfig->getLocale();
  187.             $theme  $appConfig->getTheme();
  188.  
  189.             if ($appConfig->getLangAutodetect(!= 'false'{
  190.                 // get language from the browser
  191.                 if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
  192.                     $browserLang substr($_SERVER['HTTP_ACCEPT_LANGUAGE'],0,2);
  193.  
  194.                     if (file_exists(self::THEME_DIR "/{$theme}/{$browserLang}")) {
  195.                         $lang $browserLang;
  196.                     }
  197.  
  198.                 }
  199.             }
  200.  
  201.             // initializes session with framework attributes
  202.             $_SESSION['znf']['id']            session_id();
  203.             $_SESSION['znf']['lang']          $lang;
  204.             $_SESSION['znf']['locale']        $locale;
  205.             $_SESSION['znf']['theme']         $theme;
  206.             $_SESSION['znf']['authenticated'false;
  207.             $_SESSION['znf']['roles']         array();
  208.         }
  209.         setlocale(LC_ALL$_SESSION['znf']['locale']);
  210.  
  211.         return true;
  212.     }
  213.  
  214.     /**
  215.      * Extracts the name of the action from the request.
  216.      *
  217.      * This method returns <i>null</i> if no action is found, then the
  218.      * <i>ZNF_Action_RequestProcessor->_processMapping()</i> select the default
  219.      * <i>action</i> element from the module configuration file.
  220.      *
  221.      * @access protected
  222.      * @return string 
  223.      */
  224.     protected function _processPath()
  225.     {
  226.         if (array_key_exists(ZNF::ACTION_INDEX$_GET)) {
  227.             return $_GET[ZNF::ACTION_INDEX];
  228.         }
  229.  
  230.         return null;
  231.     }
  232.  
  233.     /**
  234.      * Extracts the name of the module from the request.
  235.      *
  236.      * This method returns <i>null</i> if no module is found, then the
  237.      * <i>ZNF_Config_ModulesConfig::getInstance()</i> returns the configuration
  238.      * of the default <i>module</i> element from the application configuration
  239.      * file.
  240.      *
  241.      * @access protected
  242.      * @return string 
  243.      */
  244.     protected function _processModule()
  245.     {
  246.         if (array_key_exists(ZNF::CHANGE_MODULE_INDEX$_GET)) {
  247.             $_SESSION['module'$_GET[ZNF::CHANGE_MODULE_INDEX];
  248.         }
  249.  
  250.         if (array_key_exists(ZNF::MODULE_INDEX$_GET)) {
  251.             return $_GET[ZNF::MODULE_INDEX];
  252.         }
  253.  
  254.         if (isset($_SESSION['module'])) {
  255.             return $_SESSION['module'];
  256.         }
  257.  
  258.         return null;
  259.     }
  260.  
  261.     /**
  262.      * Update the name of the action in the request.
  263.      *
  264.      * This method is used by the <i>ZNF_Action_RequestProcessor</i> to forward
  265.      * the control flow to another module according to the current module
  266.      * configuration.
  267.      *
  268.      * @access public
  269.      * @param string $action 
  270.      */
  271.     public function updateAction($action)
  272.     {
  273.         $_GET[ZNF::ACTION_INDEX$action;
  274.     }
  275.  
  276.     /**
  277.      * Update the name of the module in the request.
  278.      *
  279.      * This method is used by the <i>ZNF_Action_RequestProcessor</i> to forward
  280.      * the control flow to another module according to the current module
  281.      * configuration.
  282.      *
  283.      * @access public
  284.      * @param string $module 
  285.      */
  286.     public function updateModule($module)
  287.     {
  288.         $_GET[ZNF::MODULE_INDEX $module;
  289.     }
  290.  
  291. }
  292.  
  293. /**
  294.  * <i>ZNFException</i> is the exception type for the <i>ZNF</i> class.
  295.  *
  296.  * <i>ZNFException</i> extends the <i>Exception</i> class of PHP5.
  297.  *
  298.  * @access     public
  299.  * @package    ZNF
  300.  * @author     Alessandro Rossini <http://www.alessandrorossini.org>
  301.  * @author     Graziano Liberati <http://www.liberati.org>
  302.  * @copyright  2004-2007 The ZNF Development Team
  303.  * @license    LGPL License 2.1 <http://www.gnu.org/copyleft/lesser.html>
  304.  * @version    SVN $Id: ZNF.php 44 2007-07-22 23:55:30Z evolic $
  305.  * @since      Release 0.6.1
  306.  * @link       http://www.zeronotice.org
  307.  */
  308. class ZNFException extends Exception
  309. {
  310. }
  311.  
  312. ?>

Documentation generated on Wed, 14 Nov 2007 23:47:43 +0100 by phpDocumentor 1.4.0