6 * The 'SimpleFile' class is used to easily add read-only immutable files to
7 * the directory structure. One usecase would be to add a 'readme.txt' to a
8 * root of a webserver with some standard content.
12 * @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
13 * @author Evert Pot (http://www.rooftopsolutions.nl/)
14 * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
16 class Sabre_DAV_SimpleFile extends Sabre_DAV_File {
23 protected $contents = array();
26 * Name of this resource
33 * A mimetype, such as 'text/plain' or 'text/html'
42 * The name of the node must be passed, as well as the contents of the
46 * @param string $contents
47 * @param string|null $mimeType
49 public function __construct($name, $contents, $mimeType = null) {
52 $this->contents = $contents;
53 $this->mimeType = $mimeType;
58 * Returns the node name for this file.
60 * This name is used to construct the url.
64 public function getName() {
73 * This method may either return a string or a readable stream resource
77 public function get() {
79 return $this->contents;
84 * Returns the size of the file, in bytes.
88 public function getSize() {
90 return strlen($this->contents);
95 * Returns the ETag for a file
97 * An ETag is a unique identifier representing the current version of the file. If the file changes, the ETag MUST change.
98 * The ETag is an arbitrary string, but MUST be surrounded by double-quotes.
100 * Return null if the ETag can not effectively be determined
103 public function getETag() {
105 return '"' . md5($this->contents) . '"';
110 * Returns the mime-type for a file
112 * If null is returned, we'll assume application/octet-stream
115 public function getContentType() {
117 return $this->mimeType;