[ Index ]

PHP Cross Reference of Limb3

title

Body

[close]

/web_app/src/request/ -> lmbRoutesRequestDispatcher.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/web_app/src/request/lmbRequestDispatcher.interface.php');
  10  
  11  /**

  12   * class lmbRoutesRequestDispatcher.

  13   *

  14   * @package web_app

  15   * @version $Id: lmbRoutesRequestDispatcher.class.php 5945 2007-06-06 08:31:43Z pachanga $

  16   */
  17  class lmbRoutesRequestDispatcher implements lmbRequestDispatcher
  18  {
  19    protected $path_offset;
  20    protected $base_path;
  21  
  22    function __construct($path_offset = null, $base_path = null)
  23    {
  24      if(is_null($path_offset) && defined('LIMB_HTTP_OFFSET_PATH'))
  25        $this->path_offset = LIMB_HTTP_OFFSET_PATH;
  26      else
  27        $this->path_offset = $path_offset;
  28  
  29      if(is_null($base_path) && defined('LIMB_HTTP_BASE_PATH'))
  30        $this->base_path = LIMB_HTTP_BASE_PATH;
  31      else
  32        $this->base_path = $base_path;
  33    }
  34  
  35    function dispatch($request)
  36    {
  37      $routes = lmbToolkit :: instance()->getRoutes();
  38  
  39      $uri = $request->getUri();
  40      $uri->normalizePath();
  41  
  42      $level = $this->_getHttpBasePathOffsetLevel($uri);
  43  
  44      $result = $routes->dispatch($uri->getPathFromLevel($level));
  45  
  46      if($action = $request->get('action'))
  47        $result['action'] = $action;
  48      return $result;
  49    }
  50  
  51    protected function _getHttpBasePathOffsetLevel($uri)
  52    {
  53      if(!$this->path_offset)
  54        return 0;
  55  
  56      $base_path_uri = new lmbUri(rtrim($this->base_path, '/'));
  57      $base_path_uri->normalizePath();
  58  
  59      $level = 1;
  60      while(($uri->getPathElement($level) == $base_path_uri->getPathElement($level)) &&
  61            ($level < $base_path_uri->countPath()))
  62      {
  63        $level++;
  64      }
  65  
  66      return $level;
  67    }
  68  }
  69  
  70  ?>


Generated: Tue Oct 7 05:02:03 2008 Cross-referenced by PHPXref 0.7