Skip to content

Commit

Permalink
Merge pull request #6 from xhuberty/1.1
Browse files Browse the repository at this point in the history
Use MoufTwigEnvironment instead of TwigEnvironment
  • Loading branch information
moufmouf committed Apr 20, 2015
2 parents fd20503 + dfa7d21 commit 25a5f32
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 21 deletions.
48 changes: 27 additions & 21 deletions src/Mouf/Html/Renderer/FileBasedRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,29 +51,34 @@ class FileBasedRenderer implements ChainableRendererInterface {
private $debugMode;

private $debugStr;
/**
*
* @param string $directory The directory of the templates, relative to the project root. Does not start and does not finish with a /
* @param CacheInterface $cacheService This service is used to speed up the mapping between the object and the template.
* @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) {

/**
* @param string $directory The directory of the templates, relative to the project root. Does not start and does not finish with a /
* @param CacheInterface $cacheService This service is used to speed up the mapping between the object and the template.
* @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 int $priority The priority of the renderer (within its type)
* @param \Twig_Environment $twig The twig environment, which is optional (by default we will use the one from the twig librairy), but we will prefer the Mouf one.
*/
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 25a5f32

Please sign in to comment.