[TASK] Clean up phpDoc comments in typo3/sysext/
[Packages/TYPO3.CMS.git] / typo3 / sysext / cms / tslib / class.tslib_fecompression.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009-2011 Dmitry Dulepov <dmitry@typo3.org>
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 *
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24
25 /**
26 * This class contains compression functions for the TYPO3 Frontend. It can be
27 * used only in EXT:cms/tslib/index_ts.php
28 *
29 * @author Dmitry Dulepov <dmitry@typo3.org>
30 * @package TYPO3
31 * @subpackage tx_cms
32 */
33 class tslib_fecompression implements t3lib_Singleton {
34
35 /**
36 * Accumulates content length for the compressed content. It is necessary to
37 * replace the Content-length HTTP header after compression if it was added
38 * by TYPO3 before compression.
39 *
40 * @var integer
41 */
42 protected $contentLength = 0;
43
44 /**
45 * Corrects HTTP "Content-length" header if it was sent by TYPO3 and compression
46 * is enabled.
47 *
48 * @param string $outputBuffer Output buffer to compress
49 * @param integer $mode One of PHP_OUTPUT_HANDLER_xxx contants
50 * @return string Compressed string
51 * @see ob_start()
52 * @see ob_gzhandler()
53 */
54 function compressionOutputHandler($outputBuffer, $mode) {
55 // Compress the content
56 $outputBuffer = ob_gzhandler($outputBuffer, $mode);
57 if ($outputBuffer !== FALSE) {
58 // Save compressed size
59 $this->contentLength += strlen($outputBuffer);
60
61 // Check if this was the last content chunk
62 if (0 != ($mode & PHP_OUTPUT_HANDLER_END)) {
63 // Check if we have content-length header
64 foreach (headers_list() as $header) {
65 if (0 == strncasecmp('Content-length:', $header, 15)) {
66 header('Content-length: ' . $this->contentLength);
67 break;
68 }
69 }
70 }
71 }
72 return $outputBuffer;
73 }
74 }
75 ?>