[ Index ]

PHP Cross Reference of Limb3

title

Body

[close]

/wact/src/tags/request/ -> site_branch_selector.tag.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  /**
  10   * @tag site_branch_selector
  11   * @package wact
  12   * @version $Id$
  13   */
  14  class WactSiteBranchSelectorTag extends WactCompilerTag
  15  {
  16    function generateChildren($code)
  17    {
  18      $is_first = true;
  19      $default = null;
  20      foreach(array_keys($this->children) as $key)
  21      {
  22        if(!is_a($this->children[$key], 'WactSiteBranchTag'))
  23          continue;
  24  
  25        $branch = $this->children[$key];
  26  
  27        if($branch->isDefault())
  28          $default = $branch;
  29  
  30        if(!$path = $branch->getPath())
  31          continue;
  32  
  33        $if = $is_first ? 'if' : 'elseif';
  34  
  35        $code->writePhp($if . '(preg_match("' . $this->_makePathRegex($path) . '",' .
  36                                            '$_SERVER["REQUEST_URI"])) {');
  37        $branch->generateNow($code);
  38        $code->writePhp('}');
  39  
  40        $is_first = false;
  41      }
  42  
  43      if($default)
  44      {
  45        $code->writePhp('else {');
  46        $default->generateNow($code);
  47        $code->writePhp('}');
  48      }
  49    }
  50  
  51    function _makePathRegex($path)
  52    {
  53      $trans = array("\*" => '.*?',
  54                     "\?" => '.');
  55      return '~^' . strtr(preg_quote($path, '~'), $trans) . '~';
  56    }
  57  }
  58  ?>


Generated: Thu Jan 8 04:06:23 2009 Cross-referenced by PHPXref 0.7