[ Index ]

PHP Cross Reference of Limb3

title

Body

[close]

/web_app/src/toolkit/ -> lmbWebAppTools.class.php (source)

   1  <?php
   2  /*

   3   * Limb PHP Framework

   4   *

   5   * @link http://limb-project.com

   6   * @copyright  Copyright &copy; 2004-2007 BIT(http://bit-creative.com)

   7   * @license    LGPL http://www.gnu.org/copyleft/lesser.html

   8   */
   9  lmb_require('limb/toolkit/src/lmbAbstractTools.class.php');
  10  
  11  @define('LIMB_CONTROLLERS_INCLUDE_PATH', 'src/controller;limb/*/src/controller');

  12  

  13  /**

  14   * class lmbWebAppTools.

  15   *

  16   * @package web_app

  17   * @version $Id: lmbWebAppTools.class.php 6025 2007-06-29 08:49:08Z serega $

  18   */
  19  class lmbWebAppTools extends lmbAbstractTools
  20  {
  21    protected $session;
  22    protected $view;
  23    protected $dispatched_controller;
  24    protected $routes;
  25    protected $flash_box;
  26  
  27    function getSession()
  28    {
  29      if(is_object($this->session))
  30        return $this->session;
  31  
  32      lmb_require('limb/session/src/lmbSession.class.php');
  33      $this->session = new lmbSession();
  34  
  35      return $this->session;
  36    }
  37  
  38    function setSession($session)
  39    {
  40      $this->session = $session;
  41    }
  42  
  43    function setView($view)
  44    {
  45      $this->view = $view;
  46    }
  47  
  48    function getView()
  49    {
  50      if(is_object($this->view))
  51        return $this->view;
  52  
  53      lmb_require('limb/view/src/lmbWactView.class.php');
  54      $this->view = new lmbWactView();
  55      $this->view->setCacheDir(LIMB_VAR_DIR . '/compiled/');
  56  
  57      return $this->view;
  58    }
  59  
  60    function renderView($template)
  61    {
  62      $view = $this->toolkit->getView();
  63      $response = $this->toolkit->getResponse();
  64      $view->setTemplate($template);
  65      $response->write($view->render());
  66    }
  67  
  68    function setDispatchedController($dispatched)
  69    {
  70      $this->dispatched_controller = $dispatched;
  71    }
  72  
  73    function getDispatchedController()
  74    {
  75      return $this->dispatched_controller;
  76    }
  77  
  78    function getRoutesUrl($params = array(), $route_name = '', $skip_controller = false)
  79    {
  80      $routes = $this->toolkit->getRoutes();
  81      if(!isset($params['controller']) && !$skip_controller)
  82        $params['controller'] = $this->toolkit->getDispatchedController()->getName();
  83  
  84      return LIMB_HTTP_GATEWAY_PATH . ltrim($routes->toUrl($params, $route_name), '/');
  85    }
  86  
  87    function getRoutes()
  88    {
  89      if(!$this->routes)
  90      {
  91        $config = $this->toolkit->getConf('routes');
  92  
  93        lmb_require('limb/web_app/src/request/lmbRoutes.class.php');
  94        $this->routes = new lmbRoutes($config->export());
  95      }
  96  
  97      return $this->routes;
  98    }
  99  
 100    function setRoutes($routes)
 101    {
 102      $this->routes = $routes;
 103    }
 104  
 105    function getFlashBox()
 106    {
 107      if(!is_object($this->flash_box))
 108      {
 109        lmb_require('limb/web_app/src/util/lmbFlashBox.class.php');
 110        $this->flash_box = lmbFlashBox :: create($this->toolkit->getSession());
 111      }
 112  
 113      return $this->flash_box;
 114    }
 115  
 116    function flashError($message)
 117    {
 118      $this->toolkit->getFlashBox()->addError($message);
 119    }
 120  
 121    function flashMessage($message)
 122    {
 123      $this->toolkit->getFlashBox()->addMessage($message);
 124    }
 125  
 126    function createController($controller_name)
 127    {
 128      $class_name = lmb_camel_case($controller_name) . 'Controller';
 129      if(!class_exists($class_name))
 130      {
 131        $file = $this->toolkit->findFileByAlias("$class_name.class.php", LIMB_CONTROLLERS_INCLUDE_PATH, 'controller');
 132        lmb_require($file);
 133      }
 134      return new $class_name;
 135    }
 136  
 137    function redirect($params_or_url = array(), $route_url = null, $append = '')
 138    {
 139      $toolkit = $this->toolkit;
 140  
 141      if(is_array($params_or_url))
 142        $toolkit->getResponse()->redirect($toolkit->getRoutesUrl($params_or_url, $route_url) . $append);
 143      else
 144        $toolkit->getResponse()->redirect($params_or_url . $append);
 145    }
 146  }
 147  ?>


Generated: Fri Aug 29 04:49:26 2008 Cross-referenced by PHPXref 0.7