http://phing.info/

Source Code Coverage

Designed for use with PHPUnit2, Xdebug and Phing.

Methods: 1 LOC: 69 Statements: 23
Legend: executednot executeddead code
Source file Statements Methods Total coverage
Cache.php 100.0% 100.0% 100.0%
 
1
<?php
2
/**
3
 * Xyster Framework
4
 *
5
 * This source file is subject to the new BSD license that is bundled
6
 * with this package in the file LICENSE.txt.
7
 * It is also available through the world-wide-web at this URL:
8
 * http://www.opensource.org/licenses/bsd-license.php
9
 *
10
 * @category  Xyster
11
 * @package   Xyster_Controller
12
 * @subpackage Plugins
13
 * @copyright Copyright LibreWorks, LLC (http://libreworks.net)
14
 * @license   http://www.opensource.org/licenses/bsd-license.php New BSD License
15
 * @version   $Id: Cache.php 418 2010-10-18 21:40:08Z jonathanhawk $
16
 */
17
namespace Xyster\Controller\Plugin;
18
/**
19
 * Turns off the PHP anti-caching headers sent when a session is active
20
 */
21 1
ini_set('session.cache_limiter', '');
22
/**
23
 * Cache control plugin
24
 *
25
 * Notice: The inclusion of this class turns off PHP's
26
 * <code>session.cache_limiter</code> directive.  Please be aware of the
27
 * effects.  Resultantly, this class MUST be required/included BEFORE the user
28
 * session is started.
29
 *
30
 * @category  Xyster
31
 * @package   Xyster_Controller
32
 * @subpackage Plugins
33
 * @copyright Copyright LibreWorks, LLC (http://libreworks.net)
34
 * @license   http://www.opensource.org/licenses/bsd-license.php New BSD License
35
 */
36
class Cache extends \Zend_Controller_Plugin_Abstract
37 1
{
38
    /**
39
     * Called before Zend_Controller_Front exits its dispatch loop.
40
     *
41
     */
42
    public function dispatchLoopShutdown()
43
    {
44 4
        $sentType = false;
45 4
        $sentTag = false;
46
47 4
        $response = $this->getResponse();
48 4
        foreach( $response->getHeaders() as $header ) {
49 3
            if ( !strcasecmp($header['name'], 'content-type') ) {
50 1
                $sentType = true;
51 1
            }
52 3
            if ( !strcasecmp($header['name'], 'etag') ) {
53 1
                $sentTag = true;
54 1
            }
55 4
        }
56
57 4
        if ( !$response->isRedirect() && !$sentType && !$sentTag ) {
58
            // these are basically the same anti-cache headers that PHP sends
59 1
            $response->setRawHeader('Cache-Control: no-store, no-cache, must-revalidate, max-age=0, pre-check=0');
60 1
            $response->setRawHeader('Pragma: no-cache');
61 1
            $response->setRawHeader('Expires: ' . gmdate('D, d M Y H:i:s', strtotime('-20 years')) . ' GMT');
62
            // also send content-length
63 1
            $response->setRawHeader('Content-Length: ' . strlen($response->getBody()));
64 1
        }
65 4
        if ( $sentTag && !$sentType ) { // last-mod responses, but not files
66 1
            $response->setRawHeader('Content-Length: ' . strlen($response->getBody()));
67 1
        }
68
    }
69 1
}


Report generated at 2010-10-18T17:19:48-04:00