Commit 8ff052cb by Taylor Otwell

Merge pull request #1180 from unikent/master

Performance enhancement for HTML Class.
parents 6140089e f02e7dc4
...@@ -10,6 +10,13 @@ class HTML { ...@@ -10,6 +10,13 @@ class HTML {
public static $macros = array(); public static $macros = array();
/** /**
* Cache application encoding locally to save expensive calls to config::get().
*
* @var string
*/
public static $encoding = null;
/**
* Registers a custom macro. * Registers a custom macro.
* *
* @param string $name * @param string $name
...@@ -31,7 +38,7 @@ class HTML { ...@@ -31,7 +38,7 @@ class HTML {
*/ */
public static function entities($value) public static function entities($value)
{ {
return htmlentities($value, ENT_QUOTES, Config::get('application.encoding'), false); return htmlentities($value, ENT_QUOTES, static::encoding(), false);
} }
/** /**
...@@ -42,7 +49,7 @@ class HTML { ...@@ -42,7 +49,7 @@ class HTML {
*/ */
public static function decode($value) public static function decode($value)
{ {
return html_entity_decode($value, ENT_QUOTES, Config::get('application.encoding')); return html_entity_decode($value, ENT_QUOTES, static::encoding());
} }
/** /**
...@@ -55,7 +62,7 @@ class HTML { ...@@ -55,7 +62,7 @@ class HTML {
*/ */
public static function specialchars($value) public static function specialchars($value)
{ {
return htmlspecialchars($value, ENT_QUOTES, Config::get('application.encoding'), false); return htmlspecialchars($value, ENT_QUOTES, static::encoding(), false);
} }
/** /**
...@@ -432,6 +439,16 @@ class HTML { ...@@ -432,6 +439,16 @@ class HTML {
} }
/** /**
* Get the appliction.encoding without needing to request it from Config::get() each time.
*
* @return string
*/
protected static function encoding()
{
return static::$encoding ?: static::$encoding = Config::get('application.encoding');
}
/**
* Dynamically handle calls to custom macros. * Dynamically handle calls to custom macros.
* *
* @param string $method * @param string $method
......
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