Blame view

mobile/source/ext/phptal/PHPTAL/Php/Attribute/PHPTAL/Id.php 1.57 KB
a1684257   Administrator   first commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
  <?php
  /**
   * PHPTAL templating engine
   *
   * PHP Version 5
   *
   * @category HTML
   * @package  PHPTAL
   * @author   Laurent Bedubourg <lbedubourg@motion-twin.com>
   * @author   Kornel LesiƄski <kornel@aardvarkmedia.co.uk>
   * @license  http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
   * @version  SVN: $Id: Id.php 671 2009-07-11 18:11:35Z kornel $
   * @link     http://phptal.org/
   */
  /**
   * @package PHPTAL
   * @subpackage Php.attribute.phptal
   * @author Laurent Bedubourg <lbedubourg@motion-twin.com>
   */
  class PHPTAL_Php_Attribute_PHPTAL_ID extends PHPTAL_Php_Attribute
  {
      private $var;
      public function before(PHPTAL_Php_CodeWriter $codewriter)
      {
          // retrieve trigger
          $this->var = $codewriter->createTempVariable();
  
          $codewriter->doSetVar(
              $this->var,
              '$tpl->getTrigger('.$codewriter->str($this->expression).')'
          );
  
          // if trigger found and trigger tells to proceed, we execute
          // the node content
          $codewriter->doIf($this->var.' &&
              '.$this->var.'->start('.$codewriter->str($this->expression).', $tpl) === PHPTAL_Trigger::PROCEED');
      }
  
      public function after(PHPTAL_Php_CodeWriter $codewriter)
      {
          // end of if PROCEED
          $codewriter->doEnd('if');
  
          // if trigger found, notify the end of the node
          $codewriter->doIf($this->var);
          $codewriter->pushCode(
              $this->var.'->end('.$codewriter->str($this->expression).', $tpl)'
          );
          $codewriter->doEnd('if');
          $codewriter->recycleTempVariable($this->var);
      }
  }