function testIt()
 {
     $dummy = new DummyObjectX();
     $dummy->foo = null;
     $res = PHPTAL_Context::path($dummy, 'method');
     $this->assertEquals('__call', $res);
     $res = phptal_path($dummy, 'foo');
     $this->assertEquals(null, $res);
 }
Example #2
0
/** 
 * Returns true if $path can be fully resolved in $ctx context. 
 */
function phptal_exists($ctx, $path)
{
    // special note: this method may requires to be extended to a full
    // phptal_path() sibling to avoid calling latest path part if it is a
    // method or a function...
    $ctx->noThrow(true);
    $res = phptal_path($ctx, $path, true);
    $ctx->noThrow(false);
    return $res !== NULL;
}
Example #3
0
 /**
  * Handles variable accesses for the tal path resolver
  *
  * @param $var String   The variable name to check
  * @return Mixed    An object/array if the path is not over or a boolean
  *
  * @todo    replace the phptal_path() with custom code
  */
 public function __get($var)
 {
     // When the iterator item is empty we just let the tal
     // expression consume by continuously returning this
     // same object which should evaluate to true for 'last'
     if (is_null($this->data)) {
         return $this;
     }
     // Find the requested variable
     $value = @phptal_path($this->data, $var, true);
     // Check if it's an object or an array
     if (is_array($value) || is_object($value)) {
         // Move the context to the requested variable and return
         $this->data = $value;
         $this->addVarName($var);
         return $this;
     }
     // get a hash of the variable contents
     $hash = md5($value);
     // compute a path for the variable to use as dictionary key
     $path = $this->branch . $this->getVarPath() . $var;
     // If we don't know about this var store in the dictionary
     if (!isset($this->cache[$path])) {
         if (!isset($this->dict[$path])) {
             $this->dict[$path] = $hash;
             $res = $this->branch === 'F';
         } else {
             // Check if the value has changed
             if ($this->dict[$path] !== $hash) {
                 $this->dict[$path] = $hash;
                 $res = true;
             } else {
                 $res = false;
             }
         }
         $this->cache[$path] = $res;
     }
     return $this->cache[$path];
 }