mirror of
https://codeberg.org/icewind/SearchDAV.git
synced 2026-06-03 17:44:06 +02:00
more tests
This commit is contained in:
parent
50b56db31b
commit
b42b650266
13 changed files with 442 additions and 12 deletions
|
|
@ -32,6 +32,7 @@ use Sabre\DAV\Xml\Element\Response;
|
|||
use Sabre\DAV\Xml\Response\MultiStatus;
|
||||
use Sabre\HTTP\RequestInterface;
|
||||
use Sabre\HTTP\ResponseInterface;
|
||||
use Sabre\Xml\ParseException;
|
||||
use Sabre\Xml\Writer;
|
||||
use SearchDAV\Backend\ISearchBackend;
|
||||
use SearchDAV\Backend\SearchPropertyDefinition;
|
||||
|
|
@ -55,11 +56,11 @@ class SearchPlugin extends ServerPlugin {
|
|||
|
||||
public function __construct(ISearchBackend $searchBackend) {
|
||||
$this->searchBackend = $searchBackend;
|
||||
$this->queryParser = new QueryParser();
|
||||
}
|
||||
|
||||
public function initialize(Server $server) {
|
||||
$this->server = $server;
|
||||
$this->queryParser = new QueryParser($this->server->xml);
|
||||
$server->on('method:SEARCH', [$this, 'searchHandler']);
|
||||
$server->on('afterMethod:OPTIONS', [$this, 'optionHandler']);
|
||||
$server->on('propFind', [$this, 'propFindHandler']);
|
||||
|
|
@ -98,7 +99,7 @@ class SearchPlugin extends ServerPlugin {
|
|||
}
|
||||
|
||||
public function optionHandler(RequestInterface $request, ResponseInterface $response) {
|
||||
if ($request->getPath() === '') {
|
||||
if ($request->getPath() === $this->searchBackend->getArbiterPath()) {
|
||||
$response->addHeader('DASL', '<DAV:basicsearch>');
|
||||
}
|
||||
}
|
||||
|
|
@ -111,11 +112,21 @@ class SearchPlugin extends ServerPlugin {
|
|||
return;
|
||||
}
|
||||
|
||||
$xml = $this->queryParser->parse(
|
||||
$request->getBody(),
|
||||
$request->getUrl(),
|
||||
$documentType
|
||||
);
|
||||
if ($request->getPath() !== $this->searchBackend->getArbiterPath()) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$xml = $this->queryParser->parse(
|
||||
$request->getBody(),
|
||||
$request->getUrl(),
|
||||
$documentType
|
||||
);
|
||||
} catch (ParseException $e) {
|
||||
$response->setStatus(400);
|
||||
$response->setBody('Parse error: ' . $e->getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
switch ($documentType) {
|
||||
case '{DAV:}searchrequest':
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@
|
|||
|
||||
namespace SearchDAV\XML;
|
||||
|
||||
use Sabre\Xml\ParseException;
|
||||
use Sabre\Xml\Reader;
|
||||
use Sabre\Xml\XmlDeserializable;
|
||||
|
||||
|
|
@ -62,10 +63,15 @@ class BasicSearch implements XmlDeserializable {
|
|||
$search = new self();
|
||||
|
||||
$elements = \Sabre\Xml\Deserializer\keyValue($reader);
|
||||
$search->select = isset($elements['{DAV:}select']) ? $elements['{DAV:}select'] : null;
|
||||
$search->from = isset($elements['{DAV:}from']) ? $elements['{DAV:}from'] : null;
|
||||
|
||||
if (!isset($elements['{DAV:}from'])) {
|
||||
throw new ParseException('Missing {DAV:}from when parsing {DAV:}basicsearch');
|
||||
}
|
||||
|
||||
$search->select = isset($elements['{DAV:}select']) ? $elements['{DAV:}select'] : [];
|
||||
$search->from = $elements['{DAV:}from'];
|
||||
$search->where = isset($elements['{DAV:}where']) ? $elements['{DAV:}where'] : null;
|
||||
$search->orderBy = isset($elements['{DAV:}orderby']) ? $elements['{DAV:}orderby'] : null;
|
||||
$search->orderBy = isset($elements['{DAV:}orderby']) ? $elements['{DAV:}orderby'] : [];
|
||||
|
||||
return $search;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ class QueryDiscoverResponse extends Response {
|
|||
|
||||
if ($this->schema) {
|
||||
$writer->writeElement('{DAV:}query-schema', [
|
||||
'{DAV:basicsearchschema}' => $this->schema
|
||||
'{DAV:}basicsearchschema' => $this->schema
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,10 +53,12 @@ class Scope implements XmlDeserializable {
|
|||
/**
|
||||
* @param string $href
|
||||
* @param int|string $depth
|
||||
* @param string|null $path
|
||||
*/
|
||||
public function __construct($href = '', $depth = 1) {
|
||||
public function __construct($href = '', $depth = 1, $path = null) {
|
||||
$this->href = $href;
|
||||
$this->depth = $depth;
|
||||
$this->path = $path;
|
||||
}
|
||||
|
||||
static function xmlDeserialize(Reader $reader) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue