<?php
/**
* Web Application Component Toolkit
*
* @link http://www.phpwact.org/
*
* @author Wact Development Team
* @link http://www.phpwact.org/team
*
* @copyright Copyright 2006, Jeff Moore
* @license http://opensource.org/licenses/mit-license.php MIT
*/

/**
* Bind to a parent data model value.
*/
class Wact_Template_Compiler_Expression_Node_Parent extends Wact_Template_Compiler_Expression_Node {
    
    private $name;
    private $count;
    
    function __construct($name, $count = 1) {
        $this->name = $name;
        $this->count = $count;
    }

    /**
    * Does this property refer to a constant value at compile time?
    * @return Boolean
    */
    function isConstant() {
        return FALSE;
    }

    /**
    * Generate the code to read the data value at run time
    * Must generate only a valid PHP Expression.
    * @param Wact_Php_Writer
    * @return void
    */
    function generateExpression($code) {
        $code->writePHP('$this' . str_repeat('->parentScope', $this->count) . '->model->' . $this->name);
    }
    
}

?>