[ Index ]

PHP Cross Reference of Limb3

title

Body

[close]

/wact/src/tags/core/ -> wrap.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  /**

  11   * Merges the current template with a wrapper template, the current

  12   * template being inserted into the wrapper at the point where the

  13   * wrap tag exists.

  14   * @tag core:WRAP

  15   * @package wact
  16   * @version $Id: wrap.tag.php 5945 2007-06-06 08:31:43Z pachanga $
  17   */
  18  class WactCoreWrapTag extends WactRuntimeComponentTag
  19  {
  20    protected $sourcefile;
  21  
  22    /**

  23    * @param WactCompiler

  24    **/
  25    function preParse($compiler)
  26    {
  27      $tree_builder = $compiler->getTreeBuilder();
  28  
  29      if($file = $this->getAttribute('file'))
  30      {
  31        $this->_compileSourceFileName($file, $compiler);
  32  
  33        $this->_makeInsertion($this, $tree_builder);
  34      }
  35      else
  36        $this->_makeInsertionIntoParent($tree_builder);
  37    }
  38  
  39    protected function _compileSourceFileName($file, $compiler)
  40    {
  41      $this->sourcefile = $compiler->getTemplateLocator()->locateSourceTemplate($file);
  42  
  43      if (empty($this->sourcefile))
  44         $this->raiseCompilerError('Template source file not found', array('file_name' => $file));
  45  
  46      $compiler->parseTemplate($file, $this);
  47    }
  48  
  49    protected function _makeInsertion($wrapper, $tree_builder, $raise_error = false)
  50    {
  51      if(($insertionId = $this->getAttribute('insertat')) || ($insertionId = $this->getAttribute('in')))
  52        $this->insert($wrapper, $tree_builder, $insertionId);
  53      else
  54      {
  55        if(($insertionId = $this->getAttribute('replaceat')) || ($insertionId = $this->getAttribute('as')))
  56          $this->replace($wrapper, $tree_builder, $insertionId);
  57        elseif($raise_error)
  58         $this->raiseRequiredAttributeError('insertat or replaceat(in or as)');
  59      }
  60    }
  61  
  62    protected function _makeInsertionIntoParent($tree_builder)
  63    {
  64      $parent = $this->findParentByClass('WactCoreWrapTag');
  65      if(!$parent || !$parent->sourcefile)
  66        $this->raiseRequiredAttributeError('file');
  67  
  68      $this->_makeInsertion($parent, $tree_builder, true, $this->location_in_template);
  69    }
  70  
  71    function insert($wrapper, $tree_builder, $point)
  72    {
  73      $this->_insertOrReplace($wrapper, $tree_builder, $point, $replace = false);
  74    }
  75  
  76    function replace($wrapper, $tree_builder, $point)
  77    {
  78      $this->_insertOrReplace($wrapper, $tree_builder, $point, $replace = true);
  79    }
  80  
  81    protected function _insertOrReplace($wrapper, $tree_builder, $point, $replace = false)
  82    {
  83      $insertionPoint = $wrapper->findChild($point);
  84      if (empty($insertionPoint))
  85      {
  86          $params = array('placeholder' => $point);
  87          if($wrapper !== $this)
  88          {
  89            $params['parent_wrap_tag_file'] = $wrapper->getTemplateFile();
  90            $params['parent_wrap_tag_line'] = $wrapper->getTemplateLine();
  91          }
  92  
  93          $this->raiseCompilerError('Wrap placeholder not found', $params);
  94      }
  95  
  96      if($replace)
  97        $insertionPoint->removeChildren();
  98  
  99      $tree_builder->pushCursor($insertionPoint, $this->location_in_template);
 100    }
 101  }
 102  ?>


Generated: Mon Dec 1 03:56:46 2008 Cross-referenced by PHPXref 0.7