示例#1
0
 /**
  * initialise
  *
  * @return  void
  */
 public function initialise()
 {
     // A workaround before Windwalker Loader fix bug
     class_alias('Windwalker\\Loader\\Loader\\VasemanPsr4Loader', 'Windwalker\\Loader\\Loader\\Psr4Loader');
     $loader = new ClassLoader();
     $loader->register();
     $config = Ioc::getConfig();
     if ($config->get('outer_project') || $config->get('mode') == 'test') {
         $loader->addPsr4('Vaseman\\', $config->get('project.path.data') . '/src');
     }
     parent::initialise();
     GlobalContainer::addExtension('vaseman', new VasemanTwigExtension());
 }
示例#2
0
    /**
     * Method to test addExtension().
     *
     * @return void
     *
     * @covers Windwalker\Renderer\Twig\GlobalContainer::addExtension
     */
    public function testAddExtension()
    {
        GlobalContainer::addExtension('stub', new StubTwigExtension());
        $renderer = new TwigRenderer(__DIR__ . '/Tmpl/twig');
        $html = $renderer->render('ext-test.twig');
        $expect = <<<HTML
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
<p>Suspendisse finibus fermentum massa ut tempus. Sed in pulvinar dolor.</p>
<ul>
\t<li>peace</li>
\t<li>sakura</li>
\t<li>Iron Man</li>
</ul>
HTML;
        $this->assertDomStringEqualsDomString($expect, $html);
        GlobalContainer::removeExtension('stub');
    }
示例#3
0
 /**
  * getTwig
  *
  * @param bool $new
  *
  * @return  \Twig_Environment
  */
 public function getEngine($new = false)
 {
     if (!$this->engine instanceof \Twig_Environment || $new) {
         $this->engine = new \Twig_Environment($this->getLoader(), $this->config->toArray());
         foreach (GlobalContainer::getExtensions() as $extension) {
             $this->engine->addExtension(clone $extension);
         }
         foreach ($this->extensions as $extension) {
             $this->engine->addExtension($extension);
         }
         foreach (GlobalContainer::getGlobals() as $name => $value) {
             $this->engine->addGlobal($name, $value);
         }
         if ($this->config->get('debug')) {
             $this->engine->addExtension($this->getDebugExtension());
         }
     }
     return $this->engine;
 }