Permalink
Browse files

add new method resolvePath - that enables quering of where the templa…

…te physicaly resides

git-svn-id: http://svn.php.net/repository/pear/packages/HTML_Template_Flexy/trunk@327241 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information...
1 parent 585b6e8 commit 038e3b1d11b3670e5aa3f5495fd4a1094d9a77f2 @roojs roojs committed Aug 23, 2012
Showing with 49 additions and 27 deletions.
  1. +49 −27 HTML/Template/Flexy.php
View
@@ -260,9 +260,37 @@ function HTML_Template_Flexy( $options=array() )
}
-
+ /**
+ * given a file, return the possible templates that will becompiled.
+ *
+ * @param string $file the template to look for.
+ * @return string|PEAR_Error $directory
+ */
-
+ function resolvePath ( $file )
+ {
+ $dirs = array_unique($this->options['templateDir']);
+ if ($this->options['templateDirOrder'] == 'reverse') {
+ $dirs = array_reverse($dirs);
+ }
+ $ret = false;
+ foreach ($dirs as $tmplDir) {
+ if (@!file_exists($tmplDir . DIRECTORY_SEPARATOR .$file)) {
+ continue;
+ }
+
+ if (!$this->options['multiSource'] && ($ret !== false)) {
+ return $this->raiseError("You have more than one template Named {$file} in your paths, found in both".
+ "<BR>{$this->currentTemplate }<BR>{$tmplDir}" . DIRECTORY_SEPARATOR . $file,
+ HTML_TEMPLATE_FLEXY_ERROR_INVALIDARGS , HTML_TEMPLATE_FLEXY_ERROR_DIE);
+ }
+
+ $ret = $tmplDir;
+
+ }
+ return $ret;
+
+ }
/**
@@ -306,38 +334,32 @@ function compile( $file )
if (preg_match('/(.*)(\.[a-z]+)$/i',$file,$parts)) {
$newfile = $parts[1].'.'.$this->options['locale'] .$parts[2];
- foreach ($this->options['templateDir'] as $tmplDir) {
- if (@!file_exists($tmplDir . DIRECTORY_SEPARATOR .$newfile)) {
- continue;
- }
- $file = $newfile;
- $this->currentTemplate = $tmplDir . DIRECTORY_SEPARATOR .$newfile;
- $tmplDirUsed = $tmplDir;
+ $match = $this->resolvePath($newfile);
+ if (is_a($match, 'PEAR_Error')) {
+ return $match;
+ }
+ if (false !== $match ) {
+ $this->currentTemplate = $match . DIRECTORY_SEPARATOR .$newfile;
+ $tmplDirUsed = $match;
}
+
+
}
// look in all the posible locations for the template directory..
if ($this->currentTemplate === false) {
- $dirs = array_unique($this->options['templateDir']);
- if ($this->options['templateDirOrder'] == 'reverse') {
- $dirs = array_reverse($dirs);
+
+
+ $match = $this->resolvePath($file);
+
+ if (is_a($match, 'PEAR_Error')) {
+ return $match;
}
- foreach ($dirs as $tmplDir) {
- if (!@file_exists($tmplDir . DIRECTORY_SEPARATOR . $file)) {
- continue;
- }
-
-
- if (!$this->options['multiSource'] && ($this->currentTemplate !== false)) {
- return $this->raiseError("You have more than one template Named {$file} in your paths, found in both".
- "<BR>{$this->currentTemplate }<BR>{$tmplDir}" . DIRECTORY_SEPARATOR . $file,
- HTML_TEMPLATE_FLEXY_ERROR_INVALIDARGS , HTML_TEMPLATE_FLEXY_ERROR_DIE);
-
- }
-
- $this->currentTemplate = $tmplDir . DIRECTORY_SEPARATOR . $file;
- $tmplDirUsed = $tmplDir;
+ if (false !== $match ) {
+ $this->currentTemplate = $match . DIRECTORY_SEPARATOR .$file;
+ $tmplDirUsed = $match;
}
+
}
if ($this->currentTemplate === false) {
// check if the compile dir has been created

0 comments on commit 038e3b1

Please sign in to comment.