From a9be66d41a01ba09cc07e772b5ee57088a0ee1d4 Mon Sep 17 00:00:00 2001 From: thybag Date: Wed, 5 Sep 2012 09:35:54 +0100 Subject: [PATCH] Refactor changes into single get_encoding() method within the HTML Class (in order to remove duplication of logic). All tests continue to pass. --- laravel/html.php | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/laravel/html.php b/laravel/html.php index 71a89080..ec6b3ae2 100644 --- a/laravel/html.php +++ b/laravel/html.php @@ -38,8 +38,7 @@ public static function macro($name, $macro) */ public static function entities($value) { - if(static::$encoding===null) static::$encoding = Config::get('application.encoding'); - return htmlentities($value, ENT_QUOTES, static::$encoding, false); + return htmlentities($value, ENT_QUOTES, static::get_encoding(), false); } /** @@ -50,8 +49,7 @@ public static function entities($value) */ public static function decode($value) { - if(static::$encoding===null) static::$encoding = Config::get('application.encoding'); - return html_entity_decode($value, ENT_QUOTES, static::$encoding); + return html_entity_decode($value, ENT_QUOTES, static::get_encoding()); } /** @@ -64,8 +62,7 @@ public static function decode($value) */ public static function specialchars($value) { - if(static::$encoding===null) static::$encoding = Config::get('application.encoding'); - return htmlspecialchars($value, ENT_QUOTES, static::$encoding, false); + return htmlspecialchars($value, ENT_QUOTES, static::get_encoding(), false); } /** @@ -417,6 +414,18 @@ protected static function obfuscate($value) return $safe; } + /** + * Get the appliction.encoding without needing to request it from Config::get() each time. + * + * @return string + */ + public static function get_encoding(){ + + if(static::$encoding===null) static::$encoding = Config::get('application.encoding'); + + return static::$encoding; + } + /** * Dynamically handle calls to custom macros. *