http://phing.info/

Source Code Coverage

Designed for use with PHPUnit2, Xdebug and Phing.

Methods: 1 LOC: 77 Statements: 22

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


Report generated at 2007-10-08T19:32:24-05:00