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); }
/** * Handles variable accesses for the tal path resolver * * @param string $var The variable name to check * * @return Mixed An object/array if the path is not over or a boolean * * @todo replace the PHPTAL_Context::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_Context::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]; }
/** * @see PHPTAL_Context::path() * @deprecated */ function phptal_path($base, $path, $nothrow = false) { return PHPTAL_Context::path($base, $path, $nothrow); }
function testZeroIndex() { $data = array(1, 0, 3); $result = PHPTAL_Context::path($data, '0'); $this->assertEquals(1, $result); }