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