http://phing.info/

Source Code Coverage

Designed for use with PHPUnit2, Xdebug and Phing.

Methods: 1 LOC: 72 Statements: 22

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 (c) 2007-2008 Irrational Logic (http://irrationallogic.net)
14
 * @license   http://www.opensource.org/licenses/bsd-license.php New BSD License
15
 * @version   $Id: Cache.php 202 2008-01-20 16:20:09Z doublecompile $
16
 */
17
/**
18
 * Turns off the PHP anti-caching headers sent when a session is active
19
 */
20 1
ini_set('session.cache_limiter', '');
21
/**
22
 * Zend_Controller_Plugin_Abstract
23
 */
24 1
require_once 'Zend/Controller/Plugin/Abstract.php';
25
/**
26
 * Cache control plugin
27
 *
28
 * Notice: The inclusion of this class turns off PHP's
29
 * <code>session.cache_limiter</code> directive.  Please be aware of the
30
 * effects.  Resultantly, this class MUST be required/included BEFORE the user
31
 * session is started.
32
 *
33
 * @category  Xyster
34
 * @package   Xyster_Controller
35
 * @subpackage Plugins
36
 * @copyright Copyright (c) 2007-2008 Irrational Logic (http://irrationallogic.net)
37
 * @license   http://www.opensource.org/licenses/bsd-license.php New BSD License
38
 */
39
class Xyster_Controller_Plugin_Cache extends Zend_Controller_Plugin_Abstract
40
{
41
    /**
42
     * Called before Zend_Controller_Front exits its dispatch loop.
43
     *
44
     */
45
    public function dispatchLoopShutdown()
46
    {
47 4
        $sentType = false;
48 4
        $sentTag = false;
49
50 4
        $response = $this->getResponse();
51 4
        foreach( $response->getHeaders() as $header ) {
52 3
            if ( !strcasecmp($header['name'], 'content-type') ) {
53 1
                $sentType = true;
54 1
            }
55 3
            if ( !strcasecmp($header['name'], 'etag') ) {
56 1
                $sentTag = true;
57 1
            }
58 3
        }
59
60 4
        if ( !$response->isRedirect() && !$sentType && !$sentTag ) {
61
            // these are basically the same anti-cache headers that PHP sends
62 1
            $response->setRawHeader('Cache-Control: no-store, no-cache, must-revalidate, max-age=0, pre-check=0');
63 1
            $response->setRawHeader('Pragma: no-cache');
64 1
            $response->setRawHeader('Expires: ' . gmdate('D, d M Y H:i:s', strtotime('-20 years')) . ' GMT');
65
            // also send content-length
66 1
            $response->setRawHeader('Content-Length: ' . strlen($response->getBody()));
67 1
        }
68 4
        if ( $sentTag && !$sentType ) { // last-mod responses, but not files
69 1
            $response->setRawHeader('Content-Length: ' . strlen($response->getBody()));
70 1
        }
71
    }
72
}


Report generated at 2008-01-20T12:13:39-05:00