本文整理汇总了PHP中Twig_Environment::setCharset方法的典型用法代码示例。如果您正苦于以下问题:PHP Twig_Environment::setCharset方法的具体用法?PHP Twig_Environment::setCharset怎么用?PHP Twig_Environment::setCharset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Twig_Environment
的用法示例。
在下文中一共展示了Twig_Environment::setCharset方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testReverseFilterOnNonUTF8String
public function testReverseFilterOnNonUTF8String()
{
$twig = new Twig_Environment($this->getMock('Twig_LoaderInterface'));
$twig->setCharset('ISO-8859-1');
$input = iconv('UTF-8', 'ISO-8859-1', 'Äé');
$output = iconv('ISO-8859-1', 'UTF-8', twig_reverse_filter($twig, $input));
$this->assertEquals($output, 'éÄ');
}
示例2: testReverseFilterOnNonUTF8String
public function testReverseFilterOnNonUTF8String()
{
if (!function_exists('iconv') && !function_exists('mb_convert_encoding')) {
$this->markTestSkipped('needs iconv or mbstring');
}
$twig = new Twig_Environment($this->getMock('Twig_LoaderInterface'));
$twig->setCharset('ISO-8859-1');
$input = twig_convert_encoding('Äé', 'ISO-8859-1', 'UTF-8');
$output = twig_convert_encoding(twig_reverse_filter($twig, $input), 'UTF-8', 'ISO-8859-1');
$this->assertEquals($output, 'éÄ');
}
示例3: getLoader
return $context;
}
class myRenderer extends sfTemplateRendererTwig
{
public function getLoader()
{
return $this->loader;
}
public function getEnvironment()
{
return $this->environment;
}
}
}
$t = new lime_test();
$t->diag('->__construct()');
$renderer = new myRenderer();
$t->is(get_class($renderer->getLoader()), 'Twig_Loader_String', '->__construct() creates an instance of "Twig_Loader_String" automatically');
$t->is($renderer->getEnvironment()->getCharset(), 'UTF-8', '->__construct() creates an instance of "Twig_Environment" automatically');
$loader = new Twig_Loader_Filesystem('./');
$environment = new Twig_Environment($loader);
$environment->setCharset('Shift_JIS');
$renderer = new myRenderer($loader, $environment);
$t->is(get_class($renderer->getLoader()), 'Twig_Loader_Filesystem', '->__construct() uses the specified instance of "Twig_Loader_Filesystem"');
$t->is($renderer->getEnvironment()->getCharset(), 'Shift_JIS', '->__construct() uses the specified instance of "Twig_Environment"');
$t->diag('->evaluate()');
$fixtureDir = realpath(dirname(__FILE__) . '/../fixtures');
$renderer = new sfTemplateRendererTwig();
$t->is($renderer->evaluate(new sfTemplateStorageString('Kousuke')), 'Kousuke', '->evaluate() returns string from the sfTemplateStorageString');
$t->is($renderer->evaluate(new sfTemplateStorageFile($fixtureDir . '/template/twig.tpl')), file_get_contents($fixtureDir . '/template/twig.tpl'), '->evaluate() returns string from the sfTemplateStorageFile');
$t->is($renderer->evaluate(new sfTemplateStorageString('{{ name }}'), array('name' => 'Ebihara')), 'Ebihara', '->evaluate() returns string from the sfTemplateStorageString and the parameters');