Example #1
0
 /**
  * Create new FigDice view.
  *
  * @param string $templatesPath Path to templates directory
  * @param array $settings environment settings
  */
 public function __construct($templatesPath = '.', $settings = array())
 {
     $this->view = new \figdice\View();
     $this->settings = $settings;
     $this->templatesPath = $templatesPath;
     array_key_exists('cache.path', $settings) ? $this->view->setTempPath($settings['cache.path']) : $this->view->setTempPath(sys_get_temp_dir());
 }
Example #2
0
    public function testDictionaryCompiler()
    {
        vfsStream::setup('root');
        $dic = <<<DIC
<fig:dictionary xmlns:fig="http://figdice.org/" language="fr">
  <entry key="foo">bar</entry>
  <entry key="David">Bowie</entry>
</fig:dictionary>
DIC;
        $vDicFile = vfsStream::newFile('en/dic.xml')->at(vfsStreamWrapper::getRoot());
        $vDicFile->withContent($dic);
        $target = vfsStream::url('root/Dictionary/en/dic.xml.php');
        $compilationResult = Dictionary::compile(vfsStream::url($vDicFile->path()), $target);
        $this->assertTrue($compilationResult);
        $this->assertFileExists($target);
        $this->assertEquals('a:2:{s:3:"foo";s:3:"bar";s:5:"David";s:5:"Bowie";}', file_get_contents($target));
        // Test the loading of a pre-compiled dictionary:
        $view = new View();
        // Indicate where the source dictionary is located
        $view->setTranslationPath(vfsStream::url('root'));
        // Indicate where the compiled dictionaries are located.
        $view->setTempPath(vfsStream::url('root'));
        $viewString = <<<ENDTEMPLATE
<fig:template>
  <fig:dictionary file="dic.xml" />
  <fig:trans key="David"/>
</fig:template>
ENDTEMPLATE;
        $view->loadString($viewString);
        $view->setLanguage('en');
        $this->assertEquals('Bowie', trim($view->render()));
    }