mirror of
https://codeberg.org/icewind/SearchDAV.git
synced 2026-06-03 17:44:06 +02:00
more types
This commit is contained in:
parent
721b8825d8
commit
d3eb42cd90
14 changed files with 32 additions and 34 deletions
|
|
@ -38,7 +38,7 @@ interface ISearchBackend {
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getArbiterPath();
|
public function getArbiterPath(): string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether or not the search backend supports search requests on this scope
|
* Whether or not the search backend supports search requests on this scope
|
||||||
|
|
@ -55,7 +55,7 @@ interface ISearchBackend {
|
||||||
* @param string|null $path the path of the search scope relative to the dav server, or null if the scope is outside the dav server
|
* @param string|null $path the path of the search scope relative to the dav server, or null if the scope is outside the dav server
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function isValidScope($href, $depth, $path);
|
public function isValidScope(string $href, $depth, ?string $path): bool;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List the available properties that can be used in search
|
* List the available properties that can be used in search
|
||||||
|
|
@ -69,7 +69,7 @@ interface ISearchBackend {
|
||||||
* @param string|null $path the path of the search scope relative to the dav server, or null if the scope is outside the dav server
|
* @param string|null $path the path of the search scope relative to the dav server, or null if the scope is outside the dav server
|
||||||
* @return SearchPropertyDefinition[]
|
* @return SearchPropertyDefinition[]
|
||||||
*/
|
*/
|
||||||
public function getPropertyDefinitionsForScope($href, $path);
|
public function getPropertyDefinitionsForScope(string $href, ?string $path): array;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Preform the search request
|
* Preform the search request
|
||||||
|
|
@ -81,7 +81,7 @@ interface ISearchBackend {
|
||||||
* @param Query $query
|
* @param Query $query
|
||||||
* @return SearchResult[]
|
* @return SearchResult[]
|
||||||
*/
|
*/
|
||||||
public function search(Query $query);
|
public function search(Query $query): array;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called by the search plugin once the nodes to be returned have been found.
|
* Called by the search plugin once the nodes to be returned have been found.
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ class SearchPropertyDefinition {
|
||||||
* @param string $dataType the datatype of the property, one of the SearchProperty::DATATYPE_ constants or any XSD datatype in clark notation
|
* @param string $dataType the datatype of the property, one of the SearchProperty::DATATYPE_ constants or any XSD datatype in clark notation
|
||||||
* @param bool $caseSensitive whether or not comparisons on the property are case sensitive, only applies to string propertries
|
* @param bool $caseSensitive whether or not comparisons on the property are case sensitive, only applies to string propertries
|
||||||
*/
|
*/
|
||||||
public function __construct($name, $searchable, $selectable, $sortable, $dataType = self::DATATYPE_STRING, $caseSensitive = true) {
|
public function __construct(string $name, bool $selectable, bool $searchable, bool $sortable, string $dataType = self::DATATYPE_STRING, bool $caseSensitive = true) {
|
||||||
$this->searchable = $searchable;
|
$this->searchable = $searchable;
|
||||||
$this->selectable = $selectable;
|
$this->selectable = $selectable;
|
||||||
$this->sortable = $sortable;
|
$this->sortable = $sortable;
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ class SearchResult {
|
||||||
* @param INode $node
|
* @param INode $node
|
||||||
* @param string $href
|
* @param string $href
|
||||||
*/
|
*/
|
||||||
public function __construct(INode $node, $href) {
|
public function __construct(INode $node, string $href) {
|
||||||
$this->node = $node;
|
$this->node = $node;
|
||||||
$this->href = $href;
|
$this->href = $href;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ class DiscoverHandler {
|
||||||
$this->queryParser = $queryParser;
|
$this->queryParser = $queryParser;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function handelDiscoverRequest($xml, RequestInterface $request, ResponseInterface $response) {
|
public function handelDiscoverRequest($xml, RequestInterface $request, ResponseInterface $response): bool {
|
||||||
if (!isset($xml['{DAV:}basicsearch'])) {
|
if (!isset($xml['{DAV:}basicsearch'])) {
|
||||||
$response->setStatus(400);
|
$response->setStatus(400);
|
||||||
$response->setBody('Unexpected xml content for query-schema-discovery, expected basicsearch');
|
$response->setBody('Unexpected xml content for query-schema-discovery, expected basicsearch');
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ class PathHelper {
|
||||||
$this->server = $server;
|
$this->server = $server;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getPathFromUri($uri): ?string {
|
public function getPathFromUri(string $uri): ?string {
|
||||||
if (strpos($uri, '://') === false) {
|
if (strpos($uri, '://') === false) {
|
||||||
return $uri;
|
return $uri;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ class SearchHandler {
|
||||||
$this->server = $server;
|
$this->server = $server;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function handleSearchRequest($xml, ResponseInterface $response) {
|
public function handleSearchRequest($xml, ResponseInterface $response): bool {
|
||||||
if (!isset($xml['{DAV:}basicsearch'])) {
|
if (!isset($xml['{DAV:}basicsearch'])) {
|
||||||
$response->setStatus(400);
|
$response->setStatus(400);
|
||||||
$response->setBody('Unexpected xml content for searchrequest, expected basicsearch');
|
$response->setBody('Unexpected xml content for searchrequest, expected basicsearch');
|
||||||
|
|
@ -129,7 +129,7 @@ class SearchHandler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param \SearchDAV\XML\Operator $operator
|
* @param \SearchDAV\XML\Operator $operator
|
||||||
* @param array $allProps
|
* @param SearchPropertyDefinition[] $allProps
|
||||||
* @return Operator
|
* @return Operator
|
||||||
* @throws BadRequest
|
* @throws BadRequest
|
||||||
*/
|
*/
|
||||||
|
|
@ -166,11 +166,11 @@ class SearchHandler {
|
||||||
* If a depth of 1 is requested child elements will also be returned.
|
* If a depth of 1 is requested child elements will also be returned.
|
||||||
*
|
*
|
||||||
* @param SearchResult[] $results
|
* @param SearchResult[] $results
|
||||||
* @param array $propertyNames
|
* @param string[] $propertyNames
|
||||||
* @param int $depth
|
* @param int $depth
|
||||||
* @return \Iterator
|
* @return \Iterator<array>
|
||||||
*/
|
*/
|
||||||
private function getPropertiesIteratorResults($results, $propertyNames = [], $depth = 0): \Iterator {
|
private function getPropertiesIteratorResults(array $results, array $propertyNames = [], int $depth = 0): \Iterator {
|
||||||
$propFindType = $propertyNames ? PropFind::NORMAL : PropFind::ALLPROPS;
|
$propFindType = $propertyNames ? PropFind::NORMAL : PropFind::ALLPROPS;
|
||||||
|
|
||||||
$this->searchBackend->preloadPropertyFor(array_map(function (SearchResult $result): INode {
|
$this->searchBackend->preloadPropertyFor(array_map(function (SearchResult $result): INode {
|
||||||
|
|
@ -179,7 +179,7 @@ class SearchHandler {
|
||||||
|
|
||||||
foreach ($results as $result) {
|
foreach ($results as $result) {
|
||||||
$node = $result->node;
|
$node = $result->node;
|
||||||
$propFind = new PropFind($result->href, (array)$propertyNames, $depth, $propFindType);
|
$propFind = new PropFind($result->href, $propertyNames, $depth, $propFindType);
|
||||||
$r = $this->server->getPropertiesByNode($propFind, $node);
|
$r = $this->server->getPropertiesByNode($propFind, $node);
|
||||||
if ($r) {
|
if ($r) {
|
||||||
$result = $propFind->getResultForMultiStatus();
|
$result = $propFind->getResultForMultiStatus();
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ class SearchPlugin extends ServerPlugin {
|
||||||
$this->queryParser = new QueryParser();
|
$this->queryParser = new QueryParser();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function initialize(Server $server) {
|
public function initialize(Server $server): void {
|
||||||
$this->server = $server;
|
$this->server = $server;
|
||||||
$this->pathHelper = new PathHelper($server);
|
$this->pathHelper = new PathHelper($server);
|
||||||
$this->search = new SearchHandler($this->searchBackend, $this->pathHelper, $server);
|
$this->search = new SearchHandler($this->searchBackend, $this->pathHelper, $server);
|
||||||
|
|
@ -67,7 +67,7 @@ class SearchPlugin extends ServerPlugin {
|
||||||
$server->on('propFind', [$this, 'propFindHandler']);
|
$server->on('propFind', [$this, 'propFindHandler']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function propFindHandler(PropFind $propFind, INode $node) {
|
public function propFindHandler(PropFind $propFind, INode $node): void {
|
||||||
if ($propFind->getPath() === $this->searchBackend->getArbiterPath()) {
|
if ($propFind->getPath() === $this->searchBackend->getArbiterPath()) {
|
||||||
$propFind->handle('{DAV:}supported-query-grammar-set', new SupportedQueryGrammar());
|
$propFind->handle('{DAV:}supported-query-grammar-set', new SupportedQueryGrammar());
|
||||||
}
|
}
|
||||||
|
|
@ -77,9 +77,9 @@ class SearchPlugin extends ServerPlugin {
|
||||||
* SEARCH is allowed for users files
|
* SEARCH is allowed for users files
|
||||||
*
|
*
|
||||||
* @param string $path
|
* @param string $path
|
||||||
* @return array
|
* @return string[]
|
||||||
*/
|
*/
|
||||||
public function getHTTPMethods($path) {
|
public function getHTTPMethods($path): array {
|
||||||
$path = $this->pathHelper->getPathFromUri($path);
|
$path = $this->pathHelper->getPathFromUri($path);
|
||||||
if ($this->searchBackend->getArbiterPath() === $path) {
|
if ($this->searchBackend->getArbiterPath() === $path) {
|
||||||
return ['SEARCH'];
|
return ['SEARCH'];
|
||||||
|
|
@ -88,13 +88,13 @@ class SearchPlugin extends ServerPlugin {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function optionHandler(RequestInterface $request, ResponseInterface $response) {
|
public function optionHandler(RequestInterface $request, ResponseInterface $response): void {
|
||||||
if ($request->getPath() === $this->searchBackend->getArbiterPath()) {
|
if ($request->getPath() === $this->searchBackend->getArbiterPath()) {
|
||||||
$response->addHeader('DASL', '<DAV:basicsearch>');
|
$response->addHeader('DASL', '<DAV:basicsearch>');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function searchHandler(RequestInterface $request, ResponseInterface $response) {
|
public function searchHandler(RequestInterface $request, ResponseInterface $response): bool {
|
||||||
$contentType = $request->getHeader('Content-Type') ?? '';
|
$contentType = $request->getHeader('Content-Type') ?? '';
|
||||||
|
|
||||||
// Currently, we only support xml search queries
|
// Currently, we only support xml search queries
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,7 @@ class Operator {
|
||||||
* Operator constructor.
|
* Operator constructor.
|
||||||
*
|
*
|
||||||
* @param string $type
|
* @param string $type
|
||||||
* @param array $arguments
|
* @param (Literal|\SearchDAV\Backend\SearchPropertyDefinition|Operator)[] $arguments
|
||||||
*/
|
*/
|
||||||
public function __construct(string $type = '', array $arguments = []) {
|
public function __construct(string $type = '', array $arguments = []) {
|
||||||
$this->type = $type;
|
$this->type = $type;
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ class BasicSearchSchema implements XmlSerializable {
|
||||||
$this->properties = $properties;
|
$this->properties = $properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function xmlSerialize(Writer $writer) {
|
public function xmlSerialize(Writer $writer): void {
|
||||||
$childs = array_map(function (PropDesc $propDesc) {
|
$childs = array_map(function (PropDesc $propDesc) {
|
||||||
return [
|
return [
|
||||||
'name' => '{DAV:}propdesc',
|
'name' => '{DAV:}propdesc',
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ class Operator implements XmlDeserializable {
|
||||||
* Operator constructor.
|
* Operator constructor.
|
||||||
*
|
*
|
||||||
* @param string $type
|
* @param string $type
|
||||||
* @param array $arguments
|
* @param (Literal|string|Operator)[] $arguments
|
||||||
*/
|
*/
|
||||||
public function __construct(string $type = '', array $arguments = []) {
|
public function __construct(string $type = '', array $arguments = []) {
|
||||||
$this->type = $type;
|
$this->type = $type;
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ class PropDesc implements XmlSerializable {
|
||||||
*/
|
*/
|
||||||
public $sortable;
|
public $sortable;
|
||||||
|
|
||||||
public function xmlSerialize(Writer $writer) {
|
public function xmlSerialize(Writer $writer): void {
|
||||||
$data = [
|
$data = [
|
||||||
'{DAV:}dataType' => [$this->dataType => null]
|
'{DAV:}dataType' => [$this->dataType => null]
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ class QueryDiscoverResponse extends Response {
|
||||||
$this->schema = $schema;
|
$this->schema = $schema;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function xmlSerialize(Writer $writer) {
|
public function xmlSerialize(Writer $writer): void {
|
||||||
if ($status = $this->getHTTPStatus()) {
|
if ($status = $this->getHTTPStatus()) {
|
||||||
$writer->writeElement('{DAV:}status', 'HTTP/1.1 ' . $status . ' ' . \Sabre\HTTP\Response::$statusCodes[$status]);
|
$writer->writeElement('{DAV:}status', 'HTTP/1.1 ' . $status . ' ' . \Sabre\HTTP\Response::$statusCodes[$status]);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,14 +25,12 @@ use Sabre\Xml\Writer;
|
||||||
use Sabre\Xml\XmlSerializable;
|
use Sabre\Xml\XmlSerializable;
|
||||||
|
|
||||||
class SupportedQueryGrammar implements XmlSerializable {
|
class SupportedQueryGrammar implements XmlSerializable {
|
||||||
const GRAMMAR_BASICSEARCH = '{DAV:}basicsearch';
|
const GRAMMAR_BASIC_SEARCH = '{DAV:}basicsearch';
|
||||||
|
|
||||||
public $grammar = self::GRAMMAR_BASICSEARCH;
|
public function xmlSerialize(Writer $writer): void {
|
||||||
|
|
||||||
public function xmlSerialize(Writer $writer) {
|
|
||||||
$writer->startElement('{DAV:}supported-query-grammar');
|
$writer->startElement('{DAV:}supported-query-grammar');
|
||||||
$writer->startElement('{DAV:}grammar');
|
$writer->startElement('{DAV:}grammar');
|
||||||
$writer->startElement($this->grammar);
|
$writer->startElement(self::GRAMMAR_BASIC_SEARCH);
|
||||||
$writer->endElement();
|
$writer->endElement();
|
||||||
$writer->endElement();
|
$writer->endElement();
|
||||||
$writer->endElement();
|
$writer->endElement();
|
||||||
|
|
|
||||||
|
|
@ -30,15 +30,15 @@ use SearchDAV\XML\BasicSearch;
|
||||||
use SearchDAV\Backend\SearchPropertyDefinition;
|
use SearchDAV\Backend\SearchPropertyDefinition;
|
||||||
|
|
||||||
class DummyBackend implements ISearchBackend {
|
class DummyBackend implements ISearchBackend {
|
||||||
public function getArbiterPath() {
|
public function getArbiterPath(): string {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isValidScope($href, $depth, $path) {
|
public function isValidScope(string $href, $depth, ?string $path): bool {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getPropertyDefinitionsForScope($href, $path) {
|
public function getPropertyDefinitionsForScope($href, $path): array {
|
||||||
return [
|
return [
|
||||||
new SearchPropertyDefinition('{DAV:}getcontentlength', true, true, true, SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER),
|
new SearchPropertyDefinition('{DAV:}getcontentlength', true, true, true, SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER),
|
||||||
new SearchPropertyDefinition('{DAV:}getcontenttype', true, true, true),
|
new SearchPropertyDefinition('{DAV:}getcontenttype', true, true, true),
|
||||||
|
|
@ -47,7 +47,7 @@ class DummyBackend implements ISearchBackend {
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function search(Query $query) {
|
public function search(Query $query): array {
|
||||||
return [
|
return [
|
||||||
new SearchResult(new SimpleFile('foo.txt', 'foobar', 'text/plain'), '/bar/foo.txt')
|
new SearchResult(new SimpleFile('foo.txt', 'foobar', 'text/plain'), '/bar/foo.txt')
|
||||||
];
|
];
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue