1<?php
2
3namespace GO\Base\Fs;
4
5
6class MemoryFile extends File{
7
8	private $_data;
9
10	public function __construct($filename, $data) {
11
12		$this->_data = $data;
13
14
15		return parent::__construct($filename);
16	}
17
18	public function getContents() {
19		return $this->_data;
20	}
21	public function contents() {
22		return $this->_data;
23	}
24
25	public function putContents($data, $flags = null, $context = null) {
26		if($flags = FILE_APPEND){
27			$this->_data .= $data;
28		}else
29		{
30			$this->_data = $data;
31		}
32	}
33
34	public function size() {
35		return strlen($this->_data);
36	}
37
38	public function mtime() {
39		return time();
40	}
41
42	public function ctime() {
43		return time();
44	}
45
46	public function exists() {
47		return true;
48	}
49
50	public function move(Base $destinationFolder, $newFileName = false, $isUploadedFile = false, $appendNumberToNameIfDestinationExists = false) {
51		throw Exception("move not implemented for memory file");
52	}
53
54	public function copy(Folder $destinationFolder, $newFileName = false) {
55		throw Exception("copy not implemented for memory file");
56	}
57	public function parent() {
58		return false;
59	}
60
61	public function child($filename) {
62		throw Exception("child not possible for memory file");
63	}
64
65	public function createChild($filename, $isFile = true) {
66		throw Exception("createChild not possible for memory file");
67	}
68
69
70		/**
71	 * Check if the file or folder is writable for the webserver user.
72	 *
73	 * @return boolean
74	 */
75	public function isWritable(){
76		return true;
77	}
78
79	/**
80	 * Change owner
81	 * @param StringHelper $user
82	 * @return boolean
83	 */
84	public function chown($user){
85		return false;
86	}
87
88	/**
89	 * Change group
90	 *
91	 * @param StringHelper $group
92	 * @return boolean
93	 */
94	public function chgrp($group){
95		return false;
96	}
97
98	/**
99	 *
100	 * @param int $permissionsMode <p>
101	 * Note that mode is not automatically
102	 * assumed to be an octal value, so strings (such as "g+w") will
103	 * not work properly. To ensure the expected operation,
104	 * you need to prefix mode with a zero (0):
105	 * </p>
106	 *
107	 * @return boolean
108	 */
109	public function chmod($permissionsMode){
110		return false;
111	}
112
113	/**
114	 * Delete the file
115	 *
116	 * @return boolean
117	 */
118	public function delete(){
119		return false;
120	}
121
122	public function isFolder() {
123		return false;
124	}
125
126	/**
127	 * Check if this object is a file.
128	 *
129	 * @return boolean
130	 */
131	public function isFile(){
132		return true;
133	}
134
135	public function rename($name){
136		$this->path=$name;
137	}
138
139	public function appendNumberToNameIfExists() {
140		return $this->path;
141	}
142
143	public function output() {
144		echo $this->_data;
145	}
146
147	public function setDefaultPermissions() {
148
149	}
150
151	public function md5Hash(){
152		return md5($this->_data);
153	}
154}
155