http://phing.info/

Source Code Coverage

Designed for use with PHPUnit2, Xdebug and Phing.

Methods: 3 LOC: 85 Statements: 14
Legend: executednot executeddead code
Source file Statements Methods Total coverage
File.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
 * @copyright Copyright LibreWorks, LLC (http://libreworks.net)
13
 * @license   http://www.opensource.org/licenses/bsd-license.php New BSD License
14
 * @version   $Id: File.php 418 2010-10-18 21:40:08Z jonathanhawk $
15
 */
16
namespace Xyster\Controller\Action\Helper;
17
/**
18
 * File response headers action helper
19
 *
20
 * @category  Xyster
21
 * @package   Xyster_Controller
22
 * @subpackage Helpers
23
 * @copyright Copyright LibreWorks, LLC (http://libreworks.net)
24
 * @license   http://www.opensource.org/licenses/bsd-license.php New BSD License
25
 */
26
class File extends \Zend_Controller_Action_Helper_Abstract
27 1
{
28
    /**
29
     * The default MIME type
30
     *
31
     */
32
    const DEFAULT_MIME = 'application/octet-stream';
33
34
    /**
35
     * Sets the appropriate headers for sending a file as a response
36
     *
37
     * This helper uses {@link Xyster_Controller_Action_Helper_Cache} to check
38
     * if the file has been modified since the user last received it.
39
     *
40
     * @param string $name The filename
41
     * @param string $mime The MIME type of the file
42
     * @param int $date The unix timestamp the file was last modified
43
     */
44
    public function direct( $name, $mime = self::DEFAULT_MIME, $date = null )
45
    {
46 2
        $this->setFileHeaders($name, $mime, $date);
47
    }
48
49
    /**
50
     * Sets the appropriate headers for sending a file as a response
51
     *
52
     * This helper uses {@link Xyster_Controller_Action_Helper_Cache} to check
53
     * if the file has been modified since the user last received it.
54
     *
55
     * @param string $name The filename
56
     * @param string $mime The MIME type of the file
57
     * @param int $date The unix timestamp the file was last modified
58
     */
59
    public function setFileHeaders( $name, $mime = self::DEFAULT_MIME, $date = null )
60
    {
61 2
        if ( $this->getActionController()->getHelper('Cache')->direct($date) ) {
62 1
            return;
63
        }
64
65 1
        if ( !headers_sent() ) {
66 1
            ini_set('zlib.output_compression', 'Off');
67 1
        }
68
69 1
        $this->getResponse()
70 1
            ->setHeader('Accept-Ranges', 'bytes')
71 1
            ->setHeader('Content-Type', $mime)
72 1
            ->setHeader('Content-Disposition', 'attachment; filename="' . $name . '"');
73
    }
74
75
    /**
76
     * Gets the name of this helper.
77
     *
78
     * @todo Remove when ZF2 is out
79
     * @return string The name of the helper
80
     */
81
    public function getName()
82
    {
83 2
        return "File";
84
    }
85 1
}


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