1<?php 2 3namespace Sabre\DAV\Mock; 4 5use Sabre\DAV; 6 7/** 8 * Mock Streaming File File 9 * 10 * Works similar to the mock file, but this one works with streams and has no 11 * content-length or etags. 12 * 13 * @copyright Copyright (C) 2007-2015 fruux GmbH (https://fruux.com/). 14 * @author Evert Pot (http://evertpot.com/) 15 * @license http://sabre.io/license/ Modified BSD License 16 */ 17class StreamingFile extends File { 18 19 /** 20 * Updates the data 21 * 22 * The data argument is a readable stream resource. 23 * 24 * After a succesful put operation, you may choose to return an ETag. The 25 * etag must always be surrounded by double-quotes. These quotes must 26 * appear in the actual string you're returning. 27 * 28 * Clients may use the ETag from a PUT request to later on make sure that 29 * when they update the file, the contents haven't changed in the mean 30 * time. 31 * 32 * If you don't plan to store the file byte-by-byte, and you return a 33 * different object on a subsequent GET you are strongly recommended to not 34 * return an ETag, and just return null. 35 * 36 * @param resource $data 37 * @return string|null 38 */ 39 function put($data) { 40 41 if (is_string($data)) { 42 $stream = fopen('php://memory','r+'); 43 fwrite($stream, $data); 44 rewind($stream); 45 $data = $stream; 46 } 47 $this->contents = $data; 48 49 } 50 51 /** 52 * Returns the data 53 * 54 * This method may either return a string or a readable stream resource 55 * 56 * @return mixed 57 */ 58 function get() { 59 60 return $this->contents; 61 62 } 63 64 /** 65 * Returns the ETag for a file 66 * 67 * An ETag is a unique identifier representing the current version of the file. If the file changes, the ETag MUST change. 68 * 69 * Return null if the ETag can not effectively be determined 70 * 71 * @return void 72 */ 73 function getETag() { 74 75 return null; 76 77 } 78 79 /** 80 * Returns the size of the node, in bytes 81 * 82 * @return int 83 */ 84 function getSize() { 85 86 return null; 87 88 } 89 90} 91