Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

- Fix bug #12243: PEAR_Errors not returned from halt()

- Add new "return" haltOnError level
- Respect haltOnError settings
- unsetVar() + tests
- clearVar()


git-svn-id: http://svn.php.net/repository/pear/packages/HTML_Template_PHPLIB/trunk@253886 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information...
commit 77e6e402f4829d420450f91c352c02a953184670 1 parent a8e5c85
@cweiske cweiske authored
View
84 HTML/Template/PHPLIB.php
@@ -78,9 +78,10 @@ class HTML_Template_PHPLIB
var $unknowns = 'remove';
/**
- * 'yes' => halt,
+ * 'yes' => halt,
* 'report' => report error, continue,
- * 'no' => ignore error quietly
+ * 'return' => return PEAR_Error object,
+ * 'no' => ignore error quietly
* @var string
*/
var $haltOnError = 'report';
@@ -182,8 +183,7 @@ function exists($var)
function setRoot($root)
{
if (!is_dir($root)) {
- $this->halt('setRoot: ' . $root . ' is not a directory.');
- return false;
+ return $this->halt('setRoot: ' . $root . ' is not a directory.');
}
$this->root = $root;
@@ -233,9 +233,10 @@ function setFile($handle, $filename = '')
if (!is_array($handle)) {
if ($filename == '') {
- $this->halt('setFile: For handle '
- . $handle . ' filename is empty.');
- return false;
+ return $this->halt(
+ 'setFile: For handle '
+ . $handle . ' filename is empty.'
+ );
}
$this->file[$handle] = $this->_filename($filename);
@@ -282,8 +283,9 @@ function setFile($handle, $filename = '')
function setBlock($parent, $handle, $name = '')
{
if (!$this->_loadFile($parent)) {
- $this->halt('setBlock: unable to load ' . $parent . '.');
- return false;
+ return $this->halt(
+ 'setBlock: unable to load ' . $parent . '.'
+ );
}
if ($name == '') {
@@ -356,8 +358,7 @@ function setVar($varname, $value = '', $append = false)
function subst($handle)
{
if (!$this->_loadFile($handle)) {
- $this->halt('subst: unable to load ' . $handle . '.');
- return false;
+ return $this->halt('subst: unable to load ' . $handle . '.');
}
return @str_replace($this->_varKeys,
@@ -487,8 +488,7 @@ function getVar($varname)
function getUndefined($handle)
{
if (!$this->_loadFile($handle)) {
- $this->halt('getUndefined: unable to load ' . $handle);
- return false;
+ return $this->halt('getUndefined: unable to load ' . $handle);
}
preg_match_all("/{([^ \t\r\n}]+)}/", $this->getVar($handle), $m);
@@ -577,7 +577,10 @@ function _filename($filename)
$filename = $this->root . '/' . $filename;
}
- if (file_exists($filename)) return $filename;
+ if (file_exists($filename)) {
+ return $filename;
+ }
+
if (is_array($this->file_fallbacks) && count($this->file_fallbacks) > 0) {
reset($this->file_fallbacks);
while (list(,$v) = each($this->file_fallbacks)) {
@@ -585,18 +588,16 @@ function _filename($filename)
return $v.basename($filename);
}
}
- $this->halt(sprintf(
+ return $this->halt(sprintf(
'filename: file %s does not exist in the fallback paths %s.',
$filename,
implode(',', $this->file_fallbacks)
));
- return false;
} else {
- $this->halt(sprintf('filename: file %s does not exist.', $filename));
- return false;
+ return $this->halt(
+ sprintf('filename: file %s does not exist.', $filename)
+ );
}
-
- return $filename;
}
@@ -647,8 +648,7 @@ function _loadFile($handle)
}
if (!isset($this->file[$handle])) {
- $this->halt('loadfile: ' . $handle . ' is not a valid handle.');
- return false;
+ return $this->halt('loadfile: ' . $handle . ' is not a valid handle.');
}
$filename = $this->file[$handle];
@@ -656,8 +656,7 @@ function _loadFile($handle)
$str = file_get_contents($filename);
} else {
if (!$fp = @fopen($filename, 'r')) {
- $this->halt('loadfile: couldn\'t open ' . $filename);
- return false;
+ return $this->halt('loadfile: couldn\'t open ' . $filename);
}
$str = fread($fp, filesize($filename));
@@ -665,9 +664,10 @@ function _loadFile($handle)
}
if ($str == '') {
- $this->halt('loadfile: While loading ' . $handle . ', '
- . $filename . ' does not exist or is empty.');
- return false;
+ return $this->halt(
+ 'loadfile: While loading ' . $handle . ', '
+ . $filename . ' does not exist or is empty.'
+ );
}
$this->setVar($handle, $str);
@@ -687,11 +687,27 @@ function halt($msg)
{
$this->_lastError = $msg;
- if ($this->haltOnError != 'no') {
- return $this->haltMsg($msg);
- }
+ switch ($this->haltOnError) {
+ case 'yes':
+ return $this->haltMsg(
+ $msg, PEAR_ERROR_TRIGGER, E_USER_ERROR
+ );
- return false;
+ case 'report':
+ $this->haltMsg(
+ $msg, PEAR_ERROR_PRINT
+ );
+ return false;
+
+ case 'return':
+ return $this->haltMsg(
+ $msg, PEAR_ERROR_RETURN
+ );
+
+ case 'no':
+ default:
+ return false;
+ }
}
/**
@@ -702,11 +718,13 @@ function halt($msg)
* @return object PEAR error object
* @access public
*/
- function haltMsg($msg)
+ function haltMsg($msg, $mode = null, $level = null)
{
require_once 'PEAR.php';
return PEAR::raiseError(
- '<b>Template Error:</b> ' . $msg . '<br/>'. "\n"
+ '<b>Template Error:</b> ' . $msg . '<br/>'. "\n",
+ null,
+ $mode, $level
);
}
View
12 package.xml
@@ -22,17 +22,19 @@ well as some speed improvements.</description>
<date>2007-10-14</date>
<time>10:15:00</time>
<version>
- <release>1.4.0a3</release>
- <api>1.3.3</api>
+ <release>1.4.1</release>
+ <api>1.4.1</api>
</version>
<stability>
- <release>alpha</release>
+ <release>stable</release>
<api>stable</api>
</stability>
<license uri="http://www.gnu.org/copyleft/lesser.html">LGPL</license>
<notes>
- - Fix bug #12229: broken blocks not detected [cweiske]
- - Validate variables
+<!-- this is for the next release -->
+ - Fix bug #12243: PEAR_Errors not returned from halt()
+ - Add new "return" haltOnError level
+ - Respect haltOnError settings
</notes>
<contents>
<dir name="/">
View
3  tests/HTML_Template_PHPLIBTest.php
@@ -24,7 +24,7 @@ public static function main() {
require_once 'PHPUnit/TextUI/TestRunner.php';
$suite = new PHPUnit_Framework_TestSuite('HTML_Template_PHPLIBTest');
- $result = PHPUnit_TextUI_TestRunner::run($suite);
+ PHPUnit_TextUI_TestRunner::run($suite);
}
/**
@@ -36,6 +36,7 @@ public static function main() {
protected function setUp() {
chdir(dirname(__FILE__) . '/');
$this->tpl = new HTML_Template_PHPLIB('templates');
+ $this->tpl->haltOnError = 'no';
$this->assertFalse($this->tpl->getLastError());
}
Please sign in to comment.
Something went wrong with that request. Please try again.