Skip to content

Commit

Permalink
Use MoufTwigEnvironment instead of TwigEnvironment
Browse files Browse the repository at this point in the history
  • Loading branch information
xhuberty committed Apr 20, 2015
1 parent fd20503 commit 599823c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
32 changes: 19 additions & 13 deletions src/Mouf/Html/Renderer/FileBasedRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,26 @@ class FileBasedRenderer implements ChainableRendererInterface {
* @param string $type The type of the renderer. Should be one of "custom", "template" or "package". Defaults to "custom" (see ChainableRendererInterface for more details)
* @param number $priority The priority of the renderer (within its type)
*/
public function __construct($directory = "src/templates", CacheInterface $cacheService = null, $type = "custom", $priority = 0) {
public function __construct($directory = "src/templates", CacheInterface $cacheService = null, $type = "custom", $priority = 0, \Twig_Environment $twig = null) {
$this->directory = trim($directory, '/\\');
$this->cacheService = $cacheService;
$this->type = $type;
$this->priority = $priority;

$loader = new \Twig_Loader_Filesystem(ROOT_PATH.$this->directory);
$this->twig = new \Twig_Environment($loader, array(
// The cache directory is in the temporary directory and reproduces the path to the directory (to avoid cache conflict between apps).
'cache' => rtrim(sys_get_temp_dir(),'/\\').'/mouftwigtemplatemain_'.str_replace(":", "", ROOT_PATH).$this->directory,
'auto_reload' => true,
'debug' => true
));
$this->twig->addExtension(new MoufTwigExtension(MoufManager::getMoufManager()));
$this->twig->addExtension(new \Twig_Extension_Debug());

if ($twig === null) {
$loader = new \Twig_Loader_Filesystem(ROOT_PATH.$this->directory);

$this->twig = new \Twig_Environment($loader, array(
// The cache directory is in the temporary directory and reproduces the path to the directory (to avoid cache conflict between apps).
'cache' => rtrim(sys_get_temp_dir(),'/\\').'/mouftwigtemplatemain_'.str_replace(":", "", ROOT_PATH).$this->directory,
'auto_reload' => true,
'debug' => true
));
$this->twig->addExtension(new MoufTwigExtension(MoufManager::getMoufManager()));
$this->twig->addExtension(new \Twig_Extension_Debug());
} else {
$this->twig = $twig;
}
}

/**
Expand Down Expand Up @@ -243,7 +248,8 @@ private function findFile($className, $context) {
}

return false;
}
}

/* (non-PHPdoc)
* @see \Mouf\Html\Renderer\ChainableRendererInterface::getRendererType()
*/
Expand All @@ -257,5 +263,5 @@ public function getRendererType() {
public function getPriority() {
return $this->priority;
}


}
1 change: 1 addition & 0 deletions src/Mouf/Html/Renderer/RendererUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public static function createPackageRenderer(MoufManager $moufManager, $packageN
$renderer->getProperty("cacheService")->setValue($moufManager->getInstanceDescriptor("rendererCacheService"));
$renderer->getProperty("type")->setValue(ChainableRendererInterface::TYPE_PACKAGE);
$renderer->getProperty("priority")->setValue($priority);
$renderer->getProperty("twig")->setValue($moufManager->getInstanceDescriptor("twigEnvironment"));
}
}
}
1 change: 1 addition & 0 deletions src/install.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
$customRenderer->getProperty("cacheService")->setValue($rendererCacheService);
$customRenderer->getProperty("type")->setValue(ChainableRendererInterface::TYPE_CUSTOM);
$customRenderer->getProperty("priority")->setValue(0);
$customRenderer->getProperty("twig")->setValue($moufManager->getInstanceDescriptor("twigEnvironment"));

$defaultRenderer = InstallUtils::getOrCreateInstance("defaultRenderer", "Mouf\\Html\\Renderer\\AutoChainRenderer", $moufManager);
$defaultRenderer->getProperty("cacheService")->setValue($rendererCacheService);
Expand Down

0 comments on commit 599823c

Please sign in to comment.