1<?php 2 3namespace Sabre\DAV; 4 5/** 6 * Collection class 7 * 8 * This is a helper class, that should aid in getting collections classes setup. 9 * Most of its methods are implemented, and throw permission denied exceptions 10 * 11 * @copyright Copyright (C) fruux GmbH (https://fruux.com/) 12 * @author Evert Pot (http://evertpot.com/) 13 * @license http://sabre.io/license/ Modified BSD License 14 */ 15abstract class Collection extends Node implements ICollection { 16 17 /** 18 * Returns a child object, by its name. 19 * 20 * This method makes use of the getChildren method to grab all the child 21 * nodes, and compares the name. 22 * Generally its wise to override this, as this can usually be optimized 23 * 24 * This method must throw Sabre\DAV\Exception\NotFound if the node does not 25 * exist. 26 * 27 * @param string $name 28 * @throws Exception\NotFound 29 * @return INode 30 */ 31 function getChild($name) { 32 33 foreach ($this->getChildren() as $child) { 34 35 if ($child->getName() === $name) return $child; 36 37 } 38 throw new Exception\NotFound('File not found: ' . $name); 39 40 } 41 42 /** 43 * Checks is a child-node exists. 44 * 45 * It is generally a good idea to try and override this. Usually it can be optimized. 46 * 47 * @param string $name 48 * @return bool 49 */ 50 function childExists($name) { 51 52 try { 53 54 $this->getChild($name); 55 return true; 56 57 } catch (Exception\NotFound $e) { 58 59 return false; 60 61 } 62 63 } 64 65 /** 66 * Creates a new file in the directory 67 * 68 * Data will either be supplied as a stream resource, or in certain cases 69 * as a string. Keep in mind that you may have to support either. 70 * 71 * After successful creation of the file, you may choose to return the ETag 72 * of the new file here. 73 * 74 * The returned ETag must be surrounded by double-quotes (The quotes should 75 * be part of the actual string). 76 * 77 * If you cannot accurately determine the ETag, you should not return it. 78 * If you don't store the file exactly as-is (you're transforming it 79 * somehow) you should also not return an ETag. 80 * 81 * This means that if a subsequent GET to this new file does not exactly 82 * return the same contents of what was submitted here, you are strongly 83 * recommended to omit the ETag. 84 * 85 * @param string $name Name of the file 86 * @param resource|string $data Initial payload 87 * @return null|string 88 */ 89 function createFile($name, $data = null) { 90 91 throw new Exception\Forbidden('Permission denied to create file (filename ' . $name . ')'); 92 93 } 94 95 /** 96 * Creates a new subdirectory 97 * 98 * @param string $name 99 * @throws Exception\Forbidden 100 * @return void 101 */ 102 function createDirectory($name) { 103 104 throw new Exception\Forbidden('Permission denied to create directory'); 105 106 } 107 108 109} 110