http://phing.info/

Source Code Coverage

Designed for use with PHPUnit2, Xdebug and Phing.

Methods: 2 LOC: 77 Statements: 12

Source file Statements Methods Total coverage
File.php 91.7% 100.0% 92.9%
   
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
 * @copyright Copyright (c) 2007-2008 Irrational Logic (http://irrationallogic.net)
13
 * @license   http://www.opensource.org/licenses/bsd-license.php New BSD License
14
 * @version   $Id: File.php 202 2008-01-20 16:20:09Z doublecompile $
15
 */
16
/**
17
 * Zend_Controller_Action_Helper_Abstract
18
 */
19 1
require_once 'Zend/Controller/Action/Helper/Abstract.php';
20
/**
21
 * File response headers action helper
22
 *
23
 * @category  Xyster
24
 * @package   Xyster_Controller
25
 * @subpackage Helpers
26
 * @copyright Copyright (c) 2007-2008 Irrational Logic (http://irrationallogic.net)
27
 * @license   http://www.opensource.org/licenses/bsd-license.php New BSD License
28
 */
29
class Xyster_Controller_Action_Helper_File extends Zend_Controller_Action_Helper_Abstract
30
{
31
    /**
32
     * The default MIME type
33
     *
34
     */
35
    const DEFAULT_MIME = 'application/octet-stream';
36
37
    /**
38
     * Sets the appropriate headers for sending a file as a response
39
     *
40
     * This helper uses {@link Xyster_Controller_Action_Helper_Cache} to check
41
     * if the file has been modified since the user last received it.
42
     *
43
     * @param string $name The filename
44
     * @param string $mime The MIME type of the file
45
     * @param int $date The unix timestamp the file was last modified
46
     */
47
    public function direct( $name, $mime = self::DEFAULT_MIME, $date = null )
48
    {
49 2
        $this->setFileHeaders($name, $mime, $date);
50
    }
51
52
    /**
53
     * Sets the appropriate headers for sending a file as a response
54
     *
55
     * This helper uses {@link Xyster_Controller_Action_Helper_Cache} to check
56
     * if the file has been modified since the user last received it.
57
     *
58
     * @param string $name The filename
59
     * @param string $mime The MIME type of the file
60
     * @param int $date The unix timestamp the file was last modified
61
     */
62
    public function setFileHeaders( $name, $mime = self::DEFAULT_MIME, $date = null )
63
    {
64 2
        if ( $this->getActionController()->getHelper('Cache')->direct($date) ) {
65 1
            return;
66 0
        }
67
68 1
        if ( !headers_sent() ) {
69 1
            ini_set('zlib.output_compression', 'Off');
70 1
        }
71
72 1
        $this->getResponse()
73 1
            ->setHeader('Accept-Ranges', 'bytes')
74 1
            ->setHeader('Content-Type', $mime)
75 1
            ->setHeader('Content-Disposition', 'attachment; filename="' . $name . '"');
76
    }
77
}


Report generated at 2008-03-05T18:27:43-05:00