more types

This commit is contained in:
Robin Appelman 2022-04-08 17:36:08 +02:00
commit d3eb42cd90
14 changed files with 32 additions and 34 deletions

View file

@ -38,7 +38,7 @@ interface ISearchBackend {
*
* @return string
*/
public function getArbiterPath();
public function getArbiterPath(): string;
/**
* 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
* @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
@ -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
* @return SearchPropertyDefinition[]
*/
public function getPropertyDefinitionsForScope($href, $path);
public function getPropertyDefinitionsForScope(string $href, ?string $path): array;
/**
* Preform the search request
@ -81,7 +81,7 @@ interface ISearchBackend {
* @param Query $query
* @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.

View file

@ -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 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->selectable = $selectable;
$this->sortable = $sortable;

View file

@ -35,7 +35,7 @@ class SearchResult {
* @param INode $node
* @param string $href
*/
public function __construct(INode $node, $href) {
public function __construct(INode $node, string $href) {
$this->node = $node;
$this->href = $href;
}

View file

@ -54,7 +54,7 @@ class DiscoverHandler {
$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'])) {
$response->setStatus(400);
$response->setBody('Unexpected xml content for query-schema-discovery, expected basicsearch');

View file

@ -37,7 +37,7 @@ class PathHelper {
$this->server = $server;
}
public function getPathFromUri($uri): ?string {
public function getPathFromUri(string $uri): ?string {
if (strpos($uri, '://') === false) {
return $uri;
}

View file

@ -55,7 +55,7 @@ class SearchHandler {
$this->server = $server;
}
public function handleSearchRequest($xml, ResponseInterface $response) {
public function handleSearchRequest($xml, ResponseInterface $response): bool {
if (!isset($xml['{DAV:}basicsearch'])) {
$response->setStatus(400);
$response->setBody('Unexpected xml content for searchrequest, expected basicsearch');
@ -129,7 +129,7 @@ class SearchHandler {
/**
* @param \SearchDAV\XML\Operator $operator
* @param array $allProps
* @param SearchPropertyDefinition[] $allProps
* @return Operator
* @throws BadRequest
*/
@ -166,11 +166,11 @@ class SearchHandler {
* If a depth of 1 is requested child elements will also be returned.
*
* @param SearchResult[] $results
* @param array $propertyNames
* @param string[] $propertyNames
* @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;
$this->searchBackend->preloadPropertyFor(array_map(function (SearchResult $result): INode {
@ -179,7 +179,7 @@ class SearchHandler {
foreach ($results as $result) {
$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);
if ($r) {
$result = $propFind->getResultForMultiStatus();

View file

@ -57,7 +57,7 @@ class SearchPlugin extends ServerPlugin {
$this->queryParser = new QueryParser();
}
public function initialize(Server $server) {
public function initialize(Server $server): void {
$this->server = $server;
$this->pathHelper = new PathHelper($server);
$this->search = new SearchHandler($this->searchBackend, $this->pathHelper, $server);
@ -67,7 +67,7 @@ class SearchPlugin extends ServerPlugin {
$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()) {
$propFind->handle('{DAV:}supported-query-grammar-set', new SupportedQueryGrammar());
}
@ -77,9 +77,9 @@ class SearchPlugin extends ServerPlugin {
* SEARCH is allowed for users files
*
* @param string $path
* @return array
* @return string[]
*/
public function getHTTPMethods($path) {
public function getHTTPMethods($path): array {
$path = $this->pathHelper->getPathFromUri($path);
if ($this->searchBackend->getArbiterPath() === $path) {
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()) {
$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') ?? '';
// Currently, we only support xml search queries

View file

@ -59,7 +59,7 @@ class Operator {
* Operator constructor.
*
* @param string $type
* @param array $arguments
* @param (Literal|\SearchDAV\Backend\SearchPropertyDefinition|Operator)[] $arguments
*/
public function __construct(string $type = '', array $arguments = []) {
$this->type = $type;

View file

@ -37,7 +37,7 @@ class BasicSearchSchema implements XmlSerializable {
$this->properties = $properties;
}
public function xmlSerialize(Writer $writer) {
public function xmlSerialize(Writer $writer): void {
$childs = array_map(function (PropDesc $propDesc) {
return [
'name' => '{DAV:}propdesc',

View file

@ -49,7 +49,7 @@ class Operator implements XmlDeserializable {
* Operator constructor.
*
* @param string $type
* @param array $arguments
* @param (Literal|string|Operator)[] $arguments
*/
public function __construct(string $type = '', array $arguments = []) {
$this->type = $type;

View file

@ -46,7 +46,7 @@ class PropDesc implements XmlSerializable {
*/
public $sortable;
public function xmlSerialize(Writer $writer) {
public function xmlSerialize(Writer $writer): void {
$data = [
'{DAV:}dataType' => [$this->dataType => null]
];

View file

@ -45,7 +45,7 @@ class QueryDiscoverResponse extends Response {
$this->schema = $schema;
}
public function xmlSerialize(Writer $writer) {
public function xmlSerialize(Writer $writer): void {
if ($status = $this->getHTTPStatus()) {
$writer->writeElement('{DAV:}status', 'HTTP/1.1 ' . $status . ' ' . \Sabre\HTTP\Response::$statusCodes[$status]);
}

View file

@ -25,14 +25,12 @@ use Sabre\Xml\Writer;
use Sabre\Xml\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) {
public function xmlSerialize(Writer $writer): void {
$writer->startElement('{DAV:}supported-query-grammar');
$writer->startElement('{DAV:}grammar');
$writer->startElement($this->grammar);
$writer->startElement(self::GRAMMAR_BASIC_SEARCH);
$writer->endElement();
$writer->endElement();
$writer->endElement();

View file

@ -30,15 +30,15 @@ use SearchDAV\XML\BasicSearch;
use SearchDAV\Backend\SearchPropertyDefinition;
class DummyBackend implements ISearchBackend {
public function getArbiterPath() {
public function getArbiterPath(): string {
return '';
}
public function isValidScope($href, $depth, $path) {
public function isValidScope(string $href, $depth, ?string $path): bool {
return true;
}
public function getPropertyDefinitionsForScope($href, $path) {
public function getPropertyDefinitionsForScope($href, $path): array {
return [
new SearchPropertyDefinition('{DAV:}getcontentlength', true, true, true, SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER),
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 [
new SearchResult(new SimpleFile('foo.txt', 'foobar', 'text/plain'), '/bar/foo.txt')
];