Commit 57c29c72 by Seldaek

BC Break: Small one that probably won't affect anyone, but it makes the…

BC Break: Small one that probably won't affect anyone, but it makes the PluginProxy feature much stronger. Basically if you used a custom one you will get a fatal error and need to update it to conform to the new IPluginProxy interface, that's it git-svn-id: svn://dwoo.org/dwoo/trunk@185 0598d79b-80c4-4d41-97ba-ac86fbbd088b
parent 70c14e91
[2008--] 1.0.0 [2008--] 1.0.0
! BC Break: Small one that probably won't affect anyone, but it makes the
PluginProxy feature much stronger. Basically if you used a custom one you
will get a fatal error and need to update it to conform to the new
IPluginProxy interface, that's it
* Plugins: improved the dump plugin, it now displays object's properties * Plugins: improved the dump plugin, it now displays object's properties
and optionally public methods (if the new show_methods arg is set to true) and optionally public methods (if the new show_methods arg is set to true)
- thanks to Stephan Wentz for the patch - thanks to Stephan Wentz for the patch
......
...@@ -13,7 +13,8 @@ ...@@ -13,7 +13,8 @@
* {@link http://www.gnu.org/copyleft/lesser.html} * {@link http://www.gnu.org/copyleft/lesser.html}
* *
* @author Denis Arh <denis@arh.cc> * @author Denis Arh <denis@arh.cc>
* @copyright Copyright (c) 2008, Denis Arh * @author Jordi Boggiano <j.boggiano@seld.be>
* @copyright Copyright (c) 2008, Denis Arh, Jordi Boggiano
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
* @link http://dwoo.org/ * @link http://dwoo.org/
* @version 1.0.0 * @version 1.0.0
...@@ -44,7 +45,7 @@ class Dwoo_Adapters_ZendFramework_PluginProxy implements Dwoo_IPluginProxy ...@@ -44,7 +45,7 @@ class Dwoo_Adapters_ZendFramework_PluginProxy implements Dwoo_IPluginProxy
* @param string $name * @param string $name
* @return bool * @return bool
*/ */
public function loadPlugin($name) { public function handles($name) {
try { try {
$this->view->getHelper($name); $this->view->getHelper($name);
} catch (Zend_Loader_PluginLoader_Exception $e) { } catch (Zend_Loader_PluginLoader_Exception $e) {
...@@ -55,14 +56,46 @@ class Dwoo_Adapters_ZendFramework_PluginProxy implements Dwoo_IPluginProxy ...@@ -55,14 +56,46 @@ class Dwoo_Adapters_ZendFramework_PluginProxy implements Dwoo_IPluginProxy
} }
/** /**
* Catch-all method for Zend view helpers. It generates code for * returns the code (as a string) to call the plugin
* Dwoo templates. * (this will be executed at runtime inside the Dwoo class)
* *
* @param string $name Name of the view helper * @param string $name the plugin name
* @param array $args Helper's parameters * @param array $params a parameter array, array key "*" is the rest array
* @return string * @return string
*/ */
public function __call($name, $args) { public function getCode($name, $params) {
return '$this->getPluginProxy()->view->'. $name .'('.Dwoo_Compiler::implode_r($args).')'; return '$this->getPluginProxy()->view->'. $name .'('.Dwoo_Compiler::implode_r($params).')';
}
/**
* returns a callback to the plugin, this is used with the reflection API to
* find out about the plugin's parameter names etc.
*
* should you need a rest array (i.e. for ZendFramework helpers) without the
* possibility to edit the plugin's code, you can provide a callback to some
* other function with the correct parameter signature, i.e. :
* <code>
* return array($this, "callbackHelper");
* // and callbackHelper would be as such:
* public function callbackHelper(array $rest=array()){}
* </code>
*
* @param string $name the plugin name
* @return callback
*/
public function getCallback($name) {
return array($this->view->getHelper($name), $name);
}
/**
* returns some code that will check if the plugin is loaded and if not load it
* this is optional, if your plugins are autoloaded or whatever, just return an
* empty string
*
* @param string $name the plugin name
* @return string
*/
public function getLoader($name) {
return '';
} }
} }
\ No newline at end of file
...@@ -719,7 +719,7 @@ class Dwoo_Compiler implements Dwoo_ICompiler ...@@ -719,7 +719,7 @@ class Dwoo_Compiler implements Dwoo_ICompiler
// build plugin preloader // build plugin preloader
foreach ($this->usedPlugins as $plugin=>$type) { foreach ($this->usedPlugins as $plugin=>$type) {
if (($type & Dwoo::CUSTOM_PLUGIN) || ($type & Dwoo::PROXY_PLUGIN)) { if ($type & Dwoo::CUSTOM_PLUGIN) {
continue; continue;
} }
...@@ -741,6 +741,9 @@ class Dwoo_Compiler implements Dwoo_ICompiler ...@@ -741,6 +741,9 @@ class Dwoo_Compiler implements Dwoo_ICompiler
case Dwoo::SMARTY_BLOCK: case Dwoo::SMARTY_BLOCK:
$output .= "if (function_exists('smarty_block_$plugin')===false)\n\t\$this->getLoader()->loadPlugin('$plugin');\n"; $output .= "if (function_exists('smarty_block_$plugin')===false)\n\t\$this->getLoader()->loadPlugin('$plugin');\n";
break; break;
case Dwoo::PROXY_PLUGIN:
$output .= $this->getDwoo()->getPluginProxy()->getPreloader($plugin);
break;
default: default:
throw new Dwoo_Compilation_Exception($this, 'Type error for '.$plugin.' with type'.$type); throw new Dwoo_Compilation_Exception($this, 'Type error for '.$plugin.' with type'.$type);
...@@ -1397,7 +1400,7 @@ class Dwoo_Compiler implements Dwoo_ICompiler ...@@ -1397,7 +1400,7 @@ class Dwoo_Compiler implements Dwoo_ICompiler
} }
// funcs // funcs
if ($pluginType & Dwoo::NATIVE_PLUGIN || $pluginType & Dwoo::PROXY_PLUGIN || $pluginType & Dwoo::SMARTY_FUNCTION || $pluginType & Dwoo::SMARTY_BLOCK) { if ($pluginType & Dwoo::NATIVE_PLUGIN || $pluginType & Dwoo::SMARTY_FUNCTION || $pluginType & Dwoo::SMARTY_BLOCK) {
$params = $this->mapParams($params, null, $state); $params = $this->mapParams($params, null, $state);
} elseif ($pluginType & Dwoo::CLASS_PLUGIN) { } elseif ($pluginType & Dwoo::CLASS_PLUGIN) {
if ($pluginType & Dwoo::CUSTOM_PLUGIN) { if ($pluginType & Dwoo::CUSTOM_PLUGIN) {
...@@ -1413,6 +1416,8 @@ class Dwoo_Compiler implements Dwoo_ICompiler ...@@ -1413,6 +1416,8 @@ class Dwoo_Compiler implements Dwoo_ICompiler
} }
} elseif ($pluginType & Dwoo::SMARTY_MODIFIER) { } elseif ($pluginType & Dwoo::SMARTY_MODIFIER) {
$output = 'smarty_modifier_'.$func.'('.implode(', ', $params).')'; $output = 'smarty_modifier_'.$func.'('.implode(', ', $params).')';
} elseif ($pluginType & Dwoo::PROXY_PLUGIN) {
$params = $this->mapParams($params, $this->getDwoo()->getPluginProxy()->getCallback($func), $state);
} }
// only keep php-syntax-safe values for non-block plugins // only keep php-syntax-safe values for non-block plugins
...@@ -1507,11 +1512,7 @@ class Dwoo_Compiler implements Dwoo_ICompiler ...@@ -1507,11 +1512,7 @@ class Dwoo_Compiler implements Dwoo_ICompiler
} }
} }
} elseif ($pluginType & Dwoo::PROXY_PLUGIN) { } elseif ($pluginType & Dwoo::PROXY_PLUGIN) {
if (isset($params['*'])) { $output = call_user_func(array($this->dwoo->getPluginProxy(), 'getCode'), $func, $params);
$output = call_user_func_array(array($this->dwoo->getPluginProxy(), $func), $params['*']);
} else {
$output = call_user_func(array($this->dwoo->getPluginProxy(), $func));
}
} elseif ($pluginType & Dwoo::SMARTY_FUNCTION) { } elseif ($pluginType & Dwoo::SMARTY_FUNCTION) {
if (isset($params['*'])) { if (isset($params['*'])) {
$params = self::implode_r($params['*'], true); $params = self::implode_r($params['*'], true);
...@@ -2404,9 +2405,10 @@ class Dwoo_Compiler implements Dwoo_ICompiler ...@@ -2404,9 +2405,10 @@ class Dwoo_Compiler implements Dwoo_ICompiler
$output = $func.'('.$params.')'; $output = $func.'('.$params.')';
} }
} elseif ($pluginType & Dwoo::PROXY_PLUGIN) { } elseif ($pluginType & Dwoo::PROXY_PLUGIN) {
$params = $this->mapParams($params, null, $state); $params = $this->mapParams($params, $this->getDwoo()->getPluginProxy()->getCallback($name), $state);
$params = $params['*'][0]; foreach ($params as &$p)
$output = call_user_func_array(array($this->dwoo->getPluginProxy(), $func), $params); $p = $p[0];
$output = call_user_func(array($this->dwoo->getPluginProxy(), 'getCode'), $func, $params);
} elseif ($pluginType & Dwoo::SMARTY_MODIFIER) { } elseif ($pluginType & Dwoo::SMARTY_MODIFIER) {
$params = $this->mapParams($params, null, $state); $params = $this->mapParams($params, null, $state);
$params = $params['*'][0]; $params = $params['*'][0];
...@@ -2595,7 +2597,7 @@ class Dwoo_Compiler implements Dwoo_ICompiler ...@@ -2595,7 +2597,7 @@ class Dwoo_Compiler implements Dwoo_ICompiler
} catch (Exception $e) { } catch (Exception $e) {
if (isset($phpFunc)) { if (isset($phpFunc)) {
$pluginType = Dwoo::NATIVE_PLUGIN; $pluginType = Dwoo::NATIVE_PLUGIN;
} elseif (is_object($this->dwoo->getPluginProxy()) && $this->dwoo->getPluginProxy()->loadPlugin($name)) { } elseif (is_object($this->dwoo->getPluginProxy()) && $this->dwoo->getPluginProxy()->handles($name)) {
$pluginType = Dwoo::PROXY_PLUGIN; $pluginType = Dwoo::PROXY_PLUGIN;
break; break;
} else { } else {
......
...@@ -12,7 +12,8 @@ ...@@ -12,7 +12,8 @@
* {@link http://www.gnu.org/copyleft/lesser.html} * {@link http://www.gnu.org/copyleft/lesser.html}
* *
* @author Denis Arh <denis@arh.cc> * @author Denis Arh <denis@arh.cc>
* @copyright Copyright (c) 2008, Denis Arh (this file + some patched bits here and there) * @author Jordi Boggiano <j.boggiano@seld.be>
* @copyright Copyright (c) 2008, Denis Arh, Jordi Boggiano
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
* @link http://dwoo.org/ * @link http://dwoo.org/
* @version 0.9.1 * @version 0.9.1
...@@ -22,10 +23,48 @@ ...@@ -22,10 +23,48 @@
interface Dwoo_IPluginProxy interface Dwoo_IPluginProxy
{ {
/** /**
* loads a plugin or returns false on failure * returns true or false to say whether the given plugin is handled by this proxy or not
* *
* @param string $name the plugin name * @param string $name the plugin name
* @return bool true if the plugin was successfully loaded * @return bool true if the plugin is known and usable, otherwise false
*/ */
public function loadPlugin($name); public function handles($name);
/**
* returns the code (as a string) to call the plugin
* (this will be executed at runtime inside the Dwoo class)
*
* @param string $name the plugin name
* @param array $params a parameter array, array key "*" is the rest array
* @return string
*/
public function getCode($name, $params);
/**
* returns a callback to the plugin, this is used with the reflection API to
* find out about the plugin's parameter names etc.
*
* should you need a rest array without the possibility to edit the
* plugin's code, you can provide a callback to some
* other function with the correct parameter signature, i.e. :
* <code>
* return array($this, "callbackHelper");
* // and callbackHelper would be as such:
* public function callbackHelper(array $rest=array()){}
* </code>
*
* @param string $name the plugin name
* @return callback
*/
public function getCallback($name);
/**
* returns some code that will check if the plugin is loaded and if not load it
* this is optional, if your plugins are autoloaded or whatever, just return an
* empty string
*
* @param string $name the plugin name
* @return string
*/
public function getLoader($name);
} }
\ 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