Commit 8610862b by Seldaek

* Split up all classes into their respective Prefix/Name.php files

+ Added a compiled version of Dwoo that loads faster, 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 git-svn-id: svn://dwoo.org/dwoo/trunk@55 0598d79b-80c4-4d41-97ba-ac86fbbd088b
parent b076166a
<?php
/**
* base class for block plugins
*
* you have to implement the <em>init()</em> method, it will receive the parameters that
* are in the template code and is called when the block starts
*
* 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
*/
abstract class Dwoo_Block_Plugin extends Dwoo_Plugin
{
/**
* stores the contents of the block while it runs
*
* @var string
*/
protected $buffer = '';
/**
* buffers input, override only if necessary
*
* @var string $input the content that must be buffered
*/
public function buffer($input)
{
$this->buffer .= $input;
}
// initialization code, receives the parameters from {block param1, param2}
// public function init($arg, $arg, ...);
/**
* called when the block ends, this is most of the time followed right away by a call
* of <em>process()</em> but not always, so this should be used to do any shutdown operations on the
* block object, if required.
*/
public function end()
{
}
/**
* called when the block output is required by a parent block
*
* this must read $this->buffer and return it processed
*
* @return string
*/
public function process()
{
return $this->buffer;
}
/**
* called at compile time to define what the block should output in the compiled template code, happens when the block is declared
*
* basically this will replace the {block arg arg arg} tag in the template
*
* @param Dwoo_Compiler $compiler the compiler instance that calls this function
* @param array $params an array containing original and compiled parameters
* @param string $prepend that is just meant to allow a child class to call
* parent::postProcessing($compiler, $params, "foo();") to add a command before the
* default commands are executed
* @param string $append that is just meant to allow a child class to call
* parent::postProcessing($compiler, $params, null, "foo();") to add a command after the
* default commands are executed
* @param string $type the type is the plugin class name used
*/
public static function preProcessing(Dwoo_Compiler $compiler, array $params, $prepend='', $append='', $type)
{
return Dwoo_Compiler::PHP_OPEN.$prepend.'$this->addStack("'.$type.'", array('.implode(', ', $compiler->getCompiledParams($params)).'));'.$append.Dwoo_Compiler::PHP_CLOSE;
}
/**
* called at compile time to define what the block should output in the compiled template code, happens when the block is ended
*
* basically this will replace the {/block} tag in the template
*
* @see preProcessing
* @param Dwoo_Compiler $compiler the compiler instance that calls this function
* @param array $params an array containing original and compiled parameters, see preProcessing() for more details
* @param string $prepend that is just meant to allow a child class to call
* parent::postProcessing($compiler, $params, "foo();") to add a command before the
* default commands are executed
* @param string $append that is just meant to allow a child class to call
* parent::postProcessing($compiler, $params, null, "foo();") to add a command after the
* default commands are executed
*/
public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend='', $append='')
{
return Dwoo_Compiler::PHP_OPEN.$prepend.'$this->delStack();'.$append.Dwoo_Compiler::PHP_CLOSE;
}
}
<?php
/**
* dwoo compilation 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_Compilation_Exception extends Dwoo_Exception
{
}
<?php
include 'Dwoo/Compilation/Exception.php';
/**
* default dwoo compiler class, compiles dwoo templates into php
*
......@@ -2517,26 +2519,3 @@ class Dwoo_Compiler implements Dwoo_ICompiler
trigger_error('Dwoo_Compiler error : '.$message."<br />\r\nNear : ".htmlentities(substr($this->templateSource, max(0, $this->pointer-30), 130)), $level);
}
}
/**
* dwoo compilation 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_Compilation_Exception extends Dwoo_Exception
{
}
<?php
/**
* main dwoo 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_Exception extends Exception
{
}
<?php
/**
* base class for filters
*
* 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
*/
abstract class Dwoo_Filter
{
/**
* the dwoo instance that runs this filter
*
* @var Dwoo
*/
protected $dwoo;
/**
* constructor, if you override it, call parent::__construct($dwoo); or assign
* the dwoo instance yourself if you need it
*
* @param Dwoo $dwoo the dwoo instance that runs this plugin
*/
public function __construct(Dwoo $dwoo)
{
$this->dwoo = $dwoo;
}
/**
* processes the input and returns it filtered
*
* @param string $input the template to process
* @return string
*/
abstract public function process($input);
}
<?php
/**
* interface that represents a compilable plugin
*
* implement this to notify the compiler that this plugin does not need to be loaded at runtime.
*
* to implement it right, you must implement <em>public static function compile(Dwoo_Compiler $compiler, $arg, $arg, ...)</em>,
* which replaces the <em>process()</em> method (that means <em>compile()</em> should have all arguments it requires).
*
* 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
*/
interface Dwoo_ICompilable
{
// this replaces the process function
//public static function compile(Dwoo_Compiler $compiler, $arg, $arg, ...);
}
<?php
/**
* interface that represents a compilable block plugin
*
* implement this to notify the compiler that this plugin does not need to be loaded at runtime.
*
* 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
*/
interface Dwoo_ICompilable_Block
{
}
<?php
/**
* interface that represents a dwoo compiler
*
* while implementing this is enough to interact with Dwoo/Dwoo_Templates, it is not
* sufficient to interact with Dwoo_Plugins, however the main purpose of creating a
* new compiler would be to interact with other/different plugins, that is why this
* interface has been left with the minimum requirements.
*
* 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
*/
interface Dwoo_ICompiler
{
/**
* compiles the provided string down to php code
*
* @param string $templateStr the template to compile
* @return string a compiled php code string
*/
public function compile(Dwoo $dwoo, Dwoo_ITemplate $template);
/**
* adds the custom plugins loaded into Dwoo to the compiler so it can load them
*
* @see Dwoo::addPlugin
* @param array $customPlugins an array of custom plugins
*/
public function setCustomPlugins(array $customPlugins);
/**
* sets the security policy object to enforce some php security settings
*
* use this if untrusted persons can modify templates,
* set it on the Dwoo object as it will be passed onto the compiler automatically
*
* @param Dwoo_Security_Policy $policy the security policy object
*/
public function setSecurityPolicy(Dwoo_Security_Policy $policy = null);
}
<?php
/**
* interface that represents a dwoo data object
*
* 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
*/
interface Dwoo_IDataProvider
{
/**
* returns the data as an associative array that will be used in the template
*
* @return array
*/
public function getData();
}
<?php
/**
* interface that represents a dwoo data object
*
* 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
*/
interface Dwoo_IDataProvider
{
/**
* returns the data as an associative array that will be used in the template
*
* @return array
*/
public function getData();
}
/**
* interface that represents a dwoo template
*
* This software is provided 'as-is', without any express or implied warranty.
......@@ -166,56 +137,3 @@ interface Dwoo_ITemplate
*/
public static function templateFactory(Dwoo $dwoo, $resourceId, $cacheTime = null, $cacheId = null, $compileId = null);
}
/**
* interface that represents a dwoo compiler
*
* while implementing this is enough to interact with Dwoo/Dwoo_Templates, it is not
* sufficient to interact with Dwoo_Plugins, however the main purpose of creating a
* new compiler would be to interact with other/different plugins, that is why this
* interface has been left with the minimum requirements.
*
* 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
*/
interface Dwoo_ICompiler
{
/**
* compiles the provided string down to php code
*
* @param string $templateStr the template to compile
* @return string a compiled php code string
*/
public function compile(Dwoo $dwoo, Dwoo_ITemplate $template);
/**
* adds the custom plugins loaded into Dwoo to the compiler so it can load them
*
* @see Dwoo::addPlugin
* @param array $customPlugins an array of custom plugins
*/
public function setCustomPlugins(array $customPlugins);
/**
* sets the security policy object to enforce some php security settings
*
* use this if untrusted persons can modify templates,
* set it on the Dwoo object as it will be passed onto the compiler automatically
*
* @param Dwoo_Security_Policy $policy the security policy object
*/
public function setSecurityPolicy(Dwoo_Security_Policy $policy = null);
}
<?php
/**
* handles plugin loading and caching of plugins names/paths relationships
*
* 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_Loader
{
/**
* stores the plugin directories
*
* @see addDirectory
* @var array
*/
protected static $paths = array();
/**
* stores the plugins names/paths relationships
* don't edit this on your own, use addDirectory
*
* @see addDirectory
* @var array
* @access protected
*/
public static $classpath = array();
/**
* rebuilds class paths, scans the given directory recursively and saves all paths in the given file
*
* @param string $path the plugin path to scan
* @param string $cacheFile the file where to store the plugin paths cache, it will be overwritten
* @access protected
*/
public static function rebuildClassPathCache($path, $cacheFile)
{
if($cacheFile!==false)
{
$tmp = self::$classpath;
self::$classpath = array();
}
// iterates over all files/folders
$list = glob($path.DIRECTORY_SEPARATOR.'*');
if(is_array($list))
foreach($list as $f)
{
if(is_dir($f))
self::rebuildClassPathCache($f, false);
else
self::$classpath[str_replace(array('function.','block.','modifier.','outputfilter.','filter.','prefilter.','postfilter.','pre.','post.','output.','shared.','helper.'), '', basename($f,'.php'))] = $f;
}
// save in file if it's the first call (not recursed)
if($cacheFile!==false)
{
if(!file_put_contents($cacheFile, '<?php Dwoo_Loader::$classpath = '.var_export(self::$classpath, true).' + Dwoo_Loader::$classpath; ?>'))
throw new Dwoo_Exception('Could not write into '.$cacheFile.', either because the folder is not there (create it) or because of the chmod configuration (please ensure this directory is writable by php)');
self::$classpath += $tmp;
}
}
/**
* loads a plugin file
*
* @param string $class the plugin name, without the Dwoo_Plugin_ prefix
* @param bool $forceRehash if true, the class path caches will be rebuilt if the plugin is not found, in case it has just been added, defaults to true
*/
public static function loadPlugin($class, $forceRehash = true)
{
// a new class was added or the include failed so we rebuild the cache
if(!isset(self::$classpath[$class]) || !include self::$classpath[$class])
{
if($forceRehash)
{
self::rebuildClassPathCache(DWOO_DIRECTORY . 'plugins', DWOO_COMPILE_DIRECTORY . DIRECTORY_SEPARATOR . 'classpath.cache.php');
foreach(self::$paths as $path=>$file)
self::rebuildClassPathCache($path, $file);
if(isset(self::$classpath[$class]))
include self::$classpath[$class];
else
throw new Dwoo_Exception('Plugin <em>'.$class.'</em> can not be found, maybe you forgot to bind it if it\'s a custom plugin ?', E_USER_NOTICE);
}
else
throw new Dwoo_Exception('Plugin <em>'.$class.'</em> can not be found, maybe you forgot to bind it if it\'s a custom plugin ?', E_USER_NOTICE);
}
}
/**
* adds a plugin directory, the plugins found in the new plugin directory
* will take precedence over the other directories (including the default
* dwoo plugin directory), you can use this for example to override plugins
* in a specific directory for a specific application while keeping all your
* usual plugins in the same place for all applications.
*
* TOCOM don't forget that php functions overrides are not rehashed so you
* need to clear the classpath caches by hand when adding those
*
* @param string $pluginDir the plugin path to scan
*/
public static function addDirectory($pluginDir)
{
if(!isset(self::$paths[$pluginDir]))
{
$cacheFile = DWOO_COMPILE_DIRECTORY . DIRECTORY_SEPARATOR . 'classpath-'.substr(strtr($pluginDir, ':/\\.', '----'), strlen($pluginDir) > 80 ? -80 : 0).'.cache.php';
self::$paths[$pluginDir] = $cacheFile;
if(file_exists($cacheFile))
include $cacheFile;
else
Dwoo_Loader::rebuildClassPathCache($pluginDir, $cacheFile);
}
}
}
......@@ -52,260 +52,3 @@ abstract class Dwoo_Plugin
// if my bug entry gets enough interest one day..
// see => http://bugs.php.net/bug.php?id=44043
}
/**
* base class for block plugins
*
* you have to implement the <em>init()</em> method, it will receive the parameters that
* are in the template code and is called when the block starts
*
* 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
*/
abstract class Dwoo_Block_Plugin extends Dwoo_Plugin
{
/**
* stores the contents of the block while it runs
*
* @var string
*/
protected $buffer = '';
/**
* buffers input, override only if necessary
*
* @var string $input the content that must be buffered
*/
public function buffer($input)
{
$this->buffer .= $input;
}
// initialization code, receives the parameters from {block param1, param2}
// public function init($arg, $arg, ...);
/**
* called when the block ends, this is most of the time followed right away by a call
* of <em>process()</em> but not always, so this should be used to do any shutdown operations on the
* block object, if required.
*/
public function end()
{
}
/**
* called when the block output is required by a parent block
*
* this must read $this->buffer and return it processed
*
* @return string
*/
public function process()
{
return $this->buffer;
}
/**
* called at compile time to define what the block should output in the compiled template code, happens when the block is declared
*
* basically this will replace the {block arg arg arg} tag in the template
*
* @param Dwoo_Compiler $compiler the compiler instance that calls this function
* @param array $params an array containing original and compiled parameters
* @param string $prepend that is just meant to allow a child class to call
* parent::postProcessing($compiler, $params, "foo();") to add a command before the
* default commands are executed
* @param string $append that is just meant to allow a child class to call
* parent::postProcessing($compiler, $params, null, "foo();") to add a command after the
* default commands are executed
* @param string $type the type is the plugin class name used
*/
public static function preProcessing(Dwoo_Compiler $compiler, array $params, $prepend='', $append='', $type)
{
return Dwoo_Compiler::PHP_OPEN.$prepend.'$this->addStack("'.$type.'", array('.implode(', ', $compiler->getCompiledParams($params)).'));'.$append.Dwoo_Compiler::PHP_CLOSE;
}
/**
* called at compile time to define what the block should output in the compiled template code, happens when the block is ended
*
* basically this will replace the {/block} tag in the template
*
* @see preProcessing
* @param Dwoo_Compiler $compiler the compiler instance that calls this function
* @param array $params an array containing original and compiled parameters, see preProcessing() for more details
* @param string $prepend that is just meant to allow a child class to call
* parent::postProcessing($compiler, $params, "foo();") to add a command before the
* default commands are executed
* @param string $append that is just meant to allow a child class to call
* parent::postProcessing($compiler, $params, null, "foo();") to add a command after the
* default commands are executed
*/
public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend='', $append='')
{
return Dwoo_Compiler::PHP_OPEN.$prepend.'$this->delStack();'.$append.Dwoo_Compiler::PHP_CLOSE;
}
}
/**
* base class for filters
*
* 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
*/
abstract class Dwoo_Filter
{
/**
* the dwoo instance that runs this filter
*
* @var Dwoo
*/
protected $dwoo;
/**
* constructor, if you override it, call parent::__construct($dwoo); or assign
* the dwoo instance yourself if you need it
*
* @param Dwoo $dwoo the dwoo instance that runs this plugin
*/
public function __construct(Dwoo $dwoo)
{
$this->dwoo = $dwoo;
}
/**
* processes the input and returns it filtered
*
* @param string $input the template to process
* @return string
*/
abstract public function process($input);
}
/**
* base class for processors
*
* 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
*/
abstract class Dwoo_Processor
{
/**
* the compiler instance that runs this processor
*
* @var Dwoo
*/
protected $compiler;
/**
* constructor, if you override it, call parent::__construct($dwoo); or assign
* the dwoo instance yourself if you need it
*
* @param Dwoo $dwoo the dwoo instance that runs this plugin
*/
public function __construct(Dwoo_Compiler $compiler)
{
$this->compiler = $compiler;
}
/**
* processes the input and returns it filtered
*
* @param string $input the template to process
* @return string
*/
abstract public function process($input);
}
/**
* interface that represents a compilable plugin
*
* implement this to notify the compiler that this plugin does not need to be loaded at runtime.
*
* to implement it right, you must implement <em>public static function compile(Dwoo_Compiler $compiler, $arg, $arg, ...)</em>,
* which replaces the <em>process()</em> method (that means <em>compile()</em> should have all arguments it requires).
*
* 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
*/
interface Dwoo_ICompilable
{
// this replaces the process function
//public static function compile(Dwoo_Compiler $compiler, $arg, $arg, ...);
}
/**
* interface that represents a compilable block plugin
*
* implement this to notify the compiler that this plugin does not need to be loaded at runtime.
*
* 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
*/
interface Dwoo_ICompilable_Block
{
}
<?php
/**
* base class for processors
*
* 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
*/
abstract class Dwoo_Processor
{
/**
* the compiler instance that runs this processor
*
* @var Dwoo
*/
protected $compiler;
/**
* constructor, if you override it, call parent::__construct($dwoo); or assign
* the dwoo instance yourself if you need it
*
* @param Dwoo $dwoo the dwoo instance that runs this plugin
*/
public function __construct(Dwoo_Compiler $compiler)
{
$this->compiler = $compiler;
}
/**
* processes the input and returns it filtered
*
* @param string $input the template to process
* @return string
*/
abstract public function process($input);
}
<?php
/**
* represents the security settings of a dwoo instance, it can be passed around to different dwoo instances
*
* 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_Policy
{
/**#@+
* php handling constants, defaults to PHP_REMOVE
*
* PHP_REMOVE : remove all <?php ?> (+ short tags if your short tags option is on) from the input template
* PHP_ALLOW : leave them as they are
* PHP_ENCODE : run htmlentities over them
*
* @var int
*/
const PHP_ENCODE = 1;
const PHP_REMOVE = 2;
const PHP_ALLOW = 3;
/**#@-*/
/**#@+
* constant handling constants, defaults to CONST_DISALLOW
*
* CONST_DISALLOW : throw an error if {$dwoo.const.*} is used in the template
* CONST_ALLOW : allow {$dwoo.const.*} calls
*/
const CONST_DISALLOW = false;
const CONST_ALLOW = true;
/**#@-*/
/**
* php functions that are allowed to be used within the template
*
* @var array
*/
protected $allowedPhpFunctions = array
(
'str_repeat', 'count', 'number_format', 'htmlentities', 'htmlspecialchars',
'long2ip', 'strlen', 'list', 'empty', 'count', 'sizeof', 'in_array', 'is_array',
);
/**
* paths that are safe to use with include or other file-access plugins
*
* @var array
*/
protected $allowedDirectories = array();
/**
* stores the php handling level
*
* defaults to Dwoo_Security_Policy::PHP_REMOVE
*
* @var int
*/
protected $phpHandling = self::PHP_REMOVE;
/**
* stores the constant handling level
*
* defaults to Dwoo_Security_Policy::CONST_DISALLOW
*
* @var bool
*/
protected $constHandling = self::CONST_DISALLOW;
/**
* adds a php function to the allowed list
*
* @param mixed $func function name or array of function names
*/
public function allowPhpFunction($func)
{
if(is_array($func))
foreach($func as $fname)
$this->allowedPhpFunctions[strtolower($fname)] = true;
else
$this->allowedPhpFunctions[strtolower($func)] = true;
}
/**
* removes a php function from the allowed list
*
* @param mixed $func function name or array of function names
*/
public function disallowPhpFunction($func)
{
if(is_array($func))
foreach($func as $fname)
unset($this->allowedPhpFunctions[strtolower($fname)]);
else
unset($this->allowedPhpFunctions[strtolower($func)]);
}
/**
* returns the list of php functions allowed to run, note that the function names
* are stored in the array keys and not values
*
* @return array
*/
public function getAllowedPhpFunctions()
{
return $this->allowedPhpFunctions;
}
/**
* adds a directory to the safelist for includes and other file-access plugins
*
* @param mixed $path a path name or an array of paths
*/
public function allowDirectory($path)
{
if(is_array($path))
foreach($path as $dir)
$this->allowedDirectories[realpath($dir)] = true;
else
$this->allowedDirectories[realpath($path)] = true;
}
/**
* removes a directory from the safelist
*
* @param mixed $path a path name or an array of paths
*/
public function disallowDirectory($path)
{
if(is_array($path))
foreach($path as $dir)
unset($this->allowedDirectories[realpath($dir)]);
else
unset($this->allowedDirectories[realpath($path)]);
}
/**
* returns the list of safe paths, note that the paths are stored in the array
* keys and not values
*
* @return array
*/
public function getAllowedDirectories()
{
return $this->allowedDirectories;
}
/**
* sets the php handling level, defaults to REMOVE
*
* @param int $level one of the Dwoo_Security_Policy::PHP_* constants
*/
public function setPhpHandling($level = self::PHP_REMOVE)
{
$this->phpHandling = $level;
}
/**
* returns the php handling level
*
* @return int the current level, one of the Dwoo_Security_Policy::PHP_* constants
*/
public function getPhpHandling()
{
return $this->phpHandling;
}
/**
* sets the constant handling level, defaults to CONST_DISALLOW
*
* @param bool $level one of the Dwoo_Security_Policy::CONST_* constants
*/
public function setConstantHandling($level = self::CONST_DISALLOW)
{
$this->constHandling = $level;
}
/**
* returns the constant handling level
*
* @return bool the current level, one of the Dwoo_Security_Policy::CONST_* constants
*/
public function getConstantHandling()
{
return $this->constHandling;
}
}
......@@ -349,5 +349,3 @@ works.bb', $this->dwoo->get($tpl, array(), $this->compiler));
$fixCall->init('');
}
}
?>
\ No newline at end of file
......@@ -127,5 +127,3 @@ class blockplugin_custom extends Dwoo_Block_Plugin
return $this->foo.$this->bar.$this->buffer;
}
}
?>
\ No newline at end of file
......@@ -350,5 +350,3 @@ class MethodCallsHelper {
}
public function __toString() { return 'obj'; }
}
?>
\ No newline at end of file
......@@ -290,5 +290,3 @@ class CoreTests extends PHPUnit_Framework_TestCase
}
}
?>
\ No newline at end of file
......@@ -73,5 +73,3 @@ class DataTests extends PHPUnit_Framework_TestCase
$this->assertEquals(array('var'=>array('val','moo'), 'var2'=>array('bar')), $data->getData());
}
}
?>
\ No newline at end of file
......@@ -68,5 +68,3 @@ class DwooConstraintStringEquals extends PHPUnit_Framework_Constraint
return 'equals "'.$this->target.'" / "'.$this->other.'"';
}
}
?>
\ No newline at end of file
......@@ -49,5 +49,3 @@ SNIPPET
$this->assertEquals('{'.Dwoo::VERSION.'}', $this->dwoo->get($tpl, array(), $cmp));
}
}
?>
\ No newline at end of file
......@@ -433,5 +433,3 @@ a"}');
$this->assertEquals("abcdefgh\nijklmnop\nqrstuvwx\nyz", $this->dwoo->get($tpl, array(), $this->compiler));
}
}
?>
\ No newline at end of file
......@@ -30,5 +30,3 @@ class HelperTests extends PHPUnit_Framework_TestCase
$this->assertEquals('true', $this->dwoo->get($tpl, array('test'=>array("hoy"=>3, 5=>"foo", "bar"=>"moo"), 'baz'=>'baz'), $this->compiler));
}
}
?>
\ No newline at end of file
......@@ -93,5 +93,3 @@ class SecurityTests extends PHPUnit_Framework_TestCase
$this->assertEquals($old, $this->policy->getAllowedPhpFunctions());
}
}
?>
\ No newline at end of file
......@@ -24,5 +24,3 @@ class SmartyTests extends PHPUnit_Framework_TestCase
$this->assertEquals('{'.Dwoo::VERSION.'}', $this->dwoo->fetch('smartytest.html'));
}
}
?>
\ No newline at end of file
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