private $_helpers = array();
/**
- * Callback for escaping.
- *
- * @var string
- */
- private $_escape = 'htmlspecialchars';
-
- /**
* Encoding to use in escaping mechanisms; defaults to UTF-8.
* @var string
*/
*/
public function __construct($config = array())
{
- // user-defined escaping callback
- if (!empty($config['escape'])) {
- $this->setEscape($config['escape']);
- }
-
// encoding
if (!empty($config['encoding'])) {
$this->setEncoding($config['encoding']);
}
/**
- * Sets the escape() callback.
- *
- * @param mixed $spec The callback for escape() to use.
- */
- public function setEscape($spec)
- {
- $this->_escape = $spec;
- }
-
- /**
* Assigns multiple variables to the view.
*
* The array keys are used as names, each assigned their
}
/**
- * Escapes a value for output in a template.
- *
- * If escaping mechanism is one of htmlspecialchars or htmlentities, uses
- * {@link $_encoding} setting.
- *
- * @param mixed $var The output to escape.
- *
- * @return mixed The escaped value.
- */
- public function escape($var)
- {
- if (in_array($this->_escape, array('htmlspecialchars', 'htmlentities'))) {
- return call_user_func($this->_escape, $var, ENT_QUOTES, $this->_encoding);
- }
-
- return call_user_func($this->_escape, $var);
- }
-
- /**
- * Set encoding to use with htmlentities() and htmlspecialchars()
+ * Set encoding
*
* @param string $encoding
*/
}
/**
- * Return current escape encoding
+ * Return current encoding
*
* @return string
*/
}
/**
+ * Escapes a value for output in a view template.
+ *
+ * <code>
+ * <p><?= $this->h($this->templateVar) ?></p>
+ * </code>
+ *
+ * @param mixed $var The output to escape.
+ * @return mixed The escaped value.
+ */
+ public function escape($var)
+ {
+ return htmlspecialchars($var, ENT_QUOTES, $this->_view->getEncoding());
+ }
+
+ /**
* Returns the escaped $html without affecting existing escaped entities.
*
* $this->escapeOnce("1 > 2 & 3")
public function addHelper($helper);
/**
- * Sets the escape() callback.
- *
- * @param mixed $spec The callback for escape() to use.
- */
- public function setEscape($spec);
-
- /**
* Assigns multiple variables to the view.
*
* The array keys are used as names, each assigned their
public function render($name);
/**
- * Escapes a value for output in a template.
- *
- * If escaping mechanism is one of htmlspecialchars or htmlentities, uses
- * {@link $_encoding} setting.
- *
- * @param mixed $var The output to escape.
- *
- * @return mixed The escaped value.
- */
- public function escape($var);
-
- /**
- * Set encoding to use with htmlentities() and htmlspecialchars()
+ * Set encoding
*
* @param string $encoding
*/
public function setEncoding($encoding);
/**
- * Return current escape encoding
+ * Return current encoding
*
* @return string
*/