1- <?php
1+ <?php declare (strict_types= 1 );
22/**
33 * @copyright Copyright (c) 2017 Robin Appelman <robin@icewind.nl>
44 *
@@ -62,11 +62,6 @@ public function handleSearchRequest($xml, ResponseInterface $response) {
6262 }
6363 /** @var BasicSearch $query */
6464 $ query = $ xml ['{DAV:}basicsearch ' ];
65- if (!$ query ->where ) {
66- $ response ->setStatus (400 );
67- $ response ->setBody ('Parse error: Missing {DAV:}where from {DAV:}basicsearch ' );
68- return false ;
69- }
7065 if (!$ query ->select ) {
7166 $ response ->setStatus (400 );
7267 $ response ->setBody ('Parse error: Missing {DAV:}select from {DAV:}basicsearch ' );
@@ -89,7 +84,8 @@ public function handleSearchRequest($xml, ResponseInterface $response) {
8984 $ response ->setBody ($ e ->getMessage ());
9085 return false ;
9186 }
92- $ data = $ this ->server ->generateMultiStatus (iterator_to_array ($ this ->getPropertiesIteratorResults ($ results , $ query ->select )), false );
87+ $ data = $ this ->server ->generateMultiStatus (iterator_to_array ($ this ->getPropertiesIteratorResults ($ results ,
88+ $ query ->select )), false );
9389 $ response ->setBody ($ data );
9490 return false ;
9591 }
@@ -98,9 +94,10 @@ public function handleSearchRequest($xml, ResponseInterface $response) {
9894 * @param BasicSearch $xml
9995 * @param SearchPropertyDefinition[] $allProps
10096 * @return Query
97+ * @throws BadRequest
10198 */
10299 private function getQueryForXML (BasicSearch $ xml , array $ allProps ) {
103- $ orderBy = array_map (function (\SearchDAV \XML \Order $ order ) use ($ allProps ) {
100+ $ orderBy = array_map (function (\SearchDAV \XML \Order $ order ) use ($ allProps ) {
104101 if (!isset ($ allProps [$ order ->property ])) {
105102 throw new BadRequest ('requested order by property is not a valid property for this scope ' );
106103 }
@@ -110,7 +107,7 @@ private function getQueryForXML(BasicSearch $xml, array $allProps) {
110107 }
111108 return new Order ($ prop , $ order ->order );
112109 }, $ xml ->orderBy );
113- $ select = array_map (function ($ propName ) use ($ allProps ) {
110+ $ select = array_map (function ($ propName ) use ($ allProps ) {
114111 if (!isset ($ allProps [$ propName ])) {
115112 return ;
116113 }
@@ -122,13 +119,19 @@ private function getQueryForXML(BasicSearch $xml, array $allProps) {
122119 }, $ xml ->select );
123120 $ select = array_filter ($ select );
124121
125- $ where = $ this ->transformOperator ($ xml ->where , $ allProps );
122+ $ where = $ xml -> where ? $ this ->transformOperator ($ xml ->where , $ allProps ) : null ;
126123
127124 return new Query ($ select , $ xml ->from , $ where , $ orderBy , $ xml ->limit );
128125 }
129126
127+ /**
128+ * @param \SearchDAV\XML\Operator $operator
129+ * @param array $allProps
130+ * @return Operator
131+ * @throws BadRequest
132+ */
130133 private function transformOperator (\SearchDAV \XML \Operator $ operator , array $ allProps ) {
131- $ arguments = array_map (function ($ argument ) use ($ allProps ) {
134+ $ arguments = array_map (function ($ argument ) use ($ allProps ) {
132135 if (is_string ($ argument )) {
133136 if (!isset ($ allProps [$ argument ])) {
134137 throw new BadRequest ('requested search property is not a valid property for this scope ' );
@@ -138,10 +141,12 @@ private function transformOperator(\SearchDAV\XML\Operator $operator, array $all
138141 throw new BadRequest ('requested search property is not searchable ' );
139142 }
140143 return $ prop ;
141- } else if ($ argument instanceof \SearchDAV \XML \Operator) {
142- return $ this ->transformOperator ($ argument , $ allProps );
143144 } else {
144- return $ argument ;
145+ if ($ argument instanceof \SearchDAV \XML \Operator) {
146+ return $ this ->transformOperator ($ argument , $ allProps );
147+ } else {
148+ return $ argument ;
149+ }
145150 }
146151 }, $ operator ->arguments );
147152
0 commit comments