1 | <?php |
---|
2 | |
---|
3 | /** |
---|
4 | * PluginProxy class for Zend View |
---|
5 | * |
---|
6 | * This software is provided 'as-is', without any express or implied warranty. |
---|
7 | * In no event will the authors be held liable for any damages arising from the |
---|
8 | * use of this software. |
---|
9 | * |
---|
10 | * @author Denis Arh <denis@arh.cc> |
---|
11 | * @author Jordi Boggiano <j.boggiano@seld.be> |
---|
12 | * @copyright Copyright (c) 2008, Denis Arh, Jordi Boggiano |
---|
13 | * @license http://dwoo.org/LICENSE Modified BSD License |
---|
14 | * @link http://dwoo.org/ |
---|
15 | * @version 1.0.0 |
---|
16 | * @date 2008-10-23 |
---|
17 | * @package Dwoo |
---|
18 | */ |
---|
19 | class Dwoo_Adapters_ZendFramework_PluginProxy implements Dwoo_IPluginProxy |
---|
20 | { |
---|
21 | /** |
---|
22 | * reference to the zend view owning this proxy |
---|
23 | * |
---|
24 | * @var Zend_View_Interface |
---|
25 | */ |
---|
26 | public $view; |
---|
27 | |
---|
28 | /** |
---|
29 | * Dwoo_Adapters_ZendFramework_PluginProxy's constructor. |
---|
30 | * |
---|
31 | * @param Zend_View_Interface $view |
---|
32 | */ |
---|
33 | public function __construct(Zend_View_Interface $view) { |
---|
34 | $this->view = $view; |
---|
35 | } |
---|
36 | |
---|
37 | /** |
---|
38 | * Called from Dwoo_Compiler to check if the requested plugin is available |
---|
39 | * |
---|
40 | * @param string $name |
---|
41 | * @return bool |
---|
42 | */ |
---|
43 | public function handles($name) { |
---|
44 | try { |
---|
45 | $this->view->getHelper($name); |
---|
46 | } catch (Zend_Loader_PluginLoader_Exception $e) { |
---|
47 | return false; |
---|
48 | } |
---|
49 | |
---|
50 | return true; |
---|
51 | } |
---|
52 | |
---|
53 | /** |
---|
54 | * returns the code (as a string) to call the plugin |
---|
55 | * (this will be executed at runtime inside the Dwoo class) |
---|
56 | * |
---|
57 | * @param string $name the plugin name |
---|
58 | * @param array $params a parameter array, array key "*" is the rest array |
---|
59 | * @return string |
---|
60 | */ |
---|
61 | public function getCode($name, $params) { |
---|
62 | return '$this->getPluginProxy()->view->'. $name .'('.Dwoo_Compiler::implode_r($params).')'; |
---|
63 | } |
---|
64 | |
---|
65 | /** |
---|
66 | * returns a callback to the plugin, this is used with the reflection API to |
---|
67 | * find out about the plugin's parameter names etc. |
---|
68 | * |
---|
69 | * should you need a rest array (i.e. for ZendFramework helpers) without the |
---|
70 | * possibility to edit the plugin's code, you can provide a callback to some |
---|
71 | * other function with the correct parameter signature, i.e. : |
---|
72 | * <code> |
---|
73 | * return array($this, "callbackHelper"); |
---|
74 | * // and callbackHelper would be as such: |
---|
75 | * public function callbackHelper(array $rest=array()){} |
---|
76 | * </code> |
---|
77 | * |
---|
78 | * @param string $name the plugin name |
---|
79 | * @return callback |
---|
80 | */ |
---|
81 | public function getCallback($name) { |
---|
82 | return array($this->view->getHelper($name), $name); |
---|
83 | } |
---|
84 | |
---|
85 | /** |
---|
86 | * returns some code that will check if the plugin is loaded and if not load it |
---|
87 | * this is optional, if your plugins are autoloaded or whatever, just return an |
---|
88 | * empty string |
---|
89 | * |
---|
90 | * @param string $name the plugin name |
---|
91 | * @return string |
---|
92 | */ |
---|
93 | public function getLoader($name) { |
---|
94 | return ''; |
---|
95 | } |
---|
96 | } |
---|