/** * returns PHP code that generates given string, including dynamic replacements */ public function interpolateTalesVarsInString($string) { if ($this->_talesMode == 'tales') { return PHPTAL_Php_TalesInternal::string($string); } // replace ${var} found in expression while (preg_match('/(?<!\\$)\\$\\{([^\\}]+)\\}/s', $string, $m)) { list($ori, $exp) = $m; $php = PHPTAL_Php_TalesInternal::php($exp); $string = str_replace($ori, '\'.' . $php . '.\'', $string); // FIXME: that is not elegant } $string = str_replace('$${', '${', $string); // FIXME: that is not elegant return '\'' . $string . '\''; }
function testDoubleVar() { $res = PHPTAL_Php_TalesInternal::string('hello $foo $bar'); $this->assertRegExp('/ctx->foo/', $res, '$foo not interpolated'); $this->assertRegExp('/ctx->bar/', $res, '$bar not interpolated'); }