1*a1a3b679SAndreas Boehler<?php 2*a1a3b679SAndreas Boehler 3*a1a3b679SAndreas Boehlernamespace Sabre\DAV\Exception; 4*a1a3b679SAndreas Boehler 5*a1a3b679SAndreas Boehleruse Sabre\DAV; 6*a1a3b679SAndreas Boehler 7*a1a3b679SAndreas Boehler/** 8*a1a3b679SAndreas Boehler * PreconditionFailed 9*a1a3b679SAndreas Boehler * 10*a1a3b679SAndreas Boehler * This exception is normally thrown when a client submitted a conditional request, 11*a1a3b679SAndreas Boehler * like for example an If, If-None-Match or If-Match header, which caused the HTTP 12*a1a3b679SAndreas Boehler * request to not execute (the condition of the header failed) 13*a1a3b679SAndreas Boehler * 14*a1a3b679SAndreas Boehler * @copyright Copyright (C) 2007-2015 fruux GmbH (https://fruux.com/). 15*a1a3b679SAndreas Boehler * @author Evert Pot (http://evertpot.com/) 16*a1a3b679SAndreas Boehler * @license http://sabre.io/license/ Modified BSD License 17*a1a3b679SAndreas Boehler */ 18*a1a3b679SAndreas Boehlerclass PreconditionFailed extends DAV\Exception { 19*a1a3b679SAndreas Boehler 20*a1a3b679SAndreas Boehler /** 21*a1a3b679SAndreas Boehler * When this exception is thrown, the header-name might be set. 22*a1a3b679SAndreas Boehler * 23*a1a3b679SAndreas Boehler * This allows the exception-catching code to determine which HTTP header 24*a1a3b679SAndreas Boehler * caused the exception. 25*a1a3b679SAndreas Boehler * 26*a1a3b679SAndreas Boehler * @var string 27*a1a3b679SAndreas Boehler */ 28*a1a3b679SAndreas Boehler public $header = null; 29*a1a3b679SAndreas Boehler 30*a1a3b679SAndreas Boehler /** 31*a1a3b679SAndreas Boehler * Create the exception 32*a1a3b679SAndreas Boehler * 33*a1a3b679SAndreas Boehler * @param string $message 34*a1a3b679SAndreas Boehler * @param string $header 35*a1a3b679SAndreas Boehler */ 36*a1a3b679SAndreas Boehler function __construct($message, $header = null) { 37*a1a3b679SAndreas Boehler 38*a1a3b679SAndreas Boehler parent::__construct($message); 39*a1a3b679SAndreas Boehler $this->header = $header; 40*a1a3b679SAndreas Boehler 41*a1a3b679SAndreas Boehler } 42*a1a3b679SAndreas Boehler 43*a1a3b679SAndreas Boehler /** 44*a1a3b679SAndreas Boehler * Returns the HTTP statuscode for this exception 45*a1a3b679SAndreas Boehler * 46*a1a3b679SAndreas Boehler * @return int 47*a1a3b679SAndreas Boehler */ 48*a1a3b679SAndreas Boehler function getHTTPCode() { 49*a1a3b679SAndreas Boehler 50*a1a3b679SAndreas Boehler return 412; 51*a1a3b679SAndreas Boehler 52*a1a3b679SAndreas Boehler } 53*a1a3b679SAndreas Boehler 54*a1a3b679SAndreas Boehler /** 55*a1a3b679SAndreas Boehler * This method allows the exception to include additional information into the WebDAV error response 56*a1a3b679SAndreas Boehler * 57*a1a3b679SAndreas Boehler * @param DAV\Server $server 58*a1a3b679SAndreas Boehler * @param \DOMElement $errorNode 59*a1a3b679SAndreas Boehler * @return void 60*a1a3b679SAndreas Boehler */ 61*a1a3b679SAndreas Boehler function serialize(DAV\Server $server, \DOMElement $errorNode) { 62*a1a3b679SAndreas Boehler 63*a1a3b679SAndreas Boehler if ($this->header) { 64*a1a3b679SAndreas Boehler $prop = $errorNode->ownerDocument->createElement('s:header'); 65*a1a3b679SAndreas Boehler $prop->nodeValue = $this->header; 66*a1a3b679SAndreas Boehler $errorNode->appendChild($prop); 67*a1a3b679SAndreas Boehler } 68*a1a3b679SAndreas Boehler 69*a1a3b679SAndreas Boehler } 70*a1a3b679SAndreas Boehler 71*a1a3b679SAndreas Boehler} 72