remotes/origin/dropdowns-bright
parent
705d208a8a
commit
e2cfcd992c
@ -0,0 +1,64 @@ |
||||
<?php |
||||
/** |
||||
* @author Joas Schilling <nickvergessen@owncloud.com> |
||||
* |
||||
* @copyright Copyright (c) 2015, ownCloud, Inc. |
||||
* @license AGPL-3.0 |
||||
* |
||||
* This code is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU Affero General Public License, version 3, |
||||
* as published by the Free Software Foundation. |
||||
* |
||||
* This program is distributed in the hope that it will be useful, |
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
* GNU Affero General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Affero General Public License, version 3, |
||||
* along with this program. If not, see <http://www.gnu.org/licenses/> |
||||
* |
||||
*/ |
||||
|
||||
namespace OCA\DAV\Connector\Sabre\Exception; |
||||
|
||||
class Forbidden extends \Sabre\DAV\Exception\Forbidden { |
||||
|
||||
const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
||||
|
||||
/** |
||||
* @var bool |
||||
*/ |
||||
private $retry; |
||||
|
||||
/** |
||||
* @param string $message |
||||
* @param bool $retry |
||||
* @param \Exception $previous |
||||
*/ |
||||
public function __construct($message, $retry = false, \Exception $previous = null) { |
||||
parent::__construct($message, 0, $previous); |
||||
$this->retry = $retry; |
||||
} |
||||
|
||||
/** |
||||
* This method allows the exception to include additional information |
||||
* into the WebDAV error response |
||||
* |
||||
* @param \Sabre\DAV\Server $server |
||||
* @param \DOMElement $errorNode |
||||
* @return void |
||||
*/ |
||||
public function serialize(\Sabre\DAV\Server $server,\DOMElement $errorNode) { |
||||
|
||||
// set ownCloud namespace |
||||
$errorNode->setAttribute('xmlns:o', self::NS_OWNCLOUD); |
||||
|
||||
// adding the retry node |
||||
$error = $errorNode->ownerDocument->createElementNS('o:','o:retry', var_export($this->retry, true)); |
||||
$errorNode->appendChild($error); |
||||
|
||||
// adding the message node |
||||
$error = $errorNode->ownerDocument->createElementNS('o:','o:reason', $this->getMessage()); |
||||
$errorNode->appendChild($error); |
||||
} |
||||
} |
@ -0,0 +1,44 @@ |
||||
<?php |
||||
/** |
||||
* Copyright (c) 2015 Thomas Müller <deepdiver@owncloud.com> |
||||
* This file is licensed under the Affero General Public License version 3 or |
||||
* later. |
||||
* See the COPYING-README file. |
||||
*/ |
||||
|
||||
namespace OCA\DAV\Tests\Unit\Connector\Sabre\Exception; |
||||
|
||||
use OCA\DAV\Connector\Sabre\Exception\Forbidden; |
||||
|
||||
class ForbiddenTest extends \Test\TestCase { |
||||
|
||||
public function testSerialization() { |
||||
|
||||
// create xml doc |
||||
$DOM = new \DOMDocument('1.0','utf-8'); |
||||
$DOM->formatOutput = true; |
||||
$error = $DOM->createElementNS('DAV:','d:error'); |
||||
$error->setAttribute('xmlns:s', \Sabre\DAV\Server::NS_SABREDAV); |
||||
$DOM->appendChild($error); |
||||
|
||||
// serialize the exception |
||||
$message = "1234567890"; |
||||
$retry = false; |
||||
$expectedXml = <<<EOD |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<d:error xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns" xmlns:o="http://owncloud.org/ns"> |
||||
<o:retry xmlns:o="o:">false</o:retry> |
||||
<o:reason xmlns:o="o:">1234567890</o:reason> |
||||
</d:error> |
||||
|
||||
EOD; |
||||
|
||||
$ex = new Forbidden($message, $retry); |
||||
$server = $this->getMock('Sabre\DAV\Server'); |
||||
$ex->serialize($server, $error); |
||||
|
||||
// assert |
||||
$xml = $DOM->saveXML(); |
||||
$this->assertEquals($expectedXml, $xml); |
||||
} |
||||
} |
@ -0,0 +1,55 @@ |
||||
<?php |
||||
/** |
||||
* @author Joas Schilling <nickvergessen@owncloud.com> |
||||
* |
||||
* @copyright Copyright (c) 2015, ownCloud, Inc. |
||||
* @license AGPL-3.0 |
||||
* |
||||
* This code is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU Affero General Public License, version 3, |
||||
* as published by the Free Software Foundation. |
||||
* |
||||
* This program is distributed in the hope that it will be useful, |
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
* GNU Affero General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Affero General Public License, version 3, |
||||
* along with this program. If not, see <http://www.gnu.org/licenses/> |
||||
* |
||||
*/ |
||||
|
||||
// use OCP namespace for all classes that are considered public. |
||||
// This means that they should be used by apps instead of the internal ownCloud classes |
||||
namespace OCP\Files; |
||||
|
||||
/** |
||||
* Class ForbiddenException |
||||
* |
||||
* @package OCP\Files |
||||
* @since 9.0.0 |
||||
*/ |
||||
class ForbiddenException extends \Exception { |
||||
|
||||
/** @var bool */ |
||||
private $retry; |
||||
|
||||
/** |
||||
* @param string $message |
||||
* @param bool $retry |
||||
* @param \Exception $previous previous exception for cascading |
||||
* @since 9.0.0 |
||||
*/ |
||||
public function __construct($message, $retry, \Exception $previous = null) { |
||||
parent::__construct($message, 0, $previous); |
||||
$this->retry = $retry; |
||||
} |
||||
|
||||
/** |
||||
* @return bool |
||||
* @since 9.0.0 |
||||
*/ |
||||
public function getRetry() { |
||||
return (bool) $this->retry; |
||||
} |
||||
} |
Loading…
Reference in new issue