<?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
*/

/**
* A property representing a constant value.
*/
class Wact_Template_Compiler_Expression_Node_Dereference extends Wact_Template_Compiler_Expression_Node_Unary {
    
    private $path;
    
    function __construct($operand, $path) {
        parent::__construct($operand);
        $this->path = $path;
    }

    /**
    * Return this value as a PHP value
    * @return String
    */
    function getValue() {
        if ($this->operand->isConstant()) {
            return Wact_Property_Binder::getPath($this->operand->getValue(), $this->path);
        } else {
            parent::getValue();
        }
    }

    /**
    * 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) {
        
        // We might be able to optimize this to select either get or getPath
        
        $code->writePHP('Wact_Property_Binder::getPath(');
        $this->operand->generateExpression($code);
        $code->writePHP(', '. var_export($this->path, TRUE) . ')');
    }
    
}

?>