public function setUp() { $_SERVER['REQUEST_METHOD'] = 'REPORT'; DAV::$REGISTRY = new DAV_Test_Registry(); DAV::$REGISTRY->setResourceClass('DAVACL_Test_Resource'); DAV_Multistatus::reset(); }
public function setUp() { $_SERVER['REQUEST_METHOD'] = 'PROPPATCH'; DAV::$REGISTRY = new DAV_Test_Registry(); DAV::$REGISTRY->setResourceClass('DAVACL_Test_Resource'); DAV::$LOCKPROVIDER = null; DAV_Multistatus::reset(); }
/** * Handles a DAV:principal-property-search REPORT request * * @param DAVACL_Principal_Collection $principal_collection The resource to perform the request on * @return void */ private function handle_principal_property_search($principal_collection) { $principals = $principal_collection->report_principal_property_search($this->entity['match']); DAV_Multistatus::inst(); foreach ($principals as $path) { $principal = DAV::$REGISTRY->resource($path); if ($principal && $principal->isVisible()) { $response = new DAV_Element_response($path); foreach ($this->entity['prop'] as $prop) { try { $propval = $principal->prop($prop); $response->setProperty($prop, $propval); } catch (DAV_Status $e) { $response->setStatus($prop, $e); } } DAV_Multistatus::inst()->addResponse($response); } } }
/** * Handle the PROPPATCH request * * @param DAV_Resource $resource * @return void * @throws DAV_Status */ protected function handle($resource) { $resource->assertLock(); if (empty($this->props)) { throw new DAV_Status(DAV::HTTP_BAD_REQUEST, 'No properties found in request body.'); } $priv_write = $resource->property_priv_write(array_keys($this->props)); $errors = array(); foreach ($this->props as $name => $value) { try { if (@DAV::$PROTECTED_PROPERTIES[$name]) { throw new DAV_Status(DAV::HTTP_FORBIDDEN, DAV::COND_CANNOT_MODIFY_PROTECTED_PROPERTY); } if (!@$priv_write[$name]) { throw DAV::forbidden(); } $resource->method_PROPPATCH($name, $value); } catch (DAV_Status $e) { $errors[$name] = $e; } } $response = new DAV_Element_response(DAV::getPath()); if (empty($errors)) { try { $resource->storeProperties(); } catch (DAV_Status $e) { foreach (array_keys($this->props) as $propname) { $errors[$propname] = $e; } } } if (empty($errors)) { foreach (array_keys($this->props) as $propname) { $response->setStatus($propname, DAV_Status::$OK); } } else { $failed_dependency = new DAV_Status(DAV::HTTP_FAILED_DEPENDENCY); foreach (array_keys($this->props) as $propname) { if (!isset($errors[$propname])) { $errors[$propname] = $failed_dependency; } } foreach ($errors as $propname => $status) { $response->setStatus($propname, $status); } } DAV_Multistatus::inst()->addResponse($response); DAV_Multistatus::inst()->close(); }
/** * Serve WebDAV HTTP request. * @param DAV_Registry $registry */ public function handleRequest() { // We want to catch every exception thrown in this code, and report about it // to the user appropriately. $shallow_lock = false; try { $shallow_lock = $this->check_if_headers(); $resource = DAV::$REGISTRY->resource(DAV::getPath()); if (!$resource || !$resource->isVisible() and in_array($_SERVER['REQUEST_METHOD'], array('ACL', 'COPY', 'DELETE', 'GET', 'HEAD', 'MOVE', 'OPTIONS', 'POST', 'PROPFIND', 'PROPPATCH', 'REPORT', 'UNLOCK'))) { throw new DAV_Status(DAV::HTTP_NOT_FOUND); } if ('/' !== substr(DAV::getPath(), -1) && ($resource && $resource instanceof DAV_Collection || 'MKCOL' === $_SERVER['REQUEST_METHOD'])) { $newPath = DAV::getPath() . '/'; DAV::setPath(DAV::encodeURIFullPath($newPath)); DAV::header(array('Content-Location' => DAV::path2uri($newPath))); } $this->handle($resource); } catch (Exception $e) { if (!$e instanceof DAV_Status) { $e = new DAV_Status(DAV::HTTP_INTERNAL_SERVER_ERROR, "{$e}"); } $e->output(); } if ($shallow_lock) { DAV::$REGISTRY->shallowUnlock(); } if (DAV_Multistatus::active()) { DAV_Multistatus::inst()->close(); } }
public function setUp() { $_SERVER['SCRIPT_NAME'] = '/path/to/script.php'; DAV_Multistatus::reset(); }
/** * Called by {@link method_PROPFIND()} * @param string $path * @param DAV_Resource $resource * @param array $props */ private function handle3($resource, $props) { $propprivs = $resource->property_priv_read($props); $response = new DAV_Element_response($resource->path); foreach ($props as $prop) { if (array_key_exists($prop, $propprivs) && !$propprivs[$prop]) { $response->setStatus($prop, DAV::forbidden()); } else { try { $value = $resource->prop($prop); if (!is_null($value)) { $response->setProperty($prop, $value); } else { $response->setStatus($prop, DAV_Status::$NOT_FOUND); } } catch (DAV_Status $e) { $response->setStatus($prop, $e); } } } DAV_Multistatus::inst()->addResponse($response); }
/** * Copy the resource and all its children * * @param DAV_Collection $resource * @param string $destination * @param string $dr destinationRoot */ private function copy_recursively($resource, $destination, $dr = null) { if (!$dr) { $dr = $destination; } elseif ($dr === $resource->path) { return; } $resource->method_COPY($destination); if (!$resource instanceof DAV_Collection || DAV::DEPTH_INF !== $this->depth()) { return; } foreach ($resource as $member) { $memberResource = DAV::$REGISTRY->resource($resource->path . $member); try { $this->copy_recursively($memberResource, $destination . $member, $dr); } catch (DAV_Status $e) { DAV_Multistatus::inst()->addStatus($resource->path . $member, $e); } } }
/** * Recursive helper function. * Callers must check DAV_Multistatus::active() afterwards. * @see delete() * @param DAV_Collection $resource * @param DAV_Resource $memberResource The resource to delete * @throws DAV_Status */ private static function delete_member($resource, $memberResource) { if ($memberResource instanceof DAV_Collection) { $failure = false; foreach ($memberResource as $child) { try { $childResource = DAV::$REGISTRY->resource($memberResource->path . $child); if (!$childResource) { throw new DAV_Status(DAV::HTTP_INTERNAL_SERVER_ERROR, "Registry didn't generate resource for path " . $memberResource->path . $child); } self::delete_member($memberResource, $childResource); } catch (DAV_Status $e) { $failure = true; DAV_Multistatus::inst()->addStatus($childResource->path, $e); } } if ($failure) { return; } } $resource->method_DELETE(substr($memberResource->path, strlen($resource->path))); DAV::$REGISTRY->forget($memberResource->path); }