@@ -16,24 +16,24 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | function Dwoo_Plugin_url_compile(Dwoo_Compiler $compiler, $route = null, $params = null, $options = null, array $rest = array()) |
| 18 | 18 | { |
| 19 | - if ($params == 'null') { |
|
| 20 | - if (count($rest)) { |
|
| 21 | - $params = array(); |
|
| 22 | - foreach ($rest as $k => $v) { |
|
| 23 | - if (is_numeric($k)) { |
|
| 24 | - $params[] = $k.'=>'.$v; |
|
| 25 | - } else { |
|
| 26 | - $params[] = '"'.$k.'"=>'.$v; |
|
| 27 | - } |
|
| 28 | - } |
|
| 29 | - $params = 'array('.implode(', ', $params).')'; |
|
| 30 | - } else { |
|
| 31 | - $params = 'array()'; |
|
| 32 | - } |
|
| 33 | - } |
|
| 34 | - if ($options == 'null') { |
|
| 35 | - $options = 'array()'; |
|
| 36 | - } |
|
| 19 | + if ($params == 'null') { |
|
| 20 | + if (count($rest)) { |
|
| 21 | + $params = array(); |
|
| 22 | + foreach ($rest as $k => $v) { |
|
| 23 | + if (is_numeric($k)) { |
|
| 24 | + $params[] = $k.'=>'.$v; |
|
| 25 | + } else { |
|
| 26 | + $params[] = '"'.$k.'"=>'.$v; |
|
| 27 | + } |
|
| 28 | + } |
|
| 29 | + $params = 'array('.implode(', ', $params).')'; |
|
| 30 | + } else { |
|
| 31 | + $params = 'array()'; |
|
| 32 | + } |
|
| 33 | + } |
|
| 34 | + if ($options == 'null') { |
|
| 35 | + $options = 'array()'; |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - return '$this->data[\'ro\']->gen('.$route.', '.$params.', '.$options.')'; |
|
| 38 | + return '$this->data[\'ro\']->gen('.$route.', '.$params.', '.$options.')'; |
|
| 39 | 39 | } |
@@ -16,15 +16,15 @@ |
||
| 16 | 16 | |
| 17 | 17 | class dwoowelcome extends Controller |
| 18 | 18 | { |
| 19 | - public function __construct() |
|
| 20 | - { |
|
| 21 | - parent::Controller(); |
|
| 22 | - } |
|
| 19 | + public function __construct() |
|
| 20 | + { |
|
| 21 | + parent::Controller(); |
|
| 22 | + } |
|
| 23 | 23 | |
| 24 | - public function index() |
|
| 25 | - { |
|
| 26 | - $this->load->library('Dwootemplate'); |
|
| 27 | - $this->dwootemplate->assign('itshowlate', date('H:i:s')); |
|
| 28 | - $this->dwootemplate->display('dwoowelcome.tpl'); |
|
| 29 | - } |
|
| 24 | + public function index() |
|
| 25 | + { |
|
| 26 | + $this->load->library('Dwootemplate'); |
|
| 27 | + $this->dwootemplate->assign('itshowlate', date('H:i:s')); |
|
| 28 | + $this->dwootemplate->display('dwoowelcome.tpl'); |
|
| 29 | + } |
|
| 30 | 30 | } |
@@ -15,7 +15,7 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | |
| 17 | 17 | if (!defined('BASEPATH')) { |
| 18 | - exit('No direct script access allowed'); |
|
| 18 | + exit('No direct script access allowed'); |
|
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | // The name of the directory where templates are located. |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | */ |
| 16 | 16 | |
| 17 | 17 | if (!defined('BASEPATH')) { |
| 18 | - exit('No direct script access allowed'); |
|
| 18 | + exit('No direct script access allowed'); |
|
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | require 'dwoo/dwooAutoload.php'; |
@@ -39,154 +39,154 @@ discard block |
||
| 39 | 39 | */ |
| 40 | 40 | class Dwootemplate extends Dwoo_Core |
| 41 | 41 | { |
| 42 | - protected $dwoo_data = array(); |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * Constructor for the DwooTemplate engine. |
|
| 46 | - */ |
|
| 47 | - public function __construct() |
|
| 48 | - { |
|
| 49 | - // Call parents constructor |
|
| 50 | - parent::__construct(); |
|
| 51 | - |
|
| 52 | - // Set the config settings |
|
| 53 | - $this->initialize(); |
|
| 54 | - |
|
| 55 | - // Assign some defaults to dwoo |
|
| 56 | - $CI = get_instance(); |
|
| 57 | - $this->dwoo_data = new Dwoo_Data(); |
|
| 58 | - $this->dwoo_data->js_files = array(); |
|
| 59 | - $this->dwoo_data->css_files = array(); |
|
| 60 | - $this->dwoo_data->CI = $CI; |
|
| 61 | - $this->dwoo_data->site_url = $CI->config->site_url(); // so we can get the full path to CI easily |
|
| 62 | - $this->dwoo_data->uniqid = uniqid(); |
|
| 63 | - $this->dwoo_data->timestamp = mktime(); |
|
| 64 | - |
|
| 65 | - log_message('debug', 'Dwoo Template Class Initialized'); |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * Assign data to dwoo data object. |
|
| 70 | - * |
|
| 71 | - * @param string $key |
|
| 72 | - * @param mixed $value |
|
| 73 | - */ |
|
| 74 | - public function assign($key, $value) |
|
| 75 | - { |
|
| 76 | - $this->dwoo_data->$key = $value; |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * Add Javascript files to template. |
|
| 81 | - * |
|
| 82 | - * @param string $js |
|
| 83 | - */ |
|
| 84 | - public function add_js($js) |
|
| 85 | - { |
|
| 86 | - $current = $this->dwoo_data->js_files; |
|
| 87 | - $current[] = $js; |
|
| 88 | - $this->dwoo_data->js_files = $current; |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * Add Css stylesheets to template. |
|
| 93 | - * |
|
| 94 | - * @param string $css |
|
| 95 | - */ |
|
| 96 | - public function add_css($css) |
|
| 97 | - { |
|
| 98 | - $current = $this->dwoo_data->css_files; |
|
| 99 | - $current[] = $css; |
|
| 100 | - $this->dwoo_data->css_files = $current; |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * Display or return the compiled template |
|
| 105 | - * Since we assign the results to the standard CI output module |
|
| 106 | - * you can also use the helper from CI in your templates!! |
|
| 107 | - * |
|
| 108 | - * @param string $sTemplate |
|
| 109 | - * @param bool $return |
|
| 110 | - * |
|
| 111 | - * @return mixed |
|
| 112 | - */ |
|
| 113 | - public function display($sTemplate, $return = false) |
|
| 114 | - { |
|
| 115 | - // Start benchmark |
|
| 116 | - $CI = get_instance(); |
|
| 117 | - $CI->benchmark->mark('dwoo_parse_start'); |
|
| 118 | - |
|
| 119 | - // Check if file exists |
|
| 120 | - if (!file_exists($this->template_dir.$sTemplate)) { |
|
| 121 | - $message = sprintf('Template file \'%s\' not found.', $sTemplate); |
|
| 122 | - show_error($message); |
|
| 123 | - log_message('error', $message); |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - // Create new template |
|
| 127 | - $tpl = new Dwoo_Template_File($this->template_dir.$sTemplate); |
|
| 128 | - |
|
| 129 | - // render the template |
|
| 130 | - $template = $this->get($tpl, $this->dwoo_data); |
|
| 131 | - |
|
| 132 | - // Finish benchmark |
|
| 133 | - $CI->benchmark->mark('dwoo_parse_end'); |
|
| 134 | - |
|
| 135 | - // Return results or not ? |
|
| 136 | - if ($return == false) { |
|
| 137 | - $CI->output->final_output = $template; |
|
| 138 | - } else { |
|
| 139 | - return $template; |
|
| 140 | - } |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * Toggle Codeigniter profiler on/off. |
|
| 145 | - */ |
|
| 146 | - public function enable_profiler($toggle = true) |
|
| 147 | - { |
|
| 148 | - $CI = get_instance(); |
|
| 149 | - $CI->output->enable_profiler($toggle); |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * Set http header. |
|
| 154 | - * |
|
| 155 | - * @example $this->output->set_header("HTTP/1.1 200 OK"); |
|
| 156 | - * @example $this->output->set_header('Last-Modified: '.gmdate('D, d M Y H:i:s', $last_update).' GMT'); |
|
| 157 | - * |
|
| 158 | - * @param string $header |
|
| 159 | - */ |
|
| 160 | - public function set_header($header) |
|
| 161 | - { |
|
| 162 | - $CI = get_instance(); |
|
| 163 | - $CI->output->set_header($header); |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - /** |
|
| 167 | - * Set status header. |
|
| 168 | - * |
|
| 169 | - * @example $this->output->set_status_header('401'); |
|
| 170 | - * @example // Sets the header as: Unauthorized |
|
| 171 | - * |
|
| 172 | - * @param string $header |
|
| 173 | - */ |
|
| 174 | - public function set_status_header($header) |
|
| 175 | - { |
|
| 176 | - $CI = get_instance(); |
|
| 177 | - $CI->output->set_status_header($header); |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - /** |
|
| 181 | - * Assign the dwootemplate config items to the instance. |
|
| 182 | - */ |
|
| 183 | - private function initialize() |
|
| 184 | - { |
|
| 185 | - $CI = get_instance(); |
|
| 186 | - $CI->config->load('dwootemplate', true); |
|
| 187 | - $config = $CI->config->item('dwootemplate'); |
|
| 188 | - foreach ($config as $key => $val) { |
|
| 189 | - $this->$key = $val; |
|
| 190 | - } |
|
| 191 | - } |
|
| 42 | + protected $dwoo_data = array(); |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * Constructor for the DwooTemplate engine. |
|
| 46 | + */ |
|
| 47 | + public function __construct() |
|
| 48 | + { |
|
| 49 | + // Call parents constructor |
|
| 50 | + parent::__construct(); |
|
| 51 | + |
|
| 52 | + // Set the config settings |
|
| 53 | + $this->initialize(); |
|
| 54 | + |
|
| 55 | + // Assign some defaults to dwoo |
|
| 56 | + $CI = get_instance(); |
|
| 57 | + $this->dwoo_data = new Dwoo_Data(); |
|
| 58 | + $this->dwoo_data->js_files = array(); |
|
| 59 | + $this->dwoo_data->css_files = array(); |
|
| 60 | + $this->dwoo_data->CI = $CI; |
|
| 61 | + $this->dwoo_data->site_url = $CI->config->site_url(); // so we can get the full path to CI easily |
|
| 62 | + $this->dwoo_data->uniqid = uniqid(); |
|
| 63 | + $this->dwoo_data->timestamp = mktime(); |
|
| 64 | + |
|
| 65 | + log_message('debug', 'Dwoo Template Class Initialized'); |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * Assign data to dwoo data object. |
|
| 70 | + * |
|
| 71 | + * @param string $key |
|
| 72 | + * @param mixed $value |
|
| 73 | + */ |
|
| 74 | + public function assign($key, $value) |
|
| 75 | + { |
|
| 76 | + $this->dwoo_data->$key = $value; |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * Add Javascript files to template. |
|
| 81 | + * |
|
| 82 | + * @param string $js |
|
| 83 | + */ |
|
| 84 | + public function add_js($js) |
|
| 85 | + { |
|
| 86 | + $current = $this->dwoo_data->js_files; |
|
| 87 | + $current[] = $js; |
|
| 88 | + $this->dwoo_data->js_files = $current; |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * Add Css stylesheets to template. |
|
| 93 | + * |
|
| 94 | + * @param string $css |
|
| 95 | + */ |
|
| 96 | + public function add_css($css) |
|
| 97 | + { |
|
| 98 | + $current = $this->dwoo_data->css_files; |
|
| 99 | + $current[] = $css; |
|
| 100 | + $this->dwoo_data->css_files = $current; |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * Display or return the compiled template |
|
| 105 | + * Since we assign the results to the standard CI output module |
|
| 106 | + * you can also use the helper from CI in your templates!! |
|
| 107 | + * |
|
| 108 | + * @param string $sTemplate |
|
| 109 | + * @param bool $return |
|
| 110 | + * |
|
| 111 | + * @return mixed |
|
| 112 | + */ |
|
| 113 | + public function display($sTemplate, $return = false) |
|
| 114 | + { |
|
| 115 | + // Start benchmark |
|
| 116 | + $CI = get_instance(); |
|
| 117 | + $CI->benchmark->mark('dwoo_parse_start'); |
|
| 118 | + |
|
| 119 | + // Check if file exists |
|
| 120 | + if (!file_exists($this->template_dir.$sTemplate)) { |
|
| 121 | + $message = sprintf('Template file \'%s\' not found.', $sTemplate); |
|
| 122 | + show_error($message); |
|
| 123 | + log_message('error', $message); |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + // Create new template |
|
| 127 | + $tpl = new Dwoo_Template_File($this->template_dir.$sTemplate); |
|
| 128 | + |
|
| 129 | + // render the template |
|
| 130 | + $template = $this->get($tpl, $this->dwoo_data); |
|
| 131 | + |
|
| 132 | + // Finish benchmark |
|
| 133 | + $CI->benchmark->mark('dwoo_parse_end'); |
|
| 134 | + |
|
| 135 | + // Return results or not ? |
|
| 136 | + if ($return == false) { |
|
| 137 | + $CI->output->final_output = $template; |
|
| 138 | + } else { |
|
| 139 | + return $template; |
|
| 140 | + } |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * Toggle Codeigniter profiler on/off. |
|
| 145 | + */ |
|
| 146 | + public function enable_profiler($toggle = true) |
|
| 147 | + { |
|
| 148 | + $CI = get_instance(); |
|
| 149 | + $CI->output->enable_profiler($toggle); |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * Set http header. |
|
| 154 | + * |
|
| 155 | + * @example $this->output->set_header("HTTP/1.1 200 OK"); |
|
| 156 | + * @example $this->output->set_header('Last-Modified: '.gmdate('D, d M Y H:i:s', $last_update).' GMT'); |
|
| 157 | + * |
|
| 158 | + * @param string $header |
|
| 159 | + */ |
|
| 160 | + public function set_header($header) |
|
| 161 | + { |
|
| 162 | + $CI = get_instance(); |
|
| 163 | + $CI->output->set_header($header); |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + /** |
|
| 167 | + * Set status header. |
|
| 168 | + * |
|
| 169 | + * @example $this->output->set_status_header('401'); |
|
| 170 | + * @example // Sets the header as: Unauthorized |
|
| 171 | + * |
|
| 172 | + * @param string $header |
|
| 173 | + */ |
|
| 174 | + public function set_status_header($header) |
|
| 175 | + { |
|
| 176 | + $CI = get_instance(); |
|
| 177 | + $CI->output->set_status_header($header); |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + /** |
|
| 181 | + * Assign the dwootemplate config items to the instance. |
|
| 182 | + */ |
|
| 183 | + private function initialize() |
|
| 184 | + { |
|
| 185 | + $CI = get_instance(); |
|
| 186 | + $CI->config->load('dwootemplate', true); |
|
| 187 | + $config = $CI->config->item('dwootemplate'); |
|
| 188 | + foreach ($config as $key => $val) { |
|
| 189 | + $this->$key = $val; |
|
| 190 | + } |
|
| 191 | + } |
|
| 192 | 192 | } |
@@ -16,26 +16,26 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | class Dwoo_Adapters_ZendFramework_Dwoo extends Dwoo_Core |
| 18 | 18 | { |
| 19 | - /** |
|
| 20 | - * Redirects all unknown properties to plugin proxy |
|
| 21 | - * to support $this->viewVariable from within templates. |
|
| 22 | - * |
|
| 23 | - * @param string $name Property name |
|
| 24 | - * |
|
| 25 | - * @return mixed |
|
| 26 | - */ |
|
| 27 | - public function __get($name) |
|
| 28 | - { |
|
| 29 | - if (isset($this->getPluginProxy()->view->$name)) { |
|
| 30 | - return $this->getPluginProxy()->view->$name; |
|
| 31 | - } |
|
| 32 | - $trace = debug_backtrace(); |
|
| 33 | - trigger_error( |
|
| 34 | - 'Undefined property via __get(): '.$name. |
|
| 35 | - ' in '.$trace[0]['file']. |
|
| 36 | - ' on line '.$trace[0]['line'], E_USER_NOTICE |
|
| 37 | - ); |
|
| 19 | + /** |
|
| 20 | + * Redirects all unknown properties to plugin proxy |
|
| 21 | + * to support $this->viewVariable from within templates. |
|
| 22 | + * |
|
| 23 | + * @param string $name Property name |
|
| 24 | + * |
|
| 25 | + * @return mixed |
|
| 26 | + */ |
|
| 27 | + public function __get($name) |
|
| 28 | + { |
|
| 29 | + if (isset($this->getPluginProxy()->view->$name)) { |
|
| 30 | + return $this->getPluginProxy()->view->$name; |
|
| 31 | + } |
|
| 32 | + $trace = debug_backtrace(); |
|
| 33 | + trigger_error( |
|
| 34 | + 'Undefined property via __get(): '.$name. |
|
| 35 | + ' in '.$trace[0]['file']. |
|
| 36 | + ' on line '.$trace[0]['line'], E_USER_NOTICE |
|
| 37 | + ); |
|
| 38 | 38 | |
| 39 | - return null; |
|
| 40 | - } |
|
| 39 | + return null; |
|
| 40 | + } |
|
| 41 | 41 | } |
@@ -23,30 +23,30 @@ |
||
| 23 | 23 | */ |
| 24 | 24 | abstract class Processor |
| 25 | 25 | { |
| 26 | - /** |
|
| 27 | - * The compiler instance that runs this processor. |
|
| 28 | - * |
|
| 29 | - * @var Core |
|
| 30 | - */ |
|
| 31 | - protected $compiler; |
|
| 26 | + /** |
|
| 27 | + * The compiler instance that runs this processor. |
|
| 28 | + * |
|
| 29 | + * @var Core |
|
| 30 | + */ |
|
| 31 | + protected $compiler; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * Constructor, if you override it, call parent::__construct($compiler); or assign |
|
| 35 | - * the dwoo instance yourself if you need it. |
|
| 36 | - * |
|
| 37 | - * @param Compiler $compiler the compiler class |
|
| 38 | - */ |
|
| 39 | - public function __construct(Compiler $compiler) |
|
| 40 | - { |
|
| 41 | - $this->compiler = $compiler; |
|
| 42 | - } |
|
| 33 | + /** |
|
| 34 | + * Constructor, if you override it, call parent::__construct($compiler); or assign |
|
| 35 | + * the dwoo instance yourself if you need it. |
|
| 36 | + * |
|
| 37 | + * @param Compiler $compiler the compiler class |
|
| 38 | + */ |
|
| 39 | + public function __construct(Compiler $compiler) |
|
| 40 | + { |
|
| 41 | + $this->compiler = $compiler; |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * Processes the input and returns it filtered. |
|
| 46 | - * |
|
| 47 | - * @param string $input the template to process |
|
| 48 | - * |
|
| 49 | - * @return string |
|
| 50 | - */ |
|
| 51 | - abstract public function process($input); |
|
| 44 | + /** |
|
| 45 | + * Processes the input and returns it filtered. |
|
| 46 | + * |
|
| 47 | + * @param string $input the template to process |
|
| 48 | + * |
|
| 49 | + * @return string |
|
| 50 | + */ |
|
| 51 | + abstract public function process($input); |
|
| 52 | 52 | } |
@@ -29,31 +29,31 @@ |
||
| 29 | 29 | */ |
| 30 | 30 | interface ICompiler |
| 31 | 31 | { |
| 32 | - /** |
|
| 33 | - * Compiles the provided string down to php code. |
|
| 34 | - * |
|
| 35 | - * @param Core $dwoo |
|
| 36 | - * @param ITemplate $template the template to compile |
|
| 37 | - * |
|
| 38 | - * @return string a compiled php code string |
|
| 39 | - */ |
|
| 40 | - public function compile(Core $dwoo, ITemplate $template); |
|
| 32 | + /** |
|
| 33 | + * Compiles the provided string down to php code. |
|
| 34 | + * |
|
| 35 | + * @param Core $dwoo |
|
| 36 | + * @param ITemplate $template the template to compile |
|
| 37 | + * |
|
| 38 | + * @return string a compiled php code string |
|
| 39 | + */ |
|
| 40 | + public function compile(Core $dwoo, ITemplate $template); |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * Adds the custom plugins loaded into Dwoo to the compiler so it can load them. |
|
| 44 | - * |
|
| 45 | - * @see Core::addPlugin |
|
| 46 | - * |
|
| 47 | - * @param array $customPlugins an array of custom plugins |
|
| 48 | - */ |
|
| 49 | - public function setCustomPlugins(array $customPlugins); |
|
| 42 | + /** |
|
| 43 | + * Adds the custom plugins loaded into Dwoo to the compiler so it can load them. |
|
| 44 | + * |
|
| 45 | + * @see Core::addPlugin |
|
| 46 | + * |
|
| 47 | + * @param array $customPlugins an array of custom plugins |
|
| 48 | + */ |
|
| 49 | + public function setCustomPlugins(array $customPlugins); |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * Sets the security policy object to enforce some php security settings. |
|
| 53 | - * use this if untrusted persons can modify templates, |
|
| 54 | - * set it on the Dwoo object as it will be passed onto the compiler automatically |
|
| 55 | - * |
|
| 56 | - * @param SecurityPolicy $policy the security policy object |
|
| 57 | - */ |
|
| 58 | - public function setSecurityPolicy(SecurityPolicy $policy = null); |
|
| 51 | + /** |
|
| 52 | + * Sets the security policy object to enforce some php security settings. |
|
| 53 | + * use this if untrusted persons can modify templates, |
|
| 54 | + * set it on the Dwoo object as it will be passed onto the compiler automatically |
|
| 55 | + * |
|
| 56 | + * @param SecurityPolicy $policy the security policy object |
|
| 57 | + */ |
|
| 58 | + public function setSecurityPolicy(SecurityPolicy $policy = null); |
|
| 59 | 59 | } |
@@ -24,241 +24,241 @@ |
||
| 24 | 24 | */ |
| 25 | 25 | class Data implements IDataProvider |
| 26 | 26 | { |
| 27 | - /** |
|
| 28 | - * Data array. |
|
| 29 | - * |
|
| 30 | - * @var array |
|
| 31 | - */ |
|
| 32 | - protected $data = array(); |
|
| 27 | + /** |
|
| 28 | + * Data array. |
|
| 29 | + * |
|
| 30 | + * @var array |
|
| 31 | + */ |
|
| 32 | + protected $data = array(); |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Returns the data array. |
|
| 36 | - * |
|
| 37 | - * @return array |
|
| 38 | - */ |
|
| 39 | - public function getData() |
|
| 40 | - { |
|
| 41 | - return $this->data; |
|
| 42 | - } |
|
| 34 | + /** |
|
| 35 | + * Returns the data array. |
|
| 36 | + * |
|
| 37 | + * @return array |
|
| 38 | + */ |
|
| 39 | + public function getData() |
|
| 40 | + { |
|
| 41 | + return $this->data; |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * Clears a the entire data or only the given key. |
|
| 46 | - * |
|
| 47 | - * @param array|string $name clears only one value if you give a name, multiple values if |
|
| 48 | - * you give an array of names, or the entire data if left null |
|
| 49 | - */ |
|
| 50 | - public function clear($name = null) |
|
| 51 | - { |
|
| 52 | - if ($name === null) { |
|
| 53 | - $this->data = array(); |
|
| 54 | - } elseif (is_array($name)) { |
|
| 55 | - foreach ($name as $index) { |
|
| 56 | - unset($this->data[$index]); |
|
| 57 | - } |
|
| 58 | - } else { |
|
| 59 | - unset($this->data[$name]); |
|
| 60 | - } |
|
| 61 | - } |
|
| 44 | + /** |
|
| 45 | + * Clears a the entire data or only the given key. |
|
| 46 | + * |
|
| 47 | + * @param array|string $name clears only one value if you give a name, multiple values if |
|
| 48 | + * you give an array of names, or the entire data if left null |
|
| 49 | + */ |
|
| 50 | + public function clear($name = null) |
|
| 51 | + { |
|
| 52 | + if ($name === null) { |
|
| 53 | + $this->data = array(); |
|
| 54 | + } elseif (is_array($name)) { |
|
| 55 | + foreach ($name as $index) { |
|
| 56 | + unset($this->data[$index]); |
|
| 57 | + } |
|
| 58 | + } else { |
|
| 59 | + unset($this->data[$name]); |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * Overwrites the entire data with the given array. |
|
| 65 | - * |
|
| 66 | - * @param array $data the new data array to use |
|
| 67 | - */ |
|
| 68 | - public function setData(array $data) |
|
| 69 | - { |
|
| 70 | - $this->data = $data; |
|
| 71 | - } |
|
| 63 | + /** |
|
| 64 | + * Overwrites the entire data with the given array. |
|
| 65 | + * |
|
| 66 | + * @param array $data the new data array to use |
|
| 67 | + */ |
|
| 68 | + public function setData(array $data) |
|
| 69 | + { |
|
| 70 | + $this->data = $data; |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * merges the given array(s) with the current data with array_merge. |
|
| 75 | - * |
|
| 76 | - * @param array $data the array to merge |
|
| 77 | - */ |
|
| 78 | - public function mergeData(array $data) |
|
| 79 | - { |
|
| 80 | - $args = func_get_args(); |
|
| 81 | - while (list(, $v) = each($args)) { |
|
| 82 | - if (is_array($v)) { |
|
| 83 | - $this->data = array_merge($this->data, $v); |
|
| 84 | - } |
|
| 85 | - } |
|
| 86 | - } |
|
| 73 | + /** |
|
| 74 | + * merges the given array(s) with the current data with array_merge. |
|
| 75 | + * |
|
| 76 | + * @param array $data the array to merge |
|
| 77 | + */ |
|
| 78 | + public function mergeData(array $data) |
|
| 79 | + { |
|
| 80 | + $args = func_get_args(); |
|
| 81 | + while (list(, $v) = each($args)) { |
|
| 82 | + if (is_array($v)) { |
|
| 83 | + $this->data = array_merge($this->data, $v); |
|
| 84 | + } |
|
| 85 | + } |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - /** |
|
| 89 | - * Assigns a value or an array of values to the data object. |
|
| 90 | - * |
|
| 91 | - * @param array|string $name an associative array of multiple (index=>value) or a string |
|
| 92 | - * that is the index to use, i.e. a value assigned to "foo" will be |
|
| 93 | - * accessible in the template through {$foo} |
|
| 94 | - * @param mixed $val the value to assign, or null if $name was an array |
|
| 95 | - */ |
|
| 96 | - public function assign($name, $val = null) |
|
| 97 | - { |
|
| 98 | - if (is_array($name)) { |
|
| 99 | - reset($name); |
|
| 100 | - while (list($k, $v) = each($name)) { |
|
| 101 | - $this->data[$k] = $v; |
|
| 102 | - } |
|
| 103 | - } else { |
|
| 104 | - $this->data[$name] = $val; |
|
| 105 | - } |
|
| 106 | - } |
|
| 88 | + /** |
|
| 89 | + * Assigns a value or an array of values to the data object. |
|
| 90 | + * |
|
| 91 | + * @param array|string $name an associative array of multiple (index=>value) or a string |
|
| 92 | + * that is the index to use, i.e. a value assigned to "foo" will be |
|
| 93 | + * accessible in the template through {$foo} |
|
| 94 | + * @param mixed $val the value to assign, or null if $name was an array |
|
| 95 | + */ |
|
| 96 | + public function assign($name, $val = null) |
|
| 97 | + { |
|
| 98 | + if (is_array($name)) { |
|
| 99 | + reset($name); |
|
| 100 | + while (list($k, $v) = each($name)) { |
|
| 101 | + $this->data[$k] = $v; |
|
| 102 | + } |
|
| 103 | + } else { |
|
| 104 | + $this->data[$name] = $val; |
|
| 105 | + } |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | - /** |
|
| 109 | - * Allows to assign variables using the object syntax. |
|
| 110 | - * |
|
| 111 | - * @param string $name the variable name |
|
| 112 | - * @param string $value the value to assign to it |
|
| 113 | - */ |
|
| 114 | - public function __set($name, $value) |
|
| 115 | - { |
|
| 116 | - $this->assign($name, $value); |
|
| 117 | - } |
|
| 108 | + /** |
|
| 109 | + * Allows to assign variables using the object syntax. |
|
| 110 | + * |
|
| 111 | + * @param string $name the variable name |
|
| 112 | + * @param string $value the value to assign to it |
|
| 113 | + */ |
|
| 114 | + public function __set($name, $value) |
|
| 115 | + { |
|
| 116 | + $this->assign($name, $value); |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | - /** |
|
| 120 | - * Assigns a value by reference to the data object. |
|
| 121 | - * |
|
| 122 | - * @param string $name the index to use, i.e. a value assigned to "foo" will be |
|
| 123 | - * accessible in the template through {$foo} |
|
| 124 | - * @param mixed $val the value to assign by reference |
|
| 125 | - */ |
|
| 126 | - public function assignByRef($name, &$val) |
|
| 127 | - { |
|
| 128 | - $this->data[$name] = &$val; |
|
| 129 | - } |
|
| 119 | + /** |
|
| 120 | + * Assigns a value by reference to the data object. |
|
| 121 | + * |
|
| 122 | + * @param string $name the index to use, i.e. a value assigned to "foo" will be |
|
| 123 | + * accessible in the template through {$foo} |
|
| 124 | + * @param mixed $val the value to assign by reference |
|
| 125 | + */ |
|
| 126 | + public function assignByRef($name, &$val) |
|
| 127 | + { |
|
| 128 | + $this->data[$name] = &$val; |
|
| 129 | + } |
|
| 130 | 130 | |
| 131 | - /** |
|
| 132 | - * Appends values or an array of values to the data object. |
|
| 133 | - * |
|
| 134 | - * @param array|string $name an associative array of multiple (index=>value) or a string |
|
| 135 | - * that is the index to use, i.e. a value assigned to "foo" will be |
|
| 136 | - * accessible in the template through {$foo} |
|
| 137 | - * @param mixed $val the value to assign, or null if $name was an array |
|
| 138 | - * @param bool $merge true to merge data or false to append, defaults to false |
|
| 139 | - */ |
|
| 140 | - public function append($name, $val = null, $merge = false) |
|
| 141 | - { |
|
| 142 | - if (is_array($name)) { |
|
| 143 | - foreach ($name as $key => $val) { |
|
| 144 | - if (isset($this->data[$key]) && !is_array($this->data[$key])) { |
|
| 145 | - settype($this->data[$key], 'array'); |
|
| 146 | - } |
|
| 131 | + /** |
|
| 132 | + * Appends values or an array of values to the data object. |
|
| 133 | + * |
|
| 134 | + * @param array|string $name an associative array of multiple (index=>value) or a string |
|
| 135 | + * that is the index to use, i.e. a value assigned to "foo" will be |
|
| 136 | + * accessible in the template through {$foo} |
|
| 137 | + * @param mixed $val the value to assign, or null if $name was an array |
|
| 138 | + * @param bool $merge true to merge data or false to append, defaults to false |
|
| 139 | + */ |
|
| 140 | + public function append($name, $val = null, $merge = false) |
|
| 141 | + { |
|
| 142 | + if (is_array($name)) { |
|
| 143 | + foreach ($name as $key => $val) { |
|
| 144 | + if (isset($this->data[$key]) && !is_array($this->data[$key])) { |
|
| 145 | + settype($this->data[$key], 'array'); |
|
| 146 | + } |
|
| 147 | 147 | |
| 148 | - if ($merge === true && is_array($val)) { |
|
| 149 | - $this->data[$key] = $val + $this->data[$key]; |
|
| 150 | - } else { |
|
| 151 | - $this->data[$key][] = $val; |
|
| 152 | - } |
|
| 153 | - } |
|
| 154 | - } elseif ($val !== null) { |
|
| 155 | - if (isset($this->data[$name]) && !is_array($this->data[$name])) { |
|
| 156 | - settype($this->data[$name], 'array'); |
|
| 157 | - } elseif (!isset($this->data[$name])) { |
|
| 158 | - $this->data[$name] = array(); |
|
| 159 | - } |
|
| 148 | + if ($merge === true && is_array($val)) { |
|
| 149 | + $this->data[$key] = $val + $this->data[$key]; |
|
| 150 | + } else { |
|
| 151 | + $this->data[$key][] = $val; |
|
| 152 | + } |
|
| 153 | + } |
|
| 154 | + } elseif ($val !== null) { |
|
| 155 | + if (isset($this->data[$name]) && !is_array($this->data[$name])) { |
|
| 156 | + settype($this->data[$name], 'array'); |
|
| 157 | + } elseif (!isset($this->data[$name])) { |
|
| 158 | + $this->data[$name] = array(); |
|
| 159 | + } |
|
| 160 | 160 | |
| 161 | - if ($merge === true && is_array($val)) { |
|
| 162 | - $this->data[$name] = $val + $this->data[$name]; |
|
| 163 | - } else { |
|
| 164 | - $this->data[$name][] = $val; |
|
| 165 | - } |
|
| 166 | - } |
|
| 167 | - } |
|
| 161 | + if ($merge === true && is_array($val)) { |
|
| 162 | + $this->data[$name] = $val + $this->data[$name]; |
|
| 163 | + } else { |
|
| 164 | + $this->data[$name][] = $val; |
|
| 165 | + } |
|
| 166 | + } |
|
| 167 | + } |
|
| 168 | 168 | |
| 169 | - /** |
|
| 170 | - * Appends a value by reference to the data object. |
|
| 171 | - * |
|
| 172 | - * @param string $name the index to use, i.e. a value assigned to "foo" will be |
|
| 173 | - * accessible in the template through {$foo} |
|
| 174 | - * @param mixed $val the value to append by reference |
|
| 175 | - * @param bool $merge true to merge data or false to append, defaults to false |
|
| 176 | - */ |
|
| 177 | - public function appendByRef($name, &$val, $merge = false) |
|
| 178 | - { |
|
| 179 | - if (isset($this->data[$name]) && !is_array($this->data[$name])) { |
|
| 180 | - settype($this->data[$name], 'array'); |
|
| 181 | - } |
|
| 169 | + /** |
|
| 170 | + * Appends a value by reference to the data object. |
|
| 171 | + * |
|
| 172 | + * @param string $name the index to use, i.e. a value assigned to "foo" will be |
|
| 173 | + * accessible in the template through {$foo} |
|
| 174 | + * @param mixed $val the value to append by reference |
|
| 175 | + * @param bool $merge true to merge data or false to append, defaults to false |
|
| 176 | + */ |
|
| 177 | + public function appendByRef($name, &$val, $merge = false) |
|
| 178 | + { |
|
| 179 | + if (isset($this->data[$name]) && !is_array($this->data[$name])) { |
|
| 180 | + settype($this->data[$name], 'array'); |
|
| 181 | + } |
|
| 182 | 182 | |
| 183 | - if ($merge === true && is_array($val)) { |
|
| 184 | - foreach ($val as $key => &$value) { |
|
| 185 | - $this->data[$name][$key] = &$value; |
|
| 186 | - } |
|
| 187 | - } else { |
|
| 188 | - $this->data[$name][] = &$val; |
|
| 189 | - } |
|
| 190 | - } |
|
| 183 | + if ($merge === true && is_array($val)) { |
|
| 184 | + foreach ($val as $key => &$value) { |
|
| 185 | + $this->data[$name][$key] = &$value; |
|
| 186 | + } |
|
| 187 | + } else { |
|
| 188 | + $this->data[$name][] = &$val; |
|
| 189 | + } |
|
| 190 | + } |
|
| 191 | 191 | |
| 192 | - /** |
|
| 193 | - * Returns true if the variable has been assigned already, false otherwise. |
|
| 194 | - * |
|
| 195 | - * @param string $name the variable name |
|
| 196 | - * |
|
| 197 | - * @return bool |
|
| 198 | - */ |
|
| 199 | - public function isAssigned($name) |
|
| 200 | - { |
|
| 201 | - return isset($this->data[$name]); |
|
| 202 | - } |
|
| 192 | + /** |
|
| 193 | + * Returns true if the variable has been assigned already, false otherwise. |
|
| 194 | + * |
|
| 195 | + * @param string $name the variable name |
|
| 196 | + * |
|
| 197 | + * @return bool |
|
| 198 | + */ |
|
| 199 | + public function isAssigned($name) |
|
| 200 | + { |
|
| 201 | + return isset($this->data[$name]); |
|
| 202 | + } |
|
| 203 | 203 | |
| 204 | - /** |
|
| 205 | - * Supports calls to isset($dwoo->var). |
|
| 206 | - * |
|
| 207 | - * @param string $name the variable name |
|
| 208 | - * |
|
| 209 | - * @return bool |
|
| 210 | - */ |
|
| 211 | - public function __isset($name) |
|
| 212 | - { |
|
| 213 | - return isset($this->data[$name]); |
|
| 214 | - } |
|
| 204 | + /** |
|
| 205 | + * Supports calls to isset($dwoo->var). |
|
| 206 | + * |
|
| 207 | + * @param string $name the variable name |
|
| 208 | + * |
|
| 209 | + * @return bool |
|
| 210 | + */ |
|
| 211 | + public function __isset($name) |
|
| 212 | + { |
|
| 213 | + return isset($this->data[$name]); |
|
| 214 | + } |
|
| 215 | 215 | |
| 216 | - /** |
|
| 217 | - * Unassigns/removes a variable. |
|
| 218 | - * |
|
| 219 | - * @param string $name the variable name |
|
| 220 | - */ |
|
| 221 | - public function unassign($name) |
|
| 222 | - { |
|
| 223 | - unset($this->data[$name]); |
|
| 224 | - } |
|
| 216 | + /** |
|
| 217 | + * Unassigns/removes a variable. |
|
| 218 | + * |
|
| 219 | + * @param string $name the variable name |
|
| 220 | + */ |
|
| 221 | + public function unassign($name) |
|
| 222 | + { |
|
| 223 | + unset($this->data[$name]); |
|
| 224 | + } |
|
| 225 | 225 | |
| 226 | - /** |
|
| 227 | - * Supports unsetting variables using the object syntax. |
|
| 228 | - * |
|
| 229 | - * @param string $name the variable name |
|
| 230 | - */ |
|
| 231 | - public function __unset($name) |
|
| 232 | - { |
|
| 233 | - unset($this->data[$name]); |
|
| 234 | - } |
|
| 226 | + /** |
|
| 227 | + * Supports unsetting variables using the object syntax. |
|
| 228 | + * |
|
| 229 | + * @param string $name the variable name |
|
| 230 | + */ |
|
| 231 | + public function __unset($name) |
|
| 232 | + { |
|
| 233 | + unset($this->data[$name]); |
|
| 234 | + } |
|
| 235 | 235 | |
| 236 | - /** |
|
| 237 | - * Returns a variable if it was assigned. |
|
| 238 | - * |
|
| 239 | - * @param string $name the variable name |
|
| 240 | - * |
|
| 241 | - * @return mixed |
|
| 242 | - */ |
|
| 243 | - public function get($name) |
|
| 244 | - { |
|
| 245 | - return $this->__get($name); |
|
| 246 | - } |
|
| 236 | + /** |
|
| 237 | + * Returns a variable if it was assigned. |
|
| 238 | + * |
|
| 239 | + * @param string $name the variable name |
|
| 240 | + * |
|
| 241 | + * @return mixed |
|
| 242 | + */ |
|
| 243 | + public function get($name) |
|
| 244 | + { |
|
| 245 | + return $this->__get($name); |
|
| 246 | + } |
|
| 247 | 247 | |
| 248 | - /** |
|
| 249 | - * Allows to read variables using the object syntax. |
|
| 250 | - * |
|
| 251 | - * @param string $name the variable name |
|
| 252 | - * |
|
| 253 | - * @return mixed |
|
| 254 | - * @throws Exception |
|
| 255 | - */ |
|
| 256 | - public function __get($name) |
|
| 257 | - { |
|
| 258 | - if (isset($this->data[$name])) { |
|
| 259 | - return $this->data[$name]; |
|
| 260 | - } else { |
|
| 261 | - throw new Exception('Tried to read a value that was not assigned yet : "' . $name . '"'); |
|
| 262 | - } |
|
| 263 | - } |
|
| 248 | + /** |
|
| 249 | + * Allows to read variables using the object syntax. |
|
| 250 | + * |
|
| 251 | + * @param string $name the variable name |
|
| 252 | + * |
|
| 253 | + * @return mixed |
|
| 254 | + * @throws Exception |
|
| 255 | + */ |
|
| 256 | + public function __get($name) |
|
| 257 | + { |
|
| 258 | + if (isset($this->data[$name])) { |
|
| 259 | + return $this->data[$name]; |
|
| 260 | + } else { |
|
| 261 | + throw new Exception('Tried to read a value that was not assigned yet : "' . $name . '"'); |
|
| 262 | + } |
|
| 263 | + } |
|
| 264 | 264 | } |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | if ($merge === true && is_array($val)) { |
| 149 | - $this->data[$key] = $val + $this->data[$key]; |
|
| 149 | + $this->data[$key] = $val+$this->data[$key]; |
|
| 150 | 150 | } else { |
| 151 | 151 | $this->data[$key][] = $val; |
| 152 | 152 | } |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | if ($merge === true && is_array($val)) { |
| 162 | - $this->data[$name] = $val + $this->data[$name]; |
|
| 162 | + $this->data[$name] = $val+$this->data[$name]; |
|
| 163 | 163 | } else { |
| 164 | 164 | $this->data[$name][] = $val; |
| 165 | 165 | } |
@@ -258,7 +258,7 @@ discard block |
||
| 258 | 258 | if (isset($this->data[$name])) { |
| 259 | 259 | return $this->data[$name]; |
| 260 | 260 | } else { |
| 261 | - throw new Exception('Tried to read a value that was not assigned yet : "' . $name . '"'); |
|
| 261 | + throw new Exception('Tried to read a value that was not assigned yet : "'.$name.'"'); |
|
| 262 | 262 | } |
| 263 | 263 | } |
| 264 | 264 | } |
@@ -25,81 +25,81 @@ |
||
| 25 | 25 | */ |
| 26 | 26 | abstract class Plugin |
| 27 | 27 | { |
| 28 | - /** |
|
| 29 | - * The dwoo instance that runs this plugin. |
|
| 30 | - * |
|
| 31 | - * @var Core |
|
| 32 | - */ |
|
| 33 | - protected $core; |
|
| 28 | + /** |
|
| 29 | + * The dwoo instance that runs this plugin. |
|
| 30 | + * |
|
| 31 | + * @var Core |
|
| 32 | + */ |
|
| 33 | + protected $core; |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * Constructor, if you override it, call parent::__construct($core); or assign |
|
| 37 | - * the dwoo instance yourself if you need it. |
|
| 38 | - * |
|
| 39 | - * @param Core $core the dwoo instance that runs this plugin |
|
| 40 | - */ |
|
| 41 | - public function __construct(Core $core) |
|
| 42 | - { |
|
| 43 | - $this->core = $core; |
|
| 44 | - } |
|
| 35 | + /** |
|
| 36 | + * Constructor, if you override it, call parent::__construct($core); or assign |
|
| 37 | + * the dwoo instance yourself if you need it. |
|
| 38 | + * |
|
| 39 | + * @param Core $core the dwoo instance that runs this plugin |
|
| 40 | + */ |
|
| 41 | + public function __construct(Core $core) |
|
| 42 | + { |
|
| 43 | + $this->core = $core; |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - // plugins should always implement : |
|
| 47 | - // public function process($arg, $arg, ...) |
|
| 48 | - // or for block plugins : |
|
| 49 | - // public function init($arg, $arg, ...) |
|
| 46 | + // plugins should always implement : |
|
| 47 | + // public function process($arg, $arg, ...) |
|
| 48 | + // or for block plugins : |
|
| 49 | + // public function init($arg, $arg, ...) |
|
| 50 | 50 | |
| 51 | - // this could be enforced with : |
|
| 52 | - // abstract public function process(...); |
|
| 53 | - // if my feature request gets enough interest one day |
|
| 54 | - // see => http://bugs.php.net/bug.php?id=44043 |
|
| 51 | + // this could be enforced with : |
|
| 52 | + // abstract public function process(...); |
|
| 53 | + // if my feature request gets enough interest one day |
|
| 54 | + // see => http://bugs.php.net/bug.php?id=44043 |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * Utility function that converts an array of compiled parameters (or rest array) to a string of xml/html tag |
|
| 58 | - * attributes. this is to be used in preProcessing or postProcessing functions, example : |
|
| 59 | - * $p = $compiler->getCompiledParams($params); |
|
| 60 | - * // get only the rest array as attributes |
|
| 61 | - * $attributes = Plugin::paramsToAttributes($p['*']); |
|
| 62 | - * // get all the parameters as attributes (if there is a rest array, it will be included) |
|
| 63 | - * $attributes = Plugin::paramsToAttributes($p); |
|
| 64 | - * |
|
| 65 | - * @param array $params an array of attributeName=>value items that will be compiled to be ready for inclusion in a php string |
|
| 66 | - * inclusion in a php string |
|
| 67 | - * @param string $delim the string delimiter you want to use (defaults to ') |
|
| 68 | - * @param Compiler $compiler the compiler instance (optional for BC, but recommended to pass it for proper escaping behavior) |
|
| 69 | - * escaping behavior) |
|
| 70 | - * |
|
| 71 | - * @return string |
|
| 72 | - */ |
|
| 73 | - public static function paramsToAttributes(array $params, $delim = '\'', Compiler $compiler = null) |
|
| 74 | - { |
|
| 75 | - if (isset($params['*'])) { |
|
| 76 | - $params = array_merge($params, $params['*']); |
|
| 77 | - unset($params['*']); |
|
| 78 | - } |
|
| 56 | + /** |
|
| 57 | + * Utility function that converts an array of compiled parameters (or rest array) to a string of xml/html tag |
|
| 58 | + * attributes. this is to be used in preProcessing or postProcessing functions, example : |
|
| 59 | + * $p = $compiler->getCompiledParams($params); |
|
| 60 | + * // get only the rest array as attributes |
|
| 61 | + * $attributes = Plugin::paramsToAttributes($p['*']); |
|
| 62 | + * // get all the parameters as attributes (if there is a rest array, it will be included) |
|
| 63 | + * $attributes = Plugin::paramsToAttributes($p); |
|
| 64 | + * |
|
| 65 | + * @param array $params an array of attributeName=>value items that will be compiled to be ready for inclusion in a php string |
|
| 66 | + * inclusion in a php string |
|
| 67 | + * @param string $delim the string delimiter you want to use (defaults to ') |
|
| 68 | + * @param Compiler $compiler the compiler instance (optional for BC, but recommended to pass it for proper escaping behavior) |
|
| 69 | + * escaping behavior) |
|
| 70 | + * |
|
| 71 | + * @return string |
|
| 72 | + */ |
|
| 73 | + public static function paramsToAttributes(array $params, $delim = '\'', Compiler $compiler = null) |
|
| 74 | + { |
|
| 75 | + if (isset($params['*'])) { |
|
| 76 | + $params = array_merge($params, $params['*']); |
|
| 77 | + unset($params['*']); |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - $out = ''; |
|
| 81 | - foreach ($params as $attr => $val) { |
|
| 82 | - $out .= ' ' . $attr . '='; |
|
| 83 | - if (trim($val, '"\'') == '' || $val == 'null') { |
|
| 84 | - $out .= str_replace($delim, '\\' . $delim, '""'); |
|
| 85 | - } elseif (substr($val, 0, 1) === $delim && substr($val, - 1) === $delim) { |
|
| 86 | - $out .= str_replace($delim, '\\' . $delim, '"' . substr($val, 1, - 1) . '"'); |
|
| 87 | - } else { |
|
| 88 | - if (!$compiler) { |
|
| 89 | - // disable double encoding since it can not be determined if it was encoded |
|
| 90 | - $escapedVal = '.(is_string($tmp2=' . $val . ') ? htmlspecialchars($tmp2, ENT_QUOTES, $this->charset, false) : $tmp2).'; |
|
| 91 | - } elseif (!$compiler->getAutoEscape() || false === strpos($val, 'isset($this->scope')) { |
|
| 92 | - // escape if auto escaping is disabled, or there was no variable in the string |
|
| 93 | - $escapedVal = '.(is_string($tmp2=' . $val . ') ? htmlspecialchars($tmp2, ENT_QUOTES, $this->charset) : $tmp2).'; |
|
| 94 | - } else { |
|
| 95 | - // print as is |
|
| 96 | - $escapedVal = '.' . $val . '.'; |
|
| 97 | - } |
|
| 80 | + $out = ''; |
|
| 81 | + foreach ($params as $attr => $val) { |
|
| 82 | + $out .= ' ' . $attr . '='; |
|
| 83 | + if (trim($val, '"\'') == '' || $val == 'null') { |
|
| 84 | + $out .= str_replace($delim, '\\' . $delim, '""'); |
|
| 85 | + } elseif (substr($val, 0, 1) === $delim && substr($val, - 1) === $delim) { |
|
| 86 | + $out .= str_replace($delim, '\\' . $delim, '"' . substr($val, 1, - 1) . '"'); |
|
| 87 | + } else { |
|
| 88 | + if (!$compiler) { |
|
| 89 | + // disable double encoding since it can not be determined if it was encoded |
|
| 90 | + $escapedVal = '.(is_string($tmp2=' . $val . ') ? htmlspecialchars($tmp2, ENT_QUOTES, $this->charset, false) : $tmp2).'; |
|
| 91 | + } elseif (!$compiler->getAutoEscape() || false === strpos($val, 'isset($this->scope')) { |
|
| 92 | + // escape if auto escaping is disabled, or there was no variable in the string |
|
| 93 | + $escapedVal = '.(is_string($tmp2=' . $val . ') ? htmlspecialchars($tmp2, ENT_QUOTES, $this->charset) : $tmp2).'; |
|
| 94 | + } else { |
|
| 95 | + // print as is |
|
| 96 | + $escapedVal = '.' . $val . '.'; |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | - $out .= str_replace($delim, '\\' . $delim, '"') . $delim . $escapedVal . $delim . str_replace($delim, '\\' . $delim, '"'); |
|
| 100 | - } |
|
| 101 | - } |
|
| 99 | + $out .= str_replace($delim, '\\' . $delim, '"') . $delim . $escapedVal . $delim . str_replace($delim, '\\' . $delim, '"'); |
|
| 100 | + } |
|
| 101 | + } |
|
| 102 | 102 | |
| 103 | - return ltrim($out); |
|
| 104 | - } |
|
| 103 | + return ltrim($out); |
|
| 104 | + } |
|
| 105 | 105 | } |
@@ -79,24 +79,24 @@ |
||
| 79 | 79 | |
| 80 | 80 | $out = ''; |
| 81 | 81 | foreach ($params as $attr => $val) { |
| 82 | - $out .= ' ' . $attr . '='; |
|
| 82 | + $out .= ' '.$attr.'='; |
|
| 83 | 83 | if (trim($val, '"\'') == '' || $val == 'null') { |
| 84 | - $out .= str_replace($delim, '\\' . $delim, '""'); |
|
| 84 | + $out .= str_replace($delim, '\\'.$delim, '""'); |
|
| 85 | 85 | } elseif (substr($val, 0, 1) === $delim && substr($val, - 1) === $delim) { |
| 86 | - $out .= str_replace($delim, '\\' . $delim, '"' . substr($val, 1, - 1) . '"'); |
|
| 86 | + $out .= str_replace($delim, '\\'.$delim, '"'.substr($val, 1, - 1).'"'); |
|
| 87 | 87 | } else { |
| 88 | 88 | if (!$compiler) { |
| 89 | 89 | // disable double encoding since it can not be determined if it was encoded |
| 90 | - $escapedVal = '.(is_string($tmp2=' . $val . ') ? htmlspecialchars($tmp2, ENT_QUOTES, $this->charset, false) : $tmp2).'; |
|
| 90 | + $escapedVal = '.(is_string($tmp2='.$val.') ? htmlspecialchars($tmp2, ENT_QUOTES, $this->charset, false) : $tmp2).'; |
|
| 91 | 91 | } elseif (!$compiler->getAutoEscape() || false === strpos($val, 'isset($this->scope')) { |
| 92 | 92 | // escape if auto escaping is disabled, or there was no variable in the string |
| 93 | - $escapedVal = '.(is_string($tmp2=' . $val . ') ? htmlspecialchars($tmp2, ENT_QUOTES, $this->charset) : $tmp2).'; |
|
| 93 | + $escapedVal = '.(is_string($tmp2='.$val.') ? htmlspecialchars($tmp2, ENT_QUOTES, $this->charset) : $tmp2).'; |
|
| 94 | 94 | } else { |
| 95 | 95 | // print as is |
| 96 | - $escapedVal = '.' . $val . '.'; |
|
| 96 | + $escapedVal = '.'.$val.'.'; |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | - $out .= str_replace($delim, '\\' . $delim, '"') . $delim . $escapedVal . $delim . str_replace($delim, '\\' . $delim, '"'); |
|
| 99 | + $out .= str_replace($delim, '\\'.$delim, '"').$delim.$escapedVal.$delim.str_replace($delim, '\\'.$delim, '"'); |
|
| 100 | 100 | } |
| 101 | 101 | } |
| 102 | 102 | |