/usr/share/php/Horde/Dav/File.php is in php-horde-dav 1.0.3-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 | <?php
/**
* Copyright 2013 Horde LLC (http://www.horde.org/)
*
* See the enclosed file LICENSE for license information (BSD). If you
* did not receive this file, see http://www.horde.org/licenses/bsd.
*
* @author Jan Schneider <jan@horde.org>
* @category Horde
* @license http://www.horde.org/licenses/bsd BSD
* @package Dav
*/
use \Sabre\DAV;
/**
* A file object.
*
* @author Jan Schneider <jan@horde.org>
* @category Horde
* @license http://www.horde.org/licenses/bsd BSD
* @package Dav
*/
class Horde_Dav_File extends Sabre\DAV\File
{
/**
* A registry object.
*
* @var Horde_Registry
*/
protected $_registry;
/**
* The path to the current file.
*
* @var string
*/
protected $_path;
/**
* File details.
*
* @var array
*/
protected $_item;
/**
* File size.
*
* This will only be set if the actual file data is requested, to avoid the
* overhead of building the file content only to retrieve the file size.
*
* @var integer
*/
protected $_size;
/**
* Constructor.
*
* @param Horde_Registry $registry A registry object.
* @param string $path The path to this file.
* @param array $item File details.
*/
public function __construct(Horde_Registry $registry, $path = null,
array $item = array())
{
$this->_registry = $registry;
$this->_path = $path;
$this->_item = $item;
}
/**
* Returns the name of the node.
*
* This is used to generate the url.
*
* @return string
*/
public function getName()
{
list($dir, $base) = DAV\URLUtil::splitPath($this->_path);
return $base;
}
/**
* Returns the last modification time, as a unix timestamp
*
* @return int
*/
public function getLastModified()
{
if (!empty($this->_item['modified'])) {
return $this->_item['modified'];
}
if (!empty($this->_item['created'])) {
return $this->_item['created'];
}
return parent::getLastModified();
}
/**
* Updates the data
*
* data is a readable stream resource.
*
* @param resource $data
* @return void
*/
public function put($data)
{
list($base) = explode('/', $this->_path);
try {
$this->_registry->callByPackage(
$base,
'put',
array(
$this->_path,
stream_get_contents($data),
$this->getContentType() ?: 'application/octet-stream'
)
);
} catch (Horde_Exception_NotFound $e) {
throw new DAV\Exception\NotFound($this->_path . ' not found');
} catch (Horde_Exception $e) {
throw new DAV\Exception($e);
}
}
/**
* Returns the data
*
* This method may either return a string or a readable stream resource
*
* @return mixed
*/
public function get()
{
list($base) = explode('/', $this->_path);
try {
$items = $this->_registry->callByPackage(
$base, 'browse', array($this->_path)
);
} catch (Horde_Exception_NotFound $e) {
throw new DAV\Exception\NotFound($this->_path . ' not found');
} catch (Horde_Exception $e) {
throw new DAV\Exception($e);
}
if (!$items) {
throw new DAV\Exception\NotFound($this->_path . ' not found');
}
$item = reset($items);
$this->_size = strlen($item);
return $item;
}
/**
* Returns the size of the file, in bytes.
*
* @return int
*/
public function getSize()
{
return isset($this->_size)
? $this->_size
: (isset($this->_item['contentlength'])
? $this->_item['contentlength']
: null);
}
/**
* Returns the mime-type for a file
*
* If null is returned, we'll assume application/octet-stream
*
* @return string|null
*/
public function getContentType()
{
return isset($this->_item['contenttype'])
? $this->_item['contenttype']
: null;
}
}
|