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