Commit fc42867d by Seldaek

* Switched to exceptions in many places

git-svn-id: svn://dwoo.org/dwoo/trunk@56 0598d79b-80c4-4d41-97ba-ac86fbbd088b
parent 8610862b
......@@ -8,6 +8,12 @@
! BC Break: $dwoo->getTemplate() changed to $dwoo->templateFactory() and
$dwoo->getCurrentTemplate() changed to $dwoo->getTemplate() for consistency
among all classes and factory functions
+ Added a compiled version of Dwoo that loads faster (especially with opcode
caches such as APC), include Dwoo.compiled.php instead of Dwoo.php on
production but if you want to file a bug use Dwoo.php please as it allows
you to get the proper file/line number where an error occurs. Do not remove
all other files however since they are not all included in the compiled
package
+ Plugins: Added {extends} and {block} to handle template inheritance, read
more about it at http://wiki.dwoo.org/index.php/TemplateInheritance
+ Plugins: Added {loop} that combines {foreach} and {with}, see
......@@ -37,6 +43,10 @@
to define the file mode of all the file/directories Dwoo will write, defaults
to 0777
+ Added a 'data' argument to {include} to be able to feed data directly into it
* The compiler now throws Dwoo_Compilation_Exception exceptions upon failure
and security problems lead to a Dwoo_Security_Exception being thrown. Runtime
plugin errors and such trigger simple php errors to allow the template
execution to complete
* Fixed a potential concurrency issue (thanks to Rasmus Schultz for the patch)
* Moved all files to Dwoo/Class.php excepted for the core Dwoo.php file
* Various performance improvements, including the removal of a lot of isset()
......
......@@ -5,6 +5,7 @@ set_include_path(get_include_path().PATH_SEPARATOR.dirname(__FILE__));
include 'Dwoo/Loader.php';
include 'Dwoo/Exception.php';
include 'Dwoo/Security/Policy.php';
include 'Dwoo/Security/Exception.php';
include 'Dwoo/ICompilable.php';
include 'Dwoo/ICompiler.php';
include 'Dwoo/IDataProvider.php';
......@@ -499,7 +500,7 @@ class Dwoo
elseif(function_exists($class))
$callback = $class;
else
$this->triggerError('Wrong filter name, when using autoload the filter must be in one of your plugin dir as "name.php" containg a class or function named "Dwoo_Filter_name"', E_USER_ERROR);
throw new Dwoo_Exception('Wrong filter name, when using autoload the filter must be in one of your plugin dir as "name.php" containg a class or function named "Dwoo_Filter_name"');
$this->filters[] = $callback;
}
......@@ -829,7 +830,7 @@ class Dwoo
*/
public function triggerError($message, $level=E_USER_NOTICE)
{
trigger_error('Dwoo error: '.$message, $level);
trigger_error('Dwoo error (in '.$this->template->getResourceIdentifier().') : '.$message, $level);
}
/*
......
<?php
/**
* dwoo security exception class
*
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from the use of this software.
*
* This file is released under the LGPL
* "GNU Lesser General Public License"
* More information can be found here:
* {@link http://www.gnu.org/copyleft/lesser.html}
*
* @author Jordi Boggiano <j.boggiano@seld.be>
* @copyright Copyright (c) 2008, Jordi Boggiano
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
* @link http://dwoo.org/
* @version 0.3.4
* @date 2008-04-09
* @package Dwoo
*/
class Dwoo_Security_Exception extends Dwoo_Exception
{
}
......@@ -46,13 +46,13 @@ class Dwoo_Plugin_foreach extends Dwoo_Block_Plugin implements Dwoo_ICompilable_
$val = $params['key'];
}
else
$compiler->triggerError('Foreach <em>item</em> parameter missing', E_USER_ERROR);
throw new Dwoo_Compilation_Exception('Foreach <em>item</em> parameter missing');
$name = $params['name'];
if(substr($val,0,1) !== '"' && substr($val,0,1) !== '\'')
$compiler->triggerError('Foreach <em>item</em> parameter must be of type string', E_USER_ERROR);
throw new Dwoo_Compilation_Exception('Foreach <em>item</em> parameter must be of type string');
if(isset($key) && substr($val,0,1) !== '"' && substr($val,0,1) !== '\'')
$compiler->triggerError('Foreach <em>key</em> parameter must be of type string', E_USER_ERROR);
throw new Dwoo_Compilation_Exception('Foreach <em>key</em> parameter must be of type string');
// evaluates which global variables have to be computed
$varName = '$dwoo.foreach.'.trim($name, '"\'').'.';
......
......@@ -105,7 +105,7 @@ class Dwoo_Plugin_if extends Dwoo_Block_Plugin implements Dwoo_ICompilable_Block
next($params);
}
else
$compiler->triggerError('If : Syntax error : syntax should be "if $a is [not] div by $b", found '.$params[$k-1].' is '.($negate?'not ':'').'div '.$params[$k+$ptr+1].' '.$params[$k+$ptr+2], E_USER_ERROR);
throw new Dwoo_Compilation_Exception('If : Syntax error : syntax should be "if $a is [not] div by $b", found '.$params[$k-1].' is '.($negate?'not ':'').'div '.$params[$k+$ptr+1].' '.$params[$k+$ptr+2]);
break;
case '"even"':
$a = array_pop($p);
......@@ -138,7 +138,7 @@ class Dwoo_Plugin_if extends Dwoo_Block_Plugin implements Dwoo_ICompilable_Block
next($params);
break;
default:
$compiler->triggerError('If : Syntax error : syntax should be "if $a is [not] (div|even|odd) [by $b]", found '.$params[$k-1].' is '.$params[$k+$ptr+1], E_USER_ERROR);
throw new Dwoo_Compilation_Exception('If : Syntax error : syntax should be "if $a is [not] (div|even|odd) [by $b]", found '.$params[$k-1].' is '.$params[$k+$ptr+1]);
}
break;
case '"%"':
......
......@@ -43,7 +43,7 @@ class Dwoo_Plugin_extends extends Dwoo_Plugin implements Dwoo_ICompilable
{
if($file === '""' || $file === "''" || (substr($file, 0, 1) !== '"' && substr($file, 0, 1) !== '"'))
{
$compiler->triggerError('Extends : The file name must be a non-empty string', E_USER_ERROR);
throw new Dwoo_Compilation_Exception('Extends : The file name must be a non-empty string');
return;
}
......@@ -63,7 +63,7 @@ class Dwoo_Plugin_extends extends Dwoo_Plugin implements Dwoo_ICompilable
while(true)
{
if(preg_match('{^([a-z]+?)://}i', $identifier))
return $compiler->triggerError('The security policy prevents you to read files from external sources.', E_USER_ERROR);
throw new Dwoo_Security_Exception('The security policy prevents you to read files from external sources.');
$identifier = realpath($identifier);
$dirs = $policy->getAllowedDirectories();
......@@ -72,25 +72,25 @@ class Dwoo_Plugin_extends extends Dwoo_Plugin implements Dwoo_ICompilable
if(strpos($identifier, $dir) === 0)
break 2;
}
return $compiler->triggerError('The security policy prevents you to read <em>'.$identifier.'</em>', E_USER_ERROR);
throw new Dwoo_Security_Exception('The security policy prevents you to read <em>'.$identifier.'</em>');
}
}
try {
$parent = $compiler->getDwoo()->templateFactory($resource, $identifier);
} catch (Dwoo_Exception $e) {
$compiler->triggerError('Extends : Resource <em>'.$resource.'</em> was not added to Dwoo, can not include <em>'.$identifier.'</em>', E_USER_ERROR);
throw new Dwoo_Compilation_Exception('Extends : Resource <em>'.$resource.'</em> was not added to Dwoo, can not include <em>'.$identifier.'</em>');
}
if($parent === null)
$compiler->triggerError('Extends : Resource "'.$resource.':'.$identifier.'" was not found.', E_USER_ERROR);
throw new Dwoo_Compilation_Exception('Extends : Resource "'.$resource.':'.$identifier.'" was not found.');
elseif($parent === false)
$compiler->triggerError('Extends : Extending "'.$resource.':'.$identifier.'" was not allowed for an unknown reason.', E_USER_ERROR);
throw new Dwoo_Compilation_Exception('Extends : Extending "'.$resource.':'.$identifier.'" was not allowed for an unknown reason.');
$newParent = array('source'=>$parent->getSource(), 'resource'=>$resource, 'identifier'=>$identifier, 'uid'=>$parent->getUid());
if(array_search($newParent, $inheritanceTree, true) !== false)
{
$compiler->triggerError('Extends : Recursive template inheritance detected', E_USER_ERROR);
throw new Dwoo_Compilation_Exception('Extends : Recursive template inheritance detected');
}
$inheritanceTree[] = $newParent;
......
......@@ -41,7 +41,7 @@ function Dwoo_Plugin_include(Dwoo $dwoo, $file, $cache_time = null, $cache_id =
while(true)
{
if(preg_match('{^([a-z]+?)://}i', $identifier))
return $dwoo->triggerError('The security policy prevents you to read files from external sources.', E_USER_WARNING);
throw new Dwoo_Security_Exception('The security policy prevents you to read files from external sources : <em>'.$identifier.'</em>.');
$identifier = realpath($identifier);
$dirs = $policy->getAllowedDirectories();
......@@ -50,7 +50,7 @@ function Dwoo_Plugin_include(Dwoo $dwoo, $file, $cache_time = null, $cache_id =
if(strpos($identifier, $dir) === 0)
break 2;
}
return $dwoo->triggerError('The security policy prevents you to read <em>'.$identifier.'</em>', E_USER_WARNING);
throw new Dwoo_Security_Exception('The security policy prevents you to read <em>'.$identifier.'</em>');
}
}
......
......@@ -111,7 +111,7 @@ function Dwoo_Plugin_math_compile(Dwoo_Compiler $compiler, $equation, $format=''
}
// parse error if we've consumed the entire equation without finding anything valid
elseif ($ptr >= strlen($equation)) {
$compiler->triggerError('Math : Syntax error or variable undefined in equation '.$equationSrc.' at '.$substr, E_USER_ERROR);
throw new Dwoo_Compilation_Exception('Math : Syntax error or variable undefined in equation '.$equationSrc.' at '.$substr);
return;
}
else
......
......@@ -54,7 +54,7 @@ class Dwoo_Processor_smarty_compat extends Dwoo_Processor
);
if(preg_match('{\|@([a-z][a-z0-9_]*)}i', $input, $matches))
$this->compiler->triggerError('The Smarty Compatibility Module has detected that you use |@'.$matches[1].' in your template, this might lead to problems as Dwoo interprets the @ operator differently than Smarty, see http://wiki.dwoo.org/index.php/Syntax#The_.40_Operator', E_USER_NOTICE);
trigger_error('The Smarty Compatibility Module has detected that you use |@'.$matches[1].' in your template, this might lead to problems as Dwoo interprets the @ operator differently than Smarty, see http://wiki.dwoo.org/index.php/Syntax#The_.40_Operator', E_USER_NOTICE);
return preg_replace($smarty, $dwoo, $input);
}
......@@ -73,7 +73,7 @@ class Dwoo_Processor_smarty_compat extends Dwoo_Processor
$params['altcontent'] = $matches[14];
if(empty($params['name']))
$this->compiler->triggerError('Missing parameter <em>name</em> for section tag');
throw new Dwoo_Compilation_Exception('Missing parameter <em>name</em> for section tag');
$name = $params['name'];
if(isset($params['loop']))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment