Source for file Adapter.php
Documentation is available at Adapter.php
define('DIR_SEP', DIRECTORY_SEPARATOR);
if (!defined('SMARTY_PHP_PASSTHRU')) {
define('SMARTY_PHP_PASSTHRU', 0);
define('SMARTY_PHP_QUOTE', 1);
define('SMARTY_PHP_REMOVE', 2);
define('SMARTY_PHP_ALLOW', 3);
require
dirname(dirname(__FILE__
)) .
'/Compiler.php';
* a Smarty compatibility layer for Dwoo
* 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.
* @author Jordi Boggiano <j.boggiano@seld.be>
* @copyright Copyright (c) 2008, Jordi Boggiano
* @license http://dwoo.org/LICENSE Modified BSD License
// magic get/set/call functions that handle unsupported features
public function __set($p, $v)
$this->triggerError('Property '.
$p.
' is not available in the Dwoo_Smarty_Adapter, however it might be implemented in the future, check out http://wiki.dwoo.org/index.php/SmartySupport for more details.', E_USER_NOTICE);
$this->compat['properties'][$p] =
$v;
$this->triggerError('Property '.
$p.
' is not available in the Dwoo_Smarty_Adapter, but it is not listed as such, so you might want to tell me about it at j.boggiano@seld.be', E_USER_NOTICE);
public function __get($p)
$this->triggerError('Property '.
$p.
' is not available in the Dwoo_Smarty_Adapter, however it might be implemented in the future, check out http://wiki.dwoo.org/index.php/SmartySupport for more details.', E_USER_NOTICE);
return $this->compat['properties'][$p];
$this->triggerError('Property '.
$p.
' is not available in the Dwoo_Smarty_Adapter, but it is not listed as such, so you might want to tell me about it at j.boggiano@seld.be', E_USER_NOTICE);
public function __call($m, $a)
$this->triggerError('Method '.
$m.
' is not available in the Dwoo_Smarty_Adapter, however it might be implemented in the future, check out http://wiki.dwoo.org/index.php/SmartySupport for more details.', E_USER_NOTICE);
$this->triggerError('Method '.
$m.
' is not available in the Dwoo_Smarty_Adapter, but it is not listed as such, so you might want to tell me about it at j.boggiano@seld.be', E_USER_NOTICE);
// list of unsupported properties and methods
'register_resource', 'unregister_resource', 'load_filter', 'clear_compiled_tpl',
'clear_config', 'get_config_vars', 'config_load'
'cache_handler_func' =>
null,
'error_reporting' =>
null,
'debugging_ctrl' =>
'NONE',
'request_vars_order' =>
'EGPCS',
'request_use_auto_globals' =>
true,
'autoload_filters' =>
array(),
'default_template_handler_func' =>
'',
'cache_modified_check' =>
false,
'default_modifiers' =>
array(),
'default_resource_type' =>
'file',
'config_overwrite' =>
true,
'config_booleanize' =>
true,
'config_read_hidden' =>
false,
'config_fix_newlines' =>
true,
'config_class' =>
'Config_File',
'list', 'empty', 'count', 'sizeof',
'MODIFIER_FUNCS' =>
array(),
'ALLOW_CONSTANTS' =>
false
// dwoo/smarty compat layer
protected $_filters =
array('pre'=>
array(), 'post'=>
array(), 'output'=>
array());
protected static $tplCache =
array();
public function display($filename, $cacheId=
null, $compileId=
null)
$this->fetch($filename, $cacheId, $compileId, true);
public function fetch($filename, $cacheId=
null, $compileId=
null, $display=
false)
$policy->setPhpHandling($phpTags);
$policy->allowDirectory(preg_replace('{^((?:[a-z]:)?[\\\\/]).*}i', '$1', __FILE__
));
$tpl =
$this->makeTemplate($filename, $cacheId, $compileId);
$tpl->forceCompilation();
$this->compiler->addPreProcessor('smarty_compat', true);
$this->compiler->setLooseOpeningHandling(true);
public function get($_tpl, $data =
array(), $_compiler =
null, $_output =
false)
if ($_compiler ===
null) {
return parent::get($_tpl, $data, $_compiler, $_output);
public function register_function($name, $callback, $cacheable=
true, $cache_attrs=
null)
if (isset
($this->plugins[$name]) &&
$this->plugins[$name][0] !==
self::SMARTY_FUNCTION) {
throw
new Dwoo_Exception('Multiple plugins of different types can not share the same name');
$this->plugins[$name] =
array('type'=>
self::SMARTY_FUNCTION, 'callback'=>
$callback);
public function register_block($name, $callback, $cacheable=
true, $cache_attrs=
null)
if (isset
($this->plugins[$name]) &&
$this->plugins[$name][0] !==
self::SMARTY_BLOCK) {
throw
new Dwoo_Exception('Multiple plugins of different types can not share the same name');
$this->plugins[$name] =
array('type'=>
self::SMARTY_BLOCK, 'callback'=>
$callback);
if (isset
($this->plugins[$name]) &&
$this->plugins[$name][0] !==
self::SMARTY_MODIFIER) {
throw
new Dwoo_Exception('Multiple plugins of different types can not share the same name');
$this->plugins[$name] =
array('type'=>
self::SMARTY_MODIFIER, 'callback'=>
$callback);
$processor =
new Dwoo_SmartyProcessorAdapter($this->compiler);
$processor->registerCallback($callback);
$this->compiler->addPreProcessor($processor);
foreach ($this->_filters['pre'] as $index =>
$processor)
if ($processor->callback ===
$callback) {
$this->compiler->removePostProcessor($processor);
$processor =
new Dwoo_SmartyProcessorAdapter($this->compiler);
$processor->registerCallback($callback);
$this->compiler->addPostProcessor($processor);
foreach ($this->_filters['post'] as $index =>
$processor)
if ($processor->callback ===
$callback) {
$this->compiler->removePostProcessor($processor);
$filter =
new Dwoo_SmartyFilterAdapter($this);
$filter->registerCallback($callback);
foreach ($this->_filters['output'] as $index =>
$filter)
if ($filter->callback ===
$callback) {
$this->removeOutputFilter($filter);
unset
($this->_filters['output'][$index]);
function register_object($object, $object_impl, $allowed =
array(), $smarty_args =
false, $block_methods =
array())
$this->triggerError('You can register objects but can not restrict the method/properties used, this is PHP5, you have proper OOP access restrictions so use them.', E_USER_NOTICE);
$this->triggerError('You can register objects but methods will be called using method($arg1, $arg2, $arg3), not as an argument array like smarty did.', E_USER_NOTICE);
if (!empty($block_methods)) {
$this->triggerError('You can register objects but can not use methods as being block methods, you have to build a plugin for that.', E_USER_NOTICE);
if (isset
($data[$name]) &&
is_object($data[$name])) {
trigger_error('Dwoo_Compiler: object "'.
$name.
'" was not registered or is not an object', E_USER_ERROR);
if (file_exists($tpl_dir.
DIRECTORY_SEPARATOR.
$filename)) {
public function is_cached($tpl, $cacheId =
null, $compileId =
null)
trigger_error('get_template_vars does not return values by reference, if you try to modify the data that way you should modify your code.', E_USER_NOTICE);
elseif (isset
($data[$name]))
public function clear_cache($template, $cacheId =
null, $compileId =
null, $olderThan =
0)
$this->makeTemplate($template, $cacheId, $compileId)->clearCache($olderThan);
public function trigger_error($error_msg, $error_type =
E_USER_WARNING)
protected function makeTemplate($file, $cacheId, $compileId)
$hash =
bin2hex(md5($file.
$cacheId.
$compileId, true));
if (!isset
(self::$tplCache[$hash])) {
if (substr($file, 0, 1) ===
'/' ||
substr($file, 1, 1) ===
':') {
self::$tplCache[$hash] =
new Dwoo_Template_File($file, null, $cacheId, $compileId);
self::$tplCache[$hash] =
new Dwoo_Template_File($file, null, $cacheId, $compileId, $this->template_dir);
throw
new Exception('Unable to load "'.
$file.
'", check the template_dir');
return self::$tplCache[$hash];
public function triggerError($message, $level=
E_USER_NOTICE)
// cloaks the adapter if possible with the smarty name to fool type-hinted plugins
Documentation generated on Sun, 07 Feb 2010 17:53:10 +0000 by phpDocumentor 1.4.0