/** * Use this method to create a new collection * * The {DAV:}resourcetype is specified using the resourceType array. * At the very least it must contain {DAV:}collection. * * The properties array can contain a list of additional properties. * * @param string $uri The new uri * @param array $resourceType The resourceType(s) * @param array $properties A list of properties * @return array|null */ public function createCollection($uri, array $resourceType, array $properties) { list($parentUri, $newName) = Sabre_DAV_URLUtil::splitPath($uri); // Making sure {DAV:}collection was specified as resourceType if (!in_array('{DAV:}collection', $resourceType)) { throw new Sabre_DAV_Exception_InvalidResourceType('The resourceType for this collection must at least include {DAV:}collection'); } // Making sure the parent exists try { $parent = $this->tree->getNodeForPath($parentUri); } catch (Sabre_DAV_Exception_NotFound $e) { throw new Sabre_DAV_Exception_Conflict('Parent node does not exist'); } // Making sure the parent is a collection if (!$parent instanceof Sabre_DAV_ICollection) { throw new Sabre_DAV_Exception_Conflict('Parent node is not a collection'); } // Making sure the child does not already exist try { $parent->getChild($newName); // If we got here.. it means there's already a node on that url, and we need to throw a 405 throw new Sabre_DAV_Exception_MethodNotAllowed('The resource you tried to create already exists'); } catch (Sabre_DAV_Exception_NotFound $e) { // This is correct } if (!$this->broadcastEvent('beforeBind', array($uri))) { return; } // There are 2 modes of operation. The standard collection // creates the directory, and then updates properties // the extended collection can create it directly. if ($parent instanceof Sabre_DAV_IExtendedCollection) { $parent->createExtendedCollection($newName, $resourceType, $properties); } else { // No special resourcetypes are supported if (count($resourceType) > 1) { throw new Sabre_DAV_Exception_InvalidResourceType('The {DAV:}resourcetype you specified is not supported here.'); } $parent->createDirectory($newName); $rollBack = false; $exception = null; $errorResult = null; if (count($properties) > 0) { try { $errorResult = $this->updateProperties($uri, $properties); if (!isset($errorResult[200])) { $rollBack = true; } } catch (Sabre_DAV_Exception $e) { $rollBack = true; $exception = $e; } } if ($rollBack) { if (!$this->broadcastEvent('beforeUnbind', array($uri))) { return; } $this->tree->delete($uri); // Re-throwing exception if ($exception) { throw $exception; } return $errorResult; } } $this->tree->markDirty($parentUri); $this->broadcastEvent('afterBind', array($uri)); }