]> git.mxchange.org Git - friendica-addons.git/blob - dav/SabreDAV/lib/Sabre/DAV/SimpleFile.php
Merge branch '3.6-release'
[friendica-addons.git] / dav / SabreDAV / lib / Sabre / DAV / SimpleFile.php
1 <?php
2
3 /**
4  * SimpleFile
5  *
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.
9  *
10  * @package Sabre
11  * @subpackage DAV
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
15  */
16 class Sabre_DAV_SimpleFile extends Sabre_DAV_File {
17
18     /**
19      * File contents
20      *
21      * @var string
22      */
23     protected $contents = array();
24
25     /**
26      * Name of this resource
27      *
28      * @var string
29      */
30     protected $name;
31
32     /**
33      * A mimetype, such as 'text/plain' or 'text/html'
34      *
35      * @var string
36      */
37     protected $mimeType;
38
39     /**
40      * Creates this node
41      *
42      * The name of the node must be passed, as well as the contents of the
43      * file.
44      *
45      * @param string $name
46      * @param string $contents
47      * @param string|null $mimeType
48      */
49     public function __construct($name, $contents, $mimeType = null) {
50
51         $this->name = $name;
52         $this->contents = $contents;
53         $this->mimeType = $mimeType;
54
55     }
56
57     /**
58      * Returns the node name for this file.
59      *
60      * This name is used to construct the url.
61      *
62      * @return string
63      */
64     public function getName() {
65
66         return $this->name;
67
68     }
69
70     /**
71      * Returns the data
72      *
73      * This method may either return a string or a readable stream resource
74      *
75      * @return mixed
76      */
77     public function get() {
78
79         return $this->contents;
80
81     }
82
83     /**
84      * Returns the size of the file, in bytes.
85      *
86      * @return int
87      */
88     public function getSize() {
89
90         return strlen($this->contents);
91
92     }
93
94     /**
95      * Returns the ETag for a file
96      *
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.
99      *
100      * Return null if the ETag can not effectively be determined
101      * @return string
102      */
103     public function getETag() {
104
105         return '"' . md5($this->contents) . '"';
106
107     }
108
109     /**
110      * Returns the mime-type for a file
111      *
112      * If null is returned, we'll assume application/octet-stream
113      * @return string
114      */
115     public function getContentType() {
116
117         return $this->mimeType;
118
119     }
120
121 }