From 7b53d04eb4b89868307c65b7c64bc0889b25b4db Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 26 Mar 2012 23:02:32 +0300 Subject: Some style adjustments and fixed comments in Router and Output classes --- system/core/Output.php | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'system/core/Output.php') diff --git a/system/core/Output.php b/system/core/Output.php index faebbbe72..9bf818e88 100755 --- a/system/core/Output.php +++ b/system/core/Output.php @@ -25,8 +25,6 @@ * @filesource */ -// ------------------------------------------------------------------------ - /** * Output Class * @@ -94,7 +92,7 @@ class CI_Output { $this->_zlib_oc = @ini_get('zlib.output_compression'); // Get mime types for later - if (defined('ENVIRONMENT') AND file_exists(APPPATH.'config/'.ENVIRONMENT.'/mimes.php')) + if (defined('ENVIRONMENT') && file_exists(APPPATH.'config/'.ENVIRONMENT.'/mimes.php')) { include APPPATH.'config/'.ENVIRONMENT.'/mimes.php'; } @@ -229,7 +227,7 @@ class CI_Output { * Set HTTP Status Header * moved to Common procedural functions in 1.7.2 * - * @param int the status code + * @param int the status code * @param string * @return void */ @@ -249,7 +247,7 @@ class CI_Output { */ public function enable_profiler($val = TRUE) { - $this->enable_profiler = (is_bool($val)) ? $val : TRUE; + $this->enable_profiler = is_bool($val) ? $val : TRUE; return $this; } @@ -267,7 +265,7 @@ class CI_Output { { foreach ($sections as $section => $enable) { - $this->_profiler_sections[$section] = ($enable !== FALSE) ? TRUE : FALSE; + $this->_profiler_sections[$section] = ($enable !== FALSE); } return $this; @@ -278,12 +276,12 @@ class CI_Output { /** * Set Cache * - * @param integer + * @param int * @return void */ public function cache($time) { - $this->cache_expiration = ( ! is_numeric($time)) ? 0 : $time; + $this->cache_expiration = is_numeric($time) ? $time : 0; return $this; } @@ -297,7 +295,7 @@ class CI_Output { * $this->final_output * * This function sends the finalized output data to the browser along - * with any server headers and profile data. It also stops the + * with any server headers and profile data. It also stops the * benchmark timer so the page rendering speed and memory usage can be shown. * * @param string @@ -343,7 +341,7 @@ class CI_Output { if ($this->parse_exec_vars === TRUE) { - $memory = ( ! function_exists('memory_get_usage')) ? '0' : round(memory_get_usage()/1024/1024, 2).'MB'; + $memory = function_exists('memory_get_usage') ? round(memory_get_usage()/1024/1024, 2).'MB' : '0'; $output = str_replace(array('{elapsed_time}', '{memory_usage}'), array($elapsed, $memory), $output); } @@ -520,4 +518,4 @@ class CI_Output { } /* End of file Output.php */ -/* Location: ./system/core/Output.php */ +/* Location: ./system/core/Output.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 52fe7bb68f9961cdd765dd38e54779ae3b66e586 Mon Sep 17 00:00:00 2001 From: Songpol Sripaoeiam Date: Sun, 1 Apr 2012 11:43:20 +0700 Subject: add function get_current_content_type to output class and user manual library --- system/core/Output.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'system/core/Output.php') diff --git a/system/core/Output.php b/system/core/Output.php index 9bf818e88..673ceb0ee 100755 --- a/system/core/Output.php +++ b/system/core/Output.php @@ -220,6 +220,24 @@ class CI_Output { $this->headers[] = array($header, TRUE); return $this; } + + // -------------------------------------------------------------------- + + /** + * Get Current Content Type Header + * Return text/html if Content-Type is not set + * + * @return string + */ + public function get_current_content_type() + { + foreach($this->headers as $header){ + if(preg_match('/^Content-Type/', $header[0])){ + return str_replace('Content-Type: ', '', $header[0]); + } + } + return 'text/html'; + } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From b966701fad01c094199a89f7e4df72d981e5cf48 Mon Sep 17 00:00:00 2001 From: Songpol Sripaoeiam Date: Sun, 1 Apr 2012 17:13:44 +0700 Subject: bracket on a new line Also add space after foreach bracket on a new line... Also add a space after if Follow up from https://github.com/EllisLab/CodeIgniter/pull/1234/files#r630522 --- system/core/Output.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'system/core/Output.php') diff --git a/system/core/Output.php b/system/core/Output.php index 673ceb0ee..c0de24bb9 100755 --- a/system/core/Output.php +++ b/system/core/Output.php @@ -231,12 +231,13 @@ class CI_Output { */ public function get_current_content_type() { - foreach($this->headers as $header){ - if(preg_match('/^Content-Type/', $header[0])){ - return str_replace('Content-Type: ', '', $header[0]); - } + foreach ($this->headers as $header){ + if (preg_match('/^Content-Type/', $header[0])) + { + return str_replace('Content-Type: ', '', $header[0]); } - return 'text/html'; + } + return 'text/html'; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 38c0a72169ffbf002c7f3c7fd3b4fd41f0d75f09 Mon Sep 17 00:00:00 2001 From: Songpol Sripao-eiam Date: Sun, 1 Apr 2012 20:10:35 +0700 Subject: Fix style coding --- system/core/Output.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'system/core/Output.php') diff --git a/system/core/Output.php b/system/core/Output.php index c0de24bb9..ea39b0223 100755 --- a/system/core/Output.php +++ b/system/core/Output.php @@ -231,7 +231,8 @@ class CI_Output { */ public function get_current_content_type() { - foreach ($this->headers as $header){ + foreach ($this->headers as $header) + { if (preg_match('/^Content-Type/', $header[0])) { return str_replace('Content-Type: ', '', $header[0]); -- cgit v1.2.3-24-g4f1b From 614db07c77e341bfe4bf92d7576f01a6cabd43ff Mon Sep 17 00:00:00 2001 From: Songpol Sripaoeiam Date: Tue, 3 Apr 2012 01:29:28 +0700 Subject: The current name is too wide change to get_content_type()consistent with set_content_type() --- system/core/Output.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/core/Output.php') diff --git a/system/core/Output.php b/system/core/Output.php index ea39b0223..09d74f0c0 100755 --- a/system/core/Output.php +++ b/system/core/Output.php @@ -229,7 +229,7 @@ class CI_Output { * * @return string */ - public function get_current_content_type() + public function get_content_type() { foreach ($this->headers as $header) { -- cgit v1.2.3-24-g4f1b From 00adf1d480f94692a625ec2165e0fcc9171c6e2f Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 3 Apr 2012 12:30:50 +0300 Subject: Some improvements to the additions from pull #1234 --- system/core/Output.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'system/core/Output.php') diff --git a/system/core/Output.php b/system/core/Output.php index 09d74f0c0..01fd1d867 100755 --- a/system/core/Output.php +++ b/system/core/Output.php @@ -220,24 +220,24 @@ class CI_Output { $this->headers[] = array($header, TRUE); return $this; } - + // -------------------------------------------------------------------- - + /** * Get Current Content Type Header - * Return text/html if Content-Type is not set * - * @return string + * @return string 'text/html', if not already set */ public function get_content_type() { - foreach ($this->headers as $header) + for ($i = 0, $c = count($this->headers); $i < $c; $i++) { - if (preg_match('/^Content-Type/', $header[0])) + if (preg_match('/^Content-Type:\s(.+)$/', $this->headers[$i][0], $matches)) { - return str_replace('Content-Type: ', '', $header[0]); + return $matches[1]; } } + return 'text/html'; } -- cgit v1.2.3-24-g4f1b