~chroot64bit/zivios/gentoo-experimental

« back to all changes in this revision

Viewing changes to application/library/Zend/Gdata/App/MediaFileSource.php

  • Committer: Mustafa A. Hashmi
  • Date: 2008-12-04 13:32:21 UTC
  • Revision ID: mhashmi@zivios.org-20081204133221-0nd1trunwevijj38
Inclusion of new installation framework with ties to zend layout and dojo layout

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
 
 
3
/**
 
4
 * Zend Framework
 
5
 *
 
6
 * LICENSE
 
7
 *
 
8
 * This source file is subject to the new BSD license that is bundled
 
9
 * with this package in the file LICENSE.txt.
 
10
 * It is also available through the world-wide-web at this URL:
 
11
 * http://framework.zend.com/license/new-bsd
 
12
 * If you did not receive a copy of the license and are unable to
 
13
 * obtain it through the world-wide-web, please send an email
 
14
 * to license@zend.com so we can send you a copy immediately.
 
15
 *
 
16
 * @category   Zend
 
17
 * @package    Zend_Gdata
 
18
 * @subpackage App
 
19
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 
20
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 
21
 */
 
22
 
 
23
/**
 
24
 * @see Zend_Gdata_App_MediaData
 
25
 */
 
26
require_once 'Zend/Gdata/App/BaseMediaSource.php';
 
27
 
 
28
/**
 
29
 * Concrete class to use a file handle as an attachment within a MediaEntry.
 
30
 *
 
31
 * @category   Zend
 
32
 * @package    Zend_Gdata
 
33
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 
34
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 
35
 */
 
36
class Zend_Gdata_App_MediaFileSource extends Zend_Gdata_App_BaseMediaSource
 
37
{
 
38
    /**
 
39
     * The filename which is represented
 
40
     *
 
41
     * @var string 
 
42
     */
 
43
    protected $_filename = null;
 
44
 
 
45
    /**
 
46
     * The content type for the file attached (example image/png)
 
47
     *
 
48
     * @var string
 
49
     */
 
50
    protected $_contentType = null;
 
51
    
 
52
    /**
 
53
     * Create a new Zend_Gdata_App_MediaFileSource object.
 
54
     *
 
55
     * @param string $filename The name of the file to read from.
 
56
     */
 
57
    public function __construct($filename)
 
58
    {
 
59
        $this->setFilename($filename);
 
60
    }
 
61
    
 
62
    /**
 
63
     * Return the MIME multipart representation of this MediaEntry.
 
64
     *
 
65
     * @return string
 
66
     * @throws Zend_Gdata_App_IOException
 
67
     */
 
68
    public function encode()
 
69
    {
 
70
        if ($this->getFilename() !== null && 
 
71
            is_readable($this->getFilename())) {
 
72
 
 
73
            // Retrieves the file, using the include path
 
74
            $fileHandle = fopen($this->getFilename(), 'r', true);
 
75
            $result = fread($fileHandle, filesize($this->getFilename()));
 
76
            if ($result === false) {
 
77
                require_once 'Zend/Gdata/App/IOException.php';
 
78
                throw new Zend_Gdata_App_IOException("Error reading file - " .
 
79
                        $this->getFilename() . '. Read failed.');
 
80
            }
 
81
            fclose($fileHandle);
 
82
            return $result;
 
83
        } else {
 
84
            require_once 'Zend/Gdata/App/IOException.php';
 
85
            throw new Zend_Gdata_App_IOException("Error reading file - " . 
 
86
                    $this->getFilename() . '. File is not readable.');
 
87
        }
 
88
    }
 
89
    
 
90
    /**
 
91
     * Get the filename associated with this reader.
 
92
     *
 
93
     * @return string
 
94
     */
 
95
    public function getFilename()
 
96
    {
 
97
        return $this->_filename;
 
98
    }
 
99
 
 
100
    /**
 
101
     * Set the filename which is to be read.
 
102
     * 
 
103
     * @param string $value The desired file handle.
 
104
     * @return Zend_Gdata_App_MediaFileSource Provides a fluent interface.
 
105
     */
 
106
    public function setFilename($value)
 
107
    {
 
108
        $this->_filename = $value;
 
109
        return $this;
 
110
    }
 
111
   
 
112
    /** 
 
113
     * The content type for the file attached (example image/png)
 
114
     *
 
115
     * @return string The content type
 
116
     */
 
117
    public function getContentType()
 
118
    {
 
119
        return $this->_contentType;
 
120
    }
 
121
 
 
122
    /** 
 
123
     * Set the content type for the file attached (example image/png)
 
124
     *
 
125
     * @param string $value The content type
 
126
     * @return Zend_Gdata_App_MediaFileSource Provides a fluent interface
 
127
     */
 
128
    public function setContentType($value)
 
129
    {
 
130
        $this->_contentType = $value;
 
131
        return $this;
 
132
    }
 
133
    
 
134
    /**
 
135
     * Alias for getFilename().
 
136
     *
 
137
     * @return string
 
138
     */
 
139
    public function __toString()
 
140
    {
 
141
        return $this->getFilename();
 
142
    }
 
143
    
 
144
}