summaryrefslogtreecommitdiffstats
path: root/system
diff options
context:
space:
mode:
authorAndrey Andreev <narf@devilix.net>2017-04-18 11:03:15 +0200
committerAndrey Andreev <narf@devilix.net>2017-04-18 11:03:15 +0200
commitf8fba7bac1c69e619f504f9960133d9b0fecc34b (patch)
tree6f3daab1224d7090247815da01c1c5a343e48bd3 /system
parentc94b244671309f0a993fba205307b51f514242d4 (diff)
[ci skip] Reduce nesting levels in CI_Output
Diffstat (limited to 'system')
-rw-r--r--system/core/Output.php95
1 files changed, 44 insertions, 51 deletions
diff --git a/system/core/Output.php b/system/core/Output.php
index 6ddded22a..a3155fece 100644
--- a/system/core/Output.php
+++ b/system/core/Output.php
@@ -586,62 +586,59 @@ class CI_Output {
return;
}
- if (flock($fp, LOCK_EX))
+ if ( ! flock($fp, LOCK_EX))
{
- // If output compression is enabled, compress the cache
- // itself, so that we don't have to do that each time
- // we're serving it
- if ($this->_compress_output === TRUE)
- {
- $output = gzencode($output);
+ log_message('error', 'Unable to secure a file lock for file at: '.$cache_path);
+ fclose($fp);
+ return;
+ }
- if ($this->get_header('content-type') === NULL)
- {
- $this->set_content_type($this->mime_type);
- }
+ // If output compression is enabled, compress the cache
+ // itself, so that we don't have to do that each time
+ // we're serving it
+ if ($this->_compress_output === TRUE)
+ {
+ $output = gzencode($output);
+
+ if ($this->get_header('content-type') === NULL)
+ {
+ $this->set_content_type($this->mime_type);
}
+ }
- $expire = time() + ($this->cache_expiration * 60);
+ $expire = time() + ($this->cache_expiration * 60);
- // Put together our serialized info.
- $cache_info = serialize(array(
- 'expire' => $expire,
- 'headers' => $this->headers
- ));
+ // Put together our serialized info.
+ $cache_info = serialize(array(
+ 'expire' => $expire,
+ 'headers' => $this->headers
+ ));
- $output = $cache_info.'ENDCI--->'.$output;
+ $output = $cache_info.'ENDCI--->'.$output;
- for ($written = 0, $length = self::strlen($output); $written < $length; $written += $result)
+ for ($written = 0, $length = self::strlen($output); $written < $length; $written += $result)
+ {
+ if (($result = fwrite($fp, self::substr($output, $written))) === FALSE)
{
- if (($result = fwrite($fp, self::substr($output, $written))) === FALSE)
- {
- break;
- }
+ break;
}
-
- flock($fp, LOCK_UN);
- }
- else
- {
- log_message('error', 'Unable to secure a file lock for file at: '.$cache_path);
- return;
}
+ flock($fp, LOCK_UN);
fclose($fp);
- if (is_int($result))
- {
- chmod($cache_path, 0640);
- log_message('debug', 'Cache file written: '.$cache_path);
-
- // Send HTTP cache-control headers to browser to match file cache settings.
- $this->set_cache_header($_SERVER['REQUEST_TIME'], $expire);
- }
- else
+ if ( ! is_int($result))
{
@unlink($cache_path);
log_message('error', 'Unable to write the complete cache content at: '.$cache_path);
+ return;
}
+
+ chmod($cache_path, 0640);
+ log_message('debug', 'Cache file written: '.$cache_path);
+
+ // Send HTTP cache-control headers to browser to match file cache settings.
+ $this->set_cache_header($_SERVER['REQUEST_TIME'], $expire);
}
// --------------------------------------------------------------------
@@ -708,11 +705,9 @@ class CI_Output {
log_message('debug', 'Cache file has expired. File deleted.');
return FALSE;
}
- else
- {
- // Or else send the HTTP cache control headers.
- $this->set_cache_header($last_modified, $expire);
- }
+
+ // Send the HTTP cache control headers
+ $this->set_cache_header($last_modified, $expire);
// Add headers from cache file.
foreach ($cache_info['headers'] as $header)
@@ -798,13 +793,11 @@ class CI_Output {
$this->set_status_header(304);
exit;
}
- else
- {
- header('Pragma: public');
- header('Cache-Control: max-age='.$max_age.', public');
- header('Expires: '.gmdate('D, d M Y H:i:s', $expiration).' GMT');
- header('Last-modified: '.gmdate('D, d M Y H:i:s', $last_modified).' GMT');
- }
+
+ header('Pragma: public');
+ header('Cache-Control: max-age='.$max_age.', public');
+ header('Expires: '.gmdate('D, d M Y H:i:s', $expiration).' GMT');
+ header('Last-modified: '.gmdate('D, d M Y H:i:s', $last_modified).' GMT');
}
// --------------------------------------------------------------------