Completed
Push — developer ( 51f696...681523 )
by Błażej
549:36 queued 490:16
created
libraries/nusoap/class.soap_val.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -63,7 +63,7 @@
 block discarded – undo
63 63
 	*
64 64
 	* @param    string $name optional name
65 65
 	* @param    mixed $type optional type name
66
-	* @param	mixed $value optional value
66
+	* @param	integer $value optional value
67 67
 	* @param	mixed $element_ns optional namespace of value
68 68
 	* @param	mixed $type_ns optional namespace of type
69 69
 	* @param	mixed $attributes associative array of attributes to add to element serialization
Please login to merge, or discard this patch.
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -59,16 +59,16 @@  discard block
 block discarded – undo
59 59
 	var $attributes;
60 60
 
61 61
 	/**
62
-	* constructor
63
-	*
64
-	* @param    string $name optional name
65
-	* @param    mixed $type optional type name
66
-	* @param	mixed $value optional value
67
-	* @param	mixed $element_ns optional namespace of value
68
-	* @param	mixed $type_ns optional namespace of type
69
-	* @param	mixed $attributes associative array of attributes to add to element serialization
70
-	* @access   public
71
-	*/
62
+	 * constructor
63
+	 *
64
+	 * @param    string $name optional name
65
+	 * @param    mixed $type optional type name
66
+	 * @param	mixed $value optional value
67
+	 * @param	mixed $element_ns optional namespace of value
68
+	 * @param	mixed $type_ns optional namespace of type
69
+	 * @param	mixed $attributes associative array of attributes to add to element serialization
70
+	 * @access   public
71
+	 */
72 72
   	public function soapval($name='soapval',$type=false,$value=-1,$element_ns=false,$type_ns=false,$attributes=false) {
73 73
 		parent::nusoap_base();
74 74
 		$this->name = $name;
@@ -77,25 +77,25 @@  discard block
 block discarded – undo
77 77
 		$this->element_ns = $element_ns;
78 78
 		$this->type_ns = $type_ns;
79 79
 		$this->attributes = $attributes;
80
-    }
80
+	}
81 81
 
82 82
 	/**
83
-	* return serialized value
84
-	*
85
-	* @param	string $use The WSDL use value (encoded|literal)
86
-	* @return	string XML data
87
-	* @access   public
88
-	*/
83
+	 * return serialized value
84
+	 *
85
+	 * @param	string $use The WSDL use value (encoded|literal)
86
+	 * @return	string XML data
87
+	 * @access   public
88
+	 */
89 89
 	public function serialize($use='encoded') {
90 90
 		return $this->serialize_val($this->value, $this->name, $this->type, $this->element_ns, $this->type_ns, $this->attributes, $use, true);
91
-    }
91
+	}
92 92
 
93 93
 	/**
94
-	* decodes a soapval object into a PHP native type
95
-	*
96
-	* @return	mixed
97
-	* @access   public
98
-	*/
94
+	 * decodes a soapval object into a PHP native type
95
+	 *
96
+	 * @return	mixed
97
+	 * @access   public
98
+	 */
99 99
 	public function decode(){
100 100
 		return $this->value;
101 101
 	}
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
 	* @param	mixed $attributes associative array of attributes to add to element serialization
70 70
 	* @access   public
71 71
 	*/
72
-  	public function soapval($name='soapval',$type=false,$value=-1,$element_ns=false,$type_ns=false,$attributes=false) {
72
+  	public function soapval($name = 'soapval', $type = false, $value = -1, $element_ns = false, $type_ns = false, $attributes = false) {
73 73
 		parent::nusoap_base();
74 74
 		$this->name = $name;
75 75
 		$this->type = $type;
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
 	* @return	string XML data
87 87
 	* @access   public
88 88
 	*/
89
-	public function serialize($use='encoded') {
89
+	public function serialize($use = 'encoded') {
90 90
 		return $this->serialize_val($this->value, $this->name, $this->type, $this->element_ns, $this->type_ns, $this->attributes, $use, true);
91 91
     }
92 92
 
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
 	* @return	mixed
97 97
 	* @access   public
98 98
 	*/
99
-	public function decode(){
99
+	public function decode() {
100 100
 		return $this->value;
101 101
 	}
102 102
 }
Please login to merge, or discard this patch.
libraries/nusoap/class.wsdl.php 4 patches
Doc Comments   +4 added lines, -3 removed lines patch added patch discarded remove patch
@@ -88,6 +88,7 @@  discard block
 block discarded – undo
88 88
 	 * fetches the WSDL document and parses it
89 89
 	 *
90 90
 	 * @access public
91
+	 * @param string $wsdl
91 92
 	 */
92 93
 	public function fetchWSDL($wsdl) {
93 94
 		$this->debug("parse and process WSDL path=$wsdl");
@@ -882,7 +883,7 @@  discard block
 block discarded – undo
882 883
 	/**
883 884
 	* serialize the parsed wsdl
884 885
 	*
885
-	* @param mixed $debug whether to put debug=1 in endpoint URL
886
+	* @param integer $debug whether to put debug=1 in endpoint URL
886 887
 	* @return string serialization of WSDL
887 888
 	* @access public 
888 889
 	*/
@@ -1105,7 +1106,7 @@  discard block
 block discarded – undo
1105 1106
 	 * @param string $direction (input|output)
1106 1107
 	 * @param mixed $parameters parameter value(s)
1107 1108
 	 * @param string $bindingType (soap|soap12)
1108
-	 * @return mixed parameters serialized as XML or false on error (e.g. operation not found)
1109
+	 * @return false|string parameters serialized as XML or false on error (e.g. operation not found)
1109 1110
 	 * @access public
1110 1111
 	 */
1111 1112
 	public function serializeRPCParameters($operation, $direction, $parameters, $bindingType = 'soap') {
@@ -1205,7 +1206,7 @@  discard block
 block discarded – undo
1205 1206
 	 * @param string $operation operation name
1206 1207
 	 * @param string $direction (input|output)
1207 1208
 	 * @param mixed $parameters parameter value(s)
1208
-	 * @return mixed parameters serialized as XML or false on error (e.g. operation not found)
1209
+	 * @return false|string parameters serialized as XML or false on error (e.g. operation not found)
1209 1210
 	 * @access public
1210 1211
 	 * @deprecated
1211 1212
 	 */
Please login to merge, or discard this patch.
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -78,8 +78,9 @@
 block discarded – undo
78 78
 		$this->proxypassword = $proxypassword;
79 79
 		$this->timeout = $timeout;
80 80
 		$this->response_timeout = $response_timeout;
81
-		if (is_array($curl_options))
82
-			$this->curl_options = $curl_options;
81
+		if (is_array($curl_options)) {
82
+					$this->curl_options = $curl_options;
83
+		}
83 84
 		$this->use_curl = $use_curl;
84 85
 		$this->fetchWSDL($wsdl);
85 86
     }
Please login to merge, or discard this patch.
Spacing   +125 added lines, -127 removed lines patch added patch discarded remove patch
@@ -47,13 +47,13 @@  discard block
 block discarded – undo
47 47
 	public $proxypassword = '';
48 48
 	public $timeout = 0;
49 49
 	public $response_timeout = 30;
50
-	public $curl_options = array();	// User-specified cURL options
51
-	public $use_curl = false;			// whether to always try to use cURL
50
+	public $curl_options = array(); // User-specified cURL options
51
+	public $use_curl = false; // whether to always try to use cURL
52 52
 	// for HTTP authentication
53
-	public $username = '';				// Username for HTTP authentication
54
-	public $password = '';				// Password for HTTP authentication
55
-	public $authtype = '';				// Type of HTTP authentication
56
-	public $certRequest = array();		// Certificate for HTTP SSL authentication
53
+	public $username = ''; // Username for HTTP authentication
54
+	public $password = ''; // Password for HTTP authentication
55
+	public $authtype = ''; // Type of HTTP authentication
56
+	public $certRequest = array(); // Certificate for HTTP SSL authentication
57 57
 
58 58
     /**
59 59
      * constructor
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
 	 * @param boolean $use_curl try to use cURL
70 70
      * @access public 
71 71
      */
72
-    public function wsdl($wsdl = '',$proxyhost=false,$proxyport=false,$proxyusername=false,$proxypassword=false,$timeout=0,$response_timeout=30,$curl_options=null,$use_curl=false){
72
+    public function wsdl($wsdl = '', $proxyhost = false, $proxyport = false, $proxyusername = false, $proxypassword = false, $timeout = 0, $response_timeout = 30, $curl_options = null, $use_curl = false) {
73 73
 		parent::nusoap_base();
74 74
 		$this->debug("ctor wsdl=$wsdl timeout=$timeout response_timeout=$response_timeout");
75 75
         $this->proxyhost = $proxyhost;
@@ -103,10 +103,10 @@  discard block
 block discarded – undo
103 103
     		// Schema imports
104 104
     		foreach ($this->schemas as $ns => $list) {
105 105
     			foreach ($list as $xs) {
106
-					$wsdlparts = parse_url($this->wsdl);	// this is bogusly simple!
106
+					$wsdlparts = parse_url($this->wsdl); // this is bogusly simple!
107 107
 		            foreach ($xs->imports as $ns2 => $list2) {
108 108
 		                for ($ii = 0; $ii < count($list2); $ii++) {
109
-		                	if (! $list2[$ii]['loaded']) {
109
+		                	if (!$list2[$ii]['loaded']) {
110 110
 		                		/*
111 111
 		                		 * Substituted with line below
112 112
 		                		 * because of error "Warning: attempt to modify property of non-object"
@@ -117,10 +117,10 @@  discard block
 block discarded – undo
117 117
 								if ($url != '') {
118 118
 									$urlparts = parse_url($url);
119 119
 									if (!isset($urlparts['host'])) {
120
-										$url = $wsdlparts['scheme'] . '://' . $wsdlparts['host'] . (isset($wsdlparts['port']) ? ':' .$wsdlparts['port'] : '') .
121
-												substr($wsdlparts['path'],0,strrpos($wsdlparts['path'],'/') + 1) .$urlparts['path'];
120
+										$url = $wsdlparts['scheme'] . '://' . $wsdlparts['host'] . (isset($wsdlparts['port']) ? ':' . $wsdlparts['port'] : '') .
121
+												substr($wsdlparts['path'], 0, strrpos($wsdlparts['path'], '/') + 1) . $urlparts['path'];
122 122
 									}
123
-									if (! in_array($url, $imported_urls)) {
123
+									if (!in_array($url, $imported_urls)) {
124 124
 					                	$this->parseWSDL($url);
125 125
 				                		$imported++;
126 126
 				                		$imported_urls[] = $url;
@@ -134,19 +134,19 @@  discard block
 block discarded – undo
134 134
     			}
135 135
     		}
136 136
     		// WSDL imports
137
-			$wsdlparts = parse_url($this->wsdl);	// this is bogusly simple!
137
+			$wsdlparts = parse_url($this->wsdl); // this is bogusly simple!
138 138
             foreach ($this->import as $ns => $list) {
139 139
                 for ($ii = 0; $ii < count($list); $ii++) {
140
-                	if (! $list[$ii]['loaded']) {
140
+                	if (!$list[$ii]['loaded']) {
141 141
                 		$this->import[$ns][$ii]['loaded'] = true;
142 142
                 		$url = $list[$ii]['location'];
143 143
 						if ($url != '') {
144 144
 							$urlparts = parse_url($url);
145 145
 							if (!isset($urlparts['host'])) {
146 146
 								$url = $wsdlparts['scheme'] . '://' . $wsdlparts['host'] . (isset($wsdlparts['port']) ? ':' . $wsdlparts['port'] : '') .
147
-										substr($wsdlparts['path'],0,strrpos($wsdlparts['path'],'/') + 1) .$urlparts['path'];
147
+										substr($wsdlparts['path'], 0, strrpos($wsdlparts['path'], '/') + 1) . $urlparts['path'];
148 148
 							}
149
-							if (! in_array($url, $imported_urls)) {
149
+							if (!in_array($url, $imported_urls)) {
150 150
 			                	$this->parseWSDL($url);
151 151
 		                		$imported++;
152 152
 		                		$imported_urls[] = $url;
@@ -159,30 +159,28 @@  discard block
 block discarded – undo
159 159
             } 
160 160
 		}
161 161
         // add new data to operation data
162
-        foreach($this->bindings as $binding => $bindingData) {
162
+        foreach ($this->bindings as $binding => $bindingData) {
163 163
             if (isset($bindingData['operations']) && is_array($bindingData['operations'])) {
164
-                foreach($bindingData['operations'] as $operation => $data) {
164
+                foreach ($bindingData['operations'] as $operation => $data) {
165 165
                     $this->debug('post-parse data gathering for ' . $operation);
166 166
                     $this->bindings[$binding]['operations'][$operation]['input'] = 
167 167
 						isset($this->bindings[$binding]['operations'][$operation]['input']) ? 
168
-						array_merge($this->bindings[$binding]['operations'][$operation]['input'], $this->portTypes[ $bindingData['portType'] ][$operation]['input']) :
169
-						$this->portTypes[ $bindingData['portType'] ][$operation]['input'];
168
+						array_merge($this->bindings[$binding]['operations'][$operation]['input'], $this->portTypes[$bindingData['portType']][$operation]['input']) : $this->portTypes[$bindingData['portType']][$operation]['input'];
170 169
                     $this->bindings[$binding]['operations'][$operation]['output'] = 
171 170
 						isset($this->bindings[$binding]['operations'][$operation]['output']) ?
172
-						array_merge($this->bindings[$binding]['operations'][$operation]['output'], $this->portTypes[ $bindingData['portType'] ][$operation]['output']) :
173
-						$this->portTypes[ $bindingData['portType'] ][$operation]['output'];
174
-                    if(isset($this->messages[ $this->bindings[$binding]['operations'][$operation]['input']['message'] ])){
175
-						$this->bindings[$binding]['operations'][$operation]['input']['parts'] = $this->messages[ $this->bindings[$binding]['operations'][$operation]['input']['message'] ];
171
+						array_merge($this->bindings[$binding]['operations'][$operation]['output'], $this->portTypes[$bindingData['portType']][$operation]['output']) : $this->portTypes[$bindingData['portType']][$operation]['output'];
172
+                    if (isset($this->messages[$this->bindings[$binding]['operations'][$operation]['input']['message']])) {
173
+						$this->bindings[$binding]['operations'][$operation]['input']['parts'] = $this->messages[$this->bindings[$binding]['operations'][$operation]['input']['message']];
176 174
 					}
177
-					if(isset($this->messages[ $this->bindings[$binding]['operations'][$operation]['output']['message'] ])){
178
-                   		$this->bindings[$binding]['operations'][$operation]['output']['parts'] = $this->messages[ $this->bindings[$binding]['operations'][$operation]['output']['message'] ];
175
+					if (isset($this->messages[$this->bindings[$binding]['operations'][$operation]['output']['message']])) {
176
+                   		$this->bindings[$binding]['operations'][$operation]['output']['parts'] = $this->messages[$this->bindings[$binding]['operations'][$operation]['output']['message']];
179 177
                     }
180 178
                     // Set operation style if necessary, but do not override one already provided
181 179
 					if (isset($bindingData['style']) && !isset($this->bindings[$binding]['operations'][$operation]['style'])) {
182 180
                         $this->bindings[$binding]['operations'][$operation]['style'] = $bindingData['style'];
183 181
                     }
184 182
                     $this->bindings[$binding]['operations'][$operation]['transport'] = isset($bindingData['transport']) ? $bindingData['transport'] : '';
185
-                    $this->bindings[$binding]['operations'][$operation]['documentation'] = isset($this->portTypes[ $bindingData['portType'] ][$operation]['documentation']) ? $this->portTypes[ $bindingData['portType'] ][$operation]['documentation'] : '';
183
+                    $this->bindings[$binding]['operations'][$operation]['documentation'] = isset($this->portTypes[$bindingData['portType']][$operation]['documentation']) ? $this->portTypes[$bindingData['portType']][$operation]['documentation'] : '';
186 184
                     $this->bindings[$binding]['operations'][$operation]['endpoint'] = isset($bindingData['endpoint']) ? $bindingData['endpoint'] : '';
187 185
                 } 
188 186
             } 
@@ -213,8 +211,8 @@  discard block
 block discarded – undo
213 211
 	        $tr = new soap_transport_http($wsdl, $this->curl_options, $this->use_curl);
214 212
 			$tr->request_method = 'GET';
215 213
 			$tr->useSOAPAction = false;
216
-			if($this->proxyhost && $this->proxyport){
217
-				$tr->setProxy($this->proxyhost,$this->proxyport,$this->proxyusername,$this->proxypassword);
214
+			if ($this->proxyhost && $this->proxyport) {
215
+				$tr->setProxy($this->proxyhost, $this->proxyport, $this->proxyusername, $this->proxypassword);
218 216
 			}
219 217
 			if ($this->authtype != '') {
220 218
 				$tr->setCredentials($this->username, $this->password, $this->authtype, array(), $this->certRequest);
@@ -223,8 +221,8 @@  discard block
 block discarded – undo
223 221
 			$wsdl_string = $tr->send('', $this->timeout, $this->response_timeout);
224 222
 			$this->appendDebug($tr->getDebug());
225 223
 			// catch errors
226
-			if($err = $tr->getError() ){
227
-				$errstr = 'Getting ' . $wsdl . ' - HTTP ERROR: '.$err;
224
+			if ($err = $tr->getError()) {
225
+				$errstr = 'Getting ' . $wsdl . ' - HTTP ERROR: ' . $err;
228 226
 				$this->debug($errstr);
229 227
 	            $this->setError($errstr);
230 228
 				unset($tr);
@@ -283,7 +281,7 @@  discard block
 block discarded – undo
283 281
         xml_parser_free($this->parser);
284 282
         $this->debug('Parsing WSDL done');
285 283
 		// catch wsdl parse errors
286
-		if($this->getError()){
284
+		if ($this->getError()) {
287 285
 			return false;
288 286
 		}
289 287
         return true;
@@ -320,8 +318,8 @@  discard block
 block discarded – undo
320 318
             // process attributes
321 319
             if (count($attrs) > 0) {
322 320
 				// register namespace declarations
323
-                foreach($attrs as $k => $v) {
324
-                    if (preg_match('/^xmlns/',$k)) {
321
+                foreach ($attrs as $k => $v) {
322
+                    if (preg_match('/^xmlns/', $k)) {
325 323
                         if ($ns_prefix = substr(strrchr($k, ':'), 1)) {
326 324
                             $this->namespaces[$ns_prefix] = $v;
327 325
                         } else {
@@ -334,7 +332,7 @@  discard block
 block discarded – undo
334 332
                     }
335 333
                 }
336 334
                 // expand each attribute prefix to its namespace
337
-                foreach($attrs as $k => $v) {
335
+                foreach ($attrs as $k => $v) {
338 336
                     $k = strpos($k, ':') ? $this->expandQname($k) : $k;
339 337
                     if ($k != 'location' && $k != 'soapAction' && $k != 'namespace') {
340 338
                         $v = strpos($v, ':') ? $this->expandQname($v) : $v;
@@ -441,8 +439,8 @@  discard block
 block discarded – undo
441 439
 					    case 'address':
442 440
 					        $this->ports[$this->currentPort]['location'] = $attrs['location'];
443 441
 					        $this->ports[$this->currentPort]['bindingType'] = $namespace;
444
-					        $this->bindings[ $this->ports[$this->currentPort]['binding'] ]['bindingType'] = $namespace;
445
-					        $this->bindings[ $this->ports[$this->currentPort]['binding'] ]['endpoint'] = $attrs['location'];
442
+					        $this->bindings[$this->ports[$this->currentPort]['binding']]['bindingType'] = $namespace;
443
+					        $this->bindings[$this->ports[$this->currentPort]['binding']]['endpoint'] = $attrs['location'];
446 444
 					        break;
447 445
 					} 
448 446
 					break;
@@ -452,13 +450,13 @@  discard block
 block discarded – undo
452 450
 			case 'import':
453 451
 			    if (isset($attrs['location'])) {
454 452
                     $this->import[$attrs['namespace']][] = array('location' => $attrs['location'], 'loaded' => false);
455
-                    $this->debug('parsing import ' . $attrs['namespace']. ' - ' . $attrs['location'] . ' (' . count($this->import[$attrs['namespace']]).')');
453
+                    $this->debug('parsing import ' . $attrs['namespace'] . ' - ' . $attrs['location'] . ' (' . count($this->import[$attrs['namespace']]) . ')');
456 454
 				} else {
457 455
                     $this->import[$attrs['namespace']][] = array('location' => '', 'loaded' => true);
458
-					if (! $this->getPrefixFromNamespace($attrs['namespace'])) {
459
-						$this->namespaces['ns'.(count($this->namespaces)+1)] = $attrs['namespace'];
456
+					if (!$this->getPrefixFromNamespace($attrs['namespace'])) {
457
+						$this->namespaces['ns' . (count($this->namespaces) + 1)] = $attrs['namespace'];
460 458
 					}
461
-                    $this->debug('parsing import ' . $attrs['namespace']. ' - [no location] (' . count($this->import[$attrs['namespace']]).')');
459
+                    $this->debug('parsing import ' . $attrs['namespace'] . ' - [no location] (' . count($this->import[$attrs['namespace']]) . ')');
462 460
 				}
463 461
 				break;
464 462
 			//wait for schema
@@ -509,7 +507,7 @@  discard block
 block discarded – undo
509 507
 	* @param string $name element name
510 508
 	* @access private 
511 509
 	*/
512
-	public function end_element($parser, $name){ 
510
+	public function end_element($parser, $name) { 
513 511
 		// unset schema status
514 512
 		if (/*preg_match('/types$/', $name) ||*/ preg_match('/schema$/', $name)) {
515 513
 			$this->status = "";
@@ -592,15 +590,15 @@  discard block
 block discarded – undo
592 590
 		}
593 591
 		$this->debug("getOperations for port '$portName' bindingType $bindingType");
594 592
 		// loop thru ports
595
-		foreach($this->ports as $port => $portData) {
593
+		foreach ($this->ports as $port => $portData) {
596 594
 			$this->debug("getOperations checking port $port bindingType " . $portData['bindingType']);
597 595
 			if ($portName == '' || $port == $portName) {
598 596
 				// binding type of port matches parameter
599 597
 				if ($portData['bindingType'] == $bindingType) {
600 598
 					$this->debug("getOperations found port $port bindingType $bindingType");
601 599
 					// merge bindings
602
-					if (isset($this->bindings[ $portData['binding'] ]['operations'])) {
603
-						$ops = array_merge ($ops, $this->bindings[ $portData['binding'] ]['operations']);
600
+					if (isset($this->bindings[$portData['binding']]['operations'])) {
601
+						$ops = array_merge($ops, $this->bindings[$portData['binding']]['operations']);
604 602
 					}
605 603
 				}
606 604
 			}
@@ -627,15 +625,15 @@  discard block
 block discarded – undo
627 625
 			$bindingType = 'http://schemas.xmlsoap.org/wsdl/soap12/';
628 626
 		}
629 627
 		// loop thru ports
630
-		foreach($this->ports as $port => $portData) {
628
+		foreach ($this->ports as $port => $portData) {
631 629
 			// binding type of port matches parameter
632 630
 			if ($portData['bindingType'] == $bindingType) {
633 631
 				// get binding
634 632
 				//foreach($this->bindings[ $portData['binding'] ]['operations'] as $bOperation => $opData) {
635
-				foreach(array_keys($this->bindings[ $portData['binding'] ]['operations']) as $bOperation) {
633
+				foreach (array_keys($this->bindings[$portData['binding']]['operations']) as $bOperation) {
636 634
 					// note that we could/should also check the namespace here
637 635
 					if ($operation == $bOperation) {
638
-						$opData = $this->bindings[ $portData['binding'] ]['operations'][$operation];
636
+						$opData = $this->bindings[$portData['binding']]['operations'][$operation];
639 637
 					    return $opData;
640 638
 					} 
641 639
 				} 
@@ -658,11 +656,11 @@  discard block
 block discarded – undo
658 656
 			$bindingType = 'http://schemas.xmlsoap.org/wsdl/soap12/';
659 657
 		}
660 658
 		// loop thru ports
661
-		foreach($this->ports as $port => $portData) {
659
+		foreach ($this->ports as $port => $portData) {
662 660
 			// binding type of port matches parameter
663 661
 			if ($portData['bindingType'] == $bindingType) {
664 662
 				// loop through operations for the binding
665
-				foreach ($this->bindings[ $portData['binding'] ]['operations'] as $bOperation => $opData) {
663
+				foreach ($this->bindings[$portData['binding']]['operations'] as $bOperation => $opData) {
666 664
 					if ($opData['soapAction'] == $soapAction) {
667 665
 					    return $opData;
668 666
 					} 
@@ -691,7 +689,7 @@  discard block
 block discarded – undo
691 689
     */
692 690
 	public function getTypeDef($type, $ns) {
693 691
 		$this->debug("in getTypeDef: type=$type, ns=$ns");
694
-		if ((! $ns) && isset($this->namespaces['tns'])) {
692
+		if ((!$ns) && isset($this->namespaces['tns'])) {
695 693
 			$ns = $this->namespaces['tns'];
696 694
 			$this->debug("in getTypeDef: type namespace forced to $ns");
697 695
 		}
@@ -749,7 +747,7 @@  discard block
 block discarded – undo
749 747
     *
750 748
     * @access private
751 749
     */
752
-    public function webDescription(){
750
+    public function webDescription() {
753 751
     	global $HTTP_SERVER_VARS;
754 752
 
755 753
 		if (isset($_SERVER)) {
@@ -761,7 +759,7 @@  discard block
 block discarded – undo
761 759
 		}
762 760
 
763 761
 		$b = '
764
-		<html><head><title>NuSOAP: '.$this->serviceName.'</title>
762
+		<html><head><title>NuSOAP: '.$this->serviceName . '</title>
765 763
 		<style type="text/css">
766 764
 		    body    { font-family: arial; color: #000000; background-color: #ffffff; margin: 0px 0px 0px 0px; }
767 765
 		    p       { font-family: arial; color: #000000; margin-top: 0px; margin-bottom: 12px; }
@@ -838,24 +836,24 @@  discard block
 block discarded – undo
838 836
 		<body>
839 837
 		<div class=content>
840 838
 			<br><br>
841
-			<div class=title>'.$this->serviceName.'</div>
839
+			<div class=title>'.$this->serviceName . '</div>
842 840
 			<div class=nav>
843
-				<p>View the <a href="'.$PHP_SELF.'?wsdl">WSDL</a> for the service.
841
+				<p>View the <a href="'.$PHP_SELF . '?wsdl">WSDL</a> for the service.
844 842
 				Click on an operation name to view it&apos;s details.</p>
845 843
 				<ul>';
846
-				foreach($this->getOperations() as $op => $data){
844
+				foreach ($this->getOperations() as $op => $data) {
847 845
 				    $b .= "<li><a href='#' onclick=\"popout();popup('$op')\">$op</a></li>";
848 846
 				    // create hidden div
849 847
 				    $b .= "<div id='$op' class='hidden'>
850 848
 				    <a href='#' onclick='popout()'><font color='#ffffff'>Close</font></a><br><br>";
851
-				    foreach($data as $donnie => $marie){ // loop through opdata
852
-						if($donnie == 'input' || $donnie == 'output'){ // show input/output data
853
-						    $b .= "<font color='white'>".ucfirst($donnie).':</font><br>';
854
-						    foreach($marie as $captain => $tenille){ // loop through data
855
-								if($captain == 'parts'){ // loop thru parts
849
+				    foreach ($data as $donnie => $marie) { // loop through opdata
850
+						if ($donnie == 'input' || $donnie == 'output') { // show input/output data
851
+						    $b .= "<font color='white'>" . ucfirst($donnie) . ':</font><br>';
852
+						    foreach ($marie as $captain => $tenille) { // loop through data
853
+								if ($captain == 'parts') { // loop thru parts
856 854
 								    $b .= "&nbsp;&nbsp;$captain:<br>";
857 855
 					                //if(is_array($tenille)){
858
-								    	foreach($tenille as $joanie => $chachi){
856
+								    	foreach ($tenille as $joanie => $chachi) {
859 857
 											$b .= "&nbsp;&nbsp;&nbsp;&nbsp;$joanie: $chachi<br>";
860 858
 								    	}
861 859
 					        		//}
@@ -864,7 +862,7 @@  discard block
 block discarded – undo
864 862
 								}
865 863
 						    }
866 864
 						} else {
867
-						    $b .= "<font color='white'>".ucfirst($donnie).":</font> $marie<br>";
865
+						    $b .= "<font color='white'>" . ucfirst($donnie) . ":</font> $marie<br>";
868 866
 						}
869 867
 				    }
870 868
 					$b .= '</div>';
@@ -887,7 +885,7 @@  discard block
 block discarded – undo
887 885
 	{
888 886
 		$xml = '<?xml version="1.0" encoding="ISO-8859-1"?>';
889 887
 		$xml .= "\n<definitions";
890
-		foreach($this->namespaces as $k => $v) {
888
+		foreach ($this->namespaces as $k => $v) {
891 889
 			$xml .= " xmlns:$k=\"$v\"";
892 890
 		} 
893 891
 		// 10.9.02 - add poulter fix for wsdl and tns declarations
@@ -900,7 +898,7 @@  discard block
 block discarded – undo
900 898
 		$xml .= '>'; 
901 899
 		// imports
902 900
 		if (sizeof($this->import) > 0) {
903
-			foreach($this->import as $ns => $list) {
901
+			foreach ($this->import as $ns => $list) {
904 902
 				foreach ($list as $ii) {
905 903
 					if ($ii['location'] != '') {
906 904
 						$xml .= '<import location="' . $ii['location'] . '" namespace="' . $ns . '" />';
@@ -911,7 +909,7 @@  discard block
 block discarded – undo
911 909
 			} 
912 910
 		} 
913 911
 		// types
914
-		if (count($this->schemas)>=1) {
912
+		if (count($this->schemas) >= 1) {
915 913
 			$xml .= "\n<types>\n";
916 914
 			foreach ($this->schemas as $ns => $list) {
917 915
 				foreach ($list as $xs) {
@@ -922,10 +920,10 @@  discard block
 block discarded – undo
922 920
 		} 
923 921
 		// messages
924 922
 		if (count($this->messages) >= 1) {
925
-			foreach($this->messages as $msgName => $msgParts) {
923
+			foreach ($this->messages as $msgName => $msgParts) {
926 924
 				$xml .= "\n<message name=\"" . $msgName . '">';
927
-				if(is_array($msgParts)){
928
-					foreach($msgParts as $partName => $partType) {
925
+				if (is_array($msgParts)) {
926
+					foreach ($msgParts as $partName => $partType) {
929 927
 						// print 'serializing '.$partType.', sv: '.$this->XMLSchemaVersion.'<br>';
930 928
 						if (strpos($partType, ':')) {
931 929
 						    $typePrefix = $this->getPrefixFromNamespace($this->getPrefix($partType));
@@ -933,7 +931,7 @@  discard block
 block discarded – undo
933 931
 						    // print 'checking typemap: '.$this->XMLSchemaVersion.'<br>';
934 932
 						    $typePrefix = 'xsd';
935 933
 						} else {
936
-						    foreach($this->typemap as $ns => $types) {
934
+						    foreach ($this->typemap as $ns => $types) {
937 935
 						        if (isset($types[$partType])) {
938 936
 						            $typePrefix = $this->getPrefixFromNamespace($ns);
939 937
 						        } 
@@ -963,13 +961,13 @@  discard block
 block discarded – undo
963 961
 		if (count($this->bindings) >= 1) {
964 962
 			$binding_xml = '';
965 963
 			$portType_xml = '';
966
-			foreach($this->bindings as $bindingName => $attrs) {
964
+			foreach ($this->bindings as $bindingName => $attrs) {
967 965
 				$binding_xml .= "\n<binding name=\"" . $bindingName . '" type="tns:' . $attrs['portType'] . '">';
968 966
 				$binding_xml .= "\n" . '  <soap:binding style="' . $attrs['style'] . '" transport="' . $attrs['transport'] . '"/>';
969 967
 				$portType_xml .= "\n<portType name=\"" . $attrs['portType'] . '">';
970
-				foreach($attrs['operations'] as $opName => $opParts) {
968
+				foreach ($attrs['operations'] as $opName => $opParts) {
971 969
 					$binding_xml .= "\n" . '  <operation name="' . $opName . '">';
972
-					$binding_xml .= "\n" . '    <soap:operation soapAction="' . $opParts['soapAction'] . '" style="'. $opParts['style'] . '"/>';
970
+					$binding_xml .= "\n" . '    <soap:operation soapAction="' . $opParts['soapAction'] . '" style="' . $opParts['style'] . '"/>';
973 971
 					if (isset($opParts['input']['encodingStyle']) && $opParts['input']['encodingStyle'] != '') {
974 972
 						$enc_style = ' encodingStyle="' . $opParts['input']['encodingStyle'] . '"';
975 973
 					} else {
@@ -988,7 +986,7 @@  discard block
 block discarded – undo
988 986
 					    $portType_xml .= ' parameterOrder="' . $opParts['parameterOrder'] . '"';
989 987
 					} 
990 988
 					$portType_xml .= '>';
991
-					if(isset($opParts['documentation']) && $opParts['documentation'] != '') {
989
+					if (isset($opParts['documentation']) && $opParts['documentation'] != '') {
992 990
 						$portType_xml .= "\n" . '    <documentation>' . htmlspecialchars($opParts['documentation']) . '</documentation>';
993 991
 					}
994 992
 					$portType_xml .= "\n" . '    <input message="tns:' . $opParts['input']['message'] . '"/>';
@@ -1003,7 +1001,7 @@  discard block
 block discarded – undo
1003 1001
 		// services
1004 1002
 		$xml .= "\n<service name=\"" . $this->serviceName . '">';
1005 1003
 		if (count($this->ports) >= 1) {
1006
-			foreach($this->ports as $pName => $attrs) {
1004
+			foreach ($this->ports as $pName => $attrs) {
1007 1005
 				$xml .= "\n" . '  <port name="' . $pName . '" binding="tns:' . $attrs['binding'] . '">';
1008 1006
 				$xml .= "\n" . '    <soap:address location="' . $attrs['location'] . ($debug ? '?debug=1' : '') . '"/>';
1009 1007
 				$xml .= "\n" . '  </port>';
@@ -1118,7 +1116,7 @@  discard block
 block discarded – undo
1118 1116
 
1119 1117
 		// Get encoding style for output and set to current
1120 1118
 		$encodingStyle = 'http://schemas.xmlsoap.org/soap/encoding/';
1121
-		if(($direction == 'input') && isset($opData['output']['encodingStyle']) && ($opData['output']['encodingStyle'] != $encodingStyle)) {
1119
+		if (($direction == 'input') && isset($opData['output']['encodingStyle']) && ($opData['output']['encodingStyle'] != $encodingStyle)) {
1122 1120
 			$encodingStyle = $opData['output']['encodingStyle'];
1123 1121
 			$enc_style = $encodingStyle;
1124 1122
 		}
@@ -1213,7 +1211,7 @@  discard block
 block discarded – undo
1213 1211
 		
1214 1212
 		// Get encoding style for output and set to current
1215 1213
 		$encodingStyle = 'http://schemas.xmlsoap.org/soap/encoding/';
1216
-		if(($direction == 'input') && isset($opData['output']['encodingStyle']) && ($opData['output']['encodingStyle'] != $encodingStyle)) {
1214
+		if (($direction == 'input') && isset($opData['output']['encodingStyle']) && ($opData['output']['encodingStyle'] != $encodingStyle)) {
1217 1215
 			$encodingStyle = $opData['output']['encodingStyle'];
1218 1216
 			$enc_style = $encodingStyle;
1219 1217
 		}
@@ -1228,10 +1226,10 @@  discard block
 block discarded – undo
1228 1226
 			if (is_array($parameters)) {
1229 1227
 				$parametersArrayType = $this->isArraySimpleOrStruct($parameters);
1230 1228
 				$this->debug('have ' . $parametersArrayType . ' parameters');
1231
-				foreach($opData[$direction]['parts'] as $name => $type) {
1232
-					$this->debug('serializing part "'.$name.'" of type "'.$type.'"');
1229
+				foreach ($opData[$direction]['parts'] as $name => $type) {
1230
+					$this->debug('serializing part "' . $name . '" of type "' . $type . '"');
1233 1231
 					// Track encoding style
1234
-					if(isset($opData[$direction]['encodingStyle']) && $encodingStyle != $opData[$direction]['encodingStyle']) {
1232
+					if (isset($opData[$direction]['encodingStyle']) && $encodingStyle != $opData[$direction]['encodingStyle']) {
1235 1233
 						$encodingStyle = $opData[$direction]['encodingStyle'];			
1236 1234
 						$enc_style = $encodingStyle;
1237 1235
 					} else {
@@ -1271,11 +1269,11 @@  discard block
 block discarded – undo
1271 1269
 	 * @return string value serialized as an XML string
1272 1270
 	 * @access private
1273 1271
 	 */
1274
-	public function serializeType($name, $type, $value, $use='encoded', $encodingStyle=false, $unqualified=false)
1272
+	public function serializeType($name, $type, $value, $use = 'encoded', $encodingStyle = false, $unqualified = false)
1275 1273
 	{
1276 1274
 		$this->debug("in serializeType: name=$name, type=$type, use=$use, encodingStyle=$encodingStyle, unqualified=" . ($unqualified ? "unqualified" : "qualified"));
1277 1275
 		$this->appendDebug("value=" . $this->varDump($value));
1278
-		if($use == 'encoded' && $encodingStyle) {
1276
+		if ($use == 'encoded' && $encodingStyle) {
1279 1277
 			$encodingStyle = ' SOAP-ENV:encodingStyle="' . $encodingStyle . '"';
1280 1278
 		}
1281 1279
 
@@ -1319,7 +1317,7 @@  discard block
 block discarded – undo
1319 1317
 				$this->debug("in serializeType: expanded prefixed type: $uqType, $ns");
1320 1318
 			}
1321 1319
 
1322
-			if($ns == $this->XMLSchemaVersion || $ns == 'http://schemas.xmlsoap.org/soap/encoding/'){
1320
+			if ($ns == $this->XMLSchemaVersion || $ns == 'http://schemas.xmlsoap.org/soap/encoding/') {
1323 1321
 				$this->debug('in serializeType: type namespace indicates XML Schema or SOAP Encoding type');
1324 1322
 				if ($unqualified && $use == 'literal') {
1325 1323
 					$elementNS = " xmlns=\"\"";
@@ -1340,7 +1338,7 @@  discard block
 block discarded – undo
1340 1338
 					return $this->serialize_val($value, $name, false, false, false, false, $use);
1341 1339
 				}
1342 1340
 		    	if ($uqType == 'boolean') {
1343
-		    		if ((is_string($value) && $value == 'false') || (! $value)) {
1341
+		    		if ((is_string($value) && $value == 'false') || (!$value)) {
1344 1342
 						$value = 'false';
1345 1343
 					} else {
1346 1344
 						$value = 'true';
@@ -1370,7 +1368,7 @@  discard block
 block discarded – undo
1370 1368
 				$this->debug('in serializeType: appears to be Apache SOAP type');
1371 1369
 				if ($uqType == 'Map') {
1372 1370
 					$tt_prefix = $this->getPrefixFromNamespace('http://xml.apache.org/xml-soap');
1373
-					if (! $tt_prefix) {
1371
+					if (!$tt_prefix) {
1374 1372
 						$this->debug('in serializeType: Add namespace for Apache SOAP type');
1375 1373
 						$tt_prefix = 'ns' . rand(1000, 9999);
1376 1374
 						$this->namespaces[$tt_prefix] = 'http://xml.apache.org/xml-soap';
@@ -1378,11 +1376,11 @@  discard block
 block discarded – undo
1378 1376
 						$tt_prefix = $this->getPrefixFromNamespace('http://xml.apache.org/xml-soap');
1379 1377
 					}
1380 1378
 					$contents = '';
1381
-					foreach($value as $k => $v) {
1379
+					foreach ($value as $k => $v) {
1382 1380
 						$this->debug("serializing map element: key $k, value $v");
1383 1381
 						$contents .= '<item>';
1384
-						$contents .= $this->serialize_val($k,'key',false,false,false,false,$use);
1385
-						$contents .= $this->serialize_val($v,'value',false,false,false,false,$use);
1382
+						$contents .= $this->serialize_val($k, 'key', false, false, false, false, $use);
1383
+						$contents .= $this->serialize_val($v, 'value', false, false, false, false, $use);
1386 1384
 						$contents .= '</item>';
1387 1385
 					}
1388 1386
 					if ($use == 'literal') {
@@ -1404,7 +1402,7 @@  discard block
 block discarded – undo
1404 1402
 			$ns = '';
1405 1403
 			$uqType = $type;
1406 1404
 		}
1407
-		if(!$typeDef = $this->getTypeDef($uqType, $ns)){
1405
+		if (!$typeDef = $this->getTypeDef($uqType, $ns)) {
1408 1406
 			$this->setError("$type ($uqType) is not a supported type.");
1409 1407
 			$this->debug("in serializeType: $type ($uqType) is not a supported type.");
1410 1408
 			return false;
@@ -1421,7 +1419,7 @@  discard block
 block discarded – undo
1421 1419
 			return false;
1422 1420
 		}
1423 1421
 		$phpType = $typeDef['phpType'];
1424
-		$this->debug("in serializeType: uqType: $uqType, ns: $ns, phptype: $phpType, arrayType: " . (isset($typeDef['arrayType']) ? $typeDef['arrayType'] : '') ); 
1422
+		$this->debug("in serializeType: uqType: $uqType, ns: $ns, phptype: $phpType, arrayType: " . (isset($typeDef['arrayType']) ? $typeDef['arrayType'] : '')); 
1425 1423
 		// if php type == struct, map value to the <all> element names
1426 1424
 		if ($phpType == 'struct') {
1427 1425
 			if (isset($typeDef['typeClass']) && $typeDef['typeClass'] == 'element') {
@@ -1501,14 +1499,14 @@  discard block
 block discarded – undo
1501 1499
 						':arrayType="' .
1502 1500
 						$this->getPrefixFromNamespace($this->getPrefix($typeDef['arrayType'])) .
1503 1501
 						':' .
1504
-						$this->getLocalPart($typeDef['arrayType'])."[0]\"/>";
1502
+						$this->getLocalPart($typeDef['arrayType']) . "[0]\"/>";
1505 1503
 				}
1506 1504
 				$this->debug("in serializeType: returning: $xml");
1507 1505
 				return $xml;
1508 1506
 			}
1509 1507
 			if (isset($typeDef['multidimensional'])) {
1510 1508
 				$nv = array();
1511
-				foreach($value as $v) {
1509
+				foreach ($value as $v) {
1512 1510
 					$cols = ',' . sizeof($v);
1513 1511
 					$nv = array_merge($nv, $v);
1514 1512
 				} 
@@ -1519,10 +1517,10 @@  discard block
 block discarded – undo
1519 1517
 			if (is_array($value) && sizeof($value) >= 1) {
1520 1518
 				$rows = sizeof($value);
1521 1519
 				$contents = '';
1522
-				foreach($value as $k => $v) {
1520
+				foreach ($value as $k => $v) {
1523 1521
 					$this->debug("serializing array element: $k, $v of type: $typeDef[arrayType]");
1524 1522
 					//if (strpos($typeDef['arrayType'], ':') ) {
1525
-					if (!in_array($typeDef['arrayType'],$this->typemap['http://www.w3.org/2001/XMLSchema'])) {
1523
+					if (!in_array($typeDef['arrayType'], $this->typemap['http://www.w3.org/2001/XMLSchema'])) {
1526 1524
 					    $contents .= $this->serializeType('item', $typeDef['arrayType'], $v, $use);
1527 1525
 					} else {
1528 1526
 					    $contents .= $this->serialize_val($v, 'item', $typeDef['arrayType'], null, $this->XMLSchemaVersion, false, $use);
@@ -1537,11 +1535,11 @@  discard block
 block discarded – undo
1537 1535
 					.$contents
1538 1536
 					."</$name>";
1539 1537
 			} else {
1540
-				$xml = "<$name$elementNS xsi:type=\"".$this->getPrefixFromNamespace('http://schemas.xmlsoap.org/soap/encoding/').':Array" '.
1538
+				$xml = "<$name$elementNS xsi:type=\"" . $this->getPrefixFromNamespace('http://schemas.xmlsoap.org/soap/encoding/') . ':Array" ' .
1541 1539
 					$this->getPrefixFromNamespace('http://schemas.xmlsoap.org/soap/encoding/')
1542 1540
 					.':arrayType="'
1543 1541
 					.$this->getPrefixFromNamespace($this->getPrefix($typeDef['arrayType']))
1544
-					.":".$this->getLocalPart($typeDef['arrayType'])."[$rows$cols]\">"
1542
+					.":" . $this->getLocalPart($typeDef['arrayType']) . "[$rows$cols]\">"
1545 1543
 					.$contents
1546 1544
 					."</$name>";
1547 1545
 			}
@@ -1621,7 +1619,7 @@  discard block
 block discarded – undo
1621 1619
 					$this->debug("no value provided for attribute $aName");
1622 1620
 				}
1623 1621
 				if ($xname) {
1624
-					$xml .=  " $aName=\"" . $this->expandEntities($xvalue[$xname]) . "\"";
1622
+					$xml .= " $aName=\"" . $this->expandEntities($xvalue[$xname]) . "\"";
1625 1623
 				}
1626 1624
 			} 
1627 1625
 		} else {
@@ -1642,7 +1640,7 @@  discard block
 block discarded – undo
1642 1640
 	 * @return string value serialized as an XML string
1643 1641
 	 * @access private
1644 1642
 	 */
1645
-	public function serializeComplexTypeElements($typeDef, $value, $ns, $uqType, $use='encoded', $encodingStyle=false) {
1643
+	public function serializeComplexTypeElements($typeDef, $value, $ns, $uqType, $use = 'encoded', $encodingStyle = false) {
1646 1644
 		$this->debug("in serializeComplexTypeElements for XML Schema type $ns:$uqType");
1647 1645
 		$xml = '';
1648 1646
 		if (isset($typeDef['extensionBase'])) {
@@ -1669,7 +1667,7 @@  discard block
 block discarded – undo
1669 1667
 				$xvalue = array();
1670 1668
 			}
1671 1669
 			// toggle whether all elements are present - ideally should validate against schema
1672
-			if (count($typeDef['elements']) != count($xvalue)){
1670
+			if (count($typeDef['elements']) != count($xvalue)) {
1673 1671
 				$optionals = true;
1674 1672
 			}
1675 1673
 			foreach ($typeDef['elements'] as $eName => $attrs) {
@@ -1682,8 +1680,8 @@  discard block
 block discarded – undo
1682 1680
 				// if user took advantage of a minOccurs=0, then only serialize named parameters
1683 1681
 				if (isset($optionals)
1684 1682
 				    && (!isset($xvalue[$eName])) 
1685
-					&& ( (!isset($attrs['nillable'])) || $attrs['nillable'] != 'true')
1686
-					){
1683
+					&& ((!isset($attrs['nillable'])) || $attrs['nillable'] != 'true')
1684
+					) {
1687 1685
 					if (isset($attrs['minOccurs']) && $attrs['minOccurs'] <> '0') {
1688 1686
 						$this->debug("apparent error: no value provided for element $eName with minOccurs=" . $attrs['minOccurs']);
1689 1687
 					}
@@ -1748,15 +1746,15 @@  discard block
 block discarded – undo
1748 1746
 	* @see nusoap_xmlschema
1749 1747
 	* @access public
1750 1748
 	*/
1751
-	public function addComplexType($name,$typeClass='complexType',$phpType='array',$compositor='',$restrictionBase='',$elements=array(),$attrs=array(),$arrayType='') {
1749
+	public function addComplexType($name, $typeClass = 'complexType', $phpType = 'array', $compositor = '', $restrictionBase = '', $elements = array(), $attrs = array(), $arrayType = '') {
1752 1750
 		if (count($elements) > 0) {
1753 1751
 			$eElements = array();
1754
-	    	foreach($elements as $n => $e){
1752
+	    	foreach ($elements as $n => $e) {
1755 1753
 	            // expand each element
1756 1754
 	            $ee = array();
1757 1755
 	            foreach ($e as $k => $v) {
1758
-		            $k = strpos($k,':') ? $this->expandQname($k) : $k;
1759
-		            $v = strpos($v,':') ? $this->expandQname($v) : $v;
1756
+		            $k = strpos($k, ':') ? $this->expandQname($k) : $k;
1757
+		            $v = strpos($v, ':') ? $this->expandQname($v) : $v;
1760 1758
 		            $ee[$k] = $v;
1761 1759
 		    	}
1762 1760
 	    		$eElements[$n] = $ee;
@@ -1765,11 +1763,11 @@  discard block
 block discarded – undo
1765 1763
 		}
1766 1764
 		
1767 1765
 		if (count($attrs) > 0) {
1768
-	    	foreach($attrs as $n => $a){
1766
+	    	foreach ($attrs as $n => $a) {
1769 1767
 	            // expand each attribute
1770 1768
 	            foreach ($a as $k => $v) {
1771
-		            $k = strpos($k,':') ? $this->expandQname($k) : $k;
1772
-		            $v = strpos($v,':') ? $this->expandQname($v) : $v;
1769
+		            $k = strpos($k, ':') ? $this->expandQname($k) : $k;
1770
+		            $v = strpos($v, ':') ? $this->expandQname($v) : $v;
1773 1771
 		            $aa[$k] = $v;
1774 1772
 		    	}
1775 1773
 	    		$eAttrs[$n] = $aa;
@@ -1777,11 +1775,11 @@  discard block
 block discarded – undo
1777 1775
 	    	$attrs = $eAttrs;
1778 1776
 		}
1779 1777
 
1780
-		$restrictionBase = strpos($restrictionBase,':') ? $this->expandQname($restrictionBase) : $restrictionBase;
1781
-		$arrayType = strpos($arrayType,':') ? $this->expandQname($arrayType) : $arrayType;
1778
+		$restrictionBase = strpos($restrictionBase, ':') ? $this->expandQname($restrictionBase) : $restrictionBase;
1779
+		$arrayType = strpos($arrayType, ':') ? $this->expandQname($arrayType) : $arrayType;
1782 1780
 
1783 1781
 		$typens = isset($this->namespaces['types']) ? $this->namespaces['types'] : $this->namespaces['tns'];
1784
-		$this->schemas[$typens][0]->addComplexType($name,$typeClass,$phpType,$compositor,$restrictionBase,$elements,$attrs,$arrayType);
1782
+		$this->schemas[$typens][0]->addComplexType($name, $typeClass, $phpType, $compositor, $restrictionBase, $elements, $attrs, $arrayType);
1785 1783
 	}
1786 1784
 
1787 1785
 	/**
@@ -1795,8 +1793,8 @@  discard block
 block discarded – undo
1795 1793
 	* @see nusoap_xmlschema
1796 1794
 	* @access public
1797 1795
 	*/
1798
-	public function addSimpleType($name, $restrictionBase='', $typeClass='simpleType', $phpType='scalar', $enumeration=array()) {
1799
-		$restrictionBase = strpos($restrictionBase,':') ? $this->expandQname($restrictionBase) : $restrictionBase;
1796
+	public function addSimpleType($name, $restrictionBase = '', $typeClass = 'simpleType', $phpType = 'scalar', $enumeration = array()) {
1797
+		$restrictionBase = strpos($restrictionBase, ':') ? $this->expandQname($restrictionBase) : $restrictionBase;
1800 1798
 
1801 1799
 		$typens = isset($this->namespaces['types']) ? $this->namespaces['types'] : $this->namespaces['tns'];
1802 1800
 		$this->schemas[$typens][0]->addSimpleType($name, $restrictionBase, $typeClass, $phpType, $enumeration);
@@ -1828,7 +1826,7 @@  discard block
 block discarded – undo
1828 1826
 	* @param string $encodingStyle optional (usually 'http://schemas.xmlsoap.org/soap/encoding/' for encoded)
1829 1827
 	* @access public 
1830 1828
 	*/
1831
-	public function addOperation($name, $in = false, $out = false, $namespace = false, $soapaction = false, $style = 'rpc', $use = 'encoded', $documentation = '', $encodingStyle = ''){
1829
+	public function addOperation($name, $in = false, $out = false, $namespace = false, $soapaction = false, $style = 'rpc', $use = 'encoded', $documentation = '', $encodingStyle = '') {
1832 1830
 		if ($use == 'encoded' && $encodingStyle == '') {
1833 1831
 			$encodingStyle = 'http://schemas.xmlsoap.org/soap/encoding/';
1834 1832
 		}
@@ -1852,7 +1850,7 @@  discard block
 block discarded – undo
1852 1850
 		}
1853 1851
 
1854 1852
 		// get binding
1855
-		$this->bindings[ $this->serviceName . 'Binding' ]['operations'][$name] =
1853
+		$this->bindings[$this->serviceName . 'Binding']['operations'][$name] =
1856 1854
 		array(
1857 1855
 		'name' => $name,
1858 1856
 		'binding' => $this->serviceName . 'Binding',
@@ -1876,29 +1874,29 @@  discard block
 block discarded – undo
1876 1874
 		'documentation' => $documentation); 
1877 1875
 		// add portTypes
1878 1876
 		// add messages
1879
-		if($in)
1877
+		if ($in)
1880 1878
 		{
1881
-			foreach($in as $pName => $pType)
1879
+			foreach ($in as $pName => $pType)
1882 1880
 			{
1883
-				if(strpos($pType,':')) {
1884
-					$pType = $this->getNamespaceFromPrefix($this->getPrefix($pType)).":".$this->getLocalPart($pType);
1881
+				if (strpos($pType, ':')) {
1882
+					$pType = $this->getNamespaceFromPrefix($this->getPrefix($pType)) . ":" . $this->getLocalPart($pType);
1885 1883
 				}
1886
-				$this->messages[$name.'Request'][$pName] = $pType;
1884
+				$this->messages[$name . 'Request'][$pName] = $pType;
1887 1885
 			}
1888 1886
 		} else {
1889
-            $this->messages[$name.'Request']= '0';
1887
+            $this->messages[$name . 'Request'] = '0';
1890 1888
         }
1891
-		if($out)
1889
+		if ($out)
1892 1890
 		{
1893
-			foreach($out as $pName => $pType)
1891
+			foreach ($out as $pName => $pType)
1894 1892
 			{
1895
-				if(strpos($pType,':')) {
1896
-					$pType = $this->getNamespaceFromPrefix($this->getPrefix($pType)).":".$this->getLocalPart($pType);
1893
+				if (strpos($pType, ':')) {
1894
+					$pType = $this->getNamespaceFromPrefix($this->getPrefix($pType)) . ":" . $this->getLocalPart($pType);
1897 1895
 				}
1898
-				$this->messages[$name.'Response'][$pName] = $pType;
1896
+				$this->messages[$name . 'Response'][$pName] = $pType;
1899 1897
 			}
1900 1898
 		} else {
1901
-            $this->messages[$name.'Response']= '0';
1899
+            $this->messages[$name . 'Response'] = '0';
1902 1900
         }
1903 1901
 		return true;
1904 1902
 	} 
Please login to merge, or discard this patch.
Indentation   +493 added lines, -493 removed lines patch added patch discarded remove patch
@@ -14,35 +14,35 @@  discard block
 block discarded – undo
14 14
 */
15 15
 class wsdl extends nusoap_base {
16 16
 	// URL or filename of the root of this WSDL
17
-    public $wsdl; 
18
-    // define internal arrays of bindings, ports, operations, messages, etc.
19
-    public $schemas = array();
20
-    public $currentSchema;
21
-    public $message = array();
22
-    public $complexTypes = array();
23
-    public $messages = array();
24
-    public $currentMessage;
25
-    public $currentOperation;
26
-    public $portTypes = array();
27
-    public $currentPortType;
28
-    public $bindings = array();
29
-    public $currentBinding;
30
-    public $ports = array();
31
-    public $currentPort;
32
-    public $opData = array();
33
-    public $status = '';
34
-    public $documentation = false;
35
-    public $endpoint = ''; 
36
-    // array of wsdl docs to import
37
-    public $import = array(); 
38
-    // parser vars
39
-    public $parser;
40
-    public $position = 0;
41
-    public $depth = 0;
42
-    public $depth_array = array();
17
+	public $wsdl; 
18
+	// define internal arrays of bindings, ports, operations, messages, etc.
19
+	public $schemas = array();
20
+	public $currentSchema;
21
+	public $message = array();
22
+	public $complexTypes = array();
23
+	public $messages = array();
24
+	public $currentMessage;
25
+	public $currentOperation;
26
+	public $portTypes = array();
27
+	public $currentPortType;
28
+	public $bindings = array();
29
+	public $currentBinding;
30
+	public $ports = array();
31
+	public $currentPort;
32
+	public $opData = array();
33
+	public $status = '';
34
+	public $documentation = false;
35
+	public $endpoint = ''; 
36
+	// array of wsdl docs to import
37
+	public $import = array(); 
38
+	// parser vars
39
+	public $parser;
40
+	public $position = 0;
41
+	public $depth = 0;
42
+	public $depth_array = array();
43 43
 	// for getting wsdl
44 44
 	public $proxyhost = '';
45
-    public $proxyport = '';
45
+	public $proxyport = '';
46 46
 	public $proxyusername = '';
47 47
 	public $proxypassword = '';
48 48
 	public $timeout = 0;
@@ -55,10 +55,10 @@  discard block
 block discarded – undo
55 55
 	public $authtype = '';				// Type of HTTP authentication
56 56
 	public $certRequest = array();		// Certificate for HTTP SSL authentication
57 57
 
58
-    /**
59
-     * constructor
60
-     * 
61
-     * @param string $wsdl WSDL document URL
58
+	/**
59
+	 * constructor
60
+	 * 
61
+	 * @param string $wsdl WSDL document URL
62 62
 	 * @param string $proxyhost
63 63
 	 * @param string $proxyport
64 64
 	 * @param string $proxyusername
@@ -67,13 +67,13 @@  discard block
 block discarded – undo
67 67
 	 * @param integer $response_timeout set the response timeout
68 68
 	 * @param array $curl_options user-specified cURL options
69 69
 	 * @param boolean $use_curl try to use cURL
70
-     * @access public 
71
-     */
72
-    public function wsdl($wsdl = '',$proxyhost=false,$proxyport=false,$proxyusername=false,$proxypassword=false,$timeout=0,$response_timeout=30,$curl_options=null,$use_curl=false){
70
+	 * @access public 
71
+	 */
72
+	public function wsdl($wsdl = '',$proxyhost=false,$proxyport=false,$proxyusername=false,$proxypassword=false,$timeout=0,$response_timeout=30,$curl_options=null,$use_curl=false){
73 73
 		parent::nusoap_base();
74 74
 		$this->debug("ctor wsdl=$wsdl timeout=$timeout response_timeout=$response_timeout");
75
-        $this->proxyhost = $proxyhost;
76
-        $this->proxyport = $proxyport;
75
+		$this->proxyhost = $proxyhost;
76
+		$this->proxyport = $proxyport;
77 77
 		$this->proxyusername = $proxyusername;
78 78
 		$this->proxypassword = $proxypassword;
79 79
 		$this->timeout = $timeout;
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
 			$this->curl_options = $curl_options;
83 83
 		$this->use_curl = $use_curl;
84 84
 		$this->fetchWSDL($wsdl);
85
-    }
85
+	}
86 86
 
87 87
 	/**
88 88
 	 * fetches the WSDL document and parses it
@@ -92,29 +92,29 @@  discard block
 block discarded – undo
92 92
 	public function fetchWSDL($wsdl) {
93 93
 		$this->debug("parse and process WSDL path=$wsdl");
94 94
 		$this->wsdl = $wsdl;
95
-        // parse wsdl file
96
-        if ($this->wsdl != "") {
97
-            $this->parseWSDL($this->wsdl);
98
-        }
99
-    	$imported_urls = array();
100
-    	$imported = 1;
101
-    	while ($imported > 0) {
102
-    		$imported = 0;
103
-    		// Schema imports
104
-    		foreach ($this->schemas as $ns => $list) {
105
-    			foreach ($list as $xs) {
95
+		// parse wsdl file
96
+		if ($this->wsdl != "") {
97
+			$this->parseWSDL($this->wsdl);
98
+		}
99
+		$imported_urls = array();
100
+		$imported = 1;
101
+		while ($imported > 0) {
102
+			$imported = 0;
103
+			// Schema imports
104
+			foreach ($this->schemas as $ns => $list) {
105
+				foreach ($list as $xs) {
106 106
 					$wsdlparts = parse_url($this->wsdl);	// this is bogusly simple!
107
-		            foreach ($xs->imports as $ns2 => $list2) {
107
+					foreach ($xs->imports as $ns2 => $list2) {
108 108
 						$countList2 = count($list2);
109
-		                for ($ii = 0; $ii < $countList2; $ii++) {
110
-		                	if (! $list2[$ii]['loaded']) {
111
-		                		/*
109
+						for ($ii = 0; $ii < $countList2; $ii++) {
110
+							if (! $list2[$ii]['loaded']) {
111
+								/*
112 112
 		                		 * Substituted with line below
113 113
 		                		 * because of error "Warning: attempt to modify property of non-object"
114 114
 		                		 * GitHub issue #1
115 115
 		                		 */
116
-		                		$list2[$ii]['loaded'] = true;
117
-		                		$url = $list2[$ii]['location'];
116
+								$list2[$ii]['loaded'] = true;
117
+								$url = $list2[$ii]['location'];
118 118
 								if ($url != '') {
119 119
 									$urlparts = parse_url($url);
120 120
 									if (!isset($urlparts['host'])) {
@@ -122,26 +122,26 @@  discard block
 block discarded – undo
122 122
 												substr($wsdlparts['path'],0,strrpos($wsdlparts['path'],'/') + 1) .$urlparts['path'];
123 123
 									}
124 124
 									if (! in_array($url, $imported_urls)) {
125
-					                	$this->parseWSDL($url);
126
-				                		$imported++;
127
-				                		$imported_urls[] = $url;
128
-				                	}
125
+										$this->parseWSDL($url);
126
+										$imported++;
127
+										$imported_urls[] = $url;
128
+									}
129 129
 								} else {
130 130
 									$this->debug("Unexpected scenario: empty URL for unloaded import");
131 131
 								}
132 132
 							}
133 133
 						}
134
-		            } 
135
-    			}
136
-    		}
137
-    		// WSDL imports
134
+					} 
135
+				}
136
+			}
137
+			// WSDL imports
138 138
 			$wsdlparts = parse_url($this->wsdl);	// this is bogusly simple!
139
-            foreach ($this->import as $ns => $list) {
139
+			foreach ($this->import as $ns => $list) {
140 140
 				$countList = count($list);
141
-                for ($ii = 0; $ii < $countList; $ii++) {
142
-                	if (! $list[$ii]['loaded']) {
143
-                		$this->import[$ns][$ii]['loaded'] = true;
144
-                		$url = $list[$ii]['location'];
141
+				for ($ii = 0; $ii < $countList; $ii++) {
142
+					if (! $list[$ii]['loaded']) {
143
+						$this->import[$ns][$ii]['loaded'] = true;
144
+						$url = $list[$ii]['location'];
145 145
 						if ($url != '') {
146 146
 							$urlparts = parse_url($url);
147 147
 							if (!isset($urlparts['host'])) {
@@ -149,70 +149,70 @@  discard block
 block discarded – undo
149 149
 										substr($wsdlparts['path'],0,strrpos($wsdlparts['path'],'/') + 1) .$urlparts['path'];
150 150
 							}
151 151
 							if (! in_array($url, $imported_urls)) {
152
-			                	$this->parseWSDL($url);
153
-		                		$imported++;
154
-		                		$imported_urls[] = $url;
155
-		                	}
152
+								$this->parseWSDL($url);
153
+								$imported++;
154
+								$imported_urls[] = $url;
155
+							}
156 156
 						} else {
157 157
 							$this->debug("Unexpected scenario: empty URL for unloaded import");
158 158
 						}
159 159
 					}
160 160
 				}
161
-            } 
161
+			} 
162 162
 		}
163
-        // add new data to operation data
164
-        foreach($this->bindings as $binding => $bindingData) {
165
-            if (isset($bindingData['operations']) && is_array($bindingData['operations'])) {
166
-                foreach($bindingData['operations'] as $operation => $data) {
167
-                    $this->debug('post-parse data gathering for ' . $operation);
168
-                    $this->bindings[$binding]['operations'][$operation]['input'] = 
163
+		// add new data to operation data
164
+		foreach($this->bindings as $binding => $bindingData) {
165
+			if (isset($bindingData['operations']) && is_array($bindingData['operations'])) {
166
+				foreach($bindingData['operations'] as $operation => $data) {
167
+					$this->debug('post-parse data gathering for ' . $operation);
168
+					$this->bindings[$binding]['operations'][$operation]['input'] = 
169 169
 						isset($this->bindings[$binding]['operations'][$operation]['input']) ? 
170 170
 						array_merge($this->bindings[$binding]['operations'][$operation]['input'], $this->portTypes[ $bindingData['portType'] ][$operation]['input']) :
171 171
 						$this->portTypes[ $bindingData['portType'] ][$operation]['input'];
172
-                    $this->bindings[$binding]['operations'][$operation]['output'] = 
172
+					$this->bindings[$binding]['operations'][$operation]['output'] = 
173 173
 						isset($this->bindings[$binding]['operations'][$operation]['output']) ?
174 174
 						array_merge($this->bindings[$binding]['operations'][$operation]['output'], $this->portTypes[ $bindingData['portType'] ][$operation]['output']) :
175 175
 						$this->portTypes[ $bindingData['portType'] ][$operation]['output'];
176
-                    if(isset($this->messages[ $this->bindings[$binding]['operations'][$operation]['input']['message'] ])){
176
+					if(isset($this->messages[ $this->bindings[$binding]['operations'][$operation]['input']['message'] ])){
177 177
 						$this->bindings[$binding]['operations'][$operation]['input']['parts'] = $this->messages[ $this->bindings[$binding]['operations'][$operation]['input']['message'] ];
178 178
 					}
179 179
 					if(isset($this->messages[ $this->bindings[$binding]['operations'][$operation]['output']['message'] ])){
180
-                   		$this->bindings[$binding]['operations'][$operation]['output']['parts'] = $this->messages[ $this->bindings[$binding]['operations'][$operation]['output']['message'] ];
181
-                    }
182
-                    // Set operation style if necessary, but do not override one already provided
180
+				   		$this->bindings[$binding]['operations'][$operation]['output']['parts'] = $this->messages[ $this->bindings[$binding]['operations'][$operation]['output']['message'] ];
181
+					}
182
+					// Set operation style if necessary, but do not override one already provided
183 183
 					if (isset($bindingData['style']) && !isset($this->bindings[$binding]['operations'][$operation]['style'])) {
184
-                        $this->bindings[$binding]['operations'][$operation]['style'] = $bindingData['style'];
185
-                    }
186
-                    $this->bindings[$binding]['operations'][$operation]['transport'] = isset($bindingData['transport']) ? $bindingData['transport'] : '';
187
-                    $this->bindings[$binding]['operations'][$operation]['documentation'] = isset($this->portTypes[ $bindingData['portType'] ][$operation]['documentation']) ? $this->portTypes[ $bindingData['portType'] ][$operation]['documentation'] : '';
188
-                    $this->bindings[$binding]['operations'][$operation]['endpoint'] = isset($bindingData['endpoint']) ? $bindingData['endpoint'] : '';
189
-                } 
190
-            } 
191
-        }
184
+						$this->bindings[$binding]['operations'][$operation]['style'] = $bindingData['style'];
185
+					}
186
+					$this->bindings[$binding]['operations'][$operation]['transport'] = isset($bindingData['transport']) ? $bindingData['transport'] : '';
187
+					$this->bindings[$binding]['operations'][$operation]['documentation'] = isset($this->portTypes[ $bindingData['portType'] ][$operation]['documentation']) ? $this->portTypes[ $bindingData['portType'] ][$operation]['documentation'] : '';
188
+					$this->bindings[$binding]['operations'][$operation]['endpoint'] = isset($bindingData['endpoint']) ? $bindingData['endpoint'] : '';
189
+				} 
190
+			} 
191
+		}
192 192
 	}
193 193
 
194
-    /**
195
-     * parses the wsdl document
196
-     * 
197
-     * @param string $wsdl path or URL
198
-     * @access private 
199
-     */
200
-    public function parseWSDL($wsdl = '') {
194
+	/**
195
+	 * parses the wsdl document
196
+	 * 
197
+	 * @param string $wsdl path or URL
198
+	 * @access private 
199
+	 */
200
+	public function parseWSDL($wsdl = '') {
201 201
 		$this->debug("parse WSDL at path=$wsdl");
202 202
 
203
-        if ($wsdl == '') {
204
-            $this->debug('no wsdl passed to parseWSDL()!!');
205
-            $this->setError('no wsdl passed to parseWSDL()!!');
206
-            return false;
207
-        }
203
+		if ($wsdl == '') {
204
+			$this->debug('no wsdl passed to parseWSDL()!!');
205
+			$this->setError('no wsdl passed to parseWSDL()!!');
206
+			return false;
207
+		}
208 208
         
209
-        // parse $wsdl for url format
210
-        $wsdl_props = parse_url($wsdl);
209
+		// parse $wsdl for url format
210
+		$wsdl_props = parse_url($wsdl);
211 211
 
212
-        if (isset($wsdl_props['scheme']) && ($wsdl_props['scheme'] == 'http' || $wsdl_props['scheme'] == 'https')) {
213
-            $this->debug('getting WSDL http(s) URL ' . $wsdl);
214
-        	// get wsdl
215
-	        $tr = new soap_transport_http($wsdl, $this->curl_options, $this->use_curl);
212
+		if (isset($wsdl_props['scheme']) && ($wsdl_props['scheme'] == 'http' || $wsdl_props['scheme'] == 'https')) {
213
+			$this->debug('getting WSDL http(s) URL ' . $wsdl);
214
+			// get wsdl
215
+			$tr = new soap_transport_http($wsdl, $this->curl_options, $this->use_curl);
216 216
 			$tr->request_method = 'GET';
217 217
 			$tr->useSOAPAction = false;
218 218
 			if($this->proxyhost && $this->proxyport){
@@ -228,239 +228,239 @@  discard block
 block discarded – undo
228 228
 			if($err = $tr->getError() ){
229 229
 				$errstr = 'Getting ' . $wsdl . ' - HTTP ERROR: '.$err;
230 230
 				$this->debug($errstr);
231
-	            $this->setError($errstr);
231
+				$this->setError($errstr);
232 232
 				unset($tr);
233
-	            return false;
233
+				return false;
234 234
 			}
235 235
 			unset($tr);
236 236
 			$this->debug("got WSDL URL");
237
-        } else {
238
-            // $wsdl is not http(s), so treat it as a file URL or plain file path
239
-        	if (isset($wsdl_props['scheme']) && ($wsdl_props['scheme'] == 'file') && isset($wsdl_props['path'])) {
240
-        		$path = isset($wsdl_props['host']) ? ($wsdl_props['host'] . ':' . $wsdl_props['path']) : $wsdl_props['path'];
241
-        	} else {
242
-        		$path = $wsdl;
243
-        	}
244
-            $this->debug('getting WSDL file ' . $path);
245
-            if ($fp = @fopen($path, 'r')) {
246
-                $wsdl_string = '';
247
-                while ($data = fread($fp, 32768)) {
248
-                    $wsdl_string .= $data;
249
-                } 
250
-                fclose($fp);
251
-            } else {
252
-            	$errstr = "Bad path to WSDL file $path";
253
-            	$this->debug($errstr);
254
-                $this->setError($errstr);
255
-                return false;
256
-            } 
257
-        }
258
-        $this->debug('Parse WSDL');
259
-        // end new code added
260
-        // Create an XML parser.
261
-        $this->parser = xml_parser_create(); 
262
-        // Set the options for parsing the XML data.
263
-        // xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
264
-        xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0); 
265
-        // Set the object for the parser.
266
-        xml_set_object($this->parser, $this); 
267
-        // Set the element handlers for the parser.
268
-        xml_set_element_handler($this->parser, 'start_element', 'end_element');
269
-        xml_set_character_data_handler($this->parser, 'character_data');
270
-        // Parse the XML file.
271
-        if (!xml_parse($this->parser, $wsdl_string, true)) {
272
-            // Display an error message.
273
-            $errstr = sprintf(
237
+		} else {
238
+			// $wsdl is not http(s), so treat it as a file URL or plain file path
239
+			if (isset($wsdl_props['scheme']) && ($wsdl_props['scheme'] == 'file') && isset($wsdl_props['path'])) {
240
+				$path = isset($wsdl_props['host']) ? ($wsdl_props['host'] . ':' . $wsdl_props['path']) : $wsdl_props['path'];
241
+			} else {
242
+				$path = $wsdl;
243
+			}
244
+			$this->debug('getting WSDL file ' . $path);
245
+			if ($fp = @fopen($path, 'r')) {
246
+				$wsdl_string = '';
247
+				while ($data = fread($fp, 32768)) {
248
+					$wsdl_string .= $data;
249
+				} 
250
+				fclose($fp);
251
+			} else {
252
+				$errstr = "Bad path to WSDL file $path";
253
+				$this->debug($errstr);
254
+				$this->setError($errstr);
255
+				return false;
256
+			} 
257
+		}
258
+		$this->debug('Parse WSDL');
259
+		// end new code added
260
+		// Create an XML parser.
261
+		$this->parser = xml_parser_create(); 
262
+		// Set the options for parsing the XML data.
263
+		// xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
264
+		xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0); 
265
+		// Set the object for the parser.
266
+		xml_set_object($this->parser, $this); 
267
+		// Set the element handlers for the parser.
268
+		xml_set_element_handler($this->parser, 'start_element', 'end_element');
269
+		xml_set_character_data_handler($this->parser, 'character_data');
270
+		// Parse the XML file.
271
+		if (!xml_parse($this->parser, $wsdl_string, true)) {
272
+			// Display an error message.
273
+			$errstr = sprintf(
274 274
 				'XML error parsing WSDL from %s on line %d: %s',
275 275
 				$wsdl,
276
-                xml_get_current_line_number($this->parser),
277
-                xml_error_string(xml_get_error_code($this->parser))
278
-                );
279
-            $this->debug($errstr);
276
+				xml_get_current_line_number($this->parser),
277
+				xml_error_string(xml_get_error_code($this->parser))
278
+				);
279
+			$this->debug($errstr);
280 280
 			$this->debug("XML payload:\n" . $wsdl_string);
281
-            $this->setError($errstr);
282
-            return false;
283
-        } 
281
+			$this->setError($errstr);
282
+			return false;
283
+		} 
284 284
 		// free the parser
285
-        xml_parser_free($this->parser);
286
-        $this->debug('Parsing WSDL done');
285
+		xml_parser_free($this->parser);
286
+		$this->debug('Parsing WSDL done');
287 287
 		// catch wsdl parse errors
288 288
 		if($this->getError()){
289 289
 			return false;
290 290
 		}
291
-        return true;
292
-    } 
291
+		return true;
292
+	} 
293 293
 
294
-    /**
295
-     * start-element handler
296
-     * 
297
-     * @param string $parser XML parser object
298
-     * @param string $name element name
299
-     * @param string $attrs associative array of attributes
300
-     * @access private 
301
-     */
302
-    public function start_element($parser, $name, $attrs)
303
-    {
304
-        if ($this->status == 'schema') {
305
-            $this->currentSchema->schemaStartElement($parser, $name, $attrs);
306
-            $this->appendDebug($this->currentSchema->getDebug());
307
-            $this->currentSchema->clearDebug();
308
-        } elseif (preg_match('/schema$/', $name)) {
309
-        	$this->debug('Parsing WSDL schema');
310
-            $this->status = 'schema';
311
-            $this->currentSchema = new nusoap_xmlschema('', '', $this->namespaces);
312
-            $this->currentSchema->schemaStartElement($parser, $name, $attrs);
313
-            $this->appendDebug($this->currentSchema->getDebug());
314
-            $this->currentSchema->clearDebug();
315
-        } else {
316
-            // position in the total number of elements, starting from 0
317
-            $pos = $this->position++;
318
-            $depth = $this->depth++; 
319
-            // set self as current value for this depth
320
-            $this->depth_array[$depth] = $pos;
321
-            $this->message[$pos] = array('cdata' => ''); 
322
-            // process attributes
323
-            if (count($attrs) > 0) {
294
+	/**
295
+	 * start-element handler
296
+	 * 
297
+	 * @param string $parser XML parser object
298
+	 * @param string $name element name
299
+	 * @param string $attrs associative array of attributes
300
+	 * @access private 
301
+	 */
302
+	public function start_element($parser, $name, $attrs)
303
+	{
304
+		if ($this->status == 'schema') {
305
+			$this->currentSchema->schemaStartElement($parser, $name, $attrs);
306
+			$this->appendDebug($this->currentSchema->getDebug());
307
+			$this->currentSchema->clearDebug();
308
+		} elseif (preg_match('/schema$/', $name)) {
309
+			$this->debug('Parsing WSDL schema');
310
+			$this->status = 'schema';
311
+			$this->currentSchema = new nusoap_xmlschema('', '', $this->namespaces);
312
+			$this->currentSchema->schemaStartElement($parser, $name, $attrs);
313
+			$this->appendDebug($this->currentSchema->getDebug());
314
+			$this->currentSchema->clearDebug();
315
+		} else {
316
+			// position in the total number of elements, starting from 0
317
+			$pos = $this->position++;
318
+			$depth = $this->depth++; 
319
+			// set self as current value for this depth
320
+			$this->depth_array[$depth] = $pos;
321
+			$this->message[$pos] = array('cdata' => ''); 
322
+			// process attributes
323
+			if (count($attrs) > 0) {
324 324
 				// register namespace declarations
325
-                foreach($attrs as $k => $v) {
326
-                    if (preg_match('/^xmlns/',$k)) {
327
-                        if ($ns_prefix = substr(strrchr($k, ':'), 1)) {
328
-                            $this->namespaces[$ns_prefix] = $v;
329
-                        } else {
330
-                            $this->namespaces['ns' . (count($this->namespaces) + 1)] = $v;
331
-                        } 
332
-                        if ($v == 'http://www.w3.org/2001/XMLSchema' || $v == 'http://www.w3.org/1999/XMLSchema' || $v == 'http://www.w3.org/2000/10/XMLSchema') {
333
-                            $this->XMLSchemaVersion = $v;
334
-                            $this->namespaces['xsi'] = $v . '-instance';
335
-                        } 
336
-                    }
337
-                }
338
-                // expand each attribute prefix to its namespace
339
-                foreach($attrs as $k => $v) {
340
-                    $k = strpos($k, ':') ? $this->expandQname($k) : $k;
341
-                    if ($k != 'location' && $k != 'soapAction' && $k != 'namespace') {
342
-                        $v = strpos($v, ':') ? $this->expandQname($v) : $v;
343
-                    } 
344
-                    $eAttrs[$k] = $v;
345
-                } 
346
-                $attrs = $eAttrs;
347
-            } else {
348
-                $attrs = array();
349
-            } 
350
-            // get element prefix, namespace and name
351
-            if (preg_match('/:/', $name)) {
352
-                // get ns prefix
353
-                $prefix = substr($name, 0, strpos($name, ':')); 
354
-                // get ns
355
-                $namespace = isset($this->namespaces[$prefix]) ? $this->namespaces[$prefix] : ''; 
356
-                // get unqualified name
357
-                $name = substr(strstr($name, ':'), 1);
358
-            } 
325
+				foreach($attrs as $k => $v) {
326
+					if (preg_match('/^xmlns/',$k)) {
327
+						if ($ns_prefix = substr(strrchr($k, ':'), 1)) {
328
+							$this->namespaces[$ns_prefix] = $v;
329
+						} else {
330
+							$this->namespaces['ns' . (count($this->namespaces) + 1)] = $v;
331
+						} 
332
+						if ($v == 'http://www.w3.org/2001/XMLSchema' || $v == 'http://www.w3.org/1999/XMLSchema' || $v == 'http://www.w3.org/2000/10/XMLSchema') {
333
+							$this->XMLSchemaVersion = $v;
334
+							$this->namespaces['xsi'] = $v . '-instance';
335
+						} 
336
+					}
337
+				}
338
+				// expand each attribute prefix to its namespace
339
+				foreach($attrs as $k => $v) {
340
+					$k = strpos($k, ':') ? $this->expandQname($k) : $k;
341
+					if ($k != 'location' && $k != 'soapAction' && $k != 'namespace') {
342
+						$v = strpos($v, ':') ? $this->expandQname($v) : $v;
343
+					} 
344
+					$eAttrs[$k] = $v;
345
+				} 
346
+				$attrs = $eAttrs;
347
+			} else {
348
+				$attrs = array();
349
+			} 
350
+			// get element prefix, namespace and name
351
+			if (preg_match('/:/', $name)) {
352
+				// get ns prefix
353
+				$prefix = substr($name, 0, strpos($name, ':')); 
354
+				// get ns
355
+				$namespace = isset($this->namespaces[$prefix]) ? $this->namespaces[$prefix] : ''; 
356
+				// get unqualified name
357
+				$name = substr(strstr($name, ':'), 1);
358
+			} 
359 359
 			// process attributes, expanding any prefixes to namespaces
360
-            // find status, register data
361
-            switch ($this->status) {
362
-                case 'message':
363
-                    if ($name == 'part') {
364
-			            if (isset($attrs['type'])) {
365
-		                    $this->debug("msg " . $this->currentMessage . ": found part (with type) $attrs[name]: " . implode(',', $attrs));
366
-		                    $this->messages[$this->currentMessage][$attrs['name']] = $attrs['type'];
367
-            			} 
368
-			            if (isset($attrs['element'])) {
369
-		                    $this->debug("msg " . $this->currentMessage . ": found part (with element) $attrs[name]: " . implode(',', $attrs));
370
-			                $this->messages[$this->currentMessage][$attrs['name']] = $attrs['element'] . '^';
371
-			            } 
372
-        			} 
373
-        			break;
374
-			    case 'portType':
375
-			        switch ($name) {
376
-			            case 'operation':
377
-			                $this->currentPortOperation = $attrs['name'];
378
-			                $this->debug("portType $this->currentPortType operation: $this->currentPortOperation");
379
-			                if (isset($attrs['parameterOrder'])) {
380
-			                	$this->portTypes[$this->currentPortType][$attrs['name']]['parameterOrder'] = $attrs['parameterOrder'];
381
-			        		} 
382
-			        		break;
383
-					    case 'documentation':
384
-					        $this->documentation = true;
385
-					        break; 
386
-					    // merge input/output data
387
-					    default:
388
-					        $m = isset($attrs['message']) ? $this->getLocalPart($attrs['message']) : '';
389
-					        $this->portTypes[$this->currentPortType][$this->currentPortOperation][$name]['message'] = $m;
390
-					        break;
360
+			// find status, register data
361
+			switch ($this->status) {
362
+				case 'message':
363
+					if ($name == 'part') {
364
+						if (isset($attrs['type'])) {
365
+							$this->debug("msg " . $this->currentMessage . ": found part (with type) $attrs[name]: " . implode(',', $attrs));
366
+							$this->messages[$this->currentMessage][$attrs['name']] = $attrs['type'];
367
+						} 
368
+						if (isset($attrs['element'])) {
369
+							$this->debug("msg " . $this->currentMessage . ": found part (with element) $attrs[name]: " . implode(',', $attrs));
370
+							$this->messages[$this->currentMessage][$attrs['name']] = $attrs['element'] . '^';
371
+						} 
391 372
 					} 
392
-			    	break;
373
+					break;
374
+				case 'portType':
375
+					switch ($name) {
376
+						case 'operation':
377
+							$this->currentPortOperation = $attrs['name'];
378
+							$this->debug("portType $this->currentPortType operation: $this->currentPortOperation");
379
+							if (isset($attrs['parameterOrder'])) {
380
+								$this->portTypes[$this->currentPortType][$attrs['name']]['parameterOrder'] = $attrs['parameterOrder'];
381
+							} 
382
+							break;
383
+						case 'documentation':
384
+							$this->documentation = true;
385
+							break; 
386
+						// merge input/output data
387
+						default:
388
+							$m = isset($attrs['message']) ? $this->getLocalPart($attrs['message']) : '';
389
+							$this->portTypes[$this->currentPortType][$this->currentPortOperation][$name]['message'] = $m;
390
+							break;
391
+					} 
392
+					break;
393 393
 				case 'binding':
394
-				    switch ($name) {
395
-				        case 'binding': 
396
-				            // get ns prefix
397
-				            if (isset($attrs['style'])) {
398
-				            $this->bindings[$this->currentBinding]['prefix'] = $prefix;
399
-					    	} 
400
-					    	$this->bindings[$this->currentBinding] = array_merge($this->bindings[$this->currentBinding], $attrs);
401
-					    	break;
394
+					switch ($name) {
395
+						case 'binding': 
396
+							// get ns prefix
397
+							if (isset($attrs['style'])) {
398
+							$this->bindings[$this->currentBinding]['prefix'] = $prefix;
399
+							} 
400
+							$this->bindings[$this->currentBinding] = array_merge($this->bindings[$this->currentBinding], $attrs);
401
+							break;
402 402
 						case 'header':
403
-						    $this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus]['headers'][] = $attrs;
404
-						    break;
403
+							$this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus]['headers'][] = $attrs;
404
+							break;
405 405
 						case 'operation':
406
-						    if (isset($attrs['soapAction'])) {
407
-						        $this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['soapAction'] = $attrs['soapAction'];
408
-						    } 
409
-						    if (isset($attrs['style'])) {
410
-						        $this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['style'] = $attrs['style'];
411
-						    } 
412
-						    if (isset($attrs['name'])) {
413
-						        $this->currentOperation = $attrs['name'];
414
-						        $this->debug("current binding operation: $this->currentOperation");
415
-						        $this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['name'] = $attrs['name'];
416
-						        $this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['binding'] = $this->currentBinding;
417
-						        $this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['endpoint'] = isset($this->bindings[$this->currentBinding]['endpoint']) ? $this->bindings[$this->currentBinding]['endpoint'] : '';
418
-						    } 
419
-						    break;
406
+							if (isset($attrs['soapAction'])) {
407
+								$this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['soapAction'] = $attrs['soapAction'];
408
+							} 
409
+							if (isset($attrs['style'])) {
410
+								$this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['style'] = $attrs['style'];
411
+							} 
412
+							if (isset($attrs['name'])) {
413
+								$this->currentOperation = $attrs['name'];
414
+								$this->debug("current binding operation: $this->currentOperation");
415
+								$this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['name'] = $attrs['name'];
416
+								$this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['binding'] = $this->currentBinding;
417
+								$this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['endpoint'] = isset($this->bindings[$this->currentBinding]['endpoint']) ? $this->bindings[$this->currentBinding]['endpoint'] : '';
418
+							} 
419
+							break;
420 420
 						case 'input':
421
-						    $this->opStatus = 'input';
422
-						    break;
421
+							$this->opStatus = 'input';
422
+							break;
423 423
 						case 'output':
424
-						    $this->opStatus = 'output';
425
-						    break;
424
+							$this->opStatus = 'output';
425
+							break;
426 426
 						case 'body':
427
-						    if (isset($this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus])) {
428
-						        $this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus] = array_merge($this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus], $attrs);
429
-						    } else {
430
-						        $this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus] = $attrs;
431
-						    } 
432
-						    break;
427
+							if (isset($this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus])) {
428
+								$this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus] = array_merge($this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus], $attrs);
429
+							} else {
430
+								$this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus] = $attrs;
431
+							} 
432
+							break;
433 433
 					} 
434 434
 					break;
435 435
 				case 'service':
436 436
 					switch ($name) {
437
-					    case 'port':
438
-					        $this->currentPort = $attrs['name'];
439
-					        $this->debug('current port: ' . $this->currentPort);
440
-					        $this->ports[$this->currentPort]['binding'] = $this->getLocalPart($attrs['binding']);
437
+						case 'port':
438
+							$this->currentPort = $attrs['name'];
439
+							$this->debug('current port: ' . $this->currentPort);
440
+							$this->ports[$this->currentPort]['binding'] = $this->getLocalPart($attrs['binding']);
441 441
 					
442
-					        break;
443
-					    case 'address':
444
-					        $this->ports[$this->currentPort]['location'] = $attrs['location'];
445
-					        $this->ports[$this->currentPort]['bindingType'] = $namespace;
446
-					        $this->bindings[ $this->ports[$this->currentPort]['binding'] ]['bindingType'] = $namespace;
447
-					        $this->bindings[ $this->ports[$this->currentPort]['binding'] ]['endpoint'] = $attrs['location'];
448
-					        break;
442
+							break;
443
+						case 'address':
444
+							$this->ports[$this->currentPort]['location'] = $attrs['location'];
445
+							$this->ports[$this->currentPort]['bindingType'] = $namespace;
446
+							$this->bindings[ $this->ports[$this->currentPort]['binding'] ]['bindingType'] = $namespace;
447
+							$this->bindings[ $this->ports[$this->currentPort]['binding'] ]['endpoint'] = $attrs['location'];
448
+							break;
449 449
 					} 
450 450
 					break;
451 451
 			} 
452 452
 		// set status
453 453
 		switch ($name) {
454 454
 			case 'import':
455
-			    if (isset($attrs['location'])) {
456
-                    $this->import[$attrs['namespace']][] = array('location' => $attrs['location'], 'loaded' => false);
457
-                    $this->debug('parsing import ' . $attrs['namespace']. ' - ' . $attrs['location'] . ' (' . count($this->import[$attrs['namespace']]).')');
455
+				if (isset($attrs['location'])) {
456
+					$this->import[$attrs['namespace']][] = array('location' => $attrs['location'], 'loaded' => false);
457
+					$this->debug('parsing import ' . $attrs['namespace']. ' - ' . $attrs['location'] . ' (' . count($this->import[$attrs['namespace']]).')');
458 458
 				} else {
459
-                    $this->import[$attrs['namespace']][] = array('location' => '', 'loaded' => true);
459
+					$this->import[$attrs['namespace']][] = array('location' => '', 'loaded' => true);
460 460
 					if (! $this->getPrefixFromNamespace($attrs['namespace'])) {
461 461
 						$this->namespaces['ns'.(count($this->namespaces)+1)] = $attrs['namespace'];
462 462
 					}
463
-                    $this->debug('parsing import ' . $attrs['namespace']. ' - [no location] (' . count($this->import[$attrs['namespace']]).')');
463
+					$this->debug('parsing import ' . $attrs['namespace']. ' - [no location] (' . count($this->import[$attrs['namespace']]).')');
464 464
 				}
465 465
 				break;
466 466
 			//wait for schema
@@ -481,9 +481,9 @@  discard block
 block discarded – undo
481 481
 				if (isset($attrs['name'])) {
482 482
 				// get binding name
483 483
 					if (strpos($attrs['name'], ':')) {
484
-			    		$this->currentBinding = $this->getLocalPart($attrs['name']);
484
+						$this->currentBinding = $this->getLocalPart($attrs['name']);
485 485
 					} else {
486
-			    		$this->currentBinding = $attrs['name'];
486
+						$this->currentBinding = $attrs['name'];
487 487
 					} 
488 488
 					$this->status = 'binding';
489 489
 					$this->bindings[$this->currentBinding]['portType'] = $this->getLocalPart($attrs['type']);
@@ -505,20 +505,20 @@  discard block
 block discarded – undo
505 505
 	} 
506 506
 
507 507
 	/**
508
-	* end-element handler
509
-	* 
510
-	* @param string $parser XML parser object
511
-	* @param string $name element name
512
-	* @access private 
513
-	*/
508
+	 * end-element handler
509
+	 * 
510
+	 * @param string $parser XML parser object
511
+	 * @param string $name element name
512
+	 * @access private 
513
+	 */
514 514
 	public function end_element($parser, $name){ 
515 515
 		// unset schema status
516 516
 		if (/*preg_match('/types$/', $name) ||*/ preg_match('/schema$/', $name)) {
517 517
 			$this->status = "";
518
-            $this->appendDebug($this->currentSchema->getDebug());
519
-            $this->currentSchema->clearDebug();
518
+			$this->appendDebug($this->currentSchema->getDebug());
519
+			$this->currentSchema->clearDebug();
520 520
 			$this->schemas[$this->currentSchema->schemaTargetNamespace][] = $this->currentSchema;
521
-        	$this->debug('Parsing WSDL schema done');
521
+			$this->debug('Parsing WSDL schema done');
522 522
 		} 
523 523
 		if ($this->status == 'schema') {
524 524
 			$this->currentSchema->schemaEndElement($parser, $name);
@@ -551,14 +551,14 @@  discard block
 block discarded – undo
551 551
 	} 
552 552
 
553 553
 	/**
554
-	* if authenticating, set user credentials here
555
-	*
556
-	* @param    string $username
557
-	* @param    string $password
558
-	* @param	string $authtype (basic|digest|certificate|ntlm)
559
-	* @param	array $certRequest (keys must be cainfofile (optional), sslcertfile, sslkeyfile, passphrase, certpassword (optional), verifypeer (optional), verifyhost (optional): see corresponding options in cURL docs)
560
-	* @access   public
561
-	*/
554
+	 * if authenticating, set user credentials here
555
+	 *
556
+	 * @param    string $username
557
+	 * @param    string $password
558
+	 * @param	string $authtype (basic|digest|certificate|ntlm)
559
+	 * @param	array $certRequest (keys must be cainfofile (optional), sslcertfile, sslkeyfile, passphrase, certpassword (optional), verifypeer (optional), verifyhost (optional): see corresponding options in cURL docs)
560
+	 * @access   public
561
+	 */
562 562
 	public function setCredentials($username, $password, $authtype = 'basic', $certRequest = array()) {
563 563
 		$this->debug("setCredentials username=$username authtype=$authtype certRequest=");
564 564
 		$this->appendDebug($this->varDump($certRequest));
@@ -638,7 +638,7 @@  discard block
 block discarded – undo
638 638
 					// note that we could/should also check the namespace here
639 639
 					if ($operation == $bOperation) {
640 640
 						$opData = $this->bindings[ $portData['binding'] ]['operations'][$operation];
641
-					    return $opData;
641
+						return $opData;
642 642
 					} 
643 643
 				} 
644 644
 			}
@@ -666,7 +666,7 @@  discard block
 block discarded – undo
666 666
 				// loop through operations for the binding
667 667
 				foreach ($this->bindings[ $portData['binding'] ]['operations'] as $bOperation => $opData) {
668 668
 					if ($opData['soapAction'] == $soapAction) {
669
-					    return $opData;
669
+						return $opData;
670 670
 					} 
671 671
 				} 
672 672
 			}
@@ -674,23 +674,23 @@  discard block
 block discarded – undo
674 674
 	}
675 675
 	
676 676
 	/**
677
-    * returns an array of information about a given type
678
-    * returns false if no type exists by the given name
679
-    *
680
-	*	 typeDef = array(
681
-	*	 'elements' => array(), // refs to elements array
682
-	*	'restrictionBase' => '',
683
-	*	'phpType' => '',
684
-	*	'order' => '(sequence|all)',
685
-	*	'attrs' => array() // refs to attributes array
686
-	*	)
687
-    *
688
-    * @param string $type the type
689
-    * @param string $ns namespace (not prefix) of the type
690
-    * @return mixed
691
-    * @access public
692
-    * @see nusoap_xmlschema
693
-    */
677
+	 * returns an array of information about a given type
678
+	 * returns false if no type exists by the given name
679
+	 *
680
+	 *	 typeDef = array(
681
+	 *	 'elements' => array(), // refs to elements array
682
+	 *	'restrictionBase' => '',
683
+	 *	'phpType' => '',
684
+	 *	'order' => '(sequence|all)',
685
+	 *	'attrs' => array() // refs to attributes array
686
+	 *	)
687
+	 *
688
+	 * @param string $type the type
689
+	 * @param string $ns namespace (not prefix) of the type
690
+	 * @return mixed
691
+	 * @access public
692
+	 * @see nusoap_xmlschema
693
+	 */
694 694
 	public function getTypeDef($type, $ns) {
695 695
 		$this->debug("in getTypeDef: type=$type, ns=$ns");
696 696
 		if ((! $ns) && isset($this->namespaces['tns'])) {
@@ -747,13 +747,13 @@  discard block
 block discarded – undo
747 747
 		return false;
748 748
 	}
749 749
 
750
-    /**
751
-    * prints html description of services
752
-    *
753
-    * @access private
754
-    */
755
-    public function webDescription(){
756
-    	global $HTTP_SERVER_VARS;
750
+	/**
751
+	 * prints html description of services
752
+	 *
753
+	 * @access private
754
+	 */
755
+	public function webDescription(){
756
+		global $HTTP_SERVER_VARS;
757 757
 
758 758
 		if (isset($_SERVER)) {
759 759
 			$PHP_SELF = $_SERVER['PHP_SELF'];
@@ -847,29 +847,29 @@  discard block
 block discarded – undo
847 847
 				Click on an operation name to view it&apos;s details.</p>
848 848
 				<ul>';
849 849
 				foreach($this->getOperations() as $op => $data){
850
-				    $b .= "<li><a href='#' onclick=\"popout();popup('$op')\">$op</a></li>";
851
-				    // create hidden div
852
-				    $b .= "<div id='$op' class='hidden'>
850
+					$b .= "<li><a href='#' onclick=\"popout();popup('$op')\">$op</a></li>";
851
+					// create hidden div
852
+					$b .= "<div id='$op' class='hidden'>
853 853
 				    <a href='#' onclick='popout()'><font color='#ffffff'>Close</font></a><br><br>";
854
-				    foreach($data as $donnie => $marie){ // loop through opdata
854
+					foreach($data as $donnie => $marie){ // loop through opdata
855 855
 						if($donnie == 'input' || $donnie == 'output'){ // show input/output data
856
-						    $b .= "<font color='white'>".ucfirst($donnie).':</font><br>';
857
-						    foreach($marie as $captain => $tenille){ // loop through data
856
+							$b .= "<font color='white'>".ucfirst($donnie).':</font><br>';
857
+							foreach($marie as $captain => $tenille){ // loop through data
858 858
 								if($captain == 'parts'){ // loop thru parts
859
-								    $b .= "&nbsp;&nbsp;$captain:<br>";
860
-					                //if(is_array($tenille)){
861
-								    	foreach($tenille as $joanie => $chachi){
859
+									$b .= "&nbsp;&nbsp;$captain:<br>";
860
+									//if(is_array($tenille)){
861
+										foreach($tenille as $joanie => $chachi){
862 862
 											$b .= "&nbsp;&nbsp;&nbsp;&nbsp;$joanie: $chachi<br>";
863
-								    	}
864
-					        		//}
863
+										}
864
+									//}
865 865
 								} else {
866
-								    $b .= "&nbsp;&nbsp;$captain: $tenille<br>";
866
+									$b .= "&nbsp;&nbsp;$captain: $tenille<br>";
867 867
 								}
868
-						    }
868
+							}
869 869
 						} else {
870
-						    $b .= "<font color='white'>".ucfirst($donnie).":</font> $marie<br>";
870
+							$b .= "<font color='white'>".ucfirst($donnie).":</font> $marie<br>";
871 871
 						}
872
-				    }
872
+					}
873 873
 					$b .= '</div>';
874 874
 				}
875 875
 				$b .= '
@@ -877,15 +877,15 @@  discard block
 block discarded – undo
877 877
 			</div>
878 878
 		</div></body></html>';
879 879
 		return $b;
880
-    }
880
+	}
881 881
 
882 882
 	/**
883
-	* serialize the parsed wsdl
884
-	*
885
-	* @param mixed $debug whether to put debug=1 in endpoint URL
886
-	* @return string serialization of WSDL
887
-	* @access public 
888
-	*/
883
+	 * serialize the parsed wsdl
884
+	 *
885
+	 * @param mixed $debug whether to put debug=1 in endpoint URL
886
+	 * @return string serialization of WSDL
887
+	 * @access public 
888
+	 */
889 889
 	public function serialize($debug = 0)
890 890
 	{
891 891
 		$xml = '<?xml version="1.0" encoding="ISO-8859-1"?>';
@@ -931,19 +931,19 @@  discard block
 block discarded – undo
931 931
 					foreach($msgParts as $partName => $partType) {
932 932
 						// print 'serializing '.$partType.', sv: '.$this->XMLSchemaVersion.'<br>';
933 933
 						if (strpos($partType, ':')) {
934
-						    $typePrefix = $this->getPrefixFromNamespace($this->getPrefix($partType));
934
+							$typePrefix = $this->getPrefixFromNamespace($this->getPrefix($partType));
935 935
 						} elseif (isset($this->typemap[$this->namespaces['xsd']][$partType])) {
936
-						    // print 'checking typemap: '.$this->XMLSchemaVersion.'<br>';
937
-						    $typePrefix = 'xsd';
936
+							// print 'checking typemap: '.$this->XMLSchemaVersion.'<br>';
937
+							$typePrefix = 'xsd';
938 938
 						} else {
939
-						    foreach($this->typemap as $ns => $types) {
940
-						        if (isset($types[$partType])) {
941
-						            $typePrefix = $this->getPrefixFromNamespace($ns);
942
-						        } 
943
-						    } 
944
-						    if (!isset($typePrefix)) {
945
-						        die("$partType has no namespace!");
946
-						    } 
939
+							foreach($this->typemap as $ns => $types) {
940
+								if (isset($types[$partType])) {
941
+									$typePrefix = $this->getPrefixFromNamespace($ns);
942
+								} 
943
+							} 
944
+							if (!isset($typePrefix)) {
945
+								die("$partType has no namespace!");
946
+							} 
947 947
 						}
948 948
 						$ns = $this->getNamespaceFromPrefix($typePrefix);
949 949
 						$localPart = $this->getLocalPart($partType);
@@ -988,7 +988,7 @@  discard block
 block discarded – undo
988 988
 					$binding_xml .= "\n" . '  </operation>';
989 989
 					$portType_xml .= "\n" . '  <operation name="' . $opParts['name'] . '"';
990 990
 					if (isset($opParts['parameterOrder'])) {
991
-					    $portType_xml .= ' parameterOrder="' . $opParts['parameterOrder'] . '"';
991
+						$portType_xml .= ' parameterOrder="' . $opParts['parameterOrder'] . '"';
992 992
 					} 
993 993
 					$portType_xml .= '>';
994 994
 					if(isset($opParts['documentation']) && $opParts['documentation'] != '') {
@@ -1283,34 +1283,34 @@  discard block
 block discarded – undo
1283 1283
 		}
1284 1284
 
1285 1285
 		// if a soapval has been supplied, let its type override the WSDL
1286
-    	if (is_object($value) && get_class($value) == 'soapval') {
1287
-    		if ($value->type_ns) {
1288
-    			$type = $value->type_ns . ':' . $value->type;
1289
-		    	$forceType = true;
1290
-		    	$this->debug("in serializeType: soapval overrides type to $type");
1291
-    		} elseif ($value->type) {
1292
-	    		$type = $value->type;
1293
-		    	$forceType = true;
1294
-		    	$this->debug("in serializeType: soapval overrides type to $type");
1295
-	    	} else {
1296
-	    		$forceType = false;
1297
-		    	$this->debug("in serializeType: soapval does not override type");
1298
-	    	}
1299
-	    	$attrs = $value->attributes;
1300
-	    	$value = $value->value;
1301
-	    	$this->debug("in serializeType: soapval overrides value to $value");
1302
-	    	if ($attrs) {
1303
-	    		if (!is_array($value)) {
1304
-	    			$value['!'] = $value;
1305
-	    		}
1306
-	    		foreach ($attrs as $n => $v) {
1307
-	    			$value['!' . $n] = $v;
1308
-	    		}
1309
-		    	$this->debug("in serializeType: soapval provides attributes");
1310
-		    }
1311
-        } else {
1312
-        	$forceType = false;
1313
-        }
1286
+		if (is_object($value) && get_class($value) == 'soapval') {
1287
+			if ($value->type_ns) {
1288
+				$type = $value->type_ns . ':' . $value->type;
1289
+				$forceType = true;
1290
+				$this->debug("in serializeType: soapval overrides type to $type");
1291
+			} elseif ($value->type) {
1292
+				$type = $value->type;
1293
+				$forceType = true;
1294
+				$this->debug("in serializeType: soapval overrides type to $type");
1295
+			} else {
1296
+				$forceType = false;
1297
+				$this->debug("in serializeType: soapval does not override type");
1298
+			}
1299
+			$attrs = $value->attributes;
1300
+			$value = $value->value;
1301
+			$this->debug("in serializeType: soapval overrides value to $value");
1302
+			if ($attrs) {
1303
+				if (!is_array($value)) {
1304
+					$value['!'] = $value;
1305
+				}
1306
+				foreach ($attrs as $n => $v) {
1307
+					$value['!' . $n] = $v;
1308
+				}
1309
+				$this->debug("in serializeType: soapval provides attributes");
1310
+			}
1311
+		} else {
1312
+			$forceType = false;
1313
+		}
1314 1314
 
1315 1315
 		$xml = '';
1316 1316
 		if (strpos($type, ':')) {
@@ -1342,8 +1342,8 @@  discard block
 block discarded – undo
1342 1342
 					// JBoss/Axis does this sometimes
1343 1343
 					return $this->serialize_val($value, $name, false, false, false, false, $use);
1344 1344
 				}
1345
-		    	if ($uqType == 'boolean') {
1346
-		    		if ((is_string($value) && $value == 'false') || (! $value)) {
1345
+				if ($uqType == 'boolean') {
1346
+					if ((is_string($value) && $value == 'false') || (! $value)) {
1347 1347
 						$value = 'false';
1348 1348
 					} else {
1349 1349
 						$value = 'true';
@@ -1526,9 +1526,9 @@  discard block
 block discarded – undo
1526 1526
 					$this->debug("serializing array element: $k, $v of type: $typeDef[arrayType]");
1527 1527
 					//if (strpos($typeDef['arrayType'], ':') ) {
1528 1528
 					if (!in_array($typeDef['arrayType'],$this->typemap['http://www.w3.org/2001/XMLSchema'])) {
1529
-					    $contents .= $this->serializeType('item', $typeDef['arrayType'], $v, $use);
1529
+						$contents .= $this->serializeType('item', $typeDef['arrayType'], $v, $use);
1530 1530
 					} else {
1531
-					    $contents .= $this->serialize_val($v, 'item', $typeDef['arrayType'], null, $this->XMLSchemaVersion, false, $use);
1531
+						$contents .= $this->serialize_val($v, 'item', $typeDef['arrayType'], null, $this->XMLSchemaVersion, false, $use);
1532 1532
 					} 
1533 1533
 				}
1534 1534
 			} else {
@@ -1684,7 +1684,7 @@  discard block
 block discarded – undo
1684 1684
 				}
1685 1685
 				// if user took advantage of a minOccurs=0, then only serialize named parameters
1686 1686
 				if (isset($optionals)
1687
-				    && (!isset($xvalue[$eName])) 
1687
+					&& (!isset($xvalue[$eName])) 
1688 1688
 					&& ( (!isset($attrs['nillable'])) || $attrs['nillable'] != 'true')
1689 1689
 					){
1690 1690
 					if (isset($attrs['minOccurs']) && $attrs['minOccurs'] <> '0') {
@@ -1695,9 +1695,9 @@  discard block
 block discarded – undo
1695 1695
 				} else {
1696 1696
 					// get value
1697 1697
 					if (isset($xvalue[$eName])) {
1698
-					    $v = $xvalue[$eName];
1698
+						$v = $xvalue[$eName];
1699 1699
 					} else {
1700
-					    $v = null;
1700
+						$v = null;
1701 1701
 					}
1702 1702
 					if (isset($attrs['form'])) {
1703 1703
 						$unqualified = ($attrs['form'] == 'unqualified');
@@ -1709,24 +1709,24 @@  discard block
 block discarded – undo
1709 1709
 						foreach ($vv as $k => $v) {
1710 1710
 							if (isset($attrs['type']) || isset($attrs['ref'])) {
1711 1711
 								// serialize schema-defined type
1712
-							    $xml .= $this->serializeType($eName, isset($attrs['type']) ? $attrs['type'] : $attrs['ref'], $v, $use, $encodingStyle, $unqualified);
1712
+								$xml .= $this->serializeType($eName, isset($attrs['type']) ? $attrs['type'] : $attrs['ref'], $v, $use, $encodingStyle, $unqualified);
1713 1713
 							} else {
1714 1714
 								// serialize generic type (can this ever really happen?)
1715
-							    $this->debug("calling serialize_val() for $v, $eName, false, false, false, false, $use");
1716
-							    $xml .= $this->serialize_val($v, $eName, false, false, false, false, $use);
1715
+								$this->debug("calling serialize_val() for $v, $eName, false, false, false, false, $use");
1716
+								$xml .= $this->serialize_val($v, $eName, false, false, false, false, $use);
1717 1717
 							}
1718 1718
 						}
1719 1719
 					} else {
1720 1720
 						if (is_null($v) && isset($attrs['minOccurs']) && $attrs['minOccurs'] == '0') {
1721 1721
 						} elseif (is_null($v) && isset($attrs['nillable']) && $attrs['nillable'] == 'true') {
1722
-						    $xml .= $this->serializeType($eName, isset($attrs['type']) ? $attrs['type'] : $attrs['ref'], $v, $use, $encodingStyle, $unqualified);
1722
+							$xml .= $this->serializeType($eName, isset($attrs['type']) ? $attrs['type'] : $attrs['ref'], $v, $use, $encodingStyle, $unqualified);
1723 1723
 						} elseif (isset($attrs['type']) || isset($attrs['ref'])) {
1724 1724
 							// serialize schema-defined type
1725
-						    $xml .= $this->serializeType($eName, isset($attrs['type']) ? $attrs['type'] : $attrs['ref'], $v, $use, $encodingStyle, $unqualified);
1725
+							$xml .= $this->serializeType($eName, isset($attrs['type']) ? $attrs['type'] : $attrs['ref'], $v, $use, $encodingStyle, $unqualified);
1726 1726
 						} else {
1727 1727
 							// serialize generic type (can this ever really happen?)
1728
-						    $this->debug("calling serialize_val() for $v, $eName, false, false, false, false, $use");
1729
-						    $xml .= $this->serialize_val($v, $eName, false, false, false, false, $use);
1728
+							$this->debug("calling serialize_val() for $v, $eName, false, false, false, false, $use");
1729
+							$xml .= $this->serialize_val($v, $eName, false, false, false, false, $use);
1730 1730
 						}
1731 1731
 					}
1732 1732
 				}
@@ -1738,46 +1738,46 @@  discard block
 block discarded – undo
1738 1738
 	}
1739 1739
 
1740 1740
 	/**
1741
-	* adds an XML Schema complex type to the WSDL types
1742
-	*
1743
-	* @param string	$name
1744
-	* @param string $typeClass (complexType|simpleType|attribute)
1745
-	* @param string $phpType currently supported are array and struct (php assoc array)
1746
-	* @param string $compositor (all|sequence|choice)
1747
-	* @param string $restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array)
1748
-	* @param array $elements e.g. array ( name => array(name=>'',type=>'') )
1749
-	* @param array $attrs e.g. array(array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'xsd:string[]'))
1750
-	* @param string $arrayType as namespace:name (xsd:string)
1751
-	* @see nusoap_xmlschema
1752
-	* @access public
1753
-	*/
1741
+	 * adds an XML Schema complex type to the WSDL types
1742
+	 *
1743
+	 * @param string	$name
1744
+	 * @param string $typeClass (complexType|simpleType|attribute)
1745
+	 * @param string $phpType currently supported are array and struct (php assoc array)
1746
+	 * @param string $compositor (all|sequence|choice)
1747
+	 * @param string $restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array)
1748
+	 * @param array $elements e.g. array ( name => array(name=>'',type=>'') )
1749
+	 * @param array $attrs e.g. array(array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'xsd:string[]'))
1750
+	 * @param string $arrayType as namespace:name (xsd:string)
1751
+	 * @see nusoap_xmlschema
1752
+	 * @access public
1753
+	 */
1754 1754
 	public function addComplexType($name,$typeClass='complexType',$phpType='array',$compositor='',$restrictionBase='',$elements=array(),$attrs=array(),$arrayType='') {
1755 1755
 		if (count($elements) > 0) {
1756 1756
 			$eElements = array();
1757
-	    	foreach($elements as $n => $e){
1758
-	            // expand each element
1759
-	            $ee = array();
1760
-	            foreach ($e as $k => $v) {
1761
-		            $k = strpos($k,':') ? $this->expandQname($k) : $k;
1762
-		            $v = strpos($v,':') ? $this->expandQname($v) : $v;
1763
-		            $ee[$k] = $v;
1764
-		    	}
1765
-	    		$eElements[$n] = $ee;
1766
-	    	}
1767
-	    	$elements = $eElements;
1757
+			foreach($elements as $n => $e){
1758
+				// expand each element
1759
+				$ee = array();
1760
+				foreach ($e as $k => $v) {
1761
+					$k = strpos($k,':') ? $this->expandQname($k) : $k;
1762
+					$v = strpos($v,':') ? $this->expandQname($v) : $v;
1763
+					$ee[$k] = $v;
1764
+				}
1765
+				$eElements[$n] = $ee;
1766
+			}
1767
+			$elements = $eElements;
1768 1768
 		}
1769 1769
 		
1770 1770
 		if (count($attrs) > 0) {
1771
-	    	foreach($attrs as $n => $a){
1772
-	            // expand each attribute
1773
-	            foreach ($a as $k => $v) {
1774
-		            $k = strpos($k,':') ? $this->expandQname($k) : $k;
1775
-		            $v = strpos($v,':') ? $this->expandQname($v) : $v;
1776
-		            $aa[$k] = $v;
1777
-		    	}
1778
-	    		$eAttrs[$n] = $aa;
1779
-	    	}
1780
-	    	$attrs = $eAttrs;
1771
+			foreach($attrs as $n => $a){
1772
+				// expand each attribute
1773
+				foreach ($a as $k => $v) {
1774
+					$k = strpos($k,':') ? $this->expandQname($k) : $k;
1775
+					$v = strpos($v,':') ? $this->expandQname($v) : $v;
1776
+					$aa[$k] = $v;
1777
+				}
1778
+				$eAttrs[$n] = $aa;
1779
+			}
1780
+			$attrs = $eAttrs;
1781 1781
 		}
1782 1782
 
1783 1783
 		$restrictionBase = strpos($restrictionBase,':') ? $this->expandQname($restrictionBase) : $restrictionBase;
@@ -1788,16 +1788,16 @@  discard block
 block discarded – undo
1788 1788
 	}
1789 1789
 
1790 1790
 	/**
1791
-	* adds an XML Schema simple type to the WSDL types
1792
-	*
1793
-	* @param string $name
1794
-	* @param string $restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array)
1795
-	* @param string $typeClass (should always be simpleType)
1796
-	* @param string $phpType (should always be scalar)
1797
-	* @param array $enumeration array of values
1798
-	* @see nusoap_xmlschema
1799
-	* @access public
1800
-	*/
1791
+	 * adds an XML Schema simple type to the WSDL types
1792
+	 *
1793
+	 * @param string $name
1794
+	 * @param string $restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array)
1795
+	 * @param string $typeClass (should always be simpleType)
1796
+	 * @param string $phpType (should always be scalar)
1797
+	 * @param array $enumeration array of values
1798
+	 * @see nusoap_xmlschema
1799
+	 * @access public
1800
+	 */
1801 1801
 	public function addSimpleType($name, $restrictionBase='', $typeClass='simpleType', $phpType='scalar', $enumeration=array()) {
1802 1802
 		$restrictionBase = strpos($restrictionBase,':') ? $this->expandQname($restrictionBase) : $restrictionBase;
1803 1803
 
@@ -1806,31 +1806,31 @@  discard block
 block discarded – undo
1806 1806
 	}
1807 1807
 
1808 1808
 	/**
1809
-	* adds an element to the WSDL types
1810
-	*
1811
-	* @param array $attrs attributes that must include name and type
1812
-	* @see nusoap_xmlschema
1813
-	* @access public
1814
-	*/
1809
+	 * adds an element to the WSDL types
1810
+	 *
1811
+	 * @param array $attrs attributes that must include name and type
1812
+	 * @see nusoap_xmlschema
1813
+	 * @access public
1814
+	 */
1815 1815
 	public function addElement($attrs) {
1816 1816
 		$typens = isset($this->namespaces['types']) ? $this->namespaces['types'] : $this->namespaces['tns'];
1817 1817
 		$this->schemas[$typens][0]->addElement($attrs);
1818 1818
 	}
1819 1819
 
1820 1820
 	/**
1821
-	* register an operation with the server
1822
-	* 
1823
-	* @param string $name operation (method) name
1824
-	* @param array $in assoc array of input values: key = param name, value = param type
1825
-	* @param array $out assoc array of output values: key = param name, value = param type
1826
-	* @param string $namespace optional The namespace for the operation
1827
-	* @param string $soapaction optional The soapaction for the operation
1828
-	* @param string $style (rpc|document) optional The style for the operation Note: when 'document' is specified, parameter and return wrappers are created for you automatically
1829
-	* @param string $use (encoded|literal) optional The use for the parameters (cannot mix right now)
1830
-	* @param string $documentation optional The description to include in the WSDL
1831
-	* @param string $encodingStyle optional (usually 'http://schemas.xmlsoap.org/soap/encoding/' for encoded)
1832
-	* @access public 
1833
-	*/
1821
+	 * register an operation with the server
1822
+	 * 
1823
+	 * @param string $name operation (method) name
1824
+	 * @param array $in assoc array of input values: key = param name, value = param type
1825
+	 * @param array $out assoc array of output values: key = param name, value = param type
1826
+	 * @param string $namespace optional The namespace for the operation
1827
+	 * @param string $soapaction optional The soapaction for the operation
1828
+	 * @param string $style (rpc|document) optional The style for the operation Note: when 'document' is specified, parameter and return wrappers are created for you automatically
1829
+	 * @param string $use (encoded|literal) optional The use for the parameters (cannot mix right now)
1830
+	 * @param string $documentation optional The description to include in the WSDL
1831
+	 * @param string $encodingStyle optional (usually 'http://schemas.xmlsoap.org/soap/encoding/' for encoded)
1832
+	 * @access public 
1833
+	 */
1834 1834
 	public function addOperation($name, $in = false, $out = false, $namespace = false, $soapaction = false, $style = 'rpc', $use = 'encoded', $documentation = '', $encodingStyle = ''){
1835 1835
 		if ($use == 'encoded' && $encodingStyle == '') {
1836 1836
 			$encodingStyle = 'http://schemas.xmlsoap.org/soap/encoding/';
@@ -1889,8 +1889,8 @@  discard block
 block discarded – undo
1889 1889
 				$this->messages[$name.'Request'][$pName] = $pType;
1890 1890
 			}
1891 1891
 		} else {
1892
-            $this->messages[$name.'Request']= '0';
1893
-        }
1892
+			$this->messages[$name.'Request']= '0';
1893
+		}
1894 1894
 		if($out)
1895 1895
 		{
1896 1896
 			foreach($out as $pName => $pType)
@@ -1901,8 +1901,8 @@  discard block
 block discarded – undo
1901 1901
 				$this->messages[$name.'Response'][$pName] = $pType;
1902 1902
 			}
1903 1903
 		} else {
1904
-            $this->messages[$name.'Response']= '0';
1905
-        }
1904
+			$this->messages[$name.'Response']= '0';
1905
+		}
1906 1906
 		return true;
1907 1907
 	} 
1908 1908
 }
Please login to merge, or discard this patch.
libraries/nusoap/class.xmlschema.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -779,7 +779,7 @@
 block discarded – undo
779 779
     * returns a sample serialization of a given type, or false if no type by the given name
780 780
     *
781 781
     * @param string $type name of type
782
-    * @return mixed
782
+    * @return string|false
783 783
     * @access public
784 784
     * @deprecated
785 785
     */
Please login to merge, or discard this patch.
Indentation   +239 added lines, -239 removed lines patch added patch discarded remove patch
@@ -44,13 +44,13 @@  discard block
 block discarded – undo
44 44
 	var $defaultNamespace = array();
45 45
     
46 46
 	/**
47
-	* constructor
48
-	*
49
-	* @param    string $schema schema document URI
50
-	* @param    string $xml xml document URI
51
-	* @param	string $namespaces namespaces defined in enclosing XML
52
-	* @access   public
53
-	*/
47
+	 * constructor
48
+	 *
49
+	 * @param    string $schema schema document URI
50
+	 * @param    string $xml xml document URI
51
+	 * @param	string $namespaces namespaces defined in enclosing XML
52
+	 * @access   public
53
+	 */
54 54
 	public function nusoap_xmlschema($schema='',$xml='',$namespaces=array()){
55 55
 		parent::nusoap_base();
56 56
 		$this->debug('nusoap_xmlschema class instantiated, inside constructor');
@@ -76,14 +76,14 @@  discard block
 block discarded – undo
76 76
 
77 77
 	}
78 78
 
79
-    /**
80
-    * parse an XML file
81
-    *
82
-    * @param string $xml path/URL to XML file
83
-    * @param string $type (schema | xml)
84
-	* @return boolean
85
-    * @access public
86
-    */
79
+	/**
80
+	 * parse an XML file
81
+	 *
82
+	 * @param string $xml path/URL to XML file
83
+	 * @param string $type (schema | xml)
84
+	 * @return boolean
85
+	 * @access public
86
+	 */
87 87
 	public function parseFile($xml,$type){
88 88
 		// parse xml file
89 89
 		if($xml != ""){
@@ -104,35 +104,35 @@  discard block
 block discarded – undo
104 104
 	}
105 105
 
106 106
 	/**
107
-	* parse an XML string
108
-	*
109
-	* @param    string $xml path or URL
110
-    * @param	string $type (schema|xml)
111
-	* @access   private
112
-	*/
107
+	 * parse an XML string
108
+	 *
109
+	 * @param    string $xml path or URL
110
+	 * @param	string $type (schema|xml)
111
+	 * @access   private
112
+	 */
113 113
 	public function parseString($xml,$type){
114 114
 		// parse xml string
115 115
 		if($xml != ""){
116 116
 
117
-	    	// Create an XML parser.
118
-	    	$this->parser = xml_parser_create();
119
-	    	// Set the options for parsing the XML data.
120
-	    	xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0);
117
+			// Create an XML parser.
118
+			$this->parser = xml_parser_create();
119
+			// Set the options for parsing the XML data.
120
+			xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0);
121 121
 
122
-	    	// Set the object for the parser.
123
-	    	xml_set_object($this->parser, $this);
122
+			// Set the object for the parser.
123
+			xml_set_object($this->parser, $this);
124 124
 
125
-	    	// Set the element handlers for the parser.
125
+			// Set the element handlers for the parser.
126 126
 			if($type == "schema"){
127
-		    	xml_set_element_handler($this->parser, 'schemaStartElement','schemaEndElement');
128
-		    	xml_set_character_data_handler($this->parser,'schemaCharacterData');
127
+				xml_set_element_handler($this->parser, 'schemaStartElement','schemaEndElement');
128
+				xml_set_character_data_handler($this->parser,'schemaCharacterData');
129 129
 			} elseif($type == "xml"){
130 130
 				xml_set_element_handler($this->parser, 'xmlStartElement','xmlEndElement');
131
-		    	xml_set_character_data_handler($this->parser,'xmlCharacterData');
131
+				xml_set_character_data_handler($this->parser,'xmlCharacterData');
132 132
 			}
133 133
 
134
-		    // Parse the XML file.
135
-		    if(!xml_parse($this->parser,$xml,true)){
134
+			// Parse the XML file.
135
+			if(!xml_parse($this->parser,$xml,true)){
136 136
 			// Display an error message.
137 137
 				$errstr = sprintf('XML error parsing XML schema on line %d: %s',
138 138
 				xml_get_current_line_number($this->parser),
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
 				$this->debug($errstr);
142 142
 				$this->debug("XML payload:\n" . $xml);
143 143
 				$this->setError($errstr);
144
-	    	}
144
+			}
145 145
             
146 146
 			xml_parser_free($this->parser);
147 147
 		} else{
@@ -166,13 +166,13 @@  discard block
 block discarded – undo
166 166
 	}
167 167
 	
168 168
 	/**
169
-	* start-element handler
170
-	*
171
-	* @param    string $parser XML parser object
172
-	* @param    string $name element name
173
-	* @param    string $attrs associative array of attributes
174
-	* @access   private
175
-	*/
169
+	 * start-element handler
170
+	 *
171
+	 * @param    string $parser XML parser object
172
+	 * @param    string $name element name
173
+	 * @param    string $attrs associative array of attributes
174
+	 * @access   private
175
+	 */
176 176
 	public function schemaStartElement($parser, $name, $attrs) {
177 177
 		
178 178
 		// position in the total number of elements, starting from 0
@@ -192,15 +192,15 @@  discard block
 block discarded – undo
192 192
 			// get unqualified name
193 193
 			$name = $this->getLocalPart($name);
194 194
 		} else {
195
-        	$prefix = '';
196
-        }
195
+			$prefix = '';
196
+		}
197 197
 		
198
-        // loop thru attributes, expanding, and registering namespace declarations
199
-        if(count($attrs) > 0){
200
-        	foreach($attrs as $k => $v){
201
-                // if ns declarations, add to class level array of valid namespaces
198
+		// loop thru attributes, expanding, and registering namespace declarations
199
+		if(count($attrs) > 0){
200
+			foreach($attrs as $k => $v){
201
+				// if ns declarations, add to class level array of valid namespaces
202 202
 				if(preg_match('/^xmlns/',$k)){
203
-                	if($ns_prefix = substr(strrchr($k,':'),1)){
203
+					if($ns_prefix = substr(strrchr($k,':'),1)){
204 204
 						$this->namespaces[$ns_prefix] = $v;
205 205
 					} else {
206 206
 						$this->defaultNamespace[$pos] = $v;
@@ -213,17 +213,17 @@  discard block
 block discarded – undo
213 213
 						$this->namespaces['xsi'] = $v.'-instance';
214 214
 					}
215 215
 				}
216
-        	}
217
-        	foreach($attrs as $k => $v){
218
-                // expand each attribute
219
-                $k = strpos($k,':') ? $this->expandQname($k) : $k;
220
-                $v = strpos($v,':') ? $this->expandQname($v) : $v;
221
-        		$eAttrs[$k] = $v;
222
-        	}
223
-        	$attrs = $eAttrs;
224
-        } else {
225
-        	$attrs = array();
226
-        }
216
+			}
217
+			foreach($attrs as $k => $v){
218
+				// expand each attribute
219
+				$k = strpos($k,':') ? $this->expandQname($k) : $k;
220
+				$v = strpos($v,':') ? $this->expandQname($v) : $v;
221
+				$eAttrs[$k] = $v;
222
+			}
223
+			$attrs = $eAttrs;
224
+		} else {
225
+			$attrs = array();
226
+		}
227 227
 		// find status, register data
228 228
 		switch($name){
229 229
 			case 'all':			// (optional) compositor content for a complexType
@@ -234,12 +234,12 @@  discard block
 block discarded – undo
234 234
 
235 235
 			break;
236 236
 			case 'attribute':	// complexType attribute
237
-            	$this->xdebug("parsing attribute:");
238
-            	$this->appendDebug($this->varDump($attrs));
237
+				$this->xdebug("parsing attribute:");
238
+				$this->appendDebug($this->varDump($attrs));
239 239
 				if (!isset($attrs['form'])) {
240 240
 					$attrs['form'] = $this->schemaInfo['attributeFormDefault'];
241 241
 				}
242
-            	if (isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'])) {
242
+				if (isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'])) {
243 243
 					$v = $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'];
244 244
 					if (!strpos($v, ':')) {
245 245
 						// no namespace in arrayType attribute value...
@@ -248,19 +248,19 @@  discard block
 block discarded – undo
248 248
 							$attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'] = $this->defaultNamespace[$pos] . ':' . $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'];
249 249
 						}
250 250
 					}
251
-            	}
252
-                if(isset($attrs['name'])){
251
+				}
252
+				if(isset($attrs['name'])){
253 253
 					$this->attributes[$attrs['name']] = $attrs;
254 254
 					$aname = $attrs['name'];
255 255
 				} elseif(isset($attrs['ref']) && $attrs['ref'] == 'http://schemas.xmlsoap.org/soap/encoding/:arrayType'){
256 256
 					if (isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'])) {
257
-	                	$aname = $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'];
258
-	                } else {
259
-	                	$aname = '';
260
-	                }
257
+						$aname = $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'];
258
+					} else {
259
+						$aname = '';
260
+					}
261 261
 				} elseif(isset($attrs['ref'])){
262 262
 					$aname = $attrs['ref'];
263
-                    $this->attributes[$attrs['ref']] = $attrs;
263
+					$this->attributes[$attrs['ref']] = $attrs;
264 264
 				}
265 265
                 
266 266
 				if($this->currentComplexType){	// This should *always* be
@@ -269,20 +269,20 @@  discard block
 block discarded – undo
269 269
 				// arrayType attribute
270 270
 				if(isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType']) || $this->getLocalPart($aname) == 'arrayType'){
271 271
 					$this->complexTypes[$this->currentComplexType]['phpType'] = 'array';
272
-                	$prefix = $this->getPrefix($aname);
272
+					$prefix = $this->getPrefix($aname);
273 273
 					if(isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'])){
274 274
 						$v = $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'];
275 275
 					} else {
276 276
 						$v = '';
277 277
 					}
278
-                    if(strpos($v,'[,]')){
279
-                        $this->complexTypes[$this->currentComplexType]['multidimensional'] = true;
280
-                    }
281
-                    $v = substr($v,0,strpos($v,'[')); // clip the []
282
-                    if(!strpos($v,':') && isset($this->typemap[$this->XMLSchemaVersion][$v])){
283
-                        $v = $this->XMLSchemaVersion.':'.$v;
284
-                    }
285
-                    $this->complexTypes[$this->currentComplexType]['arrayType'] = $v;
278
+					if(strpos($v,'[,]')){
279
+						$this->complexTypes[$this->currentComplexType]['multidimensional'] = true;
280
+					}
281
+					$v = substr($v,0,strpos($v,'[')); // clip the []
282
+					if(!strpos($v,':') && isset($this->typemap[$this->XMLSchemaVersion][$v])){
283
+						$v = $this->XMLSchemaVersion.':'.$v;
284
+					}
285
+					$this->complexTypes[$this->currentComplexType]['arrayType'] = $v;
286 286
 				}
287 287
 			break;
288 288
 			case 'complexContent':	// (optional) content for a complexType
@@ -396,21 +396,21 @@  discard block
 block discarded – undo
396 396
 				}
397 397
 			break;
398 398
 			case 'import':
399
-			    if (isset($attrs['schemaLocation'])) {
399
+				if (isset($attrs['schemaLocation'])) {
400 400
 					$this->xdebug('import namespace ' . $attrs['namespace'] . ' from ' . $attrs['schemaLocation']);
401
-                    $this->imports[$attrs['namespace']][] = array('location' => $attrs['schemaLocation'], 'loaded' => false);
401
+					$this->imports[$attrs['namespace']][] = array('location' => $attrs['schemaLocation'], 'loaded' => false);
402 402
 				} else {
403 403
 					$this->xdebug('import namespace ' . $attrs['namespace']);
404
-                    $this->imports[$attrs['namespace']][] = array('location' => '', 'loaded' => true);
404
+					$this->imports[$attrs['namespace']][] = array('location' => '', 'loaded' => true);
405 405
 					if (! $this->getPrefixFromNamespace($attrs['namespace'])) {
406 406
 						$this->namespaces['ns'.(count($this->namespaces)+1)] = $attrs['namespace'];
407 407
 					}
408 408
 				}
409 409
 			break;
410 410
 			case 'include':
411
-			    if (isset($attrs['schemaLocation'])) {
411
+				if (isset($attrs['schemaLocation'])) {
412 412
 					$this->xdebug('include into namespace ' . $this->schemaTargetNamespace . ' from ' . $attrs['schemaLocation']);
413
-                    $this->imports[$this->schemaTargetNamespace][] = array('location' => $attrs['schemaLocation'], 'loaded' => false);
413
+					$this->imports[$this->schemaTargetNamespace][] = array('location' => $attrs['schemaLocation'], 'loaded' => false);
414 414
 				} else {
415 415
 					$this->xdebug('ignoring invalid XML Schema construct: include without schemaLocation attribute');
416 416
 				}
@@ -474,26 +474,26 @@  discard block
 block discarded – undo
474 474
 	}
475 475
 
476 476
 	/**
477
-	* end-element handler
478
-	*
479
-	* @param    string $parser XML parser object
480
-	* @param    string $name element name
481
-	* @access   private
482
-	*/
477
+	 * end-element handler
478
+	 *
479
+	 * @param    string $parser XML parser object
480
+	 * @param    string $name element name
481
+	 * @access   private
482
+	 */
483 483
 	public function schemaEndElement($parser, $name) {
484 484
 		// bring depth down a notch
485 485
 		$this->depth--;
486 486
 		// position of current element is equal to the last value left in depth_array for my depth
487 487
 		if(isset($this->depth_array[$this->depth])){
488
-        	$pos = $this->depth_array[$this->depth];
489
-        }
488
+			$pos = $this->depth_array[$this->depth];
489
+		}
490 490
 		// get element prefix
491 491
 		if ($prefix = $this->getPrefix($name)){
492 492
 			// get unqualified name
493 493
 			$name = $this->getLocalPart($name);
494 494
 		} else {
495
-        	$prefix = '';
496
-        }
495
+			$prefix = '';
496
+		}
497 497
 		// move on...
498 498
 		if($name == 'complexType'){
499 499
 			$this->xdebug('done processing complexType ' . ($this->currentComplexType ? $this->currentComplexType : '(unknown)'));
@@ -512,22 +512,22 @@  discard block
 block discarded – undo
512 512
 	}
513 513
 
514 514
 	/**
515
-	* element content handler
516
-	*
517
-	* @param    string $parser XML parser object
518
-	* @param    string $data element content
519
-	* @access   private
520
-	*/
515
+	 * element content handler
516
+	 *
517
+	 * @param    string $parser XML parser object
518
+	 * @param    string $data element content
519
+	 * @access   private
520
+	 */
521 521
 	public function schemaCharacterData($parser, $data){
522 522
 		$pos = $this->depth_array[$this->depth - 1];
523 523
 		$this->message[$pos]['cdata'] .= $data;
524 524
 	}
525 525
 
526 526
 	/**
527
-	* serialize the schema
528
-	*
529
-	* @access   public
530
-	*/
527
+	 * serialize the schema
528
+	 *
529
+	 * @access   public
530
+	 */
531 531
 	public function serializeSchema(){
532 532
 
533 533
 		$schemaPrefix = $this->getPrefixFromNamespace($this->XMLSchemaVersion);
@@ -641,27 +641,27 @@  discard block
 block discarded – undo
641 641
 	}
642 642
 
643 643
 	/**
644
-	* adds debug data to the clas level debug string
645
-	*
646
-	* @param    string $string debug data
647
-	* @access   private
648
-	*/
644
+	 * adds debug data to the clas level debug string
645
+	 *
646
+	 * @param    string $string debug data
647
+	 * @access   private
648
+	 */
649 649
 	public function xdebug($string){
650 650
 		$this->debug('<' . $this->schemaTargetNamespace . '> '.$string);
651 651
 	}
652 652
 
653
-    /**
654
-    * get the PHP type of a user defined type in the schema
655
-    * PHP type is kind of a misnomer since it actually returns 'struct' for assoc. arrays
656
-    * returns false if no type exists, or not w/ the given namespace
657
-    * else returns a string that is either a native php type, or 'struct'
658
-    *
659
-    * @param string $type name of defined type
660
-    * @param string $ns namespace of type
661
-    * @return mixed
662
-    * @access public
663
-    * @deprecated
664
-    */
653
+	/**
654
+	 * get the PHP type of a user defined type in the schema
655
+	 * PHP type is kind of a misnomer since it actually returns 'struct' for assoc. arrays
656
+	 * returns false if no type exists, or not w/ the given namespace
657
+	 * else returns a string that is either a native php type, or 'struct'
658
+	 *
659
+	 * @param string $type name of defined type
660
+	 * @param string $ns namespace of type
661
+	 * @return mixed
662
+	 * @access public
663
+	 * @deprecated
664
+	 */
665 665
 	public function getPHPType($type,$ns){
666 666
 		if(isset($this->typemap[$ns][$type])){
667 667
 			//print "found type '$type' and ns $ns in typemap<br>";
@@ -674,27 +674,27 @@  discard block
 block discarded – undo
674 674
 	}
675 675
 
676 676
 	/**
677
-    * returns an associative array of information about a given type
678
-    * returns false if no type exists by the given name
679
-    *
680
-	*	For a complexType typeDef = array(
681
-	*	'restrictionBase' => '',
682
-	*	'phpType' => '',
683
-	*	'compositor' => '(sequence|all)',
684
-	*	'elements' => array(), // refs to elements array
685
-	*	'attrs' => array() // refs to attributes array
686
-	*	... and so on (see addComplexType)
687
-	*	)
688
-	*
689
-	*   For simpleType or element, the array has different keys.
690
-    *
691
-    * @param string $type
692
-    * @return mixed
693
-    * @access public
694
-    * @see addComplexType
695
-    * @see addSimpleType
696
-    * @see addElement
697
-    */
677
+	 * returns an associative array of information about a given type
678
+	 * returns false if no type exists by the given name
679
+	 *
680
+	 *	For a complexType typeDef = array(
681
+	 *	'restrictionBase' => '',
682
+	 *	'phpType' => '',
683
+	 *	'compositor' => '(sequence|all)',
684
+	 *	'elements' => array(), // refs to elements array
685
+	 *	'attrs' => array() // refs to attributes array
686
+	 *	... and so on (see addComplexType)
687
+	 *	)
688
+	 *
689
+	 *   For simpleType or element, the array has different keys.
690
+	 *
691
+	 * @param string $type
692
+	 * @return mixed
693
+	 * @access public
694
+	 * @see addComplexType
695
+	 * @see addSimpleType
696
+	 * @see addElement
697
+	 */
698 698
 	public function getTypeDef($type){
699 699
 		if (substr($type, -1) == '^') {
700 700
 			$is_element = 1;
@@ -764,49 +764,49 @@  discard block
 block discarded – undo
764 764
 	}
765 765
 
766 766
 	/**
767
-    * returns a sample serialization of a given type, or false if no type by the given name
768
-    *
769
-    * @param string $type name of type
770
-    * @return mixed
771
-    * @access public
772
-    * @deprecated
773
-    */
774
-    public function serializeTypeDef($type){
775
-    	//print "in sTD() for type $type<br>";
767
+	 * returns a sample serialization of a given type, or false if no type by the given name
768
+	 *
769
+	 * @param string $type name of type
770
+	 * @return mixed
771
+	 * @access public
772
+	 * @deprecated
773
+	 */
774
+	public function serializeTypeDef($type){
775
+		//print "in sTD() for type $type<br>";
776 776
 	if($typeDef = $this->getTypeDef($type)){
777 777
 		$str .= '<'.$type;
778
-	    if(is_array($typeDef['attrs'])){
778
+		if(is_array($typeDef['attrs'])){
779 779
 		foreach($typeDef['attrs'] as $attName => $data){
780
-		    $str .= " $attName=\"{type = ".$data['type']."}\"";
780
+			$str .= " $attName=\"{type = ".$data['type']."}\"";
781 781
 		}
782
-	    }
783
-	    $str .= " xmlns=\"".$this->schema['targetNamespace']."\"";
784
-	    if(count($typeDef['elements']) > 0){
782
+		}
783
+		$str .= " xmlns=\"".$this->schema['targetNamespace']."\"";
784
+		if(count($typeDef['elements']) > 0){
785 785
 		$str .= ">";
786 786
 		foreach($typeDef['elements'] as $element => $eData){
787
-		    $str .= $this->serializeTypeDef($element);
787
+			$str .= $this->serializeTypeDef($element);
788 788
 		}
789 789
 		$str .= "</$type>";
790
-	    } elseif($typeDef['typeClass'] == 'element') {
790
+		} elseif($typeDef['typeClass'] == 'element') {
791 791
 		$str .= "></$type>";
792
-	    } else {
792
+		} else {
793 793
 		$str .= "/>";
794
-	    }
794
+		}
795 795
 			return $str;
796 796
 	}
797
-    	return false;
798
-    }
797
+		return false;
798
+	}
799 799
 
800
-    /**
801
-    * returns HTML form elements that allow a user
802
-    * to enter values for creating an instance of the given type.
803
-    *
804
-    * @param string $name name for type instance
805
-    * @param string $type name of type
806
-    * @return string
807
-    * @access public
808
-    * @deprecated
809
-	*/
800
+	/**
801
+	 * returns HTML form elements that allow a user
802
+	 * to enter values for creating an instance of the given type.
803
+	 *
804
+	 * @param string $name name for type instance
805
+	 * @param string $type name of type
806
+	 * @return string
807
+	 * @access public
808
+	 * @deprecated
809
+	 */
810 810
 	public function typeToForm($name,$type){
811 811
 		// get typedef
812 812
 		if($typeDef = $this->getTypeDef($type)){
@@ -839,56 +839,56 @@  discard block
 block discarded – undo
839 839
 	}
840 840
 	
841 841
 	/**
842
-	* adds a complex type to the schema
843
-	* 
844
-	* example: array
845
-	* 
846
-	* addType(
847
-	* 	'ArrayOfstring',
848
-	* 	'complexType',
849
-	* 	'array',
850
-	* 	'',
851
-	* 	'SOAP-ENC:Array',
852
-	* 	array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'string[]'),
853
-	* 	'xsd:string'
854
-	* );
855
-	* 
856
-	* example: PHP associative array ( SOAP Struct )
857
-	* 
858
-	* addType(
859
-	* 	'SOAPStruct',
860
-	* 	'complexType',
861
-	* 	'struct',
862
-	* 	'all',
863
-	* 	array('myVar'=> array('name'=>'myVar','type'=>'string')
864
-	* );
865
-	* 
866
-	* @param name
867
-	* @param typeClass (complexType|simpleType|attribute)
868
-	* @param phpType: currently supported are array and struct (php assoc array)
869
-	* @param compositor (all|sequence|choice)
870
-	* @param restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array)
871
-	* @param elements = array ( name = array(name=>'',type=>'') )
872
-	* @param attrs = array(
873
-	* 	array(
874
-	*		'ref' => "http://schemas.xmlsoap.org/soap/encoding/:arrayType",
875
-	*		"http://schemas.xmlsoap.org/wsdl/:arrayType" => "string[]"
876
-	* 	)
877
-	* )
878
-	* @param arrayType: namespace:name (http://www.w3.org/2001/XMLSchema:string)
879
-	* @access public
880
-	* @see getTypeDef
881
-	*/
842
+	 * adds a complex type to the schema
843
+	 * 
844
+	 * example: array
845
+	 * 
846
+	 * addType(
847
+	 * 	'ArrayOfstring',
848
+	 * 	'complexType',
849
+	 * 	'array',
850
+	 * 	'',
851
+	 * 	'SOAP-ENC:Array',
852
+	 * 	array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'string[]'),
853
+	 * 	'xsd:string'
854
+	 * );
855
+	 * 
856
+	 * example: PHP associative array ( SOAP Struct )
857
+	 * 
858
+	 * addType(
859
+	 * 	'SOAPStruct',
860
+	 * 	'complexType',
861
+	 * 	'struct',
862
+	 * 	'all',
863
+	 * 	array('myVar'=> array('name'=>'myVar','type'=>'string')
864
+	 * );
865
+	 * 
866
+	 * @param name
867
+	 * @param typeClass (complexType|simpleType|attribute)
868
+	 * @param phpType: currently supported are array and struct (php assoc array)
869
+	 * @param compositor (all|sequence|choice)
870
+	 * @param restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array)
871
+	 * @param elements = array ( name = array(name=>'',type=>'') )
872
+	 * @param attrs = array(
873
+	 * 	array(
874
+	 *		'ref' => "http://schemas.xmlsoap.org/soap/encoding/:arrayType",
875
+	 *		"http://schemas.xmlsoap.org/wsdl/:arrayType" => "string[]"
876
+	 * 	)
877
+	 * )
878
+	 * @param arrayType: namespace:name (http://www.w3.org/2001/XMLSchema:string)
879
+	 * @access public
880
+	 * @see getTypeDef
881
+	 */
882 882
 	public function addComplexType($name,$typeClass='complexType',$phpType='array',$compositor='',$restrictionBase='',$elements=array(),$attrs=array(),$arrayType=''){
883 883
 		$this->complexTypes[$name] = array(
884
-	    'name'		=> $name,
885
-	    'typeClass'	=> $typeClass,
886
-	    'phpType'	=> $phpType,
884
+		'name'		=> $name,
885
+		'typeClass'	=> $typeClass,
886
+		'phpType'	=> $phpType,
887 887
 		'compositor'=> $compositor,
888
-	    'restrictionBase' => $restrictionBase,
888
+		'restrictionBase' => $restrictionBase,
889 889
 		'elements'	=> $elements,
890
-	    'attrs'		=> $attrs,
891
-	    'arrayType'	=> $arrayType
890
+		'attrs'		=> $attrs,
891
+		'arrayType'	=> $arrayType
892 892
 		);
893 893
 		
894 894
 		$this->xdebug("addComplexType $name:");
@@ -896,24 +896,24 @@  discard block
 block discarded – undo
896 896
 	}
897 897
 	
898 898
 	/**
899
-	* adds a simple type to the schema
900
-	*
901
-	* @param string $name
902
-	* @param string $restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array)
903
-	* @param string $typeClass (should always be simpleType)
904
-	* @param string $phpType (should always be scalar)
905
-	* @param array $enumeration array of values
906
-	* @access public
907
-	* @see nusoap_xmlschema
908
-	* @see getTypeDef
909
-	*/
899
+	 * adds a simple type to the schema
900
+	 *
901
+	 * @param string $name
902
+	 * @param string $restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array)
903
+	 * @param string $typeClass (should always be simpleType)
904
+	 * @param string $phpType (should always be scalar)
905
+	 * @param array $enumeration array of values
906
+	 * @access public
907
+	 * @see nusoap_xmlschema
908
+	 * @see getTypeDef
909
+	 */
910 910
 	public function addSimpleType($name, $restrictionBase='', $typeClass='simpleType', $phpType='scalar', $enumeration=array()) {
911 911
 		$this->simpleTypes[$name] = array(
912
-	    'name'			=> $name,
913
-	    'typeClass'		=> $typeClass,
914
-	    'phpType'		=> $phpType,
915
-	    'type'			=> $restrictionBase,
916
-	    'enumeration'	=> $enumeration
912
+		'name'			=> $name,
913
+		'typeClass'		=> $typeClass,
914
+		'phpType'		=> $phpType,
915
+		'type'			=> $restrictionBase,
916
+		'enumeration'	=> $enumeration
917 917
 		);
918 918
 		
919 919
 		$this->xdebug("addSimpleType $name:");
@@ -921,12 +921,12 @@  discard block
 block discarded – undo
921 921
 	}
922 922
 
923 923
 	/**
924
-	* adds an element to the schema
925
-	*
926
-	* @param array $attrs attributes that must include name and type
927
-	* @see nusoap_xmlschema
928
-	* @access public
929
-	*/
924
+	 * adds an element to the schema
925
+	 *
926
+	 * @param array $attrs attributes that must include name and type
927
+	 * @see nusoap_xmlschema
928
+	 * @access public
929
+	 */
930 930
 	public function addElement($attrs) {
931 931
 		if (! $this->getPrefix($attrs['type'])) {
932 932
 			$attrs['type'] = $this->schemaTargetNamespace . ':' . $attrs['type'];
Please login to merge, or discard this patch.
Spacing   +134 added lines, -134 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
 * @version  $Id: class.xmlschema.php,v 1.53 2010/04/26 20:15:08 snichol Exp $
13 13
 * @access   public
14 14
 */
15
-class nusoap_xmlschema extends nusoap_base  {
15
+class nusoap_xmlschema extends nusoap_base {
16 16
 	
17 17
 	// files
18 18
 	var $schema = '';
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
 	* @param	string $namespaces namespaces defined in enclosing XML
52 52
 	* @access   public
53 53
 	*/
54
-	public function nusoap_xmlschema($schema='',$xml='',$namespaces=array()){
54
+	public function nusoap_xmlschema($schema = '', $xml = '', $namespaces = array()) {
55 55
 		parent::nusoap_base();
56 56
 		$this->debug('nusoap_xmlschema class instantiated, inside constructor');
57 57
 		// files
@@ -63,14 +63,14 @@  discard block
 block discarded – undo
63 63
 		$this->namespaces = array_merge($this->namespaces, $namespaces);
64 64
 
65 65
 		// parse schema file
66
-		if($schema != ''){
67
-			$this->debug('initial schema file: '.$schema);
66
+		if ($schema != '') {
67
+			$this->debug('initial schema file: ' . $schema);
68 68
 			$this->parseFile($schema, 'schema');
69 69
 		}
70 70
 
71 71
 		// parse xml file
72
-		if($xml != ''){
73
-			$this->debug('initial xml file: '.$xml);
72
+		if ($xml != '') {
73
+			$this->debug('initial xml file: ' . $xml);
74 74
 			$this->parseFile($xml, 'xml');
75 75
 		}
76 76
 
@@ -84,18 +84,18 @@  discard block
 block discarded – undo
84 84
 	* @return boolean
85 85
     * @access public
86 86
     */
87
-	public function parseFile($xml,$type){
87
+	public function parseFile($xml, $type) {
88 88
 		// parse xml file
89
-		if($xml != ""){
90
-			$xmlStr = @join("",@file($xml));
91
-			if($xmlStr == ""){
92
-				$msg = 'Error reading XML from '.$xml;
89
+		if ($xml != "") {
90
+			$xmlStr = @join("", @file($xml));
91
+			if ($xmlStr == "") {
92
+				$msg = 'Error reading XML from ' . $xml;
93 93
 				$this->setError($msg);
94 94
 				$this->debug($msg);
95 95
 			return false;
96 96
 			} else {
97 97
 				$this->debug("parsing $xml");
98
-				$this->parseString($xmlStr,$type);
98
+				$this->parseString($xmlStr, $type);
99 99
 				$this->debug("done parsing $xml");
100 100
 			return true;
101 101
 			}
@@ -110,9 +110,9 @@  discard block
 block discarded – undo
110 110
     * @param	string $type (schema|xml)
111 111
 	* @access   private
112 112
 	*/
113
-	public function parseString($xml,$type){
113
+	public function parseString($xml, $type) {
114 114
 		// parse xml string
115
-		if($xml != ""){
115
+		if ($xml != "") {
116 116
 
117 117
 	    	// Create an XML parser.
118 118
 	    	$this->parser = xml_parser_create();
@@ -123,16 +123,16 @@  discard block
 block discarded – undo
123 123
 	    	xml_set_object($this->parser, $this);
124 124
 
125 125
 	    	// Set the element handlers for the parser.
126
-			if($type == "schema"){
127
-		    	xml_set_element_handler($this->parser, 'schemaStartElement','schemaEndElement');
128
-		    	xml_set_character_data_handler($this->parser,'schemaCharacterData');
129
-			} elseif($type == "xml"){
130
-				xml_set_element_handler($this->parser, 'xmlStartElement','xmlEndElement');
131
-		    	xml_set_character_data_handler($this->parser,'xmlCharacterData');
126
+			if ($type == "schema") {
127
+		    	xml_set_element_handler($this->parser, 'schemaStartElement', 'schemaEndElement');
128
+		    	xml_set_character_data_handler($this->parser, 'schemaCharacterData');
129
+			} elseif ($type == "xml") {
130
+				xml_set_element_handler($this->parser, 'xmlStartElement', 'xmlEndElement');
131
+		    	xml_set_character_data_handler($this->parser, 'xmlCharacterData');
132 132
 			}
133 133
 
134 134
 		    // Parse the XML file.
135
-		    if(!xml_parse($this->parser,$xml,true)){
135
+		    if (!xml_parse($this->parser, $xml, true)) {
136 136
 			// Display an error message.
137 137
 				$errstr = sprintf('XML error parsing XML schema on line %d: %s',
138 138
 				xml_get_current_line_number($this->parser),
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
 	    	}
145 145
             
146 146
 			xml_parser_free($this->parser);
147
-		} else{
147
+		} else {
148 148
 			$this->debug('no xml passed to parseString()!!');
149 149
 			$this->setError('no xml passed to parseString()!!');
150 150
 		}
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
 		}
189 189
 
190 190
 		// get element prefix
191
-		if($prefix = $this->getPrefix($name)){
191
+		if ($prefix = $this->getPrefix($name)) {
192 192
 			// get unqualified name
193 193
 			$name = $this->getLocalPart($name);
194 194
 		} else {
@@ -196,28 +196,28 @@  discard block
 block discarded – undo
196 196
         }
197 197
 		
198 198
         // loop thru attributes, expanding, and registering namespace declarations
199
-        if(count($attrs) > 0){
200
-        	foreach($attrs as $k => $v){
199
+        if (count($attrs) > 0) {
200
+        	foreach ($attrs as $k => $v) {
201 201
                 // if ns declarations, add to class level array of valid namespaces
202
-				if(preg_match('/^xmlns/',$k)){
203
-                	if($ns_prefix = substr(strrchr($k,':'),1)){
202
+				if (preg_match('/^xmlns/', $k)) {
203
+                	if ($ns_prefix = substr(strrchr($k, ':'), 1)) {
204 204
 						$this->namespaces[$ns_prefix] = $v;
205 205
 					} else {
206 206
 						$this->defaultNamespace[$pos] = $v;
207
-						if (! $this->getPrefixFromNamespace($v)) {
208
-							$this->namespaces['ns'.(count($this->namespaces)+1)] = $v;
207
+						if (!$this->getPrefixFromNamespace($v)) {
208
+							$this->namespaces['ns' . (count($this->namespaces) + 1)] = $v;
209 209
 						}
210 210
 					}
211
-					if($v == 'http://www.w3.org/2001/XMLSchema' || $v == 'http://www.w3.org/1999/XMLSchema' || $v == 'http://www.w3.org/2000/10/XMLSchema'){
211
+					if ($v == 'http://www.w3.org/2001/XMLSchema' || $v == 'http://www.w3.org/1999/XMLSchema' || $v == 'http://www.w3.org/2000/10/XMLSchema') {
212 212
 						$this->XMLSchemaVersion = $v;
213
-						$this->namespaces['xsi'] = $v.'-instance';
213
+						$this->namespaces['xsi'] = $v . '-instance';
214 214
 					}
215 215
 				}
216 216
         	}
217
-        	foreach($attrs as $k => $v){
217
+        	foreach ($attrs as $k => $v) {
218 218
                 // expand each attribute
219
-                $k = strpos($k,':') ? $this->expandQname($k) : $k;
220
-                $v = strpos($v,':') ? $this->expandQname($v) : $v;
219
+                $k = strpos($k, ':') ? $this->expandQname($k) : $k;
220
+                $v = strpos($v, ':') ? $this->expandQname($v) : $v;
221 221
         		$eAttrs[$k] = $v;
222 222
         	}
223 223
         	$attrs = $eAttrs;
@@ -225,7 +225,7 @@  discard block
 block discarded – undo
225 225
         	$attrs = array();
226 226
         }
227 227
 		// find status, register data
228
-		switch($name){
228
+		switch ($name) {
229 229
 			case 'all':			// (optional) compositor content for a complexType
230 230
 			case 'choice':
231 231
 			case 'group':
@@ -249,38 +249,38 @@  discard block
 block discarded – undo
249 249
 						}
250 250
 					}
251 251
             	}
252
-                if(isset($attrs['name'])){
252
+                if (isset($attrs['name'])) {
253 253
 					$this->attributes[$attrs['name']] = $attrs;
254 254
 					$aname = $attrs['name'];
255
-				} elseif(isset($attrs['ref']) && $attrs['ref'] == 'http://schemas.xmlsoap.org/soap/encoding/:arrayType'){
255
+				} elseif (isset($attrs['ref']) && $attrs['ref'] == 'http://schemas.xmlsoap.org/soap/encoding/:arrayType') {
256 256
 					if (isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'])) {
257 257
 	                	$aname = $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'];
258 258
 	                } else {
259 259
 	                	$aname = '';
260 260
 	                }
261
-				} elseif(isset($attrs['ref'])){
261
+				} elseif (isset($attrs['ref'])) {
262 262
 					$aname = $attrs['ref'];
263 263
                     $this->attributes[$attrs['ref']] = $attrs;
264 264
 				}
265 265
                 
266
-				if($this->currentComplexType){	// This should *always* be
266
+				if ($this->currentComplexType) {	// This should *always* be
267 267
 					$this->complexTypes[$this->currentComplexType]['attrs'][$aname] = $attrs;
268 268
 				}
269 269
 				// arrayType attribute
270
-				if(isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType']) || $this->getLocalPart($aname) == 'arrayType'){
270
+				if (isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType']) || $this->getLocalPart($aname) == 'arrayType') {
271 271
 					$this->complexTypes[$this->currentComplexType]['phpType'] = 'array';
272 272
                 	$prefix = $this->getPrefix($aname);
273
-					if(isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'])){
273
+					if (isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'])) {
274 274
 						$v = $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'];
275 275
 					} else {
276 276
 						$v = '';
277 277
 					}
278
-                    if(strpos($v,'[,]')){
278
+                    if (strpos($v, '[,]')) {
279 279
                         $this->complexTypes[$this->currentComplexType]['multidimensional'] = true;
280 280
                     }
281
-                    $v = substr($v,0,strpos($v,'[')); // clip the []
282
-                    if(!strpos($v,':') && isset($this->typemap[$this->XMLSchemaVersion][$v])){
283
-                        $v = $this->XMLSchemaVersion.':'.$v;
281
+                    $v = substr($v, 0, strpos($v, '[')); // clip the []
282
+                    if (!strpos($v, ':') && isset($this->typemap[$this->XMLSchemaVersion][$v])) {
283
+                        $v = $this->XMLSchemaVersion . ':' . $v;
284 284
                     }
285 285
                     $this->complexTypes[$this->currentComplexType]['arrayType'] = $v;
286 286
 				}
@@ -290,12 +290,12 @@  discard block
 block discarded – undo
290 290
 			break;
291 291
 			case 'complexType':
292 292
 				array_push($this->complexTypeStack, $this->currentComplexType);
293
-				if(isset($attrs['name'])){
294
-					$this->xdebug('processing named complexType '.$attrs['name']);
293
+				if (isset($attrs['name'])) {
294
+					$this->xdebug('processing named complexType ' . $attrs['name']);
295 295
 					$this->currentComplexType = $attrs['name'];
296 296
 					$this->complexTypes[$this->currentComplexType] = $attrs;
297 297
 					$this->complexTypes[$this->currentComplexType]['typeClass'] = 'complexType';
298
-					if(isset($attrs['base']) && preg_match('/:Array$/',$attrs['base'])){
298
+					if (isset($attrs['base']) && preg_match('/:Array$/', $attrs['base'])) {
299 299
 						$this->xdebug('complexType is unusual array');
300 300
 						$this->complexTypes[$this->currentComplexType]['phpType'] = 'array';
301 301
 					} else {
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
 					//                        minOccurs="0" maxOccurs="unbounded" />
315 315
 					//                </sequence>
316 316
 					//            </complexType>
317
-					if(isset($attrs['base']) && preg_match('/:Array$/',$attrs['base'])){
317
+					if (isset($attrs['base']) && preg_match('/:Array$/', $attrs['base'])) {
318 318
 						$this->xdebug('complexType is unusual array');
319 319
 						$this->complexTypes[$this->currentComplexType]['phpType'] = 'array';
320 320
 					} else {
@@ -333,9 +333,9 @@  discard block
 block discarded – undo
333 333
 						$attrs['form'] = 'qualified';
334 334
 					}
335 335
 				}
336
-				if(isset($attrs['type'])){
337
-					$this->xdebug("processing typed element ".$attrs['name']." of type ".$attrs['type']);
338
-					if (! $this->getPrefix($attrs['type'])) {
336
+				if (isset($attrs['type'])) {
337
+					$this->xdebug("processing typed element " . $attrs['name'] . " of type " . $attrs['type']);
338
+					if (!$this->getPrefix($attrs['type'])) {
339 339
 						if ($this->defaultNamespace[$pos]) {
340 340
 							$attrs['type'] = $this->defaultNamespace[$pos] . ':' . $attrs['type'];
341 341
 							$this->xdebug('used default namespace to make type ' . $attrs['type']);
@@ -354,9 +354,9 @@  discard block
 block discarded – undo
354 354
 					}
355 355
 					$this->currentElement = $attrs['name'];
356 356
 					$ename = $attrs['name'];
357
-				} elseif(isset($attrs['ref'])){
358
-					$this->xdebug("processing element as ref to ".$attrs['ref']);
359
-					$this->currentElement = "ref to ".$attrs['ref'];
357
+				} elseif (isset($attrs['ref'])) {
358
+					$this->xdebug("processing element as ref to " . $attrs['ref']);
359
+					$this->currentElement = "ref to " . $attrs['ref'];
360 360
 					$ename = $this->getLocalPart($attrs['ref']);
361 361
 				} else {
362 362
 					$type = $this->CreateTypeName($this->currentComplexType . '_' . $attrs['name']);
@@ -370,8 +370,8 @@  discard block
 block discarded – undo
370 370
 					$this->complexTypes[$this->currentComplexType]['elements'][$ename] = $attrs;
371 371
 				} elseif (!isset($attrs['ref'])) {
372 372
 					$this->xdebug("add element $ename to elements array");
373
-					$this->elements[ $attrs['name'] ] = $attrs;
374
-					$this->elements[ $attrs['name'] ]['typeClass'] = 'element';
373
+					$this->elements[$attrs['name']] = $attrs;
374
+					$this->elements[$attrs['name']]['typeClass'] = 'element';
375 375
 				}
376 376
 			break;
377 377
 			case 'enumeration':	//	restriction value list member
@@ -402,8 +402,8 @@  discard block
 block discarded – undo
402 402
 				} else {
403 403
 					$this->xdebug('import namespace ' . $attrs['namespace']);
404 404
                     $this->imports[$attrs['namespace']][] = array('location' => '', 'loaded' => true);
405
-					if (! $this->getPrefixFromNamespace($attrs['namespace'])) {
406
-						$this->namespaces['ns'.(count($this->namespaces)+1)] = $attrs['namespace'];
405
+					if (!$this->getPrefixFromNamespace($attrs['namespace'])) {
406
+						$this->namespaces['ns' . (count($this->namespaces) + 1)] = $attrs['namespace'];
407 407
 					}
408 408
 				}
409 409
 			break;
@@ -420,11 +420,11 @@  discard block
 block discarded – undo
420 420
 			break;
421 421
 			case 'restriction':	// simpleType, simpleContent or complexContent value restriction
422 422
 				$this->xdebug('restriction ' . $attrs['base']);
423
-				if($this->currentSimpleType){
423
+				if ($this->currentSimpleType) {
424 424
 					$this->simpleTypes[$this->currentSimpleType]['type'] = $attrs['base'];
425
-				} elseif($this->currentComplexType){
425
+				} elseif ($this->currentComplexType) {
426 426
 					$this->complexTypes[$this->currentComplexType]['restrictionBase'] = $attrs['base'];
427
-					if(strstr($attrs['base'],':') == ':Array'){
427
+					if (strstr($attrs['base'], ':') == ':Array') {
428 428
 						$this->complexTypes[$this->currentComplexType]['phpType'] = 'array';
429 429
 					}
430 430
 				}
@@ -451,12 +451,12 @@  discard block
 block discarded – undo
451 451
 			break;
452 452
 			case 'simpleType':
453 453
 				array_push($this->simpleTypeStack, $this->currentSimpleType);
454
-				if(isset($attrs['name'])){
454
+				if (isset($attrs['name'])) {
455 455
 					$this->xdebug("processing simpleType for name " . $attrs['name']);
456 456
 					$this->currentSimpleType = $attrs['name'];
457
-					$this->simpleTypes[ $attrs['name'] ] = $attrs;
458
-					$this->simpleTypes[ $attrs['name'] ]['typeClass'] = 'simpleType';
459
-					$this->simpleTypes[ $attrs['name'] ]['phpType'] = 'scalar';
457
+					$this->simpleTypes[$attrs['name']] = $attrs;
458
+					$this->simpleTypes[$attrs['name']]['typeClass'] = 'simpleType';
459
+					$this->simpleTypes[$attrs['name']]['phpType'] = 'scalar';
460 460
 				} else {
461 461
 					$name = $this->CreateTypeName($this->currentComplexType . '_' . $this->currentElement);
462 462
 					$this->xdebug('processing unnamed simpleType for element ' . $this->currentElement . ' named ' . $name);
@@ -484,27 +484,27 @@  discard block
 block discarded – undo
484 484
 		// bring depth down a notch
485 485
 		$this->depth--;
486 486
 		// position of current element is equal to the last value left in depth_array for my depth
487
-		if(isset($this->depth_array[$this->depth])){
487
+		if (isset($this->depth_array[$this->depth])) {
488 488
         	$pos = $this->depth_array[$this->depth];
489 489
         }
490 490
 		// get element prefix
491
-		if ($prefix = $this->getPrefix($name)){
491
+		if ($prefix = $this->getPrefix($name)) {
492 492
 			// get unqualified name
493 493
 			$name = $this->getLocalPart($name);
494 494
 		} else {
495 495
         	$prefix = '';
496 496
         }
497 497
 		// move on...
498
-		if($name == 'complexType'){
498
+		if ($name == 'complexType') {
499 499
 			$this->xdebug('done processing complexType ' . ($this->currentComplexType ? $this->currentComplexType : '(unknown)'));
500 500
 			$this->xdebug($this->varDump($this->complexTypes[$this->currentComplexType]));
501 501
 			$this->currentComplexType = array_pop($this->complexTypeStack);
502 502
 		}
503
-		if($name == 'element'){
503
+		if ($name == 'element') {
504 504
 			$this->xdebug('done processing element ' . ($this->currentElement ? $this->currentElement : '(unknown)'));
505 505
 			$this->currentElement = array_pop($this->elementStack);
506 506
 		}
507
-		if($name == 'simpleType'){
507
+		if ($name == 'simpleType') {
508 508
 			$this->xdebug('done processing simpleType ' . ($this->currentSimpleType ? $this->currentSimpleType : '(unknown)'));
509 509
 			$this->xdebug($this->varDump($this->simpleTypes[$this->currentSimpleType]));
510 510
 			$this->currentSimpleType = array_pop($this->simpleTypeStack);
@@ -518,7 +518,7 @@  discard block
 block discarded – undo
518 518
 	* @param    string $data element content
519 519
 	* @access   private
520 520
 	*/
521
-	public function schemaCharacterData($parser, $data){
521
+	public function schemaCharacterData($parser, $data) {
522 522
 		$pos = $this->depth_array[$this->depth - 1];
523 523
 		$this->message[$pos]['cdata'] .= $data;
524 524
 	}
@@ -528,13 +528,13 @@  discard block
 block discarded – undo
528 528
 	*
529 529
 	* @access   public
530 530
 	*/
531
-	public function serializeSchema(){
531
+	public function serializeSchema() {
532 532
 
533 533
 		$schemaPrefix = $this->getPrefixFromNamespace($this->XMLSchemaVersion);
534 534
 		$xml = '';
535 535
 		// imports
536 536
 		if (sizeof($this->imports) > 0) {
537
-			foreach($this->imports as $ns => $list) {
537
+			foreach ($this->imports as $ns => $list) {
538 538
 				foreach ($list as $ii) {
539 539
 					if ($ii['location'] != '') {
540 540
 						$xml .= " <$schemaPrefix:import location=\"" . $ii['location'] . '" namespace="' . $ns . "\" />\n";
@@ -545,12 +545,12 @@  discard block
 block discarded – undo
545 545
 			} 
546 546
 		} 
547 547
 		// complex types
548
-		foreach($this->complexTypes as $typeName => $attrs){
548
+		foreach ($this->complexTypes as $typeName => $attrs) {
549 549
 			$contentStr = '';
550 550
 			// serialize child elements
551
-			if(isset($attrs['elements']) && (count($attrs['elements']) > 0)){
552
-				foreach($attrs['elements'] as $element => $eParts){
553
-					if(isset($eParts['ref'])){
551
+			if (isset($attrs['elements']) && (count($attrs['elements']) > 0)) {
552
+				foreach ($attrs['elements'] as $element => $eParts) {
553
+					if (isset($eParts['ref'])) {
554 554
 						$contentStr .= "   <$schemaPrefix:element ref=\"$element\"/>\n";
555 555
 					} else {
556 556
 						$contentStr .= "   <$schemaPrefix:element name=\"$element\" type=\"" . $this->contractQName($eParts['type']) . "\"";
@@ -565,19 +565,19 @@  discard block
 block discarded – undo
565 565
 				}
566 566
 				// compositor wraps elements
567 567
 				if (isset($attrs['compositor']) && ($attrs['compositor'] != '')) {
568
-					$contentStr = "  <$schemaPrefix:$attrs[compositor]>\n".$contentStr."  </$schemaPrefix:$attrs[compositor]>\n";
568
+					$contentStr = "  <$schemaPrefix:$attrs[compositor]>\n" . $contentStr . "  </$schemaPrefix:$attrs[compositor]>\n";
569 569
 				}
570 570
 			}
571 571
 			// attributes
572
-			if(isset($attrs['attrs']) && (count($attrs['attrs']) >= 1)){
573
-				foreach($attrs['attrs'] as $attr => $aParts){
572
+			if (isset($attrs['attrs']) && (count($attrs['attrs']) >= 1)) {
573
+				foreach ($attrs['attrs'] as $attr => $aParts) {
574 574
 					$contentStr .= "    <$schemaPrefix:attribute";
575 575
 					foreach ($aParts as $a => $v) {
576 576
 						if ($a == 'ref' || $a == 'type') {
577
-							$contentStr .= " $a=\"".$this->contractQName($v).'"';
577
+							$contentStr .= " $a=\"" . $this->contractQName($v) . '"';
578 578
 						} elseif ($a == 'http://schemas.xmlsoap.org/wsdl/:arrayType') {
579 579
 							$this->usedNamespaces['wsdl'] = $this->namespaces['wsdl'];
580
-							$contentStr .= ' wsdl:arrayType="'.$this->contractQName($v).'"';
580
+							$contentStr .= ' wsdl:arrayType="' . $this->contractQName($v) . '"';
581 581
 						} else {
582 582
 							$contentStr .= " $a=\"$v\"";
583 583
 						}
@@ -586,25 +586,25 @@  discard block
 block discarded – undo
586 586
 				}
587 587
 			}
588 588
 			// if restriction
589
-			if (isset($attrs['restrictionBase']) && $attrs['restrictionBase'] != ''){
590
-				$contentStr = "   <$schemaPrefix:restriction base=\"".$this->contractQName($attrs['restrictionBase'])."\">\n".$contentStr."   </$schemaPrefix:restriction>\n";
589
+			if (isset($attrs['restrictionBase']) && $attrs['restrictionBase'] != '') {
590
+				$contentStr = "   <$schemaPrefix:restriction base=\"" . $this->contractQName($attrs['restrictionBase']) . "\">\n" . $contentStr . "   </$schemaPrefix:restriction>\n";
591 591
 				// complex or simple content
592
-				if ((isset($attrs['elements']) && count($attrs['elements']) > 0) || (isset($attrs['attrs']) && count($attrs['attrs']) > 0)){
593
-					$contentStr = "  <$schemaPrefix:complexContent>\n".$contentStr."  </$schemaPrefix:complexContent>\n";
592
+				if ((isset($attrs['elements']) && count($attrs['elements']) > 0) || (isset($attrs['attrs']) && count($attrs['attrs']) > 0)) {
593
+					$contentStr = "  <$schemaPrefix:complexContent>\n" . $contentStr . "  </$schemaPrefix:complexContent>\n";
594 594
 				}
595 595
 			}
596 596
 			// finalize complex type
597
-			if($contentStr != ''){
598
-				$contentStr = " <$schemaPrefix:complexType name=\"$typeName\">\n".$contentStr." </$schemaPrefix:complexType>\n";
597
+			if ($contentStr != '') {
598
+				$contentStr = " <$schemaPrefix:complexType name=\"$typeName\">\n" . $contentStr . " </$schemaPrefix:complexType>\n";
599 599
 			} else {
600 600
 				$contentStr = " <$schemaPrefix:complexType name=\"$typeName\"/>\n";
601 601
 			}
602 602
 			$xml .= $contentStr;
603 603
 		}
604 604
 		// simple types
605
-		if(isset($this->simpleTypes) && count($this->simpleTypes) > 0){
606
-			foreach($this->simpleTypes as $typeName => $eParts){
607
-				$xml .= " <$schemaPrefix:simpleType name=\"$typeName\">\n  <$schemaPrefix:restriction base=\"".$this->contractQName($eParts['type'])."\">\n";
605
+		if (isset($this->simpleTypes) && count($this->simpleTypes) > 0) {
606
+			foreach ($this->simpleTypes as $typeName => $eParts) {
607
+				$xml .= " <$schemaPrefix:simpleType name=\"$typeName\">\n  <$schemaPrefix:restriction base=\"" . $this->contractQName($eParts['type']) . "\">\n";
608 608
 				if (isset($eParts['enumeration'])) {
609 609
 					foreach ($eParts['enumeration'] as $e) {
610 610
 						$xml .= "  <$schemaPrefix:enumeration value=\"$e\"/>\n";
@@ -614,15 +614,15 @@  discard block
 block discarded – undo
614 614
 			}
615 615
 		}
616 616
 		// elements
617
-		if(isset($this->elements) && count($this->elements) > 0){
618
-			foreach($this->elements as $element => $eParts){
619
-				$xml .= " <$schemaPrefix:element name=\"$element\" type=\"".$this->contractQName($eParts['type'])."\"/>\n";
617
+		if (isset($this->elements) && count($this->elements) > 0) {
618
+			foreach ($this->elements as $element => $eParts) {
619
+				$xml .= " <$schemaPrefix:element name=\"$element\" type=\"" . $this->contractQName($eParts['type']) . "\"/>\n";
620 620
 			}
621 621
 		}
622 622
 		// attributes
623
-		if(isset($this->attributes) && count($this->attributes) > 0){
624
-			foreach($this->attributes as $attr => $aParts){
625
-				$xml .= " <$schemaPrefix:attribute name=\"$attr\" type=\"".$this->contractQName($aParts['type'])."\"\n/>";
623
+		if (isset($this->attributes) && count($this->attributes) > 0) {
624
+			foreach ($this->attributes as $attr => $aParts) {
625
+				$xml .= " <$schemaPrefix:attribute name=\"$attr\" type=\"" . $this->contractQName($aParts['type']) . "\"\n/>";
626 626
 			}
627 627
 		}
628 628
 		// finish 'er up
@@ -636,7 +636,7 @@  discard block
 block discarded – undo
636 636
 		foreach (array_diff($this->usedNamespaces, $this->enclosingNamespaces) as $nsp => $ns) {
637 637
 			$el .= " xmlns:$nsp=\"$ns\"";
638 638
 		}
639
-		$xml = $el . ">\n".$xml."</$schemaPrefix:schema>\n";
639
+		$xml = $el . ">\n" . $xml . "</$schemaPrefix:schema>\n";
640 640
 		return $xml;
641 641
 	}
642 642
 
@@ -646,8 +646,8 @@  discard block
 block discarded – undo
646 646
 	* @param    string $string debug data
647 647
 	* @access   private
648 648
 	*/
649
-	public function xdebug($string){
650
-		$this->debug('<' . $this->schemaTargetNamespace . '> '.$string);
649
+	public function xdebug($string) {
650
+		$this->debug('<' . $this->schemaTargetNamespace . '> ' . $string);
651 651
 	}
652 652
 
653 653
     /**
@@ -662,11 +662,11 @@  discard block
 block discarded – undo
662 662
     * @access public
663 663
     * @deprecated
664 664
     */
665
-	public function getPHPType($type,$ns){
666
-		if(isset($this->typemap[$ns][$type])){
665
+	public function getPHPType($type, $ns) {
666
+		if (isset($this->typemap[$ns][$type])) {
667 667
 			//print "found type '$type' and ns $ns in typemap<br>";
668 668
 			return $this->typemap[$ns][$type];
669
-		} elseif(isset($this->complexTypes[$type])){
669
+		} elseif (isset($this->complexTypes[$type])) {
670 670
 			//print "getting type '$type' and ns $ns from complexTypes array<br>";
671 671
 			return $this->complexTypes[$type]['phpType'];
672 672
 		}
@@ -695,7 +695,7 @@  discard block
 block discarded – undo
695 695
     * @see addSimpleType
696 696
     * @see addElement
697 697
     */
698
-	public function getTypeDef($type){
698
+	public function getTypeDef($type) {
699 699
 		if (substr($type, -1) == '^') {
700 700
 			$is_element = 1;
701 701
 			$type = substr($type, 0, -1);
@@ -703,10 +703,10 @@  discard block
 block discarded – undo
703 703
 			$is_element = 0;
704 704
 		}
705 705
 
706
-		if((! $is_element) && isset($this->complexTypes[$type])){
706
+		if ((!$is_element) && isset($this->complexTypes[$type])) {
707 707
 			$this->xdebug("in getTypeDef, found complexType $type");
708 708
 			return $this->complexTypes[$type];
709
-		} elseif((! $is_element) && isset($this->simpleTypes[$type])){
709
+		} elseif ((!$is_element) && isset($this->simpleTypes[$type])) {
710 710
 			$this->xdebug("in getTypeDef, found simpleType $type");
711 711
 			if (!isset($this->simpleTypes[$type]['phpType'])) {
712 712
 				$uqType = substr($this->simpleTypes[$type]['type'], strrpos($this->simpleTypes[$type]['type'], ':') + 1);
@@ -724,7 +724,7 @@  discard block
 block discarded – undo
724 724
 				}
725 725
 			}
726 726
 			return $this->simpleTypes[$type];
727
-		} elseif(isset($this->elements[$type])){
727
+		} elseif (isset($this->elements[$type])) {
728 728
 			$this->xdebug("in getTypeDef, found element $type");
729 729
 			if (!isset($this->elements[$type]['phpType'])) {
730 730
 				// get info for type to tack onto the element
@@ -749,7 +749,7 @@  discard block
 block discarded – undo
749 749
 				}
750 750
 			}
751 751
 			return $this->elements[$type];
752
-		} elseif(isset($this->attributes[$type])){
752
+		} elseif (isset($this->attributes[$type])) {
753 753
 			$this->xdebug("in getTypeDef, found attribute $type");
754 754
 			return $this->attributes[$type];
755 755
 		} elseif (preg_match('/_ContainedType$/', $type)) {
@@ -771,23 +771,23 @@  discard block
 block discarded – undo
771 771
     * @access public
772 772
     * @deprecated
773 773
     */
774
-    public function serializeTypeDef($type){
774
+    public function serializeTypeDef($type) {
775 775
     	//print "in sTD() for type $type<br>";
776
-	if($typeDef = $this->getTypeDef($type)){
777
-		$str .= '<'.$type;
778
-	    if(is_array($typeDef['attrs'])){
779
-		foreach($typeDef['attrs'] as $attName => $data){
780
-		    $str .= " $attName=\"{type = ".$data['type']."}\"";
776
+	if ($typeDef = $this->getTypeDef($type)) {
777
+		$str .= '<' . $type;
778
+	    if (is_array($typeDef['attrs'])) {
779
+		foreach ($typeDef['attrs'] as $attName => $data) {
780
+		    $str .= " $attName=\"{type = " . $data['type'] . "}\"";
781 781
 		}
782 782
 	    }
783
-	    $str .= " xmlns=\"".$this->schema['targetNamespace']."\"";
784
-	    if(count($typeDef['elements']) > 0){
783
+	    $str .= " xmlns=\"" . $this->schema['targetNamespace'] . "\"";
784
+	    if (count($typeDef['elements']) > 0) {
785 785
 		$str .= ">";
786
-		foreach($typeDef['elements'] as $element => $eData){
786
+		foreach ($typeDef['elements'] as $element => $eData) {
787 787
 		    $str .= $this->serializeTypeDef($element);
788 788
 		}
789 789
 		$str .= "</$type>";
790
-	    } elseif($typeDef['typeClass'] == 'element') {
790
+	    } elseif ($typeDef['typeClass'] == 'element') {
791 791
 		$str .= "></$type>";
792 792
 	    } else {
793 793
 		$str .= "/>";
@@ -807,25 +807,25 @@  discard block
 block discarded – undo
807 807
     * @access public
808 808
     * @deprecated
809 809
 	*/
810
-	public function typeToForm($name,$type){
810
+	public function typeToForm($name, $type) {
811 811
 		// get typedef
812
-		if($typeDef = $this->getTypeDef($type)){
812
+		if ($typeDef = $this->getTypeDef($type)) {
813 813
 			// if struct
814
-			if($typeDef['phpType'] == 'struct'){
814
+			if ($typeDef['phpType'] == 'struct') {
815 815
 				$buffer .= '<table>';
816
-				foreach($typeDef['elements'] as $child => $childDef){
816
+				foreach ($typeDef['elements'] as $child => $childDef) {
817 817
 					$buffer .= "
818
-					<tr><td align='right'>$childDef[name] (type: ".$this->getLocalPart($childDef['type'])."):</td>
819
-					<td><input type='text' name='parameters[".$name."][$childDef[name]]'></td></tr>";
818
+					<tr><td align='right'>$childDef[name] (type: " . $this->getLocalPart($childDef['type']) . "):</td>
819
+					<td><input type='text' name='parameters[".$name . "][$childDef[name]]'></td></tr>";
820 820
 				}
821 821
 				$buffer .= '</table>';
822 822
 			// if array
823
-			} elseif($typeDef['phpType'] == 'array'){
823
+			} elseif ($typeDef['phpType'] == 'array') {
824 824
 				$buffer .= '<table>';
825
-				for($i=0;$i < 3; $i++){
825
+				for ($i = 0; $i < 3; $i++) {
826 826
 					$buffer .= "
827 827
 					<tr><td align='right'>array item (type: $typeDef[arrayType]):</td>
828
-					<td><input type='text' name='parameters[".$name."][]'></td></tr>";
828
+					<td><input type='text' name='parameters[" . $name . "][]'></td></tr>";
829 829
 				}
830 830
 				$buffer .= '</table>';
831 831
 			// if scalar
@@ -879,7 +879,7 @@  discard block
 block discarded – undo
879 879
 	* @access public
880 880
 	* @see getTypeDef
881 881
 	*/
882
-	public function addComplexType($name,$typeClass='complexType',$phpType='array',$compositor='',$restrictionBase='',$elements=array(),$attrs=array(),$arrayType=''){
882
+	public function addComplexType($name, $typeClass = 'complexType', $phpType = 'array', $compositor = '', $restrictionBase = '', $elements = array(), $attrs = array(), $arrayType = '') {
883 883
 		$this->complexTypes[$name] = array(
884 884
 	    'name'		=> $name,
885 885
 	    'typeClass'	=> $typeClass,
@@ -907,7 +907,7 @@  discard block
 block discarded – undo
907 907
 	* @see nusoap_xmlschema
908 908
 	* @see getTypeDef
909 909
 	*/
910
-	public function addSimpleType($name, $restrictionBase='', $typeClass='simpleType', $phpType='scalar', $enumeration=array()) {
910
+	public function addSimpleType($name, $restrictionBase = '', $typeClass = 'simpleType', $phpType = 'scalar', $enumeration = array()) {
911 911
 		$this->simpleTypes[$name] = array(
912 912
 	    'name'			=> $name,
913 913
 	    'typeClass'		=> $typeClass,
@@ -928,14 +928,14 @@  discard block
 block discarded – undo
928 928
 	* @access public
929 929
 	*/
930 930
 	public function addElement($attrs) {
931
-		if (! $this->getPrefix($attrs['type'])) {
931
+		if (!$this->getPrefix($attrs['type'])) {
932 932
 			$attrs['type'] = $this->schemaTargetNamespace . ':' . $attrs['type'];
933 933
 		}
934
-		$this->elements[ $attrs['name'] ] = $attrs;
935
-		$this->elements[ $attrs['name'] ]['typeClass'] = 'element';
934
+		$this->elements[$attrs['name']] = $attrs;
935
+		$this->elements[$attrs['name']]['typeClass'] = 'element';
936 936
 		
937 937
 		$this->xdebug("addElement " . $attrs['name']);
938
-		$this->appendDebug($this->varDump($this->elements[ $attrs['name'] ]));
938
+		$this->appendDebug($this->varDump($this->elements[$attrs['name']]));
939 939
 	}
940 940
 }
941 941
 
Please login to merge, or discard this patch.
libraries/nusoap/nusoapmime.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -447,7 +447,7 @@
 block discarded – undo
447 447
 	*
448 448
 	* @param	array	$headers	The HTTP headers
449 449
 	* @param	string	$data		unprocessed request data from client
450
-	* @return	mixed	value of the message, decoded into a PHP type
450
+	* @return	false|null	value of the message, decoded into a PHP type
451 451
 	* @access   private
452 452
 	*/
453 453
     function parseRequest($headers, $data) {
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
 	* @access public
87 87
 	*/
88 88
 	public function addAttachment($data, $filename = '', $contenttype = 'application/octet-stream', $cid = false) {
89
-		if (! $cid) {
89
+		if (!$cid) {
90 90
 			$cid = md5(uniqid(time()));
91 91
 		}
92 92
 
@@ -316,7 +316,7 @@  discard block
 block discarded – undo
316 316
 	* @access public
317 317
 	*/
318 318
 	public function addAttachment($data, $filename = '', $contenttype = 'application/octet-stream', $cid = false) {
319
-		if (! $cid) {
319
+		if (!$cid) {
320 320
 			$cid = md5(uniqid(time()));
321 321
 		}
322 322
 
Please login to merge, or discard this patch.
Indentation   +112 added lines, -112 removed lines patch added patch discarded remove patch
@@ -71,20 +71,20 @@  discard block
 block discarded – undo
71 71
 	var $mimeContentType;
72 72
 	
73 73
 	/**
74
-	* adds a MIME attachment to the current request.
75
-	*
76
-	* If the $data parameter contains an empty string, this method will read
77
-	* the contents of the file named by the $filename parameter.
78
-	*
79
-	* If the $cid parameter is false, this method will generate the cid.
80
-	*
81
-	* @param string $data The data of the attachment
82
-	* @param string $filename The filename of the attachment (default is empty string)
83
-	* @param string $contenttype The MIME Content-Type of the attachment (default is application/octet-stream)
84
-	* @param string $cid The content-id (cid) of the attachment (default is false)
85
-	* @return string The content-id (cid) of the attachment
86
-	* @access public
87
-	*/
74
+	 * adds a MIME attachment to the current request.
75
+	 *
76
+	 * If the $data parameter contains an empty string, this method will read
77
+	 * the contents of the file named by the $filename parameter.
78
+	 *
79
+	 * If the $cid parameter is false, this method will generate the cid.
80
+	 *
81
+	 * @param string $data The data of the attachment
82
+	 * @param string $filename The filename of the attachment (default is empty string)
83
+	 * @param string $contenttype The MIME Content-Type of the attachment (default is application/octet-stream)
84
+	 * @param string $cid The content-id (cid) of the attachment (default is false)
85
+	 * @return string The content-id (cid) of the attachment
86
+	 * @access public
87
+	 */
88 88
 	public function addAttachment($data, $filename = '', $contenttype = 'application/octet-stream', $cid = false) {
89 89
 		if (! $cid) {
90 90
 			$cid = md5(uniqid(time()));
@@ -101,35 +101,35 @@  discard block
 block discarded – undo
101 101
 	}
102 102
 
103 103
 	/**
104
-	* clears the MIME attachments for the current request.
105
-	*
106
-	* @access public
107
-	*/
104
+	 * clears the MIME attachments for the current request.
105
+	 *
106
+	 * @access public
107
+	 */
108 108
 	public function clearAttachments() {
109 109
 		$this->requestAttachments = array();
110 110
 	}
111 111
 
112 112
 	/**
113
-	* gets the MIME attachments from the current response.
114
-	*
115
-	* Each array element in the return is an associative array with keys
116
-	* data, filename, contenttype, cid.  These keys correspond to the parameters
117
-	* for addAttachment.
118
-	*
119
-	* @return array The attachments.
120
-	* @access public
121
-	*/
113
+	 * gets the MIME attachments from the current response.
114
+	 *
115
+	 * Each array element in the return is an associative array with keys
116
+	 * data, filename, contenttype, cid.  These keys correspond to the parameters
117
+	 * for addAttachment.
118
+	 *
119
+	 * @return array The attachments.
120
+	 * @access public
121
+	 */
122 122
 	public function getAttachments() {
123 123
 		return $this->responseAttachments;
124 124
 	}
125 125
 
126 126
 	/**
127
-	* gets the HTTP body for the current request.
128
-	*
129
-	* @param string $soapmsg The SOAP payload
130
-	* @return string The HTTP body, which includes the SOAP payload
131
-	* @access private
132
-	*/
127
+	 * gets the HTTP body for the current request.
128
+	 *
129
+	 * @param string $soapmsg The SOAP payload
130
+	 * @return string The HTTP body, which includes the SOAP payload
131
+	 * @access private
132
+	 */
133 133
 	public function getHTTPBody($soapmsg) {
134 134
 		if (count($this->requestAttachments) > 0) {
135 135
 			$params['content_type'] = 'multipart/related; type="text/xml"';
@@ -182,13 +182,13 @@  discard block
 block discarded – undo
182 182
 	}
183 183
 	
184 184
 	/**
185
-	* gets the HTTP content type for the current request.
186
-	*
187
-	* Note: getHTTPBody must be called before this.
188
-	*
189
-	* @return string the HTTP content type for the current request.
190
-	* @access private
191
-	*/
185
+	 * gets the HTTP content type for the current request.
186
+	 *
187
+	 * Note: getHTTPBody must be called before this.
188
+	 *
189
+	 * @return string the HTTP content type for the current request.
190
+	 * @access private
191
+	 */
192 192
 	public function getHTTPContentType() {
193 193
 		if (count($this->requestAttachments) > 0) {
194 194
 			return $this->mimeContentType;
@@ -197,14 +197,14 @@  discard block
 block discarded – undo
197 197
 	}
198 198
 	
199 199
 	/**
200
-	* gets the HTTP content type charset for the current request.
201
-	* returns false for non-text content types.
202
-	*
203
-	* Note: getHTTPBody must be called before this.
204
-	*
205
-	* @return string the HTTP content type charset for the current request.
206
-	* @access private
207
-	*/
200
+	 * gets the HTTP content type charset for the current request.
201
+	 * returns false for non-text content types.
202
+	 *
203
+	 * Note: getHTTPBody must be called before this.
204
+	 *
205
+	 * @return string the HTTP content type charset for the current request.
206
+	 * @access private
207
+	 */
208 208
 	public function getHTTPContentTypeCharset() {
209 209
 		if (count($this->requestAttachments) > 0) {
210 210
 			return false;
@@ -213,14 +213,14 @@  discard block
 block discarded – undo
213 213
 	}
214 214
 
215 215
 	/**
216
-	* processes SOAP message returned from server
217
-	*
218
-	* @param	array	$headers	The HTTP headers
219
-	* @param	string	$data		unprocessed response data from server
220
-	* @return	mixed	value of the message, decoded into a PHP type
221
-	* @access   private
222
-	*/
223
-    public function parseResponse($headers, $data) {
216
+	 * processes SOAP message returned from server
217
+	 *
218
+	 * @param	array	$headers	The HTTP headers
219
+	 * @param	string	$data		unprocessed response data from server
220
+	 * @return	mixed	value of the message, decoded into a PHP type
221
+	 * @access   private
222
+	 */
223
+	public function parseResponse($headers, $data) {
224 224
 		$this->debug('Entering parseResponse() for payload of length ' . strlen($data) . ' and type of ' . $headers['content-type']);
225 225
 		$this->responseAttachments = array();
226 226
 		if (strstr($headers['content-type'], 'multipart/related')) {
@@ -301,20 +301,20 @@  discard block
 block discarded – undo
301 301
 	var $mimeContentType;
302 302
 	
303 303
 	/**
304
-	* adds a MIME attachment to the current response.
305
-	*
306
-	* If the $data parameter contains an empty string, this method will read
307
-	* the contents of the file named by the $filename parameter.
308
-	*
309
-	* If the $cid parameter is false, this method will generate the cid.
310
-	*
311
-	* @param string $data The data of the attachment
312
-	* @param string $filename The filename of the attachment (default is empty string)
313
-	* @param string $contenttype The MIME Content-Type of the attachment (default is application/octet-stream)
314
-	* @param string $cid The content-id (cid) of the attachment (default is false)
315
-	* @return string The content-id (cid) of the attachment
316
-	* @access public
317
-	*/
304
+	 * adds a MIME attachment to the current response.
305
+	 *
306
+	 * If the $data parameter contains an empty string, this method will read
307
+	 * the contents of the file named by the $filename parameter.
308
+	 *
309
+	 * If the $cid parameter is false, this method will generate the cid.
310
+	 *
311
+	 * @param string $data The data of the attachment
312
+	 * @param string $filename The filename of the attachment (default is empty string)
313
+	 * @param string $contenttype The MIME Content-Type of the attachment (default is application/octet-stream)
314
+	 * @param string $cid The content-id (cid) of the attachment (default is false)
315
+	 * @return string The content-id (cid) of the attachment
316
+	 * @access public
317
+	 */
318 318
 	public function addAttachment($data, $filename = '', $contenttype = 'application/octet-stream', $cid = false) {
319 319
 		if (! $cid) {
320 320
 			$cid = md5(uniqid(time()));
@@ -331,35 +331,35 @@  discard block
 block discarded – undo
331 331
 	}
332 332
 
333 333
 	/**
334
-	* clears the MIME attachments for the current response.
335
-	*
336
-	* @access public
337
-	*/
334
+	 * clears the MIME attachments for the current response.
335
+	 *
336
+	 * @access public
337
+	 */
338 338
 	public function clearAttachments() {
339 339
 		$this->responseAttachments = array();
340 340
 	}
341 341
 
342 342
 	/**
343
-	* gets the MIME attachments from the current request.
344
-	*
345
-	* Each array element in the return is an associative array with keys
346
-	* data, filename, contenttype, cid.  These keys correspond to the parameters
347
-	* for addAttachment.
348
-	*
349
-	* @return array The attachments.
350
-	* @access public
351
-	*/
343
+	 * gets the MIME attachments from the current request.
344
+	 *
345
+	 * Each array element in the return is an associative array with keys
346
+	 * data, filename, contenttype, cid.  These keys correspond to the parameters
347
+	 * for addAttachment.
348
+	 *
349
+	 * @return array The attachments.
350
+	 * @access public
351
+	 */
352 352
 	public function getAttachments() {
353 353
 		return $this->requestAttachments;
354 354
 	}
355 355
 
356 356
 	/**
357
-	* gets the HTTP body for the current response.
358
-	*
359
-	* @param string $soapmsg The SOAP payload
360
-	* @return string The HTTP body, which includes the SOAP payload
361
-	* @access private
362
-	*/
357
+	 * gets the HTTP body for the current response.
358
+	 *
359
+	 * @param string $soapmsg The SOAP payload
360
+	 * @return string The HTTP body, which includes the SOAP payload
361
+	 * @access private
362
+	 */
363 363
 	public function getHTTPBody($soapmsg) {
364 364
 		if (count($this->responseAttachments) > 0) {
365 365
 			$params['content_type'] = 'multipart/related; type="text/xml"';
@@ -412,13 +412,13 @@  discard block
 block discarded – undo
412 412
 	}
413 413
 	
414 414
 	/**
415
-	* gets the HTTP content type for the current response.
416
-	*
417
-	* Note: getHTTPBody must be called before this.
418
-	*
419
-	* @return string the HTTP content type for the current response.
420
-	* @access private
421
-	*/
415
+	 * gets the HTTP content type for the current response.
416
+	 *
417
+	 * Note: getHTTPBody must be called before this.
418
+	 *
419
+	 * @return string the HTTP content type for the current response.
420
+	 * @access private
421
+	 */
422 422
 	public function getHTTPContentType() {
423 423
 		if (count($this->responseAttachments) > 0) {
424 424
 			return $this->mimeContentType;
@@ -427,14 +427,14 @@  discard block
 block discarded – undo
427 427
 	}
428 428
 	
429 429
 	/**
430
-	* gets the HTTP content type charset for the current response.
431
-	* returns false for non-text content types.
432
-	*
433
-	* Note: getHTTPBody must be called before this.
434
-	*
435
-	* @return string the HTTP content type charset for the current response.
436
-	* @access private
437
-	*/
430
+	 * gets the HTTP content type charset for the current response.
431
+	 * returns false for non-text content types.
432
+	 *
433
+	 * Note: getHTTPBody must be called before this.
434
+	 *
435
+	 * @return string the HTTP content type charset for the current response.
436
+	 * @access private
437
+	 */
438 438
 	public function getHTTPContentTypeCharset() {
439 439
 		if (count($this->responseAttachments) > 0) {
440 440
 			return false;
@@ -443,14 +443,14 @@  discard block
 block discarded – undo
443 443
 	}
444 444
 
445 445
 	/**
446
-	* processes SOAP message received from client
447
-	*
448
-	* @param	array	$headers	The HTTP headers
449
-	* @param	string	$data		unprocessed request data from client
450
-	* @return	mixed	value of the message, decoded into a PHP type
451
-	* @access   private
452
-	*/
453
-    public function parseRequest($headers, $data) {
446
+	 * processes SOAP message received from client
447
+	 *
448
+	 * @param	array	$headers	The HTTP headers
449
+	 * @param	string	$data		unprocessed request data from client
450
+	 * @return	mixed	value of the message, decoded into a PHP type
451
+	 * @access   private
452
+	 */
453
+	public function parseRequest($headers, $data) {
454 454
 		$this->debug('Entering parseRequest() for payload of length ' . strlen($data) . ' and type of ' . $headers['content-type']);
455 455
 		$this->requestAttachments = array();
456 456
 		if (strstr($headers['content-type'], 'multipart/related')) {
Please login to merge, or discard this patch.
libraries/restler/restler.php 4 patches
Doc Comments   +21 added lines, -4 removed lines patch added patch discarded remove patch
@@ -268,9 +268,9 @@  discard block
 block discarded – undo
268 268
      *
269 269
      * All the protected methods that do not start with _ (underscore)
270 270
      * will exposed as protected api which will require authentication
271
-     * @param string $class name of the service class
272
-     * @param string $basePath optional url prefix for mapping, uses
271
+     * @param string $base_path optional url prefix for mapping, uses
273 272
      * lowercase version of the class name when not specified
273
+     * @param string $class_name
274 274
      * @throws Exception when supplied with invalid class name
275 275
      */
276 276
     public function addAPIClass($class_name, $base_path = null)
@@ -322,8 +322,8 @@  discard block
 block discarded – undo
322 322
 
323 323
     /**
324 324
      * Convenience method to respond with an error message
325
-     * @param int $statusCode http error code
326
-     * @param string $errorMessage optional custom error message
325
+     * @param int $status_code http error code
326
+     * @param string $error_message optional custom error message
327 327
      */
328 328
     public function handleError($status_code, $error_message = null)
329 329
     {
@@ -916,6 +916,10 @@  discard block
 block discarded – undo
916 916
 {
917 917
 
918 918
 
919
+    /**
920
+     * @param integer $http_status_code
921
+     * @param string $error_message
922
+     */
919 923
     public function __construct($http_status_code, $error_message = null)
920 924
     {
921 925
         parent::__construct($error_message, $http_status_code);
@@ -1033,12 +1037,14 @@  discard block
 block discarded – undo
1033 1037
     /**
1034 1038
      * Set the selected MIME type
1035 1039
      * @param string $mime MIME type
1040
+     * @return void
1036 1041
      */
1037 1042
     public function setMIME($mime);
1038 1043
 
1039 1044
 
1040 1045
     /**
1041 1046
      * Get selected MIME type
1047
+     * @return string
1042 1048
      */
1043 1049
     public function getMIME();
1044 1050
 
@@ -1046,6 +1052,7 @@  discard block
 block discarded – undo
1046 1052
     /**
1047 1053
      * Set the selected file extension
1048 1054
      * @param string $extension file extension
1055
+     * @return void
1049 1056
      */
1050 1057
     public function setExtension($extension);
1051 1058
 
@@ -1349,6 +1356,9 @@  discard block
 block discarded – undo
1349 1356
     }
1350 1357
 
1351 1358
 
1359
+    /**
1360
+     * @param string[] $lines
1361
+     */
1352 1362
     private function parseLines($lines)
1353 1363
     {
1354 1364
         foreach ($lines as $line) {
@@ -1398,6 +1408,10 @@  discard block
 block discarded – undo
1398 1408
     }
1399 1409
 
1400 1410
 
1411
+    /**
1412
+     * @param string $param
1413
+     * @param string $value
1414
+     */
1401 1415
     private function setParam($param, $value)
1402 1416
     {
1403 1417
         if ($param == 'param' || $param == 'return') {
@@ -1454,6 +1468,9 @@  discard block
 block discarded – undo
1454 1468
 //
1455 1469
 // ------------------------------------------------------------------
1456 1470
 
1471
+/**
1472
+ * @param string $php_doc_comment
1473
+ */
1457 1474
 function parse_doc($php_doc_comment)
1458 1475
 {
1459 1476
     $p = new DocParser();
Please login to merge, or discard this patch.
Spacing   +7 added lines, -11 removed lines patch added patch discarded remove patch
@@ -472,9 +472,9 @@  discard block
 block discarded – undo
472 472
         header('Content-Type: ' . $this->response_format->getMIME());
473 473
         //.'; charset=utf-8');
474 474
         header("X-Powered-By: Luracast Restler v" . Restler::VERSION);
475
-		if($this->production_mode){
475
+		if ($this->production_mode) {
476 476
 			die($data);
477
-		}else{
477
+		} else {
478 478
 			echo $data;
479 479
 		}
480 480
     }
@@ -649,8 +649,7 @@  discard block
 block discarded – undo
649 649
                 $parts = explode(';q=', trim($accept));
650 650
                 $type = array_shift($parts);
651 651
                 $quality = count($parts) ? 
652
-                    floatval(array_shift($parts)) : 
653
-                    (1000 - $pos) / 1000;
652
+                    floatval(array_shift($parts)) : (1000 - $pos) / 1000;
654 653
                 $acceptList[$type] = $quality;
655 654
             }
656 655
             arsort($acceptList);
@@ -839,8 +838,7 @@  discard block
 block discarded – undo
839 838
                 $position++;
840 839
             }
841 840
             $method_flag = $method->isProtected() ? 
842
-                (isRestlerCompatibilityModeEnabled() ? 2 : 3) : 
843
-                (isset($metadata['protected']) ? 1 : 0);
841
+                (isRestlerCompatibilityModeEnabled() ? 2 : 3) : (isset($metadata['protected']) ? 1 : 0);
844 842
 
845 843
             //take note of the order
846 844
             $call = array(
@@ -873,8 +871,7 @@  discard block
 block discarded – undo
873 871
                     $http_method = 'GET';
874 872
                 }
875 873
                 $url = $base_path
876
-                    . ($method_url == 'index' || $method_url == 'default' ? '' :
877
-                        $method_url);
874
+                    . ($method_url == 'index' || $method_url == 'default' ? '' : $method_url);
878 875
                 $url = rtrim($url, '/');
879 876
                 $this->routes[$http_method][$url] = $call;
880 877
                 foreach ($params as $param) {
@@ -1198,8 +1195,7 @@  discard block
 block discarded – undo
1198 1195
     public function encode($data, $human_readable = false)
1199 1196
     {
1200 1197
         return $human_readable ? 
1201
-            $this->json_format(json_encode(object_to_array($data))) : 
1202
-            json_encode(object_to_array($data));
1198
+            $this->json_format(json_encode(object_to_array($data))) : json_encode(object_to_array($data));
1203 1199
     }
1204 1200
 
1205 1201
 
@@ -1225,7 +1221,7 @@  discard block
 block discarded – undo
1225 1221
                     $message = 'malformed JSON';
1226 1222
                     break;
1227 1223
                 case JSON_ERROR_UTF8:
1228
-                    $message = 'malformed UTF-8 characters, '.
1224
+                    $message = 'malformed UTF-8 characters, ' .
1229 1225
                         'possibly incorrectly encoded';
1230 1226
                     break;
1231 1227
                 default:
Please login to merge, or discard this patch.
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -474,7 +474,7 @@
 block discarded – undo
474 474
         header("X-Powered-By: Luracast Restler v" . Restler::VERSION);
475 475
 		if($this->production_mode){
476 476
 			die($data);
477
-		}else{
477
+		} else{
478 478
 			echo $data;
479 479
 		}
480 480
     }
Please login to merge, or discard this patch.
Indentation   +1299 added lines, -1299 removed lines patch added patch discarded remove patch
@@ -16,883 +16,883 @@  discard block
 block discarded – undo
16 16
  */
17 17
 class Restler
18 18
 {
19
-    // ==================================================================
20
-    //
21
-    // Public variables
22
-    //
23
-    // ------------------------------------------------------------------
24
-
25
-    const VERSION = '2.2.1';
26
-
27
-    /**
28
-     * URL of the currently mapped service
29
-     * @var string
30
-     */
31
-    public $url;
32
-
33
-    /**
34
-     * Http request method of the current request.
35
-     * Any value between [GET, PUT, POST, DELETE]
36
-     * @var string
37
-     */
38
-    public $request_method;
39
-
40
-    /**
41
-     * Requested data format. Instance of the current format class
42
-     * which implements the iFormat interface
43
-     * @var iFormat
44
-     * @example jsonFormat, xmlFormat, yamlFormat etc
45
-     */
46
-    public $request_format;
47
-
48
-    /**
49
-     * Data sent to the service
50
-     * @var array
51
-     */
52
-    public $request_data = array();
53
-
54
-    /**
55
-     * Used in production mode to store the URL Map to disk
56
-     * @var string
57
-     */
58
-    public $cache_dir;
59
-
60
-    /**
61
-     * base directory to locate format and auth files
62
-     * @var string
63
-     */
64
-    public $base_dir;
65
-
66
-    /**
67
-     * Name of an iRespond implementation class
68
-     * @var string
69
-     */
70
-    public $response = 'DefaultResponse';
71
-
72
-    /**
73
-     * Response data format. Instance of the current format class
74
-     * which implements the iFormat interface
75
-     * @var iFormat
76
-     * @example jsonFormat, xmlFormat, yamlFormat etc
77
-     */
78
-    public $response_format;
79
-
80
-    // ==================================================================
81
-    //
82
-    // Private & Protected variables
83
-    //
84
-    // ------------------------------------------------------------------
85
-
86
-    /**
87
-     * When set to false, it will run in debug mode and parse the
88
-     * class files every time to map it to the URL
89
-     * @var boolean
90
-     */
91
-    protected $production_mode;
92
-
93
-    /**
94
-     * Associated array that maps urls to their respective class and method
95
-     * @var array
96
-     */
97
-    protected $routes = array();
98
-
99
-    /**
100
-     * Associated array that maps formats to their respective format class name
101
-     * @var array
102
-     */
103
-    protected $format_map = array();
104
-
105
-    /**
106
-     * Instance of the current api service class
107
-     * @var object
108
-     */
109
-    protected $service_class_instance;
110
-
111
-    /**
112
-     * Name of the api method being called
113
-     * @var string
114
-     */
115
-    protected $service_method;
116
-
117
-    /**
118
-     * list of authentication classes
119
-     * @var array
120
-     */
121
-    protected $auth_classes = array();
122
-
123
-    /**
124
-     * list of error handling classes
125
-     * @var array
126
-     */
127
-    protected $error_classes = array();
128
-
129
-    /**
130
-     * HTTP status codes
131
-     * @var array
132
-     */
133
-    private $codes = array(
134
-        100 => 'Continue',
135
-        101 => 'Switching Protocols',
136
-        200 => 'OK',
137
-        201 => 'Created',
138
-        202 => 'Accepted',
139
-        203 => 'Non-Authoritative Information',
140
-        204 => 'No Content',
141
-        205 => 'Reset Content',
142
-        206 => 'Partial Content',
143
-        300 => 'Multiple Choices',
144
-        301 => 'Moved Permanently',
145
-        302 => 'Found',
146
-        303 => 'See Other',
147
-        304 => 'Not Modified',
148
-        305 => 'Use Proxy',
149
-        306 => '(Unused)',
150
-        307 => 'Temporary Redirect',
151
-        400 => 'Bad Request',
152
-        401 => 'Unauthorized',
153
-        402 => 'Payment Required',
154
-        403 => 'Forbidden',
155
-        404 => 'Not Found',
156
-        405 => 'Method Not Allowed',
157
-        406 => 'Not Acceptable',
158
-        407 => 'Proxy Authentication Required',
159
-        408 => 'Request Timeout',
160
-        409 => 'Conflict',
161
-        410 => 'Gone',
162
-        411 => 'Length Required',
163
-        412 => 'Precondition Failed',
164
-        413 => 'Request Entity Too Large',
165
-        414 => 'Request-URI Too Long',
166
-        415 => 'Unsupported Media Type',
167
-        416 => 'Requested Range Not Satisfiable',
168
-        417 => 'Expectation Failed',
169
-        500 => 'Internal Server Error',
170
-        501 => 'Not Implemented',
171
-        502 => 'Bad Gateway',
172
-        503 => 'Service Unavailable',
173
-        504 => 'Gateway Timeout',
174
-        505 => 'HTTP Version Not Supported'
175
-    );
176
-
177
-    /**
178
-     * Caching of url map is enabled or not
179
-     * @var boolean
180
-     */
181
-    protected $cached;
182
-
183
-    // ==================================================================
184
-    //
185
-    // Public functions
186
-    //
187
-    // ------------------------------------------------------------------
188
-
189
-
190
-    /**
191
-     * Constructor
192
-     * @param boolean $production_mode When set to false, it will run in
193
-     * debug mode and parse the class files every time to map it to the URL
194
-     */
195
-    public function __construct($production_mode = false)
196
-    {
197
-        $this->production_mode = $production_mode;
198
-        $this->cache_dir = getcwd();
199
-        $this->base_dir = RESTLER_PATH;
200
-    }
201
-
202
-
203
-    /**
204
-     * Store the url map cache if needed
205
-     */
206
-    public function __destruct()
207
-    {
208
-        if ($this->production_mode && !($this->cached)) {
209
-            $this->saveCache();
210
-        }
211
-    }
212
-
213
-
214
-    /**
215
-     * Use it in production mode to refresh the url map cache
216
-     */
217
-    public function refreshCache()
218
-    {
219
-        $this->routes = array();
220
-        $this->cached = false;
221
-    }
222
-
223
-
224
-    /**
225
-     * Call this method and pass all the formats that should be
226
-     * supported by the API. Accepts multiple parameters
227
-     * @param string class name of the format class that implements iFormat
228
-     * @example $restler->setSupportedFormats('JsonFormat', 'XmlFormat'...);
229
-     */
230
-    public function setSupportedFormats()
231
-    {
232
-        $args = func_get_args();
233
-        $extensions = array();
234
-        foreach ($args as $class_name) {
235
-            if (!is_string($class_name) || !class_exists($class_name)) {
236
-                throw new Exception("$class_name is not a vaild Format Class.");
237
-            }
238
-            $obj = new $class_name;
239
-            if (!($obj instanceof iFormat)) {
240
-                throw new Exception('Invalid format class; must implement '
241
-                    . 'iFormat interface');
242
-            }
243
-            foreach ($obj->getMIMEMap() as $extension => $mime) {
244
-                if (!isset($this->format_map[$extension])) {
245
-                    $this->format_map[$extension] = $class_name;
246
-                }
247
-                $mime = explode(',', $mime);
248
-                if (!is_array($mime)) {
249
-                    $mime = array($mime);
250
-                }
251
-                foreach ($mime as $value) {
252
-                    if (!isset($this->format_map[$value])) {
253
-                        $this->format_map[$value] = $class_name;
254
-                    }
255
-                }
256
-                $extensions[".$extension"] = true;
257
-            }
258
-        }
259
-        $this->format_map['default'] = $args[0];
260
-        $this->format_map['extensions'] = array_keys($extensions);
261
-    }
262
-
263
-
264
-    /**
265
-     * Add api classes throgh this method. All the public methods
266
-     * that do not start with _ (underscore) will be  will be exposed
267
-     * as the public api by default.
268
-     *
269
-     * All the protected methods that do not start with _ (underscore)
270
-     * will exposed as protected api which will require authentication
271
-     * @param string $class name of the service class
272
-     * @param string $basePath optional url prefix for mapping, uses
273
-     * lowercase version of the class name when not specified
274
-     * @throws Exception when supplied with invalid class name
275
-     */
276
-    public function addAPIClass($class_name, $base_path = null)
277
-    {
278
-        if (!class_exists($class_name)) {
279
-            throw new Exception("API class $class_name is missing.");
280
-        }
281
-        $this->loadCache();
282
-        if (!$this->cached) {
283
-            if (is_null($base_path)) {
284
-                $base_path = strtolower($class_name);
285
-                $index = strrpos($class_name, '\\');
286
-                if ($index !== false) {
287
-                    $base_path = substr($base_path, $index + 1);
288
-                }
289
-            } else {
290
-                $base_path = trim($base_path, '/');
291
-            }
292
-            if (strlen($base_path) > 0) {
293
-                $base_path .= '/';
294
-            }
295
-            $this->generateMap($class_name, $base_path);
296
-        }
297
-    }
298
-
299
-
300
-    /**
301
-     * protected methods will need atleast one authentication class to be set
302
-     * in order to allow that method to be executed
303
-     * @param string $class_name of the authentication class
304
-     * @param string $base_path optional url prefix for mapping
305
-     */
306
-    public function addAuthenticationClass($class_name, $base_path = null)
307
-    {
308
-        $this->auth_classes[] = $class_name;
309
-        $this->addAPIClass($class_name, $base_path);
310
-    }
311
-
312
-
313
-    /**
314
-     * Add class for custom error handling
315
-     * @param string $class_name of the error handling class
316
-     */
317
-    public function addErrorClass($class_name)
318
-    {
319
-        $this->error_classes[] = $class_name;
320
-    }
321
-
322
-
323
-    /**
324
-     * Convenience method to respond with an error message
325
-     * @param int $statusCode http error code
326
-     * @param string $errorMessage optional custom error message
327
-     */
328
-    public function handleError($status_code, $error_message = null)
329
-    {
330
-        $method = "handle$status_code";
331
-        $handled = false;
332
-        foreach ($this->error_classes as $class_name) {
333
-            if (method_exists($class_name, $method)) {
334
-                $obj = new $class_name();
335
-                $obj->restler = $this;
336
-                $obj->$method();
337
-                $handled = true;
338
-            }
339
-        }
340
-        if ($handled) {
341
-            return;
342
-        }
343
-        $message = $this->codes[$status_code]
344
-            . (!$error_message ? '' : ': ' . $error_message);
345
-        $this->setStatus($status_code);
346
-        $responder = new $this->response();
347
-        $responder->restler = $this;
348
-        $this->sendData($responder->__formatError($status_code, $message));
349
-    }
350
-
351
-
352
-    /**
353
-     * An initialize function to allow use of the restler error generation 
354
-     * functions for pre-processing and pre-routing of requests.
355
-     */
356
-    public function init()
357
-    {
358
-        if (empty($this->format_map)) {
359
-            $this->setSupportedFormats('JsonFormat');
360
-        }
361
-        $this->url = $this->getPath();
362
-        $this->request_method = $this->getRequestMethod();
363
-        $this->response_format = $this->getResponseFormat();
364
-        $this->request_format = $this->getRequestFormat();
365
-        if (is_null($this->request_format)) {
366
-            $this->request_format = $this->response_format;
367
-        }
368
-        if ($this->request_method == 'PUT' || $this->request_method == 'POST') {
369
-            $this->request_data = $this->getRequestData();
370
-        }
371
-    }
372
-
373
-
374
-    /**
375
-     * Main function for processing the api request
376
-     * and return the response
377
-     * @throws Exception when the api service class is missing
378
-     * @throws RestException to send error response
379
-     */
380
-    public function handle()
381
-    {
382
-        $this->init();
383
-        $o = $this->mapUrlToMethod();
384
-
385
-        if (!isset($o->class_name)) {
386
-            $this->handleError(404);
387
-        } else {
388
-            try {
389
-                if ($o->method_flag) {
390
-                    $auth_method = '__isAuthenticated';
391
-                    if (!count($this->auth_classes)) {
392
-                        throw new RestException(401);
393
-                    }
394
-                    foreach ($this->auth_classes as $auth_class) {
395
-                        $auth_obj = new $auth_class();
396
-                        $auth_obj->restler = $this;
397
-                        $this->applyClassMetadata($auth_class, $auth_obj, $o);
398
-                        if (!method_exists($auth_obj, $auth_method)) {
399
-                            throw new RestException(401, 'Authentication Class '
400
-                                . 'should implement iAuthenticate');
401
-                        } else if (!$auth_obj->$auth_method()) {
402
-                            throw new RestException(401);
403
-                        }
404
-                    }
405
-                }
406
-                $this->applyClassMetadata(get_class($this->request_format),
407
-                    $this->request_format, $o);
408
-                $pre_process = '_' . $this->request_format->getExtension() . '_'
409
-                    . $o->method_name;
410
-                $this->service_method = $o->method_name;
411
-                if ($o->method_flag == 2) {
412
-                    $o = unprotect($o);
413
-                }
414
-                $object = $this->service_class_instance = new $o->class_name();
415
-                $object->restler = $this;
416
-                if (method_exists($o->class_name, $pre_process)) {
417
-                    call_user_func_array(
418
-                        array($object, $pre_process), $o->arguments
419
-                    );
420
-                }
421
-                switch ($o->method_flag) {
422
-                    case 3:
423
-                        $reflection_method = new ReflectionMethod($object,
424
-                                $o->method_name);
425
-                        $reflection_method->setAccessible(true);
426
-                        $result = $reflection_method->invokeArgs($object,
427
-                            $o->arguments);
428
-                        break;
429
-                    case 2:
430
-                    case 1:
431
-                    default:
432
-                        $result = call_user_func_array(array(
433
-                            $object,
434
-                            $o->method_name), $o->arguments
435
-                        );
436
-                        break;
437
-                }
438
-            } catch (RestException $e) {
439
-                $this->handleError($e->getCode(), $e->getMessage());
440
-            }
441
-        }
442
-        $responder = new $this->response();
443
-        $responder->restler = $this;
444
-        $this->applyClassMetadata($this->response, $responder, $o);
445
-        if (isset($result) && $result !== null) {
446
-            $result = $responder->__formatResponse($result);
447
-            $this->sendData($result);
448
-        }
449
-    }
450
-
451
-
452
-    /**
453
-     * Encodes the response in the prefered format
454
-     * and sends back
455
-     * @param $data array php data
456
-     */
457
-    public function sendData($data)
458
-    {
459
-        $data = $this->response_format->encode($data, 
460
-            !($this->production_mode)
461
-        );
462
-        $post_process = '_' . $this->service_method . '_'
463
-            . $this->response_format->getExtension();
464
-        if (isset($this->service_class_instance)
465
-            && method_exists($this->service_class_instance, $post_process)
466
-        ) {
467
-            $data = call_user_func(array($this->service_class_instance,
468
-                $post_process), $data);
469
-        }
470
-        header("Cache-Control: no-cache, must-revalidate");
471
-        header("Expires: 0");
472
-        header('Content-Type: ' . $this->response_format->getMIME());
473
-        //.'; charset=utf-8');
474
-        header("X-Powered-By: Luracast Restler v" . Restler::VERSION);
19
+	// ==================================================================
20
+	//
21
+	// Public variables
22
+	//
23
+	// ------------------------------------------------------------------
24
+
25
+	const VERSION = '2.2.1';
26
+
27
+	/**
28
+	 * URL of the currently mapped service
29
+	 * @var string
30
+	 */
31
+	public $url;
32
+
33
+	/**
34
+	 * Http request method of the current request.
35
+	 * Any value between [GET, PUT, POST, DELETE]
36
+	 * @var string
37
+	 */
38
+	public $request_method;
39
+
40
+	/**
41
+	 * Requested data format. Instance of the current format class
42
+	 * which implements the iFormat interface
43
+	 * @var iFormat
44
+	 * @example jsonFormat, xmlFormat, yamlFormat etc
45
+	 */
46
+	public $request_format;
47
+
48
+	/**
49
+	 * Data sent to the service
50
+	 * @var array
51
+	 */
52
+	public $request_data = array();
53
+
54
+	/**
55
+	 * Used in production mode to store the URL Map to disk
56
+	 * @var string
57
+	 */
58
+	public $cache_dir;
59
+
60
+	/**
61
+	 * base directory to locate format and auth files
62
+	 * @var string
63
+	 */
64
+	public $base_dir;
65
+
66
+	/**
67
+	 * Name of an iRespond implementation class
68
+	 * @var string
69
+	 */
70
+	public $response = 'DefaultResponse';
71
+
72
+	/**
73
+	 * Response data format. Instance of the current format class
74
+	 * which implements the iFormat interface
75
+	 * @var iFormat
76
+	 * @example jsonFormat, xmlFormat, yamlFormat etc
77
+	 */
78
+	public $response_format;
79
+
80
+	// ==================================================================
81
+	//
82
+	// Private & Protected variables
83
+	//
84
+	// ------------------------------------------------------------------
85
+
86
+	/**
87
+	 * When set to false, it will run in debug mode and parse the
88
+	 * class files every time to map it to the URL
89
+	 * @var boolean
90
+	 */
91
+	protected $production_mode;
92
+
93
+	/**
94
+	 * Associated array that maps urls to their respective class and method
95
+	 * @var array
96
+	 */
97
+	protected $routes = array();
98
+
99
+	/**
100
+	 * Associated array that maps formats to their respective format class name
101
+	 * @var array
102
+	 */
103
+	protected $format_map = array();
104
+
105
+	/**
106
+	 * Instance of the current api service class
107
+	 * @var object
108
+	 */
109
+	protected $service_class_instance;
110
+
111
+	/**
112
+	 * Name of the api method being called
113
+	 * @var string
114
+	 */
115
+	protected $service_method;
116
+
117
+	/**
118
+	 * list of authentication classes
119
+	 * @var array
120
+	 */
121
+	protected $auth_classes = array();
122
+
123
+	/**
124
+	 * list of error handling classes
125
+	 * @var array
126
+	 */
127
+	protected $error_classes = array();
128
+
129
+	/**
130
+	 * HTTP status codes
131
+	 * @var array
132
+	 */
133
+	private $codes = array(
134
+		100 => 'Continue',
135
+		101 => 'Switching Protocols',
136
+		200 => 'OK',
137
+		201 => 'Created',
138
+		202 => 'Accepted',
139
+		203 => 'Non-Authoritative Information',
140
+		204 => 'No Content',
141
+		205 => 'Reset Content',
142
+		206 => 'Partial Content',
143
+		300 => 'Multiple Choices',
144
+		301 => 'Moved Permanently',
145
+		302 => 'Found',
146
+		303 => 'See Other',
147
+		304 => 'Not Modified',
148
+		305 => 'Use Proxy',
149
+		306 => '(Unused)',
150
+		307 => 'Temporary Redirect',
151
+		400 => 'Bad Request',
152
+		401 => 'Unauthorized',
153
+		402 => 'Payment Required',
154
+		403 => 'Forbidden',
155
+		404 => 'Not Found',
156
+		405 => 'Method Not Allowed',
157
+		406 => 'Not Acceptable',
158
+		407 => 'Proxy Authentication Required',
159
+		408 => 'Request Timeout',
160
+		409 => 'Conflict',
161
+		410 => 'Gone',
162
+		411 => 'Length Required',
163
+		412 => 'Precondition Failed',
164
+		413 => 'Request Entity Too Large',
165
+		414 => 'Request-URI Too Long',
166
+		415 => 'Unsupported Media Type',
167
+		416 => 'Requested Range Not Satisfiable',
168
+		417 => 'Expectation Failed',
169
+		500 => 'Internal Server Error',
170
+		501 => 'Not Implemented',
171
+		502 => 'Bad Gateway',
172
+		503 => 'Service Unavailable',
173
+		504 => 'Gateway Timeout',
174
+		505 => 'HTTP Version Not Supported'
175
+	);
176
+
177
+	/**
178
+	 * Caching of url map is enabled or not
179
+	 * @var boolean
180
+	 */
181
+	protected $cached;
182
+
183
+	// ==================================================================
184
+	//
185
+	// Public functions
186
+	//
187
+	// ------------------------------------------------------------------
188
+
189
+
190
+	/**
191
+	 * Constructor
192
+	 * @param boolean $production_mode When set to false, it will run in
193
+	 * debug mode and parse the class files every time to map it to the URL
194
+	 */
195
+	public function __construct($production_mode = false)
196
+	{
197
+		$this->production_mode = $production_mode;
198
+		$this->cache_dir = getcwd();
199
+		$this->base_dir = RESTLER_PATH;
200
+	}
201
+
202
+
203
+	/**
204
+	 * Store the url map cache if needed
205
+	 */
206
+	public function __destruct()
207
+	{
208
+		if ($this->production_mode && !($this->cached)) {
209
+			$this->saveCache();
210
+		}
211
+	}
212
+
213
+
214
+	/**
215
+	 * Use it in production mode to refresh the url map cache
216
+	 */
217
+	public function refreshCache()
218
+	{
219
+		$this->routes = array();
220
+		$this->cached = false;
221
+	}
222
+
223
+
224
+	/**
225
+	 * Call this method and pass all the formats that should be
226
+	 * supported by the API. Accepts multiple parameters
227
+	 * @param string class name of the format class that implements iFormat
228
+	 * @example $restler->setSupportedFormats('JsonFormat', 'XmlFormat'...);
229
+	 */
230
+	public function setSupportedFormats()
231
+	{
232
+		$args = func_get_args();
233
+		$extensions = array();
234
+		foreach ($args as $class_name) {
235
+			if (!is_string($class_name) || !class_exists($class_name)) {
236
+				throw new Exception("$class_name is not a vaild Format Class.");
237
+			}
238
+			$obj = new $class_name;
239
+			if (!($obj instanceof iFormat)) {
240
+				throw new Exception('Invalid format class; must implement '
241
+					. 'iFormat interface');
242
+			}
243
+			foreach ($obj->getMIMEMap() as $extension => $mime) {
244
+				if (!isset($this->format_map[$extension])) {
245
+					$this->format_map[$extension] = $class_name;
246
+				}
247
+				$mime = explode(',', $mime);
248
+				if (!is_array($mime)) {
249
+					$mime = array($mime);
250
+				}
251
+				foreach ($mime as $value) {
252
+					if (!isset($this->format_map[$value])) {
253
+						$this->format_map[$value] = $class_name;
254
+					}
255
+				}
256
+				$extensions[".$extension"] = true;
257
+			}
258
+		}
259
+		$this->format_map['default'] = $args[0];
260
+		$this->format_map['extensions'] = array_keys($extensions);
261
+	}
262
+
263
+
264
+	/**
265
+	 * Add api classes throgh this method. All the public methods
266
+	 * that do not start with _ (underscore) will be  will be exposed
267
+	 * as the public api by default.
268
+	 *
269
+	 * All the protected methods that do not start with _ (underscore)
270
+	 * will exposed as protected api which will require authentication
271
+	 * @param string $class name of the service class
272
+	 * @param string $basePath optional url prefix for mapping, uses
273
+	 * lowercase version of the class name when not specified
274
+	 * @throws Exception when supplied with invalid class name
275
+	 */
276
+	public function addAPIClass($class_name, $base_path = null)
277
+	{
278
+		if (!class_exists($class_name)) {
279
+			throw new Exception("API class $class_name is missing.");
280
+		}
281
+		$this->loadCache();
282
+		if (!$this->cached) {
283
+			if (is_null($base_path)) {
284
+				$base_path = strtolower($class_name);
285
+				$index = strrpos($class_name, '\\');
286
+				if ($index !== false) {
287
+					$base_path = substr($base_path, $index + 1);
288
+				}
289
+			} else {
290
+				$base_path = trim($base_path, '/');
291
+			}
292
+			if (strlen($base_path) > 0) {
293
+				$base_path .= '/';
294
+			}
295
+			$this->generateMap($class_name, $base_path);
296
+		}
297
+	}
298
+
299
+
300
+	/**
301
+	 * protected methods will need atleast one authentication class to be set
302
+	 * in order to allow that method to be executed
303
+	 * @param string $class_name of the authentication class
304
+	 * @param string $base_path optional url prefix for mapping
305
+	 */
306
+	public function addAuthenticationClass($class_name, $base_path = null)
307
+	{
308
+		$this->auth_classes[] = $class_name;
309
+		$this->addAPIClass($class_name, $base_path);
310
+	}
311
+
312
+
313
+	/**
314
+	 * Add class for custom error handling
315
+	 * @param string $class_name of the error handling class
316
+	 */
317
+	public function addErrorClass($class_name)
318
+	{
319
+		$this->error_classes[] = $class_name;
320
+	}
321
+
322
+
323
+	/**
324
+	 * Convenience method to respond with an error message
325
+	 * @param int $statusCode http error code
326
+	 * @param string $errorMessage optional custom error message
327
+	 */
328
+	public function handleError($status_code, $error_message = null)
329
+	{
330
+		$method = "handle$status_code";
331
+		$handled = false;
332
+		foreach ($this->error_classes as $class_name) {
333
+			if (method_exists($class_name, $method)) {
334
+				$obj = new $class_name();
335
+				$obj->restler = $this;
336
+				$obj->$method();
337
+				$handled = true;
338
+			}
339
+		}
340
+		if ($handled) {
341
+			return;
342
+		}
343
+		$message = $this->codes[$status_code]
344
+			. (!$error_message ? '' : ': ' . $error_message);
345
+		$this->setStatus($status_code);
346
+		$responder = new $this->response();
347
+		$responder->restler = $this;
348
+		$this->sendData($responder->__formatError($status_code, $message));
349
+	}
350
+
351
+
352
+	/**
353
+	 * An initialize function to allow use of the restler error generation 
354
+	 * functions for pre-processing and pre-routing of requests.
355
+	 */
356
+	public function init()
357
+	{
358
+		if (empty($this->format_map)) {
359
+			$this->setSupportedFormats('JsonFormat');
360
+		}
361
+		$this->url = $this->getPath();
362
+		$this->request_method = $this->getRequestMethod();
363
+		$this->response_format = $this->getResponseFormat();
364
+		$this->request_format = $this->getRequestFormat();
365
+		if (is_null($this->request_format)) {
366
+			$this->request_format = $this->response_format;
367
+		}
368
+		if ($this->request_method == 'PUT' || $this->request_method == 'POST') {
369
+			$this->request_data = $this->getRequestData();
370
+		}
371
+	}
372
+
373
+
374
+	/**
375
+	 * Main function for processing the api request
376
+	 * and return the response
377
+	 * @throws Exception when the api service class is missing
378
+	 * @throws RestException to send error response
379
+	 */
380
+	public function handle()
381
+	{
382
+		$this->init();
383
+		$o = $this->mapUrlToMethod();
384
+
385
+		if (!isset($o->class_name)) {
386
+			$this->handleError(404);
387
+		} else {
388
+			try {
389
+				if ($o->method_flag) {
390
+					$auth_method = '__isAuthenticated';
391
+					if (!count($this->auth_classes)) {
392
+						throw new RestException(401);
393
+					}
394
+					foreach ($this->auth_classes as $auth_class) {
395
+						$auth_obj = new $auth_class();
396
+						$auth_obj->restler = $this;
397
+						$this->applyClassMetadata($auth_class, $auth_obj, $o);
398
+						if (!method_exists($auth_obj, $auth_method)) {
399
+							throw new RestException(401, 'Authentication Class '
400
+								. 'should implement iAuthenticate');
401
+						} else if (!$auth_obj->$auth_method()) {
402
+							throw new RestException(401);
403
+						}
404
+					}
405
+				}
406
+				$this->applyClassMetadata(get_class($this->request_format),
407
+					$this->request_format, $o);
408
+				$pre_process = '_' . $this->request_format->getExtension() . '_'
409
+					. $o->method_name;
410
+				$this->service_method = $o->method_name;
411
+				if ($o->method_flag == 2) {
412
+					$o = unprotect($o);
413
+				}
414
+				$object = $this->service_class_instance = new $o->class_name();
415
+				$object->restler = $this;
416
+				if (method_exists($o->class_name, $pre_process)) {
417
+					call_user_func_array(
418
+						array($object, $pre_process), $o->arguments
419
+					);
420
+				}
421
+				switch ($o->method_flag) {
422
+					case 3:
423
+						$reflection_method = new ReflectionMethod($object,
424
+								$o->method_name);
425
+						$reflection_method->setAccessible(true);
426
+						$result = $reflection_method->invokeArgs($object,
427
+							$o->arguments);
428
+						break;
429
+					case 2:
430
+					case 1:
431
+					default:
432
+						$result = call_user_func_array(array(
433
+							$object,
434
+							$o->method_name), $o->arguments
435
+						);
436
+						break;
437
+				}
438
+			} catch (RestException $e) {
439
+				$this->handleError($e->getCode(), $e->getMessage());
440
+			}
441
+		}
442
+		$responder = new $this->response();
443
+		$responder->restler = $this;
444
+		$this->applyClassMetadata($this->response, $responder, $o);
445
+		if (isset($result) && $result !== null) {
446
+			$result = $responder->__formatResponse($result);
447
+			$this->sendData($result);
448
+		}
449
+	}
450
+
451
+
452
+	/**
453
+	 * Encodes the response in the prefered format
454
+	 * and sends back
455
+	 * @param $data array php data
456
+	 */
457
+	public function sendData($data)
458
+	{
459
+		$data = $this->response_format->encode($data, 
460
+			!($this->production_mode)
461
+		);
462
+		$post_process = '_' . $this->service_method . '_'
463
+			. $this->response_format->getExtension();
464
+		if (isset($this->service_class_instance)
465
+			&& method_exists($this->service_class_instance, $post_process)
466
+		) {
467
+			$data = call_user_func(array($this->service_class_instance,
468
+				$post_process), $data);
469
+		}
470
+		header("Cache-Control: no-cache, must-revalidate");
471
+		header("Expires: 0");
472
+		header('Content-Type: ' . $this->response_format->getMIME());
473
+		//.'; charset=utf-8');
474
+		header("X-Powered-By: Luracast Restler v" . Restler::VERSION);
475 475
 		if($this->production_mode){
476 476
 			die($data);
477 477
 		}else{
478 478
 			echo $data;
479 479
 		}
480
-    }
481
-
482
-
483
-    /**
484
-     * Sets the HTTP response status
485
-     * @param int $code response code
486
-     */
487
-    public function setStatus($code)
488
-    {
489
-        header("{$_SERVER['SERVER_PROTOCOL']} $code " . 
490
-            $this->codes[strval($code)]);
491
-    }
492
-
493
-
494
-    /**
495
-     * Compare two strings and remove the common
496
-     * sub string from the first string and return it
497
-     * @param string $first
498
-     * @param string $second
499
-     * @param string $char optional, set it as
500
-     * blank string for char by char comparison
501
-     * @return string
502
-     */
503
-    public function removeCommonPath($first, $second, $char = '/')
504
-    {
505
-        $first = explode($char, $first);
506
-        $second = explode($char, $second);
507
-        while (count($second)) {
508
-            if ($first[0] == $second[0]) {
509
-                array_shift($first);
510
-            } else {
511
-                break;
512
-            }
513
-            array_shift($second);
514
-        }
515
-        return implode($char, $first);
516
-    }
517
-
518
-
519
-    /**
520
-     * Save cache to file
521
-     */
522
-    public function saveCache()
523
-    {
524
-        $file = $this->cache_dir . '/routes.php';
525
-        $s = '$o=array();' . PHP_EOL;
526
-        foreach ($this->routes as $key => $value) {
527
-            $s .= PHP_EOL . PHP_EOL . PHP_EOL . 
528
-                "############### $key ###############" . PHP_EOL . PHP_EOL;
529
-            $s .= '$o[\'' . $key . '\']=array();';
530
-            foreach ($value as $ke => $va) {
531
-                $s .= PHP_EOL . PHP_EOL . "#==== $key $ke" . PHP_EOL . PHP_EOL;
532
-                $s .= '$o[\'' . $key . '\'][\'' . $ke . '\']=' . str_replace(
533
-                        PHP_EOL, PHP_EOL . "\t", var_export($va, true)
534
-                    ) . ';';
535
-            }
536
-        }
537
-        $s .= PHP_EOL . 'return $o;';
538
-        $r = @file_put_contents($file, "<?php $s");
539
-        @chmod($file, 0777);
540
-        if ($r === false) {
541
-            throw new Exception(
542
-                "The cache directory located at '$this->cache_dir' needs to "
543
-                . "have the permissions set to read/write/execute for everyone"
544
-                . " in order to save cache and improve performance.");
545
-        }
546
-    }
547
-
548
-    // ==================================================================
549
-    //
550
-    // Protected functions
551
-    //
552
-    // ------------------------------------------------------------------
553
-
554
-
555
-    /**
556
-     * Parses the requst url and get the api path
557
-     * @return string api path
558
-     */
559
-    protected function getPath()
560
-    {
561
-        $path = urldecode($this->removeCommonPath($_SERVER['REQUEST_URI'],
562
-                $_SERVER['SCRIPT_NAME']));
563
-        $path = preg_replace('/(\/*\?.*$)|(\/$)/', '', $path);
564
-        $path = str_replace($this->format_map['extensions'], '', $path);
565
-        return $path;
566
-    }
567
-
568
-
569
-    /**
570
-     * Parses the request to figure out the http request type
571
-     * @return string which will be one of the following
572
-     * [GET, POST, PUT, DELETE]
573
-     * @example GET
574
-     */
575
-    protected function getRequestMethod()
576
-    {
577
-        $method = $_SERVER['REQUEST_METHOD'];
578
-        if (isset($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'])) {
579
-            $method = $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'];
580
-        }
581
-        //support for HEAD request
582
-        if ($method == 'HEAD') {
583
-            $method = 'GET';
584
-        }
585
-        return $method;
586
-    }
587
-
588
-
589
-    /**
590
-     * Parses the request to figure out format of the request data
591
-     * @return iFormat any class that implements iFormat
592
-     * @example JsonFormat
593
-     */
594
-    protected function getRequestFormat()
595
-    {
596
-        $format = null;
597
-        //check if client has sent any information on request format
598
-        if (isset($_SERVER['CONTENT_TYPE'])) {
599
-            $mime = explode(';', $_SERVER['CONTENT_TYPE']);
600
-            $mime = $mime[0];
601
-            if ($mime == UrlEncodedFormat::MIME) {
602
-                $format = new UrlEncodedFormat();
603
-            } else {
604
-                if (isset($this->format_map[$mime])) {
605
-                    $format = $this->format_map[$mime];
606
-                    $format = is_string($format) ? new $format : $format;
607
-                    $format->setMIME($mime);
608
-                }
609
-            }
610
-        }
611
-        return $format;
612
-    }
613
-
614
-
615
-    /**
616
-     * Parses the request to figure out the best format for response
617
-     * @return iFormat any class that implements iFormat
618
-     * @example JsonFormat
619
-     */
620
-    protected function getResponseFormat()
621
-    {
622
-        //check if client has specified an extension
623
-        /**
624
-         * @var iFormat
625
-         */
626
-        $format = null;
627
-        $extensions = explode('.',
628
-            parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
629
-        while ($extensions) {
630
-            $extension = array_pop($extensions);
631
-            $extension = explode('/', $extension);
632
-            $extension = array_shift($extension);
633
-            if ($extension && isset($this->format_map[$extension])) {
634
-                $format = $this->format_map[$extension];
635
-                $format = is_string($format) ? new $format : $format;
636
-                $format->setExtension($extension);
637
-                //echo "Extension $extension";
638
-                return $format;
639
-            }
640
-        }
641
-        //check if client has sent list of accepted data formats
642
-        if (isset($_SERVER['HTTP_ACCEPT'])) {
643
-            $acceptList = array();
644
-            $accepts = explode(',', strtolower($_SERVER['HTTP_ACCEPT']));
645
-            if (!is_array($accepts)) {
646
-                $accepts = array($accepts);
647
-            }
648
-            foreach ($accepts as $pos => $accept) {
649
-                $parts = explode(';q=', trim($accept));
650
-                $type = array_shift($parts);
651
-                $quality = count($parts) ? 
652
-                    floatval(array_shift($parts)) : 
653
-                    (1000 - $pos) / 1000;
654
-                $acceptList[$type] = $quality;
655
-            }
656
-            arsort($acceptList);
657
-            foreach ($acceptList as $accept => $quality) {
658
-                if (isset($this->format_map[$accept])) {
659
-                    $format = $this->format_map[$accept];
660
-                    $format = is_string($format) ? new $format : $format;
661
-                    $format->setMIME($accept);
662
-                    //echo "MIME $accept";
663
-                    // Tell cache content is based on Accept header
664
-                    header("Vary: Accept"); 
665
-                    return $format;
666
-                }
667
-            }
668
-        } else {
669
-            // RFC 2616: If no Accept header field is
670
-            // present, then it is assumed that the
671
-            // client accepts all media types.
672
-            $_SERVER['HTTP_ACCEPT'] = '*/*';
673
-        }
674
-        if (strpos($_SERVER['HTTP_ACCEPT'], '*') !== false) {
675
-            if (strpos($_SERVER['HTTP_ACCEPT'], 'application/*') !== false) {
676
-                $format = new JsonFormat;
677
-            } else if (strpos($_SERVER['HTTP_ACCEPT'], 'text/*') !== false) {
678
-                $format = new XmlFormat;
679
-            } else if (strpos($_SERVER['HTTP_ACCEPT'], '*/*') !== false) {
680
-                $format = new $this->format_map['default'];
681
-            }
682
-        }
683
-        if (empty($format)) {
684
-            // RFC 2616: If an Accept header field is present, and if the 
685
-            // server cannot send a response which is acceptable according to 
686
-            // the combined Accept field value, then the server SHOULD send 
687
-            // a 406 (not acceptable) response.
688
-            header('HTTP/1.1 406 Not Acceptable');
689
-            die('406 Not Acceptable: The server was unable to ' . 
690
-                    'negotiate content for this request.');
691
-        } else {
692
-            // Tell cache content is based ot Accept header
693
-            header("Vary: Accept"); 
694
-            return $format;
695
-        }
696
-    }
697
-
698
-
699
-    /**
700
-     * Parses the request data and returns it
701
-     * @return array php data
702
-     */
703
-    protected function getRequestData()
704
-    {
705
-        try {
706
-            $r = file_get_contents('php://input');
707
-            if (is_null($r)) {
708
-                return $_GET;
709
-            }
710
-            $r = $this->request_format->decode($r);
711
-            return is_null($r) ? array() : $r;
712
-        } catch (RestException $e) {
713
-            $this->handleError($e->getCode(), $e->getMessage());
714
-        }
715
-    }
716
-
717
-
718
-    protected function mapUrlToMethod()
719
-    {
720
-        if (!isset($this->routes[$this->request_method])) {
721
-            return array();
722
-        }
723
-        $urls = $this->routes[$this->request_method];
724
-        if (!$urls) {
725
-            return array();
726
-        }
727
-
728
-        $found = false;
729
-        $this->request_data += $_GET;
730
-        $params = array('request_data' => $this->request_data);
731
-        $params += $this->request_data;
732
-        $lc = strtolower($this->url);
733
-        foreach ($urls as $url => $call) {
734
-            //echo PHP_EOL.$url.' = '.$this->url.PHP_EOL;
735
-            $call = (object) $call;
736
-            if (strstr($url, ':')) {
737
-                $regex = preg_replace('/\\\:([^\/]+)/', '(?P<$1>[^/]+)',
738
-                    preg_quote($url));
739
-                if (preg_match(":^$regex$:i", $this->url, $matches)) {
740
-                    foreach ($matches as $arg => $match) {
741
-                        if (isset($call->arguments[$arg])) {
742
-                            //flog("$arg => $match $args[$arg]");
743
-                            $params[$arg] = $match;
744
-                        }
745
-                    }
746
-                    $found = true;
747
-                    break;
748
-                }
749
-            } else if ($url == $lc) {
750
-                $found = true;
751
-                break;
752
-            }
753
-        }
754
-        if ($found) {
755
-            //echo PHP_EOL."Found $url ";
756
-            //print_r($call);
757
-            $p = $call->defaults;
758
-            foreach ($call->arguments as $key => $value) {
759
-                //echo "$key => $value \n";
760
-                if (isset($params[$key])) {
761
-                    $p[$value] = $params[$key];
762
-                }
763
-            }
764
-            $call->arguments = $p;
765
-            return $call;
766
-        }
767
-    }
768
-
769
-
770
-    /**
771
-     * Apply static and non-static properties defined in
772
-     * the method information anotation
773
-     * @param String $class_name
774
-     * @param Object $instance instance of that class
775
-     * @param Object $method_info method information and metadata
776
-     */
777
-    protected function applyClassMetadata($class_name, $instance, $method_info)
778
-    {
779
-        if (isset($method_info->metadata[$class_name])
780
-            && is_array($method_info->metadata[$class_name])
781
-        ) {
782
-            foreach ($method_info->metadata[$class_name] as
783
-                    $property => $value) {
784
-                if (property_exists($class_name, $property)) {
785
-                    $reflection_property = 
786
-                        new ReflectionProperty($class_name, $property);
787
-                    $reflection_property->setValue($instance, $value);
788
-                }
789
-            }
790
-        }
791
-    }
792
-
793
-
794
-    protected function loadCache()
795
-    {
796
-        if ($this->cached !== null) {
797
-            return;
798
-        }
799
-        $file = $this->cache_dir . '/routes.php';
800
-        $this->cached = false;
801
-
802
-        if ($this->production_mode) {
803
-            if (file_exists($file)) {
804
-                $routes = include($file);
805
-            }
806
-            if (isset($routes) && is_array($routes)) {
807
-                $this->routes = $routes;
808
-                $this->cached = true;
809
-            }
810
-        } else {
811
-            //@unlink($this->cache_dir . "/$name.php");
812
-        }
813
-    }
814
-
815
-
816
-    /**
817
-     * Generates cachable url to method mapping
818
-     * @param string $class_name
819
-     * @param string $base_path
820
-     */
821
-    protected function generateMap($class_name, $base_path = '')
822
-    {
823
-        $reflection = new ReflectionClass($class_name);
824
-        $class_metadata = parse_doc($reflection->getDocComment());
825
-        $methods = $reflection->getMethods(
826
-            ReflectionMethod::IS_PUBLIC + ReflectionMethod::IS_PROTECTED
827
-        );
828
-        foreach ($methods as $method) {
829
-            $doc = $method->getDocComment();
830
-            $arguments = array();
831
-            $defaults = array();
832
-            $metadata = $class_metadata + parse_doc($doc);
833
-            $params = $method->getParameters();
834
-            $position = 0;
835
-            foreach ($params as $param) {
836
-                $arguments[$param->getName()] = $position;
837
-                $defaults[$position] = $param->isDefaultValueAvailable() ? 
838
-                    $param->getDefaultValue() : null;
839
-                $position++;
840
-            }
841
-            $method_flag = $method->isProtected() ? 
842
-                (isRestlerCompatibilityModeEnabled() ? 2 : 3) : 
843
-                (isset($metadata['protected']) ? 1 : 0);
844
-
845
-            //take note of the order
846
-            $call = array(
847
-                'class_name' => $class_name,
848
-                'method_name' => $method->getName(),
849
-                'arguments' => $arguments,
850
-                'defaults' => $defaults,
851
-                'metadata' => $metadata,
852
-                'method_flag' => $method_flag
853
-            );
854
-            $method_url = strtolower($method->getName());
855
-            if (preg_match_all(
856
-                '/@url\s+(GET|POST|PUT|DELETE|HEAD|OPTIONS)[ \t]*\/?(\S*)/s',
857
-                    $doc, $matches, PREG_SET_ORDER)
858
-            ) {
859
-                foreach ($matches as $match) {
860
-                    $http_method = $match[1];
861
-                    $url = rtrim($base_path . $match[2], '/');
862
-                    $this->routes[$http_method][$url] = $call;
863
-                }
864
-            } elseif ($method_url[0] != '_') { 
865
-                //not prefixed with underscore
866
-                // no configuration found so use convention
867
-                if (preg_match_all('/^(GET|POST|PUT|DELETE|HEAD|OPTIONS)/i',
868
-                        $method_url, $matches)
869
-                ) {
870
-                    $http_method = strtoupper($matches[0][0]);
871
-                    $method_url = substr($method_url, strlen($http_method));
872
-                } else {
873
-                    $http_method = 'GET';
874
-                }
875
-                $url = $base_path
876
-                    . ($method_url == 'index' || $method_url == 'default' ? '' :
877
-                        $method_url);
878
-                $url = rtrim($url, '/');
879
-                $this->routes[$http_method][$url] = $call;
880
-                foreach ($params as $param) {
881
-                    if ($param->getName() == 'request_data') {
882
-                        break;
883
-                    }
884
-                    $url .= $url == '' ? ':' : '/:';
885
-                    $url .= $param->getName();
886
-                    $this->routes[$http_method][$url] = $call;
887
-                }
888
-            }
889
-        }
890
-    }
480
+	}
481
+
482
+
483
+	/**
484
+	 * Sets the HTTP response status
485
+	 * @param int $code response code
486
+	 */
487
+	public function setStatus($code)
488
+	{
489
+		header("{$_SERVER['SERVER_PROTOCOL']} $code " . 
490
+			$this->codes[strval($code)]);
491
+	}
492
+
493
+
494
+	/**
495
+	 * Compare two strings and remove the common
496
+	 * sub string from the first string and return it
497
+	 * @param string $first
498
+	 * @param string $second
499
+	 * @param string $char optional, set it as
500
+	 * blank string for char by char comparison
501
+	 * @return string
502
+	 */
503
+	public function removeCommonPath($first, $second, $char = '/')
504
+	{
505
+		$first = explode($char, $first);
506
+		$second = explode($char, $second);
507
+		while (count($second)) {
508
+			if ($first[0] == $second[0]) {
509
+				array_shift($first);
510
+			} else {
511
+				break;
512
+			}
513
+			array_shift($second);
514
+		}
515
+		return implode($char, $first);
516
+	}
517
+
518
+
519
+	/**
520
+	 * Save cache to file
521
+	 */
522
+	public function saveCache()
523
+	{
524
+		$file = $this->cache_dir . '/routes.php';
525
+		$s = '$o=array();' . PHP_EOL;
526
+		foreach ($this->routes as $key => $value) {
527
+			$s .= PHP_EOL . PHP_EOL . PHP_EOL . 
528
+				"############### $key ###############" . PHP_EOL . PHP_EOL;
529
+			$s .= '$o[\'' . $key . '\']=array();';
530
+			foreach ($value as $ke => $va) {
531
+				$s .= PHP_EOL . PHP_EOL . "#==== $key $ke" . PHP_EOL . PHP_EOL;
532
+				$s .= '$o[\'' . $key . '\'][\'' . $ke . '\']=' . str_replace(
533
+						PHP_EOL, PHP_EOL . "\t", var_export($va, true)
534
+					) . ';';
535
+			}
536
+		}
537
+		$s .= PHP_EOL . 'return $o;';
538
+		$r = @file_put_contents($file, "<?php $s");
539
+		@chmod($file, 0777);
540
+		if ($r === false) {
541
+			throw new Exception(
542
+				"The cache directory located at '$this->cache_dir' needs to "
543
+				. "have the permissions set to read/write/execute for everyone"
544
+				. " in order to save cache and improve performance.");
545
+		}
546
+	}
547
+
548
+	// ==================================================================
549
+	//
550
+	// Protected functions
551
+	//
552
+	// ------------------------------------------------------------------
553
+
554
+
555
+	/**
556
+	 * Parses the requst url and get the api path
557
+	 * @return string api path
558
+	 */
559
+	protected function getPath()
560
+	{
561
+		$path = urldecode($this->removeCommonPath($_SERVER['REQUEST_URI'],
562
+				$_SERVER['SCRIPT_NAME']));
563
+		$path = preg_replace('/(\/*\?.*$)|(\/$)/', '', $path);
564
+		$path = str_replace($this->format_map['extensions'], '', $path);
565
+		return $path;
566
+	}
567
+
568
+
569
+	/**
570
+	 * Parses the request to figure out the http request type
571
+	 * @return string which will be one of the following
572
+	 * [GET, POST, PUT, DELETE]
573
+	 * @example GET
574
+	 */
575
+	protected function getRequestMethod()
576
+	{
577
+		$method = $_SERVER['REQUEST_METHOD'];
578
+		if (isset($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'])) {
579
+			$method = $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'];
580
+		}
581
+		//support for HEAD request
582
+		if ($method == 'HEAD') {
583
+			$method = 'GET';
584
+		}
585
+		return $method;
586
+	}
587
+
588
+
589
+	/**
590
+	 * Parses the request to figure out format of the request data
591
+	 * @return iFormat any class that implements iFormat
592
+	 * @example JsonFormat
593
+	 */
594
+	protected function getRequestFormat()
595
+	{
596
+		$format = null;
597
+		//check if client has sent any information on request format
598
+		if (isset($_SERVER['CONTENT_TYPE'])) {
599
+			$mime = explode(';', $_SERVER['CONTENT_TYPE']);
600
+			$mime = $mime[0];
601
+			if ($mime == UrlEncodedFormat::MIME) {
602
+				$format = new UrlEncodedFormat();
603
+			} else {
604
+				if (isset($this->format_map[$mime])) {
605
+					$format = $this->format_map[$mime];
606
+					$format = is_string($format) ? new $format : $format;
607
+					$format->setMIME($mime);
608
+				}
609
+			}
610
+		}
611
+		return $format;
612
+	}
613
+
614
+
615
+	/**
616
+	 * Parses the request to figure out the best format for response
617
+	 * @return iFormat any class that implements iFormat
618
+	 * @example JsonFormat
619
+	 */
620
+	protected function getResponseFormat()
621
+	{
622
+		//check if client has specified an extension
623
+		/**
624
+		 * @var iFormat
625
+		 */
626
+		$format = null;
627
+		$extensions = explode('.',
628
+			parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
629
+		while ($extensions) {
630
+			$extension = array_pop($extensions);
631
+			$extension = explode('/', $extension);
632
+			$extension = array_shift($extension);
633
+			if ($extension && isset($this->format_map[$extension])) {
634
+				$format = $this->format_map[$extension];
635
+				$format = is_string($format) ? new $format : $format;
636
+				$format->setExtension($extension);
637
+				//echo "Extension $extension";
638
+				return $format;
639
+			}
640
+		}
641
+		//check if client has sent list of accepted data formats
642
+		if (isset($_SERVER['HTTP_ACCEPT'])) {
643
+			$acceptList = array();
644
+			$accepts = explode(',', strtolower($_SERVER['HTTP_ACCEPT']));
645
+			if (!is_array($accepts)) {
646
+				$accepts = array($accepts);
647
+			}
648
+			foreach ($accepts as $pos => $accept) {
649
+				$parts = explode(';q=', trim($accept));
650
+				$type = array_shift($parts);
651
+				$quality = count($parts) ? 
652
+					floatval(array_shift($parts)) : 
653
+					(1000 - $pos) / 1000;
654
+				$acceptList[$type] = $quality;
655
+			}
656
+			arsort($acceptList);
657
+			foreach ($acceptList as $accept => $quality) {
658
+				if (isset($this->format_map[$accept])) {
659
+					$format = $this->format_map[$accept];
660
+					$format = is_string($format) ? new $format : $format;
661
+					$format->setMIME($accept);
662
+					//echo "MIME $accept";
663
+					// Tell cache content is based on Accept header
664
+					header("Vary: Accept"); 
665
+					return $format;
666
+				}
667
+			}
668
+		} else {
669
+			// RFC 2616: If no Accept header field is
670
+			// present, then it is assumed that the
671
+			// client accepts all media types.
672
+			$_SERVER['HTTP_ACCEPT'] = '*/*';
673
+		}
674
+		if (strpos($_SERVER['HTTP_ACCEPT'], '*') !== false) {
675
+			if (strpos($_SERVER['HTTP_ACCEPT'], 'application/*') !== false) {
676
+				$format = new JsonFormat;
677
+			} else if (strpos($_SERVER['HTTP_ACCEPT'], 'text/*') !== false) {
678
+				$format = new XmlFormat;
679
+			} else if (strpos($_SERVER['HTTP_ACCEPT'], '*/*') !== false) {
680
+				$format = new $this->format_map['default'];
681
+			}
682
+		}
683
+		if (empty($format)) {
684
+			// RFC 2616: If an Accept header field is present, and if the 
685
+			// server cannot send a response which is acceptable according to 
686
+			// the combined Accept field value, then the server SHOULD send 
687
+			// a 406 (not acceptable) response.
688
+			header('HTTP/1.1 406 Not Acceptable');
689
+			die('406 Not Acceptable: The server was unable to ' . 
690
+					'negotiate content for this request.');
691
+		} else {
692
+			// Tell cache content is based ot Accept header
693
+			header("Vary: Accept"); 
694
+			return $format;
695
+		}
696
+	}
697
+
698
+
699
+	/**
700
+	 * Parses the request data and returns it
701
+	 * @return array php data
702
+	 */
703
+	protected function getRequestData()
704
+	{
705
+		try {
706
+			$r = file_get_contents('php://input');
707
+			if (is_null($r)) {
708
+				return $_GET;
709
+			}
710
+			$r = $this->request_format->decode($r);
711
+			return is_null($r) ? array() : $r;
712
+		} catch (RestException $e) {
713
+			$this->handleError($e->getCode(), $e->getMessage());
714
+		}
715
+	}
716
+
717
+
718
+	protected function mapUrlToMethod()
719
+	{
720
+		if (!isset($this->routes[$this->request_method])) {
721
+			return array();
722
+		}
723
+		$urls = $this->routes[$this->request_method];
724
+		if (!$urls) {
725
+			return array();
726
+		}
727
+
728
+		$found = false;
729
+		$this->request_data += $_GET;
730
+		$params = array('request_data' => $this->request_data);
731
+		$params += $this->request_data;
732
+		$lc = strtolower($this->url);
733
+		foreach ($urls as $url => $call) {
734
+			//echo PHP_EOL.$url.' = '.$this->url.PHP_EOL;
735
+			$call = (object) $call;
736
+			if (strstr($url, ':')) {
737
+				$regex = preg_replace('/\\\:([^\/]+)/', '(?P<$1>[^/]+)',
738
+					preg_quote($url));
739
+				if (preg_match(":^$regex$:i", $this->url, $matches)) {
740
+					foreach ($matches as $arg => $match) {
741
+						if (isset($call->arguments[$arg])) {
742
+							//flog("$arg => $match $args[$arg]");
743
+							$params[$arg] = $match;
744
+						}
745
+					}
746
+					$found = true;
747
+					break;
748
+				}
749
+			} else if ($url == $lc) {
750
+				$found = true;
751
+				break;
752
+			}
753
+		}
754
+		if ($found) {
755
+			//echo PHP_EOL."Found $url ";
756
+			//print_r($call);
757
+			$p = $call->defaults;
758
+			foreach ($call->arguments as $key => $value) {
759
+				//echo "$key => $value \n";
760
+				if (isset($params[$key])) {
761
+					$p[$value] = $params[$key];
762
+				}
763
+			}
764
+			$call->arguments = $p;
765
+			return $call;
766
+		}
767
+	}
768
+
769
+
770
+	/**
771
+	 * Apply static and non-static properties defined in
772
+	 * the method information anotation
773
+	 * @param String $class_name
774
+	 * @param Object $instance instance of that class
775
+	 * @param Object $method_info method information and metadata
776
+	 */
777
+	protected function applyClassMetadata($class_name, $instance, $method_info)
778
+	{
779
+		if (isset($method_info->metadata[$class_name])
780
+			&& is_array($method_info->metadata[$class_name])
781
+		) {
782
+			foreach ($method_info->metadata[$class_name] as
783
+					$property => $value) {
784
+				if (property_exists($class_name, $property)) {
785
+					$reflection_property = 
786
+						new ReflectionProperty($class_name, $property);
787
+					$reflection_property->setValue($instance, $value);
788
+				}
789
+			}
790
+		}
791
+	}
792
+
793
+
794
+	protected function loadCache()
795
+	{
796
+		if ($this->cached !== null) {
797
+			return;
798
+		}
799
+		$file = $this->cache_dir . '/routes.php';
800
+		$this->cached = false;
801
+
802
+		if ($this->production_mode) {
803
+			if (file_exists($file)) {
804
+				$routes = include($file);
805
+			}
806
+			if (isset($routes) && is_array($routes)) {
807
+				$this->routes = $routes;
808
+				$this->cached = true;
809
+			}
810
+		} else {
811
+			//@unlink($this->cache_dir . "/$name.php");
812
+		}
813
+	}
814
+
815
+
816
+	/**
817
+	 * Generates cachable url to method mapping
818
+	 * @param string $class_name
819
+	 * @param string $base_path
820
+	 */
821
+	protected function generateMap($class_name, $base_path = '')
822
+	{
823
+		$reflection = new ReflectionClass($class_name);
824
+		$class_metadata = parse_doc($reflection->getDocComment());
825
+		$methods = $reflection->getMethods(
826
+			ReflectionMethod::IS_PUBLIC + ReflectionMethod::IS_PROTECTED
827
+		);
828
+		foreach ($methods as $method) {
829
+			$doc = $method->getDocComment();
830
+			$arguments = array();
831
+			$defaults = array();
832
+			$metadata = $class_metadata + parse_doc($doc);
833
+			$params = $method->getParameters();
834
+			$position = 0;
835
+			foreach ($params as $param) {
836
+				$arguments[$param->getName()] = $position;
837
+				$defaults[$position] = $param->isDefaultValueAvailable() ? 
838
+					$param->getDefaultValue() : null;
839
+				$position++;
840
+			}
841
+			$method_flag = $method->isProtected() ? 
842
+				(isRestlerCompatibilityModeEnabled() ? 2 : 3) : 
843
+				(isset($metadata['protected']) ? 1 : 0);
844
+
845
+			//take note of the order
846
+			$call = array(
847
+				'class_name' => $class_name,
848
+				'method_name' => $method->getName(),
849
+				'arguments' => $arguments,
850
+				'defaults' => $defaults,
851
+				'metadata' => $metadata,
852
+				'method_flag' => $method_flag
853
+			);
854
+			$method_url = strtolower($method->getName());
855
+			if (preg_match_all(
856
+				'/@url\s+(GET|POST|PUT|DELETE|HEAD|OPTIONS)[ \t]*\/?(\S*)/s',
857
+					$doc, $matches, PREG_SET_ORDER)
858
+			) {
859
+				foreach ($matches as $match) {
860
+					$http_method = $match[1];
861
+					$url = rtrim($base_path . $match[2], '/');
862
+					$this->routes[$http_method][$url] = $call;
863
+				}
864
+			} elseif ($method_url[0] != '_') { 
865
+				//not prefixed with underscore
866
+				// no configuration found so use convention
867
+				if (preg_match_all('/^(GET|POST|PUT|DELETE|HEAD|OPTIONS)/i',
868
+						$method_url, $matches)
869
+				) {
870
+					$http_method = strtoupper($matches[0][0]);
871
+					$method_url = substr($method_url, strlen($http_method));
872
+				} else {
873
+					$http_method = 'GET';
874
+				}
875
+				$url = $base_path
876
+					. ($method_url == 'index' || $method_url == 'default' ? '' :
877
+						$method_url);
878
+				$url = rtrim($url, '/');
879
+				$this->routes[$http_method][$url] = $call;
880
+				foreach ($params as $param) {
881
+					if ($param->getName() == 'request_data') {
882
+						break;
883
+					}
884
+					$url .= $url == '' ? ':' : '/:';
885
+					$url .= $param->getName();
886
+					$this->routes[$http_method][$url] = $call;
887
+				}
888
+			}
889
+		}
890
+	}
891 891
 
892 892
 }
893 893
 
894 894
 if (version_compare(PHP_VERSION, '5.3.0') < 0) {
895
-    require_once 'compat.php';
895
+	require_once 'compat.php';
896 896
 }
897 897
 
898 898
 // ==================================================================
@@ -916,10 +916,10 @@  discard block
 block discarded – undo
916 916
 {
917 917
 
918 918
 
919
-    public function __construct($http_status_code, $error_message = null)
920
-    {
921
-        parent::__construct($error_message, $http_status_code);
922
-    }
919
+	public function __construct($http_status_code, $error_message = null)
920
+	{
921
+		parent::__construct($error_message, $http_status_code);
922
+	}
923 923
 
924 924
 }
925 925
 
@@ -937,21 +937,21 @@  discard block
 block discarded – undo
937 937
 {
938 938
 
939 939
 
940
-    /**
941
-     * Result of an api call is passed to this method
942
-     * to create a standard structure for the data
943
-     * @param unknown_type $result can be a primitive or array or object
944
-     */
945
-    public function __formatResponse($result);
940
+	/**
941
+	 * Result of an api call is passed to this method
942
+	 * to create a standard structure for the data
943
+	 * @param unknown_type $result can be a primitive or array or object
944
+	 */
945
+	public function __formatResponse($result);
946 946
 
947 947
 
948
-    /**
949
-     * When the api call results in RestException this method
950
-     * will be called to return the error message
951
-     * @param int $status_code
952
-     * @param String $message
953
-     */
954
-    public function __formatError($status_code, $message);
948
+	/**
949
+	 * When the api call results in RestException this method
950
+	 * will be called to return the error message
951
+	 * @param int $status_code
952
+	 * @param String $message
953
+	 */
954
+	public function __formatError($status_code, $message);
955 955
 }
956 956
 
957 957
 /**
@@ -968,21 +968,21 @@  discard block
 block discarded – undo
968 968
 {
969 969
 
970 970
 
971
-    public function __formatResponse($result)
972
-    {
973
-        return $result;
974
-    }
971
+	public function __formatResponse($result)
972
+	{
973
+		return $result;
974
+	}
975 975
 
976 976
 
977
-    public function __formatError($statusCode, $message)
978
-    {
979
-        return array(
980
-            'error' => array(
981
-                'code' => $statusCode,
982
-                'message' => $message
983
-            )
984
-        );
985
-    }
977
+	public function __formatError($statusCode, $message)
978
+	{
979
+		return array(
980
+			'error' => array(
981
+				'code' => $statusCode,
982
+				'message' => $message
983
+			)
984
+		);
985
+	}
986 986
 
987 987
 }
988 988
 
@@ -1000,11 +1000,11 @@  discard block
 block discarded – undo
1000 1000
 {
1001 1001
 
1002 1002
 
1003
-    /**
1004
-     * Auth function that is called when a protected method is requested
1005
-     * @return boolean true or false
1006
-     */
1007
-    public function __isAuthenticated();
1003
+	/**
1004
+	 * Auth function that is called when a protected method is requested
1005
+	 * @return boolean true or false
1006
+	 */
1007
+	public function __isAuthenticated();
1008 1008
 }
1009 1009
 
1010 1010
 /**
@@ -1022,60 +1022,60 @@  discard block
 block discarded – undo
1022 1022
 {
1023 1023
 
1024 1024
 
1025
-    /**
1026
-     * Get Extension => MIME type mappings as an associative array
1027
-     * @return array list of mime strings for the format
1028
-     * @example array('json'=>'application/json');
1029
-     */
1030
-    public function getMIMEMap();
1025
+	/**
1026
+	 * Get Extension => MIME type mappings as an associative array
1027
+	 * @return array list of mime strings for the format
1028
+	 * @example array('json'=>'application/json');
1029
+	 */
1030
+	public function getMIMEMap();
1031 1031
 
1032 1032
 
1033
-    /**
1034
-     * Set the selected MIME type
1035
-     * @param string $mime MIME type
1036
-     */
1037
-    public function setMIME($mime);
1033
+	/**
1034
+	 * Set the selected MIME type
1035
+	 * @param string $mime MIME type
1036
+	 */
1037
+	public function setMIME($mime);
1038 1038
 
1039 1039
 
1040
-    /**
1041
-     * Get selected MIME type
1042
-     */
1043
-    public function getMIME();
1040
+	/**
1041
+	 * Get selected MIME type
1042
+	 */
1043
+	public function getMIME();
1044 1044
 
1045 1045
 
1046
-    /**
1047
-     * Set the selected file extension
1048
-     * @param string $extension file extension
1049
-     */
1050
-    public function setExtension($extension);
1046
+	/**
1047
+	 * Set the selected file extension
1048
+	 * @param string $extension file extension
1049
+	 */
1050
+	public function setExtension($extension);
1051 1051
 
1052 1052
 
1053
-    /**
1054
-     * Get the selected file extension
1055
-     * @return string file extension
1056
-     */
1057
-    public function getExtension();
1053
+	/**
1054
+	 * Get the selected file extension
1055
+	 * @return string file extension
1056
+	 */
1057
+	public function getExtension();
1058 1058
 
1059 1059
 
1060
-    /**
1061
-     * Encode the given data in the format
1062
-     * @param array $data resulting data that needs to
1063
-     * be encoded in the given format
1064
-     * @param boolean $human_readable set to true when restler
1065
-     * is not running in production mode. Formatter has to
1066
-     * make the encoded output more human readable
1067
-     * @return string encoded string
1068
-     */
1069
-    public function encode($data, $human_readable = false);
1060
+	/**
1061
+	 * Encode the given data in the format
1062
+	 * @param array $data resulting data that needs to
1063
+	 * be encoded in the given format
1064
+	 * @param boolean $human_readable set to true when restler
1065
+	 * is not running in production mode. Formatter has to
1066
+	 * make the encoded output more human readable
1067
+	 * @return string encoded string
1068
+	 */
1069
+	public function encode($data, $human_readable = false);
1070 1070
 
1071 1071
 
1072
-    /**
1073
-     * Decode the given data from the format
1074
-     * @param string $data data sent from client to
1075
-     * the api in the given format.
1076
-     * @return array associative array of the parsed data
1077
-     */
1078
-    public function decode($data);
1072
+	/**
1073
+	 * Decode the given data from the format
1074
+	 * @param string $data data sent from client to
1075
+	 * the api in the given format.
1076
+	 * @return array associative array of the parsed data
1077
+	 */
1078
+	public function decode($data);
1079 1079
 }
1080 1080
 
1081 1081
 /**
@@ -1091,57 +1091,57 @@  discard block
 block discarded – undo
1091 1091
 class UrlEncodedFormat implements iFormat
1092 1092
 {
1093 1093
 
1094
-    const MIME = 'application/x-www-form-urlencoded';
1095
-    const EXTENSION = 'post';
1094
+	const MIME = 'application/x-www-form-urlencoded';
1095
+	const EXTENSION = 'post';
1096 1096
 
1097 1097
 
1098
-    public function getMIMEMap()
1099
-    {
1100
-        return array(self::EXTENSION => self::MIME);
1101
-    }
1098
+	public function getMIMEMap()
1099
+	{
1100
+		return array(self::EXTENSION => self::MIME);
1101
+	}
1102 1102
 
1103 1103
 
1104
-    public function getMIME()
1105
-    {
1106
-        return self::MIME;
1107
-    }
1104
+	public function getMIME()
1105
+	{
1106
+		return self::MIME;
1107
+	}
1108 1108
 
1109 1109
 
1110
-    public function getExtension()
1111
-    {
1112
-        return self::EXTENSION;
1113
-    }
1110
+	public function getExtension()
1111
+	{
1112
+		return self::EXTENSION;
1113
+	}
1114 1114
 
1115 1115
 
1116
-    public function setMIME($mime)
1117
-    {
1118
-        //do nothing
1119
-    }
1116
+	public function setMIME($mime)
1117
+	{
1118
+		//do nothing
1119
+	}
1120 1120
 
1121 1121
 
1122
-    public function setExtension($extension)
1123
-    {
1124
-        //do nothing
1125
-    }
1122
+	public function setExtension($extension)
1123
+	{
1124
+		//do nothing
1125
+	}
1126 1126
 
1127 1127
 
1128
-    public function encode($data, $human_readable = false)
1129
-    {
1130
-        return http_build_query($data);
1131
-    }
1128
+	public function encode($data, $human_readable = false)
1129
+	{
1130
+		return http_build_query($data);
1131
+	}
1132 1132
 
1133 1133
 
1134
-    public function decode($data)
1135
-    {
1136
-        parse_str($data, $r);
1137
-        return $r;
1138
-    }
1134
+	public function decode($data)
1135
+	{
1136
+		parse_str($data, $r);
1137
+		return $r;
1138
+	}
1139 1139
 
1140 1140
 
1141
-    public function __toString()
1142
-    {
1143
-        return $this->getExtension();
1144
-    }
1141
+	public function __toString()
1142
+	{
1143
+		return $this->getExtension();
1144
+	}
1145 1145
 
1146 1146
 }
1147 1147
 
@@ -1158,158 +1158,158 @@  discard block
 block discarded – undo
1158 1158
 class JsonFormat implements iFormat
1159 1159
 {
1160 1160
 
1161
-    const MIME = 'application/json,application/javascript';
1162
-
1163
-    static $mime = 'application/json';
1164
-
1165
-    const EXTENSION = 'json';
1166
-
1167
-
1168
-    public function getMIMEMap()
1169
-    {
1170
-        return array(self::EXTENSION => self::MIME);
1171
-    }
1172
-
1173
-
1174
-    public function getMIME()
1175
-    {
1176
-        return self::$mime;
1177
-    }
1178
-
1179
-
1180
-    public function getExtension()
1181
-    {
1182
-        return self::EXTENSION;
1183
-    }
1184
-
1185
-
1186
-    public function setMIME($mime)
1187
-    {
1188
-        self::$mime = $mime;
1189
-    }
1190
-
1191
-
1192
-    public function setExtension($extension)
1193
-    {
1194
-        //do nothing
1195
-    }
1196
-
1197
-
1198
-    public function encode($data, $human_readable = false)
1199
-    {
1200
-        return $human_readable ? 
1201
-            $this->json_format(json_encode(object_to_array($data))) : 
1202
-            json_encode(object_to_array($data));
1203
-    }
1204
-
1205
-
1206
-    public function decode($data)
1207
-    {
1208
-        $decoded = json_decode($data);
1209
-        if (function_exists('json_last_error')) {
1210
-            $message = '';
1211
-            switch (json_last_error()) {
1212
-                case JSON_ERROR_NONE:
1213
-                    return object_to_array($decoded);
1214
-                    break;
1215
-                case JSON_ERROR_DEPTH:
1216
-                    $message = 'maximum stack depth exceeded';
1217
-                    break;
1218
-                case JSON_ERROR_STATE_MISMATCH:
1219
-                    $message = 'underflow or the modes mismatch';
1220
-                    break;
1221
-                case JSON_ERROR_CTRL_CHAR:
1222
-                    $message = 'unexpected control character found';
1223
-                    break;
1224
-                case JSON_ERROR_SYNTAX:
1225
-                    $message = 'malformed JSON';
1226
-                    break;
1227
-                case JSON_ERROR_UTF8:
1228
-                    $message = 'malformed UTF-8 characters, '.
1229
-                        'possibly incorrectly encoded';
1230
-                    break;
1231
-                default:
1232
-                    $message = 'unknown error';
1233
-                    break;
1234
-            }
1235
-            throw new RestException(400, 'Error parsing JSON, ' . $message);
1236
-        } else if (strlen($data) && $decoded === null || $decoded === $data) {
1237
-            throw new RestException(400, 'Error parsing JSON');
1238
-        }
1239
-        return object_to_array($decoded);
1240
-    }
1241
-
1242
-
1243
-    /**
1244
-     * Pretty print JSON string
1245
-     * @param string $json
1246
-     * @return string formated json
1247
-     */
1248
-    private function json_format($json)
1249
-    {
1250
-        $tab = "  ";
1251
-        $new_json = "";
1252
-        $indent_level = 0;
1253
-        $in_string = false;
1254
-        $len = strlen($json);
1255
-
1256
-        for ($c = 0; $c < $len; $c++) {
1257
-            $char = $json[$c];
1258
-            switch ($char) {
1259
-                case '{':
1260
-                case '[':
1261
-                    if (!$in_string) {
1262
-                        $new_json .= $char . "\n" .
1263
-                            str_repeat($tab, $indent_level + 1);
1264
-                        $indent_level++;
1265
-                    } else {
1266
-                        $new_json .= $char;
1267
-                    }
1268
-                    break;
1269
-                case '}':
1270
-                case ']':
1271
-                    if (!$in_string) {
1272
-                        $indent_level--;
1273
-                        $new_json .= "\n" . str_repeat($tab, $indent_level) 
1274
-                            . $char;
1275
-                    } else {
1276
-                        $new_json .= $char;
1277
-                    }
1278
-                    break;
1279
-                case ',':
1280
-                    if (!$in_string) {
1281
-                        $new_json .= ",\n" . str_repeat($tab, $indent_level);
1282
-                    } else {
1283
-                        $new_json .= $char;
1284
-                    }
1285
-                    break;
1286
-                case ':':
1287
-                    if (!$in_string) {
1288
-                        $new_json .= ": ";
1289
-                    } else {
1290
-                        $new_json .= $char;
1291
-                    }
1292
-                    break;
1293
-                case '"':
1294
-                    if ($c == 0) {
1295
-                        $in_string = true;
1296
-                    } else if ($c > 0 && $json[$c - 1] != '\\') {
1297
-                        $in_string = !$in_string;
1298
-                    }
1299
-                default:
1300
-                    $new_json .= $char;
1301
-                    break;
1302
-            }
1303
-        }
1304
-
1305
-        return $new_json;
1306
-    }
1307
-
1308
-
1309
-    public function __toString()
1310
-    {
1311
-        return $this->getExtension();
1312
-    }
1161
+	const MIME = 'application/json,application/javascript';
1162
+
1163
+	static $mime = 'application/json';
1164
+
1165
+	const EXTENSION = 'json';
1166
+
1167
+
1168
+	public function getMIMEMap()
1169
+	{
1170
+		return array(self::EXTENSION => self::MIME);
1171
+	}
1172
+
1173
+
1174
+	public function getMIME()
1175
+	{
1176
+		return self::$mime;
1177
+	}
1178
+
1179
+
1180
+	public function getExtension()
1181
+	{
1182
+		return self::EXTENSION;
1183
+	}
1184
+
1185
+
1186
+	public function setMIME($mime)
1187
+	{
1188
+		self::$mime = $mime;
1189
+	}
1190
+
1191
+
1192
+	public function setExtension($extension)
1193
+	{
1194
+		//do nothing
1195
+	}
1196
+
1197
+
1198
+	public function encode($data, $human_readable = false)
1199
+	{
1200
+		return $human_readable ? 
1201
+			$this->json_format(json_encode(object_to_array($data))) : 
1202
+			json_encode(object_to_array($data));
1203
+	}
1204
+
1205
+
1206
+	public function decode($data)
1207
+	{
1208
+		$decoded = json_decode($data);
1209
+		if (function_exists('json_last_error')) {
1210
+			$message = '';
1211
+			switch (json_last_error()) {
1212
+				case JSON_ERROR_NONE:
1213
+					return object_to_array($decoded);
1214
+					break;
1215
+				case JSON_ERROR_DEPTH:
1216
+					$message = 'maximum stack depth exceeded';
1217
+					break;
1218
+				case JSON_ERROR_STATE_MISMATCH:
1219
+					$message = 'underflow or the modes mismatch';
1220
+					break;
1221
+				case JSON_ERROR_CTRL_CHAR:
1222
+					$message = 'unexpected control character found';
1223
+					break;
1224
+				case JSON_ERROR_SYNTAX:
1225
+					$message = 'malformed JSON';
1226
+					break;
1227
+				case JSON_ERROR_UTF8:
1228
+					$message = 'malformed UTF-8 characters, '.
1229
+						'possibly incorrectly encoded';
1230
+					break;
1231
+				default:
1232
+					$message = 'unknown error';
1233
+					break;
1234
+			}
1235
+			throw new RestException(400, 'Error parsing JSON, ' . $message);
1236
+		} else if (strlen($data) && $decoded === null || $decoded === $data) {
1237
+			throw new RestException(400, 'Error parsing JSON');
1238
+		}
1239
+		return object_to_array($decoded);
1240
+	}
1241
+
1242
+
1243
+	/**
1244
+	 * Pretty print JSON string
1245
+	 * @param string $json
1246
+	 * @return string formated json
1247
+	 */
1248
+	private function json_format($json)
1249
+	{
1250
+		$tab = "  ";
1251
+		$new_json = "";
1252
+		$indent_level = 0;
1253
+		$in_string = false;
1254
+		$len = strlen($json);
1255
+
1256
+		for ($c = 0; $c < $len; $c++) {
1257
+			$char = $json[$c];
1258
+			switch ($char) {
1259
+				case '{':
1260
+				case '[':
1261
+					if (!$in_string) {
1262
+						$new_json .= $char . "\n" .
1263
+							str_repeat($tab, $indent_level + 1);
1264
+						$indent_level++;
1265
+					} else {
1266
+						$new_json .= $char;
1267
+					}
1268
+					break;
1269
+				case '}':
1270
+				case ']':
1271
+					if (!$in_string) {
1272
+						$indent_level--;
1273
+						$new_json .= "\n" . str_repeat($tab, $indent_level) 
1274
+							. $char;
1275
+					} else {
1276
+						$new_json .= $char;
1277
+					}
1278
+					break;
1279
+				case ',':
1280
+					if (!$in_string) {
1281
+						$new_json .= ",\n" . str_repeat($tab, $indent_level);
1282
+					} else {
1283
+						$new_json .= $char;
1284
+					}
1285
+					break;
1286
+				case ':':
1287
+					if (!$in_string) {
1288
+						$new_json .= ": ";
1289
+					} else {
1290
+						$new_json .= $char;
1291
+					}
1292
+					break;
1293
+				case '"':
1294
+					if ($c == 0) {
1295
+						$in_string = true;
1296
+					} else if ($c > 0 && $json[$c - 1] != '\\') {
1297
+						$in_string = !$in_string;
1298
+					}
1299
+				default:
1300
+					$new_json .= $char;
1301
+					break;
1302
+			}
1303
+		}
1304
+
1305
+		return $new_json;
1306
+	}
1307
+
1308
+
1309
+	public function __toString()
1310
+	{
1311
+		return $this->getExtension();
1312
+	}
1313 1313
 
1314 1314
 }
1315 1315
 
@@ -1327,123 +1327,123 @@  discard block
 block discarded – undo
1327 1327
 class DocParser
1328 1328
 {
1329 1329
 
1330
-    private $params = array();
1331
-
1332
-
1333
-    public function parse($doc = '')
1334
-    {
1335
-        if ($doc == '') {
1336
-            return $this->params;
1337
-        }
1338
-        //Get the comment
1339
-        if (preg_match('#^/\*\*(.*)\*/#s', $doc, $comment) === false) {
1340
-            return $this->params;
1341
-        }
1342
-        $comment = trim($comment[1]);
1343
-        //Get all the lines and strip the * from the first character
1344
-        if (preg_match_all('#^\s*\*(.*)#m', $comment, $lines) === false) {
1345
-            return $this->params;
1346
-        }
1347
-        $this->parseLines($lines[1]);
1348
-        return $this->params;
1349
-    }
1350
-
1351
-
1352
-    private function parseLines($lines)
1353
-    {
1354
-        foreach ($lines as $line) {
1355
-            $parsedLine = $this->parseLine($line); //Parse the line
1356
-
1357
-            if ($parsedLine === false && !isset($this->params['description'])) {
1358
-                if (isset($desc)) {
1359
-                    //Store the first line in the short description
1360
-                    $this->params['description'] = implode(PHP_EOL, $desc);
1361
-                }
1362
-                $desc = array();
1363
-            } else if ($parsedLine !== false) {
1364
-                $desc[] = $parsedLine; //Store the line in the long description
1365
-            }
1366
-        }
1367
-        $desc = implode(' ', $desc);
1368
-        if (!empty($desc)) {
1369
-            $this->params['long_description'] = $desc;
1370
-        }
1371
-    }
1372
-
1373
-
1374
-    private function parseLine($line)
1375
-    {
1376
-        //trim the whitespace from the line
1377
-        $line = trim($line);
1378
-
1379
-        if (empty($line)) {
1380
-            return false; //Empty line
1381
-        }
1382
-
1383
-        if (strpos($line, '@') === 0) {
1384
-            if (strpos($line, ' ') > 0) {
1385
-                //Get the parameter name
1386
-                $param = substr($line, 1, strpos($line, ' ') - 1);
1387
-                $value = substr($line, strlen($param) + 2); //Get the value
1388
-            } else {
1389
-                $param = substr($line, 1);
1390
-                $value = '';
1391
-            }
1392
-            //Parse the line and return false if the parameter is valid
1393
-            if ($this->setParam($param, $value)) {
1394
-                return false;
1395
-            }
1396
-        }
1397
-        return $line;
1398
-    }
1399
-
1400
-
1401
-    private function setParam($param, $value)
1402
-    {
1403
-        if ($param == 'param' || $param == 'return') {
1404
-            $value = $this->formatParamOrReturn($value);
1405
-        }
1406
-        if ($param == 'class') {
1407
-            list($param, $value) = $this->formatClass($value);
1408
-        }
1409
-
1410
-        if (empty($this->params[$param])) {
1411
-            $this->params[$param] = $value;
1412
-        } else if ($param == 'param') {
1413
-            $arr = array($this->params[$param], $value);
1414
-            $this->params[$param] = $arr;
1415
-        } else {
1416
-            $this->params[$param] = $value + $this->params[$param];
1417
-        }
1418
-        return true;
1419
-    }
1420
-
1421
-
1422
-    private function formatClass($value)
1423
-    {
1424
-        $r = preg_split("[\(|\)]", $value);
1425
-        if (count($r) > 1) {
1426
-            $param = $r[0];
1427
-            parse_str($r[1], $value);
1428
-            foreach ($value as $key => $val) {
1429
-                $val = explode(',', $val);
1430
-                if (count($val) > 1) {
1431
-                    $value[$key] = $val;
1432
-                }
1433
-            }
1434
-        } else {
1435
-            $param = 'Unknown';
1436
-        }
1437
-        return array($param, $value);
1438
-    }
1439
-
1440
-
1441
-    private function formatParamOrReturn($string)
1442
-    {
1443
-        $pos = strpos($string, ' ');
1444
-        $type = substr($string, 0, $pos);
1445
-        return '(' . $type . ')' . substr($string, $pos + 1);
1446
-    }
1330
+	private $params = array();
1331
+
1332
+
1333
+	public function parse($doc = '')
1334
+	{
1335
+		if ($doc == '') {
1336
+			return $this->params;
1337
+		}
1338
+		//Get the comment
1339
+		if (preg_match('#^/\*\*(.*)\*/#s', $doc, $comment) === false) {
1340
+			return $this->params;
1341
+		}
1342
+		$comment = trim($comment[1]);
1343
+		//Get all the lines and strip the * from the first character
1344
+		if (preg_match_all('#^\s*\*(.*)#m', $comment, $lines) === false) {
1345
+			return $this->params;
1346
+		}
1347
+		$this->parseLines($lines[1]);
1348
+		return $this->params;
1349
+	}
1350
+
1351
+
1352
+	private function parseLines($lines)
1353
+	{
1354
+		foreach ($lines as $line) {
1355
+			$parsedLine = $this->parseLine($line); //Parse the line
1356
+
1357
+			if ($parsedLine === false && !isset($this->params['description'])) {
1358
+				if (isset($desc)) {
1359
+					//Store the first line in the short description
1360
+					$this->params['description'] = implode(PHP_EOL, $desc);
1361
+				}
1362
+				$desc = array();
1363
+			} else if ($parsedLine !== false) {
1364
+				$desc[] = $parsedLine; //Store the line in the long description
1365
+			}
1366
+		}
1367
+		$desc = implode(' ', $desc);
1368
+		if (!empty($desc)) {
1369
+			$this->params['long_description'] = $desc;
1370
+		}
1371
+	}
1372
+
1373
+
1374
+	private function parseLine($line)
1375
+	{
1376
+		//trim the whitespace from the line
1377
+		$line = trim($line);
1378
+
1379
+		if (empty($line)) {
1380
+			return false; //Empty line
1381
+		}
1382
+
1383
+		if (strpos($line, '@') === 0) {
1384
+			if (strpos($line, ' ') > 0) {
1385
+				//Get the parameter name
1386
+				$param = substr($line, 1, strpos($line, ' ') - 1);
1387
+				$value = substr($line, strlen($param) + 2); //Get the value
1388
+			} else {
1389
+				$param = substr($line, 1);
1390
+				$value = '';
1391
+			}
1392
+			//Parse the line and return false if the parameter is valid
1393
+			if ($this->setParam($param, $value)) {
1394
+				return false;
1395
+			}
1396
+		}
1397
+		return $line;
1398
+	}
1399
+
1400
+
1401
+	private function setParam($param, $value)
1402
+	{
1403
+		if ($param == 'param' || $param == 'return') {
1404
+			$value = $this->formatParamOrReturn($value);
1405
+		}
1406
+		if ($param == 'class') {
1407
+			list($param, $value) = $this->formatClass($value);
1408
+		}
1409
+
1410
+		if (empty($this->params[$param])) {
1411
+			$this->params[$param] = $value;
1412
+		} else if ($param == 'param') {
1413
+			$arr = array($this->params[$param], $value);
1414
+			$this->params[$param] = $arr;
1415
+		} else {
1416
+			$this->params[$param] = $value + $this->params[$param];
1417
+		}
1418
+		return true;
1419
+	}
1420
+
1421
+
1422
+	private function formatClass($value)
1423
+	{
1424
+		$r = preg_split("[\(|\)]", $value);
1425
+		if (count($r) > 1) {
1426
+			$param = $r[0];
1427
+			parse_str($r[1], $value);
1428
+			foreach ($value as $key => $val) {
1429
+				$val = explode(',', $val);
1430
+				if (count($val) > 1) {
1431
+					$value[$key] = $val;
1432
+				}
1433
+			}
1434
+		} else {
1435
+			$param = 'Unknown';
1436
+		}
1437
+		return array($param, $value);
1438
+	}
1439
+
1440
+
1441
+	private function formatParamOrReturn($string)
1442
+	{
1443
+		$pos = strpos($string, ' ');
1444
+		$type = substr($string, 0, $pos);
1445
+		return '(' . $type . ')' . substr($string, $pos + 1);
1446
+	}
1447 1447
 
1448 1448
 }
1449 1449
 
@@ -1456,30 +1456,30 @@  discard block
 block discarded – undo
1456 1456
 
1457 1457
 function parse_doc($php_doc_comment)
1458 1458
 {
1459
-    $p = new DocParser();
1460
-    return $p->parse($php_doc_comment);
1459
+	$p = new DocParser();
1460
+	return $p->parse($php_doc_comment);
1461 1461
 
1462
-    $p = new Parser($php_doc_comment);
1463
-    return $p;
1462
+	$p = new Parser($php_doc_comment);
1463
+	return $p;
1464 1464
 
1465
-    $php_doc_comment = preg_replace(
1466
-        "/(^[\\s]*\\/\\*\\*)
1465
+	$php_doc_comment = preg_replace(
1466
+		"/(^[\\s]*\\/\\*\\*)
1467 1467
         |(^[\\s]\\*\\/)
1468 1468
         |(^[\\s]*\\*?\\s)
1469 1469
         |(^[\\s]*)
1470 1470
         |(^[\\t]*)/ixm",
1471
-        "", $php_doc_comment);
1472
-    $php_doc_comment = str_replace("\r", "", $php_doc_comment);
1473
-    $php_doc_comment = preg_replace("/([\\t])+/", "\t", $php_doc_comment);
1474
-    return explode("\n", $php_doc_comment);
1475
-
1476
-    $php_doc_comment = trim(preg_replace('/\r?\n *\* */', ' ', 
1477
-            $php_doc_comment));
1478
-    return $php_doc_comment;
1479
-
1480
-    preg_match_all('/@([a-z]+)\s+(.*?)\s*(?=$|@[a-z]+\s)/s', $php_doc_comment,
1481
-        $matches);
1482
-    return array_combine($matches[1], $matches[2]);
1471
+		"", $php_doc_comment);
1472
+	$php_doc_comment = str_replace("\r", "", $php_doc_comment);
1473
+	$php_doc_comment = preg_replace("/([\\t])+/", "\t", $php_doc_comment);
1474
+	return explode("\n", $php_doc_comment);
1475
+
1476
+	$php_doc_comment = trim(preg_replace('/\r?\n *\* */', ' ', 
1477
+			$php_doc_comment));
1478
+	return $php_doc_comment;
1479
+
1480
+	preg_match_all('/@([a-z]+)\s+(.*?)\s*(?=$|@[a-z]+\s)/s', $php_doc_comment,
1481
+		$matches);
1482
+	return array_combine($matches[1], $matches[2]);
1483 1483
 }
1484 1484
 
1485 1485
 
@@ -1498,21 +1498,21 @@  discard block
 block discarded – undo
1498 1498
  */
1499 1499
 function object_to_array($object, $utf_encode = false)
1500 1500
 {
1501
-    if (is_array($object)
1502
-        || (is_object($object)
1503
-        && !($object instanceof JsonSerializable))
1504
-    ) {
1505
-        $array = array();
1506
-        foreach ($object as $key => $value) {
1507
-            $value = object_to_array($value, $utf_encode);
1508
-            if ($utf_encode && is_string($value)) {
1509
-                $value = utf8_encode($value);
1510
-            }
1511
-            $array[$key] = $value;
1512
-        }
1513
-        return $array;
1514
-    }
1515
-    return $object;
1501
+	if (is_array($object)
1502
+		|| (is_object($object)
1503
+		&& !($object instanceof JsonSerializable))
1504
+	) {
1505
+		$array = array();
1506
+		foreach ($object as $key => $value) {
1507
+			$value = object_to_array($value, $utf_encode);
1508
+			if ($utf_encode && is_string($value)) {
1509
+				$value = utf8_encode($value);
1510
+			}
1511
+			$array[$key] = $value;
1512
+		}
1513
+		return $array;
1514
+	}
1515
+	return $object;
1516 1516
 }
1517 1517
 
1518 1518
 
@@ -1522,21 +1522,21 @@  discard block
 block discarded – undo
1522 1522
  */
1523 1523
 function autoload_formats($class_name)
1524 1524
 {
1525
-    $class_name = strtolower($class_name);
1525
+	$class_name = strtolower($class_name);
1526 1526
 	
1527
-    $file = RESTLER_PATH . "../../../api/mobile_services/$class_name.php";
1528
-    if (file_exists($file)) {
1529
-        require_once ($file);
1530
-    } else {
1527
+	$file = RESTLER_PATH . "../../../api/mobile_services/$class_name.php";
1528
+	if (file_exists($file)) {
1529
+		require_once ($file);
1530
+	} else {
1531 1531
 		$file = RESTLER_PATH . "/../../api/mobile_services/$class_name.php";
1532
-        if (file_exists($file)) {
1533
-            require_once ($file);
1534
-        } elseif (file_exists(RESTLER_PATH . "/../api/mobile_services/$class_name.php")) {
1535
-            require_once ("/../api/mobile_services/$class_name.php");
1536
-        } elseif (file_exists("$class_name.php")) {
1537
-            require_once ("$class_name.php");
1538
-        }
1539
-    }
1532
+		if (file_exists($file)) {
1533
+			require_once ($file);
1534
+		} elseif (file_exists(RESTLER_PATH . "/../api/mobile_services/$class_name.php")) {
1535
+			require_once ("/../api/mobile_services/$class_name.php");
1536
+		} elseif (file_exists("$class_name.php")) {
1537
+			require_once ("$class_name.php");
1538
+		}
1539
+	}
1540 1540
 }
1541 1541
 
1542 1542
 // ==================================================================
@@ -1553,10 +1553,10 @@  discard block
 block discarded – undo
1553 1553
 if (!function_exists('isRestlerCompatibilityModeEnabled')) {
1554 1554
 
1555 1555
 
1556
-    function isRestlerCompatibilityModeEnabled()
1557
-    {
1558
-        return false;
1559
-    }
1556
+	function isRestlerCompatibilityModeEnabled()
1557
+	{
1558
+		return false;
1559
+	}
1560 1560
 
1561 1561
 }
1562 1562
 define('RESTLER_PATH', dirname(__FILE__));
Please login to merge, or discard this patch.
libraries/SabreDAV/DAVACL/FS/HomeCollection.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -70,7 +70,7 @@
 block discarded – undo
70 70
      * supplied by the authentication backend.
71 71
      *
72 72
      * @param array $principalInfo
73
-     * @return void
73
+     * @return Collection
74 74
      */
75 75
     function getChildForPrincipal(array $principalInfo) {
76 76
 
Please login to merge, or discard this patch.
Unused Use Statements   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -2,10 +2,10 @@
 block discarded – undo
2 2
 
3 3
 namespace Sabre\DAVACL\FS;
4 4
 
5
-use Sabre\DAV\Exception\Forbidden;
6 5
 use Sabre\DAVACL\AbstractPrincipalCollection;
7 6
 use Sabre\DAVACL\IACL;
8 7
 use Sabre\DAVACL\PrincipalBackend\BackendInterface;
8
+use Sabre\DAV\Exception\Forbidden;
9 9
 use Sabre\Uri;
10 10
 
11 11
 /**
Please login to merge, or discard this patch.
Indentation   +163 added lines, -163 removed lines patch added patch discarded remove patch
@@ -21,168 +21,168 @@
 block discarded – undo
21 21
  */
22 22
 class HomeCollection extends AbstractPrincipalCollection implements IACL {
23 23
 
24
-    /**
25
-     * Name of this collection.
26
-     *
27
-     * @var string
28
-     */
29
-    public $collectionName = 'home';
30
-
31
-    /**
32
-     * Path to where the users' files are actually stored.
33
-     *
34
-     * @var string
35
-     */
36
-    protected $storagePath;
37
-
38
-    /**
39
-     * Creates the home collection.
40
-     *
41
-     * @param BackendInterface $principalBackend
42
-     * @param string $storagePath Where the actual files are stored.
43
-     * @param string $principalPrefix list of principals to iterate.
44
-     */
45
-    public function __construct(BackendInterface $principalBackend, $storagePath, $principalPrefix = 'principals') {
46
-
47
-        parent::__construct($principalBackend, $principalPrefix);
48
-        $this->storagePath = $storagePath;
49
-
50
-    }
51
-
52
-    /**
53
-     * Returns the name of the node.
54
-     *
55
-     * This is used to generate the url.
56
-     *
57
-     * @return string
58
-     */
59
-    public function getName() {
60
-
61
-        return $this->collectionName;
62
-
63
-    }
64
-
65
-    /**
66
-     * Returns a principals' collection of files.
67
-     *
68
-     * The passed array contains principal information, and is guaranteed to
69
-     * at least contain a uri item. Other properties may or may not be
70
-     * supplied by the authentication backend.
71
-     *
72
-     * @param array $principalInfo
73
-     * @return void
74
-     */
75
-    public function getChildForPrincipal(array $principalInfo) {
76
-
77
-        $owner = $principalInfo['uri'];
78
-        $acl = [
79
-            [
80
-                'privilege' => '{DAV:}read',
81
-                'principal' => $owner,
82
-                'protected' => true,
83
-            ],
84
-            [
85
-                'privilege' => '{DAV:}write',
86
-                'principal' => $owner,
87
-                'protected' => true,
88
-            ],
89
-        ];
90
-
91
-        list(, $principalBaseName) = Uri\split($owner);
92
-
93
-        $path = $this->storagePath . '/' . $principalBaseName;
94
-
95
-        if (!is_dir($path)) {
96
-            mkdir($path, 0777, true);
97
-        }
98
-        return new Collection(
99
-            $path,
100
-            $acl,
101
-            $owner
102
-        );
103
-
104
-    }
105
-
106
-    /**
107
-     * Returns the owner principal
108
-     *
109
-     * This must be a url to a principal, or null if there's no owner
110
-     *
111
-     * @return string|null
112
-     */
113
-    public function getOwner() {
114
-
115
-        return null;
116
-
117
-    }
118
-
119
-    /**
120
-     * Returns a group principal
121
-     *
122
-     * This must be a url to a principal, or null if there's no owner
123
-     *
124
-     * @return string|null
125
-     */
126
-    public function getGroup() {
127
-
128
-        return null;
129
-
130
-    }
131
-
132
-    /**
133
-     * Returns a list of ACE's for this node.
134
-     *
135
-     * Each ACE has the following properties:
136
-     *   * 'privilege', a string such as {DAV:}read or {DAV:}write. These are
137
-     *     currently the only supported privileges
138
-     *   * 'principal', a url to the principal who owns the node
139
-     *   * 'protected' (optional), indicating that this ACE is not allowed to
140
-     *      be updated.
141
-     *
142
-     * @return array
143
-     */
144
-    public function getACL() {
145
-
146
-        return [
147
-            [
148
-                'principal' => '{DAV:}authenticated',
149
-                'privilege' => '{DAV:}read',
150
-                'protected' => true,
151
-            ]
152
-        ];
153
-
154
-    }
155
-
156
-    /**
157
-     * Updates the ACL
158
-     *
159
-     * This method will receive a list of new ACE's as an array argument.
160
-     *
161
-     * @param array $acl
162
-     * @return void
163
-     */
164
-    public function setACL(array $acl) {
165
-
166
-        throw new Forbidden('Setting ACL is not allowed here');
167
-
168
-    }
169
-
170
-    /**
171
-     * Returns the list of supported privileges for this node.
172
-     *
173
-     * The returned data structure is a list of nested privileges.
174
-     * See Sabre\DAVACL\Plugin::getDefaultSupportedPrivilegeSet for a simple
175
-     * standard structure.
176
-     *
177
-     * If null is returned from this method, the default privilege set is used,
178
-     * which is fine for most common usecases.
179
-     *
180
-     * @return array|null
181
-     */
182
-    public function getSupportedPrivilegeSet() {
183
-
184
-        return null;
185
-
186
-    }
24
+	/**
25
+	 * Name of this collection.
26
+	 *
27
+	 * @var string
28
+	 */
29
+	public $collectionName = 'home';
30
+
31
+	/**
32
+	 * Path to where the users' files are actually stored.
33
+	 *
34
+	 * @var string
35
+	 */
36
+	protected $storagePath;
37
+
38
+	/**
39
+	 * Creates the home collection.
40
+	 *
41
+	 * @param BackendInterface $principalBackend
42
+	 * @param string $storagePath Where the actual files are stored.
43
+	 * @param string $principalPrefix list of principals to iterate.
44
+	 */
45
+	public function __construct(BackendInterface $principalBackend, $storagePath, $principalPrefix = 'principals') {
46
+
47
+		parent::__construct($principalBackend, $principalPrefix);
48
+		$this->storagePath = $storagePath;
49
+
50
+	}
51
+
52
+	/**
53
+	 * Returns the name of the node.
54
+	 *
55
+	 * This is used to generate the url.
56
+	 *
57
+	 * @return string
58
+	 */
59
+	public function getName() {
60
+
61
+		return $this->collectionName;
62
+
63
+	}
64
+
65
+	/**
66
+	 * Returns a principals' collection of files.
67
+	 *
68
+	 * The passed array contains principal information, and is guaranteed to
69
+	 * at least contain a uri item. Other properties may or may not be
70
+	 * supplied by the authentication backend.
71
+	 *
72
+	 * @param array $principalInfo
73
+	 * @return void
74
+	 */
75
+	public function getChildForPrincipal(array $principalInfo) {
76
+
77
+		$owner = $principalInfo['uri'];
78
+		$acl = [
79
+			[
80
+				'privilege' => '{DAV:}read',
81
+				'principal' => $owner,
82
+				'protected' => true,
83
+			],
84
+			[
85
+				'privilege' => '{DAV:}write',
86
+				'principal' => $owner,
87
+				'protected' => true,
88
+			],
89
+		];
90
+
91
+		list(, $principalBaseName) = Uri\split($owner);
92
+
93
+		$path = $this->storagePath . '/' . $principalBaseName;
94
+
95
+		if (!is_dir($path)) {
96
+			mkdir($path, 0777, true);
97
+		}
98
+		return new Collection(
99
+			$path,
100
+			$acl,
101
+			$owner
102
+		);
103
+
104
+	}
105
+
106
+	/**
107
+	 * Returns the owner principal
108
+	 *
109
+	 * This must be a url to a principal, or null if there's no owner
110
+	 *
111
+	 * @return string|null
112
+	 */
113
+	public function getOwner() {
114
+
115
+		return null;
116
+
117
+	}
118
+
119
+	/**
120
+	 * Returns a group principal
121
+	 *
122
+	 * This must be a url to a principal, or null if there's no owner
123
+	 *
124
+	 * @return string|null
125
+	 */
126
+	public function getGroup() {
127
+
128
+		return null;
129
+
130
+	}
131
+
132
+	/**
133
+	 * Returns a list of ACE's for this node.
134
+	 *
135
+	 * Each ACE has the following properties:
136
+	 *   * 'privilege', a string such as {DAV:}read or {DAV:}write. These are
137
+	 *     currently the only supported privileges
138
+	 *   * 'principal', a url to the principal who owns the node
139
+	 *   * 'protected' (optional), indicating that this ACE is not allowed to
140
+	 *      be updated.
141
+	 *
142
+	 * @return array
143
+	 */
144
+	public function getACL() {
145
+
146
+		return [
147
+			[
148
+				'principal' => '{DAV:}authenticated',
149
+				'privilege' => '{DAV:}read',
150
+				'protected' => true,
151
+			]
152
+		];
153
+
154
+	}
155
+
156
+	/**
157
+	 * Updates the ACL
158
+	 *
159
+	 * This method will receive a list of new ACE's as an array argument.
160
+	 *
161
+	 * @param array $acl
162
+	 * @return void
163
+	 */
164
+	public function setACL(array $acl) {
165
+
166
+		throw new Forbidden('Setting ACL is not allowed here');
167
+
168
+	}
169
+
170
+	/**
171
+	 * Returns the list of supported privileges for this node.
172
+	 *
173
+	 * The returned data structure is a list of nested privileges.
174
+	 * See Sabre\DAVACL\Plugin::getDefaultSupportedPrivilegeSet for a simple
175
+	 * standard structure.
176
+	 *
177
+	 * If null is returned from this method, the default privilege set is used,
178
+	 * which is fine for most common usecases.
179
+	 *
180
+	 * @return array|null
181
+	 */
182
+	public function getSupportedPrivilegeSet() {
183
+
184
+		return null;
185
+
186
+	}
187 187
 
188 188
 }
Please login to merge, or discard this patch.
libraries/SabreDAV/DAVACL/Plugin.php 5 patches
Doc Comments   +9 added lines, -11 removed lines patch added patch discarded remove patch
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
      *
114 114
      * This list is used in the response of a HTTP OPTIONS request.
115 115
      *
116
-     * @return array
116
+     * @return string[]
117 117
      */
118 118
     function getFeatures() {
119 119
 
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
      * Returns a list of available methods for a given url
126 126
      *
127 127
      * @param string $uri
128
-     * @return array
128
+     * @return string[]
129 129
      */
130 130
     function getMethods($uri) {
131 131
 
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
      * implement them
156 156
      *
157 157
      * @param string $uri
158
-     * @return array
158
+     * @return string[]
159 159
      */
160 160
     function getSupportedReportSet($uri) {
161 161
 
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
      * and return true otherwise.
177 177
      *
178 178
      * @param string $uri
179
-     * @param array|string $privileges
179
+     * @param string $privileges
180 180
      * @param int $recursion
181 181
      * @param bool $throwExceptions if set to false, this method won't throw exceptions.
182 182
      * @throws Sabre\DAVACL\Exception\NeedPrivileges
@@ -269,7 +269,7 @@  discard block
 block discarded – undo
269 269
     /**
270 270
      * Returns all the principal groups the specified principal is a member of.
271 271
      *
272
-     * @param string $principal
272
+     * @param string $mainPrincipal
273 273
      * @return array
274 274
      */
275 275
     function getPrincipalMembership($mainPrincipal) {
@@ -831,10 +831,8 @@  discard block
 block discarded – undo
831 831
      *
832 832
      * @param DAV\PropFind $propFind
833 833
      * @param DAV\INode $node
834
-     * @param array $requestedProperties
835
-     * @param array $returnedProperties
836 834
      * @TODO really should be broken into multiple methods, or even a class.
837
-     * @return bool
835
+     * @return false|null
838 836
      */
839 837
     function propFind(DAV\PropFind $propFind, DAV\INode $node) {
840 838
 
@@ -982,7 +980,7 @@  discard block
 block discarded – undo
982 980
      * @param string $reportName
983 981
      * @param mixed $report
984 982
      * @param mixed $path
985
-     * @return bool
983
+     * @return false|null
986 984
      */
987 985
     function report($reportName, $report, $path) {
988 986
 
@@ -1133,7 +1131,7 @@  discard block
 block discarded – undo
1133 1131
      * @param array $path
1134 1132
      * @param array $requestedProperties the list of required properties
1135 1133
      * @param int $depth
1136
-     * @return array
1134
+     * @return DAV\Xml\Element\Response[]
1137 1135
      */
1138 1136
     protected function expandProperties($path, array $requestedProperties, $depth) {
1139 1137
 
@@ -1278,7 +1276,7 @@  discard block
 block discarded – undo
1278 1276
      *
1279 1277
      * @param DAV\INode $node
1280 1278
      * @param string $output
1281
-     * @return bool
1279
+     * @return null|false
1282 1280
      */
1283 1281
     function htmlActionsPanel(DAV\INode $node, &$output) {
1284 1282
 
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -674,15 +674,15 @@
 block discarded – undo
674 674
     function initialize(DAV\Server $server) {
675 675
 
676 676
         $this->server = $server;
677
-        $server->on('propFind',            [$this, 'propFind'], 20);
678
-        $server->on('beforeMethod',        [$this, 'beforeMethod'], 20);
679
-        $server->on('beforeBind',          [$this, 'beforeBind'], 20);
680
-        $server->on('beforeUnbind',        [$this, 'beforeUnbind'], 20);
681
-        $server->on('propPatch',           [$this, 'propPatch']);
682
-        $server->on('beforeUnlock',        [$this, 'beforeUnlock'], 20);
683
-        $server->on('report',              [$this, 'report']);
684
-        $server->on('method:ACL',          [$this, 'httpAcl']);
685
-        $server->on('onHTMLActionsPanel',  [$this, 'htmlActionsPanel']);
677
+        $server->on('propFind', [$this, 'propFind'], 20);
678
+        $server->on('beforeMethod', [$this, 'beforeMethod'], 20);
679
+        $server->on('beforeBind', [$this, 'beforeBind'], 20);
680
+        $server->on('beforeUnbind', [$this, 'beforeUnbind'], 20);
681
+        $server->on('propPatch', [$this, 'propPatch']);
682
+        $server->on('beforeUnlock', [$this, 'beforeUnlock'], 20);
683
+        $server->on('report', [$this, 'report']);
684
+        $server->on('method:ACL', [$this, 'httpAcl']);
685
+        $server->on('onHTMLActionsPanel', [$this, 'htmlActionsPanel']);
686 686
 
687 687
         array_push($server->protectedProperties,
688 688
             '{DAV:}alternate-URI-set',
Please login to merge, or discard this patch.
Braces   +49 added lines, -25 removed lines patch added patch discarded remove patch
@@ -184,7 +184,9 @@  discard block
 block discarded – undo
184 184
      */
185 185
     function checkPrivileges($uri, $privileges, $recursion = self::R_PARENT, $throwExceptions = true) {
186 186
 
187
-        if (!is_array($privileges)) $privileges = [$privileges];
187
+        if (!is_array($privileges)) {
188
+        	$privileges = [$privileges];
189
+        }
188 190
 
189 191
         $acl = $this->getCurrentUserPrivilegeSet($uri);
190 192
 
@@ -192,10 +194,11 @@  discard block
 block discarded – undo
192 194
             if ($this->allowAccessToNodesWithoutACL) {
193 195
                 return true;
194 196
             } else {
195
-                if ($throwExceptions)
196
-                    throw new Exception\NeedPrivileges($uri, $privileges);
197
-                else
198
-                    return false;
197
+                if ($throwExceptions) {
198
+                                    throw new Exception\NeedPrivileges($uri, $privileges);
199
+                } else {
200
+                                    return false;
201
+                }
199 202
 
200 203
             }
201 204
         }
@@ -210,10 +213,11 @@  discard block
 block discarded – undo
210 213
         }
211 214
 
212 215
         if ($failed) {
213
-            if ($throwExceptions)
214
-                throw new Exception\NeedPrivileges($uri, $failed);
215
-            else
216
-                return false;
216
+            if ($throwExceptions) {
217
+                            throw new Exception\NeedPrivileges($uri, $failed);
218
+            } else {
219
+                            return false;
220
+            }
217 221
         }
218 222
         return true;
219 223
 
@@ -230,7 +234,9 @@  discard block
 block discarded – undo
230 234
     function getCurrentUserPrincipal() {
231 235
 
232 236
         $authPlugin = $this->server->getPlugin('auth');
233
-        if (is_null($authPlugin)) return null;
237
+        if (is_null($authPlugin)) {
238
+        	return null;
239
+        }
234 240
         /** @var $authPlugin Sabre\DAV\Auth\Plugin */
235 241
 
236 242
         return $authPlugin->getCurrentPrincipal();
@@ -248,7 +254,9 @@  discard block
 block discarded – undo
248 254
 
249 255
         $currentUser = $this->getCurrentUserPrincipal();
250 256
 
251
-        if (is_null($currentUser)) return [];
257
+        if (is_null($currentUser)) {
258
+        	return [];
259
+        }
252 260
 
253 261
         return array_merge(
254 262
             [$currentUser],
@@ -331,8 +339,9 @@  discard block
 block discarded – undo
331 339
         if ($node instanceof IACL) {
332 340
             $result = $node->getSupportedPrivilegeSet();
333 341
 
334
-            if ($result)
335
-                return $result;
342
+            if ($result) {
343
+                            return $result;
344
+            }
336 345
         }
337 346
 
338 347
         return self::getDefaultSupportedPrivilegeSet();
@@ -506,7 +515,9 @@  discard block
 block discarded – undo
506 515
 
507 516
         $acl = $this->getACL($node);
508 517
 
509
-        if (is_null($acl)) return null;
518
+        if (is_null($acl)) {
519
+        	return null;
520
+        }
510 521
 
511 522
         $principals = $this->getCurrentUserPrincipals();
512 523
 
@@ -730,7 +741,9 @@  discard block
 block discarded – undo
730 741
         $exists = $this->server->tree->nodeExists($path);
731 742
 
732 743
         // If the node doesn't exists, none of these checks apply
733
-        if (!$exists) return;
744
+        if (!$exists) {
745
+        	return;
746
+        }
734 747
 
735 748
         switch ($method) {
736 749
 
@@ -891,7 +904,9 @@  discard block
 block discarded – undo
891 904
 
892 905
             $val = $this->principalCollectionSet;
893 906
             // Ensuring all collections end with a slash
894
-            foreach ($val as $k => $v) $val[$k] = $v . '/';
907
+            foreach ($val as $k => $v) {
908
+            	$val[$k] = $v . '/';
909
+            }
895 910
             return new DAV\Xml\Property\Href($val);
896 911
 
897 912
         });
@@ -1042,7 +1057,9 @@  discard block
 block discarded – undo
1042 1057
            not overwritten. */
1043 1058
         foreach ($oldAcl as $oldAce) {
1044 1059
 
1045
-            if (!isset($oldAce['protected']) || !$oldAce['protected']) continue;
1060
+            if (!isset($oldAce['protected']) || !$oldAce['protected']) {
1061
+            	continue;
1062
+            }
1046 1063
 
1047 1064
             $found = false;
1048 1065
             foreach ($newAcl as $newAce) {
@@ -1050,12 +1067,14 @@  discard block
 block discarded – undo
1050 1067
                     $newAce['privilege'] === $oldAce['privilege'] &&
1051 1068
                     $newAce['principal'] === $oldAce['principal'] &&
1052 1069
                     $newAce['protected']
1053
-                )
1054
-                $found = true;
1070
+                ) {
1071
+                                $found = true;
1072
+                }
1055 1073
             }
1056 1074
 
1057
-            if (!$found)
1058
-                throw new Exception\AceConflict('This resource contained a protected {DAV:}ace, but this privilege did not occur in the ACL request');
1075
+            if (!$found) {
1076
+                            throw new Exception\AceConflict('This resource contained a protected {DAV:}ace, but this privilege did not occur in the ACL request');
1077
+            }
1059 1078
 
1060 1079
         }
1061 1080
 
@@ -1146,11 +1165,15 @@  discard block
 block discarded – undo
1146 1165
             foreach ($requestedProperties as $propertyName => $childRequestedProperties) {
1147 1166
 
1148 1167
                 // We're only traversing if sub-properties were requested
1149
-                if (count($childRequestedProperties) === 0) continue;
1168
+                if (count($childRequestedProperties) === 0) {
1169
+                	continue;
1170
+                }
1150 1171
 
1151 1172
                 // We only have to do the expansion if the property was found
1152 1173
                 // and it contains an href element.
1153
-                if (!array_key_exists($propertyName, $node[200])) continue;
1174
+                if (!array_key_exists($propertyName, $node[200])) {
1175
+                	continue;
1176
+                }
1154 1177
 
1155 1178
                 if (!$node[200][$propertyName] instanceof DAV\Xml\Property\Href) {
1156 1179
                     continue;
@@ -1282,8 +1305,9 @@  discard block
 block discarded – undo
1282 1305
      */
1283 1306
     function htmlActionsPanel(DAV\INode $node, &$output) {
1284 1307
 
1285
-        if (!$node instanceof PrincipalCollection)
1286
-            return;
1308
+        if (!$node instanceof PrincipalCollection) {
1309
+                    return;
1310
+        }
1287 1311
 
1288 1312
         $output .= '<tr><td colspan="2"><form method="post" action="">
1289 1313
             <h3>Create new principal</h3>
Please login to merge, or discard this patch.
Unused Use Statements   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -3,8 +3,8 @@
 block discarded – undo
3 3
 namespace Sabre\DAVACL;
4 4
 
5 5
 use Sabre\DAV;
6
-use Sabre\DAV\INode;
7 6
 use Sabre\DAV\Exception\BadRequest;
7
+use Sabre\DAV\INode;
8 8
 use Sabre\HTTP\RequestInterface;
9 9
 use Sabre\HTTP\ResponseInterface;
10 10
 use Sabre\Uri;
Please login to merge, or discard this patch.
Indentation   +1255 added lines, -1255 removed lines patch added patch discarded remove patch
@@ -25,1265 +25,1265 @@  discard block
 block discarded – undo
25 25
  */
26 26
 class Plugin extends DAV\ServerPlugin {
27 27
 
28
-    /**
29
-     * Recursion constants
30
-     *
31
-     * This only checks the base node
32
-     */
33
-    const R_PARENT = 1;
34
-
35
-    /**
36
-     * Recursion constants
37
-     *
38
-     * This checks every node in the tree
39
-     */
40
-    const R_RECURSIVE = 2;
41
-
42
-    /**
43
-     * Recursion constants
44
-     *
45
-     * This checks every parentnode in the tree, but not leaf-nodes.
46
-     */
47
-    const R_RECURSIVEPARENTS = 3;
48
-
49
-    /**
50
-     * Reference to server object.
51
-     *
52
-     * @var Sabre\DAV\Server
53
-     */
54
-    protected $server;
55
-
56
-    /**
57
-     * List of urls containing principal collections.
58
-     * Modify this if your principals are located elsewhere.
59
-     *
60
-     * @var array
61
-     */
62
-    public $principalCollectionSet = [
63
-        'principals',
64
-    ];
65
-
66
-    /**
67
-     * By default ACL is only enforced for nodes that have ACL support (the
68
-     * ones that implement IACL). For any other node, access is
69
-     * always granted.
70
-     *
71
-     * To override this behaviour you can turn this setting off. This is useful
72
-     * if you plan to fully support ACL in the entire tree.
73
-     *
74
-     * @var bool
75
-     */
76
-    public $allowAccessToNodesWithoutACL = true;
77
-
78
-    /**
79
-     * By default nodes that are inaccessible by the user, can still be seen
80
-     * in directory listings (PROPFIND on parent with Depth: 1)
81
-     *
82
-     * In certain cases it's desirable to hide inaccessible nodes. Setting this
83
-     * to true will cause these nodes to be hidden from directory listings.
84
-     *
85
-     * @var bool
86
-     */
87
-    public $hideNodesFromListings = false;
88
-
89
-    /**
90
-     * This list of properties are the properties a client can search on using
91
-     * the {DAV:}principal-property-search report.
92
-     *
93
-     * The keys are the property names, values are descriptions.
94
-     *
95
-     * @var array
96
-     */
97
-    public $principalSearchPropertySet = [
98
-        '{DAV:}displayname'                     => 'Display name',
99
-        '{http://sabredav.org/ns}email-address' => 'Email address',
100
-    ];
101
-
102
-    /**
103
-     * Any principal uri's added here, will automatically be added to the list
104
-     * of ACL's. They will effectively receive {DAV:}all privileges, as a
105
-     * protected privilege.
106
-     *
107
-     * @var array
108
-     */
109
-    public $adminPrincipals = [];
110
-
111
-    /**
112
-     * Returns a list of features added by this plugin.
113
-     *
114
-     * This list is used in the response of a HTTP OPTIONS request.
115
-     *
116
-     * @return array
117
-     */
118
-    public function getFeatures() {
119
-
120
-        return ['access-control', 'calendarserver-principal-property-search'];
121
-
122
-    }
123
-
124
-    /**
125
-     * Returns a list of available methods for a given url
126
-     *
127
-     * @param string $uri
128
-     * @return array
129
-     */
130
-    public function getMethods($uri) {
131
-
132
-        return ['ACL'];
133
-
134
-    }
135
-
136
-    /**
137
-     * Returns a plugin name.
138
-     *
139
-     * Using this name other plugins will be able to access other plugins
140
-     * using Sabre\DAV\Server::getPlugin
141
-     *
142
-     * @return string
143
-     */
144
-    public function getPluginName() {
145
-
146
-        return 'acl';
147
-
148
-    }
149
-
150
-    /**
151
-     * Returns a list of reports this plugin supports.
152
-     *
153
-     * This will be used in the {DAV:}supported-report-set property.
154
-     * Note that you still need to subscribe to the 'report' event to actually
155
-     * implement them
156
-     *
157
-     * @param string $uri
158
-     * @return array
159
-     */
160
-    public function getSupportedReportSet($uri) {
161
-
162
-        return [
163
-            '{DAV:}expand-property',
164
-            '{DAV:}principal-property-search',
165
-            '{DAV:}principal-search-property-set',
166
-        ];
167
-
168
-    }
169
-
170
-
171
-    /**
172
-     * Checks if the current user has the specified privilege(s).
173
-     *
174
-     * You can specify a single privilege, or a list of privileges.
175
-     * This method will throw an exception if the privilege is not available
176
-     * and return true otherwise.
177
-     *
178
-     * @param string $uri
179
-     * @param array|string $privileges
180
-     * @param int $recursion
181
-     * @param bool $throwExceptions if set to false, this method won't throw exceptions.
182
-     * @throws Sabre\DAVACL\Exception\NeedPrivileges
183
-     * @return bool
184
-     */
185
-    public function checkPrivileges($uri, $privileges, $recursion = self::R_PARENT, $throwExceptions = true) {
186
-
187
-        if (!is_array($privileges)) $privileges = [$privileges];
188
-
189
-        $acl = $this->getCurrentUserPrivilegeSet($uri);
190
-
191
-        if (is_null($acl)) {
192
-            if ($this->allowAccessToNodesWithoutACL) {
193
-                return true;
194
-            } else {
195
-                if ($throwExceptions)
196
-                    throw new Exception\NeedPrivileges($uri, $privileges);
197
-                else
198
-                    return false;
199
-
200
-            }
201
-        }
202
-
203
-        $failed = [];
204
-        foreach ($privileges as $priv) {
205
-
206
-            if (!in_array($priv, $acl)) {
207
-                $failed[] = $priv;
208
-            }
209
-
210
-        }
211
-
212
-        if ($failed) {
213
-            if ($throwExceptions)
214
-                throw new Exception\NeedPrivileges($uri, $failed);
215
-            else
216
-                return false;
217
-        }
218
-        return true;
28
+	/**
29
+	 * Recursion constants
30
+	 *
31
+	 * This only checks the base node
32
+	 */
33
+	const R_PARENT = 1;
34
+
35
+	/**
36
+	 * Recursion constants
37
+	 *
38
+	 * This checks every node in the tree
39
+	 */
40
+	const R_RECURSIVE = 2;
41
+
42
+	/**
43
+	 * Recursion constants
44
+	 *
45
+	 * This checks every parentnode in the tree, but not leaf-nodes.
46
+	 */
47
+	const R_RECURSIVEPARENTS = 3;
48
+
49
+	/**
50
+	 * Reference to server object.
51
+	 *
52
+	 * @var Sabre\DAV\Server
53
+	 */
54
+	protected $server;
55
+
56
+	/**
57
+	 * List of urls containing principal collections.
58
+	 * Modify this if your principals are located elsewhere.
59
+	 *
60
+	 * @var array
61
+	 */
62
+	public $principalCollectionSet = [
63
+		'principals',
64
+	];
65
+
66
+	/**
67
+	 * By default ACL is only enforced for nodes that have ACL support (the
68
+	 * ones that implement IACL). For any other node, access is
69
+	 * always granted.
70
+	 *
71
+	 * To override this behaviour you can turn this setting off. This is useful
72
+	 * if you plan to fully support ACL in the entire tree.
73
+	 *
74
+	 * @var bool
75
+	 */
76
+	public $allowAccessToNodesWithoutACL = true;
77
+
78
+	/**
79
+	 * By default nodes that are inaccessible by the user, can still be seen
80
+	 * in directory listings (PROPFIND on parent with Depth: 1)
81
+	 *
82
+	 * In certain cases it's desirable to hide inaccessible nodes. Setting this
83
+	 * to true will cause these nodes to be hidden from directory listings.
84
+	 *
85
+	 * @var bool
86
+	 */
87
+	public $hideNodesFromListings = false;
88
+
89
+	/**
90
+	 * This list of properties are the properties a client can search on using
91
+	 * the {DAV:}principal-property-search report.
92
+	 *
93
+	 * The keys are the property names, values are descriptions.
94
+	 *
95
+	 * @var array
96
+	 */
97
+	public $principalSearchPropertySet = [
98
+		'{DAV:}displayname'                     => 'Display name',
99
+		'{http://sabredav.org/ns}email-address' => 'Email address',
100
+	];
101
+
102
+	/**
103
+	 * Any principal uri's added here, will automatically be added to the list
104
+	 * of ACL's. They will effectively receive {DAV:}all privileges, as a
105
+	 * protected privilege.
106
+	 *
107
+	 * @var array
108
+	 */
109
+	public $adminPrincipals = [];
110
+
111
+	/**
112
+	 * Returns a list of features added by this plugin.
113
+	 *
114
+	 * This list is used in the response of a HTTP OPTIONS request.
115
+	 *
116
+	 * @return array
117
+	 */
118
+	public function getFeatures() {
119
+
120
+		return ['access-control', 'calendarserver-principal-property-search'];
121
+
122
+	}
123
+
124
+	/**
125
+	 * Returns a list of available methods for a given url
126
+	 *
127
+	 * @param string $uri
128
+	 * @return array
129
+	 */
130
+	public function getMethods($uri) {
131
+
132
+		return ['ACL'];
133
+
134
+	}
135
+
136
+	/**
137
+	 * Returns a plugin name.
138
+	 *
139
+	 * Using this name other plugins will be able to access other plugins
140
+	 * using Sabre\DAV\Server::getPlugin
141
+	 *
142
+	 * @return string
143
+	 */
144
+	public function getPluginName() {
145
+
146
+		return 'acl';
147
+
148
+	}
149
+
150
+	/**
151
+	 * Returns a list of reports this plugin supports.
152
+	 *
153
+	 * This will be used in the {DAV:}supported-report-set property.
154
+	 * Note that you still need to subscribe to the 'report' event to actually
155
+	 * implement them
156
+	 *
157
+	 * @param string $uri
158
+	 * @return array
159
+	 */
160
+	public function getSupportedReportSet($uri) {
161
+
162
+		return [
163
+			'{DAV:}expand-property',
164
+			'{DAV:}principal-property-search',
165
+			'{DAV:}principal-search-property-set',
166
+		];
167
+
168
+	}
169
+
170
+
171
+	/**
172
+	 * Checks if the current user has the specified privilege(s).
173
+	 *
174
+	 * You can specify a single privilege, or a list of privileges.
175
+	 * This method will throw an exception if the privilege is not available
176
+	 * and return true otherwise.
177
+	 *
178
+	 * @param string $uri
179
+	 * @param array|string $privileges
180
+	 * @param int $recursion
181
+	 * @param bool $throwExceptions if set to false, this method won't throw exceptions.
182
+	 * @throws Sabre\DAVACL\Exception\NeedPrivileges
183
+	 * @return bool
184
+	 */
185
+	public function checkPrivileges($uri, $privileges, $recursion = self::R_PARENT, $throwExceptions = true) {
186
+
187
+		if (!is_array($privileges)) $privileges = [$privileges];
188
+
189
+		$acl = $this->getCurrentUserPrivilegeSet($uri);
190
+
191
+		if (is_null($acl)) {
192
+			if ($this->allowAccessToNodesWithoutACL) {
193
+				return true;
194
+			} else {
195
+				if ($throwExceptions)
196
+					throw new Exception\NeedPrivileges($uri, $privileges);
197
+				else
198
+					return false;
199
+
200
+			}
201
+		}
202
+
203
+		$failed = [];
204
+		foreach ($privileges as $priv) {
205
+
206
+			if (!in_array($priv, $acl)) {
207
+				$failed[] = $priv;
208
+			}
209
+
210
+		}
211
+
212
+		if ($failed) {
213
+			if ($throwExceptions)
214
+				throw new Exception\NeedPrivileges($uri, $failed);
215
+			else
216
+				return false;
217
+		}
218
+		return true;
219 219
 
220
-    }
221
-
222
-    /**
223
-     * Returns the standard users' principal.
224
-     *
225
-     * This is one authorative principal url for the current user.
226
-     * This method will return null if the user wasn't logged in.
227
-     *
228
-     * @return string|null
229
-     */
230
-    public function getCurrentUserPrincipal() {
231
-
232
-        $authPlugin = $this->server->getPlugin('auth');
233
-        if (is_null($authPlugin)) return null;
234
-        /** @var $authPlugin Sabre\DAV\Auth\Plugin */
235
-
236
-        return $authPlugin->getCurrentPrincipal();
237
-
238
-    }
239
-
240
-
241
-    /**
242
-     * Returns a list of principals that's associated to the current
243
-     * user, either directly or through group membership.
244
-     *
245
-     * @return array
246
-     */
247
-    public function getCurrentUserPrincipals() {
248
-
249
-        $currentUser = $this->getCurrentUserPrincipal();
250
-
251
-        if (is_null($currentUser)) return [];
252
-
253
-        return array_merge(
254
-            [$currentUser],
255
-            $this->getPrincipalMembership($currentUser)
256
-        );
257
-
258
-    }
259
-
260
-    /**
261
-     * This array holds a cache for all the principals that are associated with
262
-     * a single principal.
263
-     *
264
-     * @var array
265
-     */
266
-    protected $principalMembershipCache = [];
267
-
268
-
269
-    /**
270
-     * Returns all the principal groups the specified principal is a member of.
271
-     *
272
-     * @param string $principal
273
-     * @return array
274
-     */
275
-    public function getPrincipalMembership($mainPrincipal) {
276
-
277
-        // First check our cache
278
-        if (isset($this->principalMembershipCache[$mainPrincipal])) {
279
-            return $this->principalMembershipCache[$mainPrincipal];
280
-        }
281
-
282
-        $check = [$mainPrincipal];
283
-        $principals = [];
284
-
285
-        while (count($check)) {
286
-
287
-            $principal = array_shift($check);
288
-
289
-            $node = $this->server->tree->getNodeForPath($principal);
290
-            if ($node instanceof IPrincipal) {
291
-                foreach ($node->getGroupMembership() as $groupMember) {
292
-
293
-                    if (!in_array($groupMember, $principals)) {
294
-
295
-                        $check[] = $groupMember;
296
-                        $principals[] = $groupMember;
297
-
298
-                    }
299
-
300
-                }
301
-
302
-            }
303
-
304
-        }
305
-
306
-        // Store the result in the cache
307
-        $this->principalMembershipCache[$mainPrincipal] = $principals;
308
-
309
-        return $principals;
310
-
311
-    }
312
-
313
-    /**
314
-     * Returns the supported privilege structure for this ACL plugin.
315
-     *
316
-     * See RFC3744 for more details. Currently we default on a simple,
317
-     * standard structure.
318
-     *
319
-     * You can either get the list of privileges by a uri (path) or by
320
-     * specifying a Node.
321
-     *
322
-     * @param string|INode $node
323
-     * @return array
324
-     */
325
-    public function getSupportedPrivilegeSet($node) {
326
-
327
-        if (is_string($node)) {
328
-            $node = $this->server->tree->getNodeForPath($node);
329
-        }
330
-
331
-        if ($node instanceof IACL) {
332
-            $result = $node->getSupportedPrivilegeSet();
333
-
334
-            if ($result)
335
-                return $result;
336
-        }
337
-
338
-        return self::getDefaultSupportedPrivilegeSet();
339
-
340
-    }
341
-
342
-    /**
343
-     * Returns a fairly standard set of privileges, which may be useful for
344
-     * other systems to use as a basis.
345
-     *
346
-     * @return array
347
-     */
348
-    static function getDefaultSupportedPrivilegeSet() {
349
-
350
-        return [
351
-            'privilege'  => '{DAV:}all',
352
-            'abstract'   => true,
353
-            'aggregates' => [
354
-                [
355
-                    'privilege'  => '{DAV:}read',
356
-                    'aggregates' => [
357
-                        [
358
-                            'privilege' => '{DAV:}read-acl',
359
-                            'abstract'  => false,
360
-                        ],
361
-                        [
362
-                            'privilege' => '{DAV:}read-current-user-privilege-set',
363
-                            'abstract'  => false,
364
-                        ],
365
-                    ],
366
-                ], // {DAV:}read
367
-                [
368
-                    'privilege'  => '{DAV:}write',
369
-                    'aggregates' => [
370
-                        [
371
-                            'privilege' => '{DAV:}write-acl',
372
-                            'abstract'  => false,
373
-                        ],
374
-                        [
375
-                            'privilege' => '{DAV:}write-properties',
376
-                            'abstract'  => false,
377
-                        ],
378
-                        [
379
-                            'privilege' => '{DAV:}write-content',
380
-                            'abstract'  => false,
381
-                        ],
382
-                        [
383
-                            'privilege' => '{DAV:}bind',
384
-                            'abstract'  => false,
385
-                        ],
386
-                        [
387
-                            'privilege' => '{DAV:}unbind',
388
-                            'abstract'  => false,
389
-                        ],
390
-                        [
391
-                            'privilege' => '{DAV:}unlock',
392
-                            'abstract'  => false,
393
-                        ],
394
-                    ],
395
-                ], // {DAV:}write
396
-            ],
397
-        ]; // {DAV:}all
398
-
399
-    }
400
-
401
-    /**
402
-     * Returns the supported privilege set as a flat list
403
-     *
404
-     * This is much easier to parse.
405
-     *
406
-     * The returned list will be index by privilege name.
407
-     * The value is a struct containing the following properties:
408
-     *   - aggregates
409
-     *   - abstract
410
-     *   - concrete
411
-     *
412
-     * @param string|INode $node
413
-     * @return array
414
-     */
415
-    final function getFlatPrivilegeSet($node) {
416
-
417
-        $privs = $this->getSupportedPrivilegeSet($node);
418
-
419
-        $fpsTraverse = null;
420
-        $fpsTraverse = function($priv, $concrete, &$flat) use (&$fpsTraverse) {
421
-
422
-            $myPriv = [
423
-                'privilege'  => $priv['privilege'],
424
-                'abstract'   => isset($priv['abstract']) && $priv['abstract'],
425
-                'aggregates' => [],
426
-                'concrete'   => isset($priv['abstract']) && $priv['abstract'] ? $concrete : $priv['privilege'],
427
-            ];
428
-
429
-            if (isset($priv['aggregates'])) {
430
-
431
-                foreach ($priv['aggregates'] as $subPriv) {
432
-
433
-                    $myPriv['aggregates'][] = $subPriv['privilege'];
434
-
435
-                }
436
-
437
-            }
438
-
439
-            $flat[$priv['privilege']] = $myPriv;
440
-
441
-            if (isset($priv['aggregates'])) {
442
-
443
-                foreach ($priv['aggregates'] as $subPriv) {
444
-
445
-                    $fpsTraverse($subPriv, $myPriv['concrete'], $flat);
446
-
447
-                }
448
-
449
-            }
450
-
451
-        };
452
-
453
-        $flat = [];
454
-        $fpsTraverse($privs, null, $flat);
455
-
456
-        return $flat;
457
-
458
-    }
459
-
460
-    /**
461
-     * Returns the full ACL list.
462
-     *
463
-     * Either a uri or a INode may be passed.
464
-     *
465
-     * null will be returned if the node doesn't support ACLs.
466
-     *
467
-     * @param string|DAV\INode $node
468
-     * @return array
469
-     */
470
-    public function getACL($node) {
471
-
472
-        if (is_string($node)) {
473
-            $node = $this->server->tree->getNodeForPath($node);
474
-        }
475
-        if (!$node instanceof IACL) {
476
-            return null;
477
-        }
478
-        $acl = $node->getACL();
479
-        foreach ($this->adminPrincipals as $adminPrincipal) {
480
-            $acl[] = [
481
-                'principal' => $adminPrincipal,
482
-                'privilege' => '{DAV:}all',
483
-                'protected' => true,
484
-            ];
485
-        }
486
-        return $acl;
220
+	}
221
+
222
+	/**
223
+	 * Returns the standard users' principal.
224
+	 *
225
+	 * This is one authorative principal url for the current user.
226
+	 * This method will return null if the user wasn't logged in.
227
+	 *
228
+	 * @return string|null
229
+	 */
230
+	public function getCurrentUserPrincipal() {
231
+
232
+		$authPlugin = $this->server->getPlugin('auth');
233
+		if (is_null($authPlugin)) return null;
234
+		/** @var $authPlugin Sabre\DAV\Auth\Plugin */
235
+
236
+		return $authPlugin->getCurrentPrincipal();
237
+
238
+	}
239
+
240
+
241
+	/**
242
+	 * Returns a list of principals that's associated to the current
243
+	 * user, either directly or through group membership.
244
+	 *
245
+	 * @return array
246
+	 */
247
+	public function getCurrentUserPrincipals() {
248
+
249
+		$currentUser = $this->getCurrentUserPrincipal();
250
+
251
+		if (is_null($currentUser)) return [];
252
+
253
+		return array_merge(
254
+			[$currentUser],
255
+			$this->getPrincipalMembership($currentUser)
256
+		);
257
+
258
+	}
259
+
260
+	/**
261
+	 * This array holds a cache for all the principals that are associated with
262
+	 * a single principal.
263
+	 *
264
+	 * @var array
265
+	 */
266
+	protected $principalMembershipCache = [];
267
+
268
+
269
+	/**
270
+	 * Returns all the principal groups the specified principal is a member of.
271
+	 *
272
+	 * @param string $principal
273
+	 * @return array
274
+	 */
275
+	public function getPrincipalMembership($mainPrincipal) {
276
+
277
+		// First check our cache
278
+		if (isset($this->principalMembershipCache[$mainPrincipal])) {
279
+			return $this->principalMembershipCache[$mainPrincipal];
280
+		}
281
+
282
+		$check = [$mainPrincipal];
283
+		$principals = [];
284
+
285
+		while (count($check)) {
286
+
287
+			$principal = array_shift($check);
288
+
289
+			$node = $this->server->tree->getNodeForPath($principal);
290
+			if ($node instanceof IPrincipal) {
291
+				foreach ($node->getGroupMembership() as $groupMember) {
292
+
293
+					if (!in_array($groupMember, $principals)) {
294
+
295
+						$check[] = $groupMember;
296
+						$principals[] = $groupMember;
297
+
298
+					}
299
+
300
+				}
301
+
302
+			}
303
+
304
+		}
305
+
306
+		// Store the result in the cache
307
+		$this->principalMembershipCache[$mainPrincipal] = $principals;
308
+
309
+		return $principals;
310
+
311
+	}
312
+
313
+	/**
314
+	 * Returns the supported privilege structure for this ACL plugin.
315
+	 *
316
+	 * See RFC3744 for more details. Currently we default on a simple,
317
+	 * standard structure.
318
+	 *
319
+	 * You can either get the list of privileges by a uri (path) or by
320
+	 * specifying a Node.
321
+	 *
322
+	 * @param string|INode $node
323
+	 * @return array
324
+	 */
325
+	public function getSupportedPrivilegeSet($node) {
326
+
327
+		if (is_string($node)) {
328
+			$node = $this->server->tree->getNodeForPath($node);
329
+		}
330
+
331
+		if ($node instanceof IACL) {
332
+			$result = $node->getSupportedPrivilegeSet();
333
+
334
+			if ($result)
335
+				return $result;
336
+		}
337
+
338
+		return self::getDefaultSupportedPrivilegeSet();
339
+
340
+	}
341
+
342
+	/**
343
+	 * Returns a fairly standard set of privileges, which may be useful for
344
+	 * other systems to use as a basis.
345
+	 *
346
+	 * @return array
347
+	 */
348
+	static function getDefaultSupportedPrivilegeSet() {
349
+
350
+		return [
351
+			'privilege'  => '{DAV:}all',
352
+			'abstract'   => true,
353
+			'aggregates' => [
354
+				[
355
+					'privilege'  => '{DAV:}read',
356
+					'aggregates' => [
357
+						[
358
+							'privilege' => '{DAV:}read-acl',
359
+							'abstract'  => false,
360
+						],
361
+						[
362
+							'privilege' => '{DAV:}read-current-user-privilege-set',
363
+							'abstract'  => false,
364
+						],
365
+					],
366
+				], // {DAV:}read
367
+				[
368
+					'privilege'  => '{DAV:}write',
369
+					'aggregates' => [
370
+						[
371
+							'privilege' => '{DAV:}write-acl',
372
+							'abstract'  => false,
373
+						],
374
+						[
375
+							'privilege' => '{DAV:}write-properties',
376
+							'abstract'  => false,
377
+						],
378
+						[
379
+							'privilege' => '{DAV:}write-content',
380
+							'abstract'  => false,
381
+						],
382
+						[
383
+							'privilege' => '{DAV:}bind',
384
+							'abstract'  => false,
385
+						],
386
+						[
387
+							'privilege' => '{DAV:}unbind',
388
+							'abstract'  => false,
389
+						],
390
+						[
391
+							'privilege' => '{DAV:}unlock',
392
+							'abstract'  => false,
393
+						],
394
+					],
395
+				], // {DAV:}write
396
+			],
397
+		]; // {DAV:}all
398
+
399
+	}
400
+
401
+	/**
402
+	 * Returns the supported privilege set as a flat list
403
+	 *
404
+	 * This is much easier to parse.
405
+	 *
406
+	 * The returned list will be index by privilege name.
407
+	 * The value is a struct containing the following properties:
408
+	 *   - aggregates
409
+	 *   - abstract
410
+	 *   - concrete
411
+	 *
412
+	 * @param string|INode $node
413
+	 * @return array
414
+	 */
415
+	final function getFlatPrivilegeSet($node) {
416
+
417
+		$privs = $this->getSupportedPrivilegeSet($node);
418
+
419
+		$fpsTraverse = null;
420
+		$fpsTraverse = function($priv, $concrete, &$flat) use (&$fpsTraverse) {
421
+
422
+			$myPriv = [
423
+				'privilege'  => $priv['privilege'],
424
+				'abstract'   => isset($priv['abstract']) && $priv['abstract'],
425
+				'aggregates' => [],
426
+				'concrete'   => isset($priv['abstract']) && $priv['abstract'] ? $concrete : $priv['privilege'],
427
+			];
428
+
429
+			if (isset($priv['aggregates'])) {
430
+
431
+				foreach ($priv['aggregates'] as $subPriv) {
432
+
433
+					$myPriv['aggregates'][] = $subPriv['privilege'];
434
+
435
+				}
436
+
437
+			}
438
+
439
+			$flat[$priv['privilege']] = $myPriv;
440
+
441
+			if (isset($priv['aggregates'])) {
442
+
443
+				foreach ($priv['aggregates'] as $subPriv) {
444
+
445
+					$fpsTraverse($subPriv, $myPriv['concrete'], $flat);
446
+
447
+				}
448
+
449
+			}
450
+
451
+		};
452
+
453
+		$flat = [];
454
+		$fpsTraverse($privs, null, $flat);
455
+
456
+		return $flat;
457
+
458
+	}
459
+
460
+	/**
461
+	 * Returns the full ACL list.
462
+	 *
463
+	 * Either a uri or a INode may be passed.
464
+	 *
465
+	 * null will be returned if the node doesn't support ACLs.
466
+	 *
467
+	 * @param string|DAV\INode $node
468
+	 * @return array
469
+	 */
470
+	public function getACL($node) {
471
+
472
+		if (is_string($node)) {
473
+			$node = $this->server->tree->getNodeForPath($node);
474
+		}
475
+		if (!$node instanceof IACL) {
476
+			return null;
477
+		}
478
+		$acl = $node->getACL();
479
+		foreach ($this->adminPrincipals as $adminPrincipal) {
480
+			$acl[] = [
481
+				'principal' => $adminPrincipal,
482
+				'privilege' => '{DAV:}all',
483
+				'protected' => true,
484
+			];
485
+		}
486
+		return $acl;
487 487
 
488
-    }
488
+	}
489 489
 
490
-    /**
491
-     * Returns a list of privileges the current user has
492
-     * on a particular node.
493
-     *
494
-     * Either a uri or a DAV\INode may be passed.
495
-     *
496
-     * null will be returned if the node doesn't support ACLs.
497
-     *
498
-     * @param string|DAV\INode $node
499
-     * @return array
500
-     */
501
-    public function getCurrentUserPrivilegeSet($node) {
490
+	/**
491
+	 * Returns a list of privileges the current user has
492
+	 * on a particular node.
493
+	 *
494
+	 * Either a uri or a DAV\INode may be passed.
495
+	 *
496
+	 * null will be returned if the node doesn't support ACLs.
497
+	 *
498
+	 * @param string|DAV\INode $node
499
+	 * @return array
500
+	 */
501
+	public function getCurrentUserPrivilegeSet($node) {
502 502
 
503
-        if (is_string($node)) {
504
-            $node = $this->server->tree->getNodeForPath($node);
505
-        }
503
+		if (is_string($node)) {
504
+			$node = $this->server->tree->getNodeForPath($node);
505
+		}
506 506
 
507
-        $acl = $this->getACL($node);
507
+		$acl = $this->getACL($node);
508 508
 
509
-        if (is_null($acl)) return null;
509
+		if (is_null($acl)) return null;
510 510
 
511
-        $principals = $this->getCurrentUserPrincipals();
511
+		$principals = $this->getCurrentUserPrincipals();
512 512
 
513
-        $collected = [];
513
+		$collected = [];
514 514
 
515
-        foreach ($acl as $ace) {
515
+		foreach ($acl as $ace) {
516 516
 
517
-            $principal = $ace['principal'];
517
+			$principal = $ace['principal'];
518 518
 
519
-            switch ($principal) {
519
+			switch ($principal) {
520 520
 
521
-                case '{DAV:}owner' :
522
-                    $owner = $node->getOwner();
523
-                    if ($owner && in_array($owner, $principals)) {
524
-                        $collected[] = $ace;
525
-                    }
526
-                    break;
521
+				case '{DAV:}owner' :
522
+					$owner = $node->getOwner();
523
+					if ($owner && in_array($owner, $principals)) {
524
+						$collected[] = $ace;
525
+					}
526
+					break;
527 527
 
528 528
 
529
-                // 'all' matches for every user
530
-                case '{DAV:}all' :
529
+				// 'all' matches for every user
530
+				case '{DAV:}all' :
531 531
 
532
-                // 'authenticated' matched for every user that's logged in.
533
-                // Since it's not possible to use ACL while not being logged
534
-                // in, this is also always true.
535
-                case '{DAV:}authenticated' :
536
-                    $collected[] = $ace;
537
-                    break;
538
-
539
-                // 'unauthenticated' can never occur either, so we simply
540
-                // ignore these.
541
-                case '{DAV:}unauthenticated' :
542
-                    break;
543
-
544
-                default :
545
-                    if (in_array($ace['principal'], $principals)) {
546
-                        $collected[] = $ace;
547
-                    }
548
-                    break;
549
-
550
-            }
551
-
552
-
553
-        }
554
-
555
-        // Now we deduct all aggregated privileges.
556
-        $flat = $this->getFlatPrivilegeSet($node);
557
-
558
-        $collected2 = [];
559
-        while (count($collected)) {
560
-
561
-            $current = array_pop($collected);
562
-            $collected2[] = $current['privilege'];
563
-
564
-            foreach ($flat[$current['privilege']]['aggregates'] as $subPriv) {
565
-                $collected2[] = $subPriv;
566
-                $collected[] = $flat[$subPriv];
567
-            }
568
-
569
-        }
570
-
571
-        return array_values(array_unique($collected2));
572
-
573
-    }
574
-
575
-
576
-    /**
577
-     * Returns a principal based on its uri.
578
-     *
579
-     * Returns null if the principal could not be found.
580
-     *
581
-     * @param string $uri
582
-     * @return null|string
583
-     */
584
-    public function getPrincipalByUri($uri) {
585
-
586
-        $result = null;
587
-        $collections = $this->principalCollectionSet;
588
-        foreach ($collections as $collection) {
589
-
590
-            $principalCollection = $this->server->tree->getNodeForPath($collection);
591
-            if (!$principalCollection instanceof IPrincipalCollection) {
592
-                // Not a principal collection, we're simply going to ignore
593
-                // this.
594
-                continue;
595
-            }
596
-
597
-            $result = $principalCollection->findByUri($uri);
598
-            if ($result) {
599
-                return $result;
600
-            }
601
-
602
-        }
603
-
604
-    }
605
-
606
-    /**
607
-     * Principal property search
608
-     *
609
-     * This method can search for principals matching certain values in
610
-     * properties.
611
-     *
612
-     * This method will return a list of properties for the matched properties.
613
-     *
614
-     * @param array $searchProperties    The properties to search on. This is a
615
-     *                                   key-value list. The keys are property
616
-     *                                   names, and the values the strings to
617
-     *                                   match them on.
618
-     * @param array $requestedProperties This is the list of properties to
619
-     *                                   return for every match.
620
-     * @param string $collectionUri      The principal collection to search on.
621
-     *                                   If this is ommitted, the standard
622
-     *                                   principal collection-set will be used.
623
-     * @param string $test               "allof" to use AND to search the
624
-     *                                   properties. 'anyof' for OR.
625
-     * @return array     This method returns an array structure similar to
626
-     *                  Sabre\DAV\Server::getPropertiesForPath. Returned
627
-     *                  properties are index by a HTTP status code.
628
-     */
629
-    public function principalSearch(array $searchProperties, array $requestedProperties, $collectionUri = null, $test = 'allof') {
630
-
631
-        if (!is_null($collectionUri)) {
632
-            $uris = [$collectionUri];
633
-        } else {
634
-            $uris = $this->principalCollectionSet;
635
-        }
636
-
637
-        $lookupResults = [];
638
-        foreach ($uris as $uri) {
639
-
640
-            $principalCollection = $this->server->tree->getNodeForPath($uri);
641
-            if (!$principalCollection instanceof IPrincipalCollection) {
642
-                // Not a principal collection, we're simply going to ignore
643
-                // this.
644
-                continue;
645
-            }
646
-
647
-            $results = $principalCollection->searchPrincipals($searchProperties, $test);
648
-            foreach ($results as $result) {
649
-                $lookupResults[] = rtrim($uri, '/') . '/' . $result;
650
-            }
651
-
652
-        }
653
-
654
-        $matches = [];
655
-
656
-        foreach ($lookupResults as $lookupResult) {
657
-
658
-            list($matches[]) = $this->server->getPropertiesForPath($lookupResult, $requestedProperties, 0);
659
-
660
-        }
661
-
662
-        return $matches;
663
-
664
-    }
665
-
666
-    /**
667
-     * Sets up the plugin
668
-     *
669
-     * This method is automatically called by the server class.
670
-     *
671
-     * @param DAV\Server $server
672
-     * @return void
673
-     */
674
-    public function initialize(DAV\Server $server) {
675
-
676
-        $this->server = $server;
677
-        $server->on('propFind',            [$this, 'propFind'], 20);
678
-        $server->on('beforeMethod',        [$this, 'beforeMethod'], 20);
679
-        $server->on('beforeBind',          [$this, 'beforeBind'], 20);
680
-        $server->on('beforeUnbind',        [$this, 'beforeUnbind'], 20);
681
-        $server->on('propPatch',           [$this, 'propPatch']);
682
-        $server->on('beforeUnlock',        [$this, 'beforeUnlock'], 20);
683
-        $server->on('report',              [$this, 'report']);
684
-        $server->on('method:ACL',          [$this, 'httpAcl']);
685
-        $server->on('onHTMLActionsPanel',  [$this, 'htmlActionsPanel']);
686
-
687
-        array_push($server->protectedProperties,
688
-            '{DAV:}alternate-URI-set',
689
-            '{DAV:}principal-URL',
690
-            '{DAV:}group-membership',
691
-            '{DAV:}principal-collection-set',
692
-            '{DAV:}current-user-principal',
693
-            '{DAV:}supported-privilege-set',
694
-            '{DAV:}current-user-privilege-set',
695
-            '{DAV:}acl',
696
-            '{DAV:}acl-restrictions',
697
-            '{DAV:}inherited-acl-set',
698
-            '{DAV:}owner',
699
-            '{DAV:}group'
700
-        );
701
-
702
-        // Automatically mapping nodes implementing IPrincipal to the
703
-        // {DAV:}principal resourcetype.
704
-        $server->resourceTypeMapping['Sabre\\DAVACL\\IPrincipal'] = '{DAV:}principal';
705
-
706
-        // Mapping the group-member-set property to the HrefList property
707
-        // class.
708
-        $server->xml->elementMap['{DAV:}group-member-set'] = 'Sabre\\DAV\\Xml\\Property\\Href';
709
-        $server->xml->elementMap['{DAV:}acl'] = 'Sabre\\DAVACL\\Xml\\Property\\Acl';
710
-        $server->xml->elementMap['{DAV:}expand-property'] = 'Sabre\\DAVACL\\Xml\\Request\\ExpandPropertyReport';
711
-        $server->xml->elementMap['{DAV:}principal-property-search'] = 'Sabre\\DAVACL\\Xml\\Request\\PrincipalPropertySearchReport';
712
-        $server->xml->elementMap['{DAV:}principal-search-property-set'] = 'Sabre\\DAVACL\\Xml\\Request\\PrincipalSearchPropertySetReport';
713
-
714
-    }
715
-
716
-    /* {{{ Event handlers */
717
-
718
-    /**
719
-     * Triggered before any method is handled
720
-     *
721
-     * @param RequestInterface $request
722
-     * @param ResponseInterface $response
723
-     * @return void
724
-     */
725
-    public function beforeMethod(RequestInterface $request, ResponseInterface $response) {
726
-
727
-        $method = $request->getMethod();
728
-        $path = $request->getPath();
729
-
730
-        $exists = $this->server->tree->nodeExists($path);
731
-
732
-        // If the node doesn't exists, none of these checks apply
733
-        if (!$exists) return;
734
-
735
-        switch ($method) {
736
-
737
-            case 'GET' :
738
-            case 'HEAD' :
739
-            case 'OPTIONS' :
740
-                // For these 3 we only need to know if the node is readable.
741
-                $this->checkPrivileges($path, '{DAV:}read');
742
-                break;
743
-
744
-            case 'PUT' :
745
-            case 'LOCK' :
746
-            case 'UNLOCK' :
747
-                // This method requires the write-content priv if the node
748
-                // already exists, and bind on the parent if the node is being
749
-                // created.
750
-                // The bind privilege is handled in the beforeBind event.
751
-                $this->checkPrivileges($path, '{DAV:}write-content');
752
-                break;
753
-
754
-
755
-            case 'PROPPATCH' :
756
-                $this->checkPrivileges($path, '{DAV:}write-properties');
757
-                break;
758
-
759
-            case 'ACL' :
760
-                $this->checkPrivileges($path, '{DAV:}write-acl');
761
-                break;
762
-
763
-            case 'COPY' :
764
-            case 'MOVE' :
765
-                // Copy requires read privileges on the entire source tree.
766
-                // If the target exists write-content normally needs to be
767
-                // checked, however, we're deleting the node beforehand and
768
-                // creating a new one after, so this is handled by the
769
-                // beforeUnbind event.
770
-                //
771
-                // The creation of the new node is handled by the beforeBind
772
-                // event.
773
-                //
774
-                // If MOVE is used beforeUnbind will also be used to check if
775
-                // the sourcenode can be deleted.
776
-                $this->checkPrivileges($path, '{DAV:}read', self::R_RECURSIVE);
777
-
778
-                break;
779
-
780
-        }
781
-
782
-    }
783
-
784
-    /**
785
-     * Triggered before a new node is created.
786
-     *
787
-     * This allows us to check permissions for any operation that creates a
788
-     * new node, such as PUT, MKCOL, MKCALENDAR, LOCK, COPY and MOVE.
789
-     *
790
-     * @param string $uri
791
-     * @return void
792
-     */
793
-    public function beforeBind($uri) {
794
-
795
-        list($parentUri) = Uri\split($uri);
796
-        $this->checkPrivileges($parentUri, '{DAV:}bind');
797
-
798
-    }
799
-
800
-    /**
801
-     * Triggered before a node is deleted
802
-     *
803
-     * This allows us to check permissions for any operation that will delete
804
-     * an existing node.
805
-     *
806
-     * @param string $uri
807
-     * @return void
808
-     */
809
-    public function beforeUnbind($uri) {
810
-
811
-        list($parentUri) = Uri\split($uri);
812
-        $this->checkPrivileges($parentUri, '{DAV:}unbind', self::R_RECURSIVEPARENTS);
813
-
814
-    }
815
-
816
-    /**
817
-     * Triggered before a node is unlocked.
818
-     *
819
-     * @param string $uri
820
-     * @param DAV\Locks\LockInfo $lock
821
-     * @return void
822
-     */
823
-    public function beforeUnlock($uri, DAV\Locks\LockInfo $lock) {
824
-
825
-
826
-    }
827
-
828
-    /**
829
-     * Triggered before properties are looked up in specific nodes.
830
-     *
831
-     * @param DAV\PropFind $propFind
832
-     * @param DAV\INode $node
833
-     * @param array $requestedProperties
834
-     * @param array $returnedProperties
835
-     * @return bool
836
-     */
837
-    public function propFind(DAV\PropFind $propFind, DAV\INode $node) {
838
-
839
-        $path = $propFind->getPath();
840
-
841
-        // Checking the read permission
842
-        if (!$this->checkPrivileges($path, '{DAV:}read', self::R_PARENT, false)) {
843
-            // User is not allowed to read properties
844
-
845
-            // Returning false causes the property-fetching system to pretend
846
-            // that the node does not exist, and will cause it to be hidden
847
-            // from listings such as PROPFIND or the browser plugin.
848
-            if ($this->hideNodesFromListings) {
849
-                return false;
850
-            }
851
-
852
-            // Otherwise we simply mark every property as 403.
853
-            foreach ($propFind->getRequestedProperties() as $requestedProperty) {
854
-                $propFind->set($requestedProperty, null, 403);
855
-            }
856
-
857
-            return;
858
-
859
-        }
860
-
861
-        /* Adding principal properties */
862
-        if ($node instanceof IPrincipal) {
863
-
864
-            $propFind->handle('{DAV:}alternate-URI-set', function() use ($node) {
865
-                return new DAV\Xml\Property\Href($node->getAlternateUriSet());
866
-            });
867
-            $propFind->handle('{DAV:}principal-URL', function() use ($node) {
868
-                return new DAV\Xml\Property\Href($node->getPrincipalUrl() . '/');
869
-            });
870
-            $propFind->handle('{DAV:}group-member-set', function() use ($node) {
871
-                $members = $node->getGroupMemberSet();
872
-                foreach ($members as $k => $member) {
873
-                    $members[$k] = rtrim($member, '/') . '/';
874
-                }
875
-                return new DAV\Xml\Property\Href($members);
876
-            });
877
-            $propFind->handle('{DAV:}group-membership', function() use ($node) {
878
-                $members = $node->getGroupMembership();
879
-                foreach ($members as $k => $member) {
880
-                    $members[$k] = rtrim($member, '/') . '/';
881
-                }
882
-                return new DAV\Xml\Property\Href($members);
883
-            });
884
-            $propFind->handle('{DAV:}displayname', [$node, 'getDisplayName']);
885
-
886
-        }
887
-
888
-        $propFind->handle('{DAV:}principal-collection-set', function() {
889
-
890
-            $val = $this->principalCollectionSet;
891
-            // Ensuring all collections end with a slash
892
-            foreach ($val as $k => $v) $val[$k] = $v . '/';
893
-            return new DAV\Xml\Property\Href($val);
894
-
895
-        });
896
-        $propFind->handle('{DAV:}current-user-principal', function() {
897
-            if ($url = $this->getCurrentUserPrincipal()) {
898
-                return new Xml\Property\Principal(Xml\Property\Principal::HREF, $url . '/');
899
-            } else {
900
-                return new Xml\Property\Principal(Xml\Property\Principal::UNAUTHENTICATED);
901
-            }
902
-        });
903
-        $propFind->handle('{DAV:}supported-privilege-set', function() use ($node) {
904
-            return new Xml\Property\SupportedPrivilegeSet($this->getSupportedPrivilegeSet($node));
905
-        });
906
-        $propFind->handle('{DAV:}current-user-privilege-set', function() use ($node, $propFind, $path) {
907
-            if (!$this->checkPrivileges($path, '{DAV:}read-current-user-privilege-set', self::R_PARENT, false)) {
908
-                $propFind->set('{DAV:}current-user-privilege-set', null, 403);
909
-            } else {
910
-                $val = $this->getCurrentUserPrivilegeSet($node);
911
-                if (!is_null($val)) {
912
-                    return new Xml\Property\CurrentUserPrivilegeSet($val);
913
-                }
914
-            }
915
-        });
916
-        $propFind->handle('{DAV:}acl', function() use ($node, $propFind, $path) {
917
-            /* The ACL property contains all the permissions */
918
-            if (!$this->checkPrivileges($path, '{DAV:}read-acl', self::R_PARENT, false)) {
919
-                $propFind->set('{DAV:}acl', null, 403);
920
-            } else {
921
-                $acl = $this->getACL($node);
922
-                if (!is_null($acl)) {
923
-                    return new Xml\Property\Acl($this->getACL($node));
924
-                }
925
-            }
926
-        });
927
-        $propFind->handle('{DAV:}acl-restrictions', function() {
928
-            return new Xml\Property\AclRestrictions();
929
-        });
930
-
931
-        /* Adding ACL properties */
932
-        if ($node instanceof IACL) {
933
-            $propFind->handle('{DAV:}owner', function() use ($node) {
934
-                return new DAV\Xml\Property\Href($node->getOwner() . '/');
935
-            });
936
-        }
937
-
938
-    }
939
-
940
-    /**
941
-     * This method intercepts PROPPATCH methods and make sure the
942
-     * group-member-set is updated correctly.
943
-     *
944
-     * @param string $path
945
-     * @param DAV\PropPatch $propPatch
946
-     * @return void
947
-     */
948
-    public function propPatch($path, DAV\PropPatch $propPatch) {
949
-
950
-        $propPatch->handle('{DAV:}group-member-set', function($value) use ($path) {
951
-            if (is_null($value)) {
952
-                $memberSet = [];
953
-            } elseif ($value instanceof DAV\Xml\Property\Href) {
954
-                $memberSet = array_map(
955
-                    [$this->server, 'calculateUri'],
956
-                    $value->getHrefs()
957
-                );
958
-            } else {
959
-                throw new DAV\Exception('The group-member-set property MUST be an instance of Sabre\DAV\Property\HrefList or null');
960
-            }
961
-            $node = $this->server->tree->getNodeForPath($path);
962
-            if (!($node instanceof IPrincipal)) {
963
-                // Fail
964
-                return false;
965
-            }
966
-
967
-            $node->setGroupMemberSet($memberSet);
968
-            // We must also clear our cache, just in case
969
-
970
-            $this->principalMembershipCache = [];
971
-
972
-            return true;
973
-        });
974
-
975
-    }
976
-
977
-    /**
978
-     * This method handles HTTP REPORT requests
979
-     *
980
-     * @param string $reportName
981
-     * @param mixed $report
982
-     * @param mixed $path
983
-     * @return bool
984
-     */
985
-    public function report($reportName, $report, $path) {
986
-
987
-        switch ($reportName) {
988
-
989
-            case '{DAV:}principal-property-search' :
990
-                $this->server->transactionType = 'report-principal-property-search';
991
-                $this->principalPropertySearchReport($report);
992
-                return false;
993
-            case '{DAV:}principal-search-property-set' :
994
-                $this->server->transactionType = 'report-principal-search-property-set';
995
-                $this->principalSearchPropertySetReport($report);
996
-                return false;
997
-            case '{DAV:}expand-property' :
998
-                $this->server->transactionType = 'report-expand-property';
999
-                $this->expandPropertyReport($report);
1000
-                return false;
1001
-
1002
-        }
1003
-
1004
-    }
1005
-
1006
-    /**
1007
-     * This method is responsible for handling the 'ACL' event.
1008
-     *
1009
-     * @param RequestInterface $request
1010
-     * @param ResponseInterface $response
1011
-     * @return bool
1012
-     */
1013
-    public function httpAcl(RequestInterface $request, ResponseInterface $response) {
1014
-
1015
-        $path = $request->getPath();
1016
-        $body = $request->getBodyAsString();
1017
-
1018
-        if (!$body) {
1019
-            throw new DAV\Exception\BadRequest('XML body expected in ACL request');
1020
-        }
1021
-
1022
-        $acl = $this->server->xml->expect('{DAV:}acl', $body);
1023
-        $newAcl = $acl->getPrivileges();
1024
-
1025
-        // Normalizing urls
1026
-        foreach ($newAcl as $k => $newAce) {
1027
-            $newAcl[$k]['principal'] = $this->server->calculateUri($newAce['principal']);
1028
-        }
1029
-        $node = $this->server->tree->getNodeForPath($path);
1030
-
1031
-        if (!$node instanceof IACL) {
1032
-            throw new DAV\Exception\MethodNotAllowed('This node does not support the ACL method');
1033
-        }
1034
-
1035
-        $oldAcl = $this->getACL($node);
1036
-
1037
-        $supportedPrivileges = $this->getFlatPrivilegeSet($node);
1038
-
1039
-        /* Checking if protected principals from the existing principal set are
532
+				// 'authenticated' matched for every user that's logged in.
533
+				// Since it's not possible to use ACL while not being logged
534
+				// in, this is also always true.
535
+				case '{DAV:}authenticated' :
536
+					$collected[] = $ace;
537
+					break;
538
+
539
+				// 'unauthenticated' can never occur either, so we simply
540
+				// ignore these.
541
+				case '{DAV:}unauthenticated' :
542
+					break;
543
+
544
+				default :
545
+					if (in_array($ace['principal'], $principals)) {
546
+						$collected[] = $ace;
547
+					}
548
+					break;
549
+
550
+			}
551
+
552
+
553
+		}
554
+
555
+		// Now we deduct all aggregated privileges.
556
+		$flat = $this->getFlatPrivilegeSet($node);
557
+
558
+		$collected2 = [];
559
+		while (count($collected)) {
560
+
561
+			$current = array_pop($collected);
562
+			$collected2[] = $current['privilege'];
563
+
564
+			foreach ($flat[$current['privilege']]['aggregates'] as $subPriv) {
565
+				$collected2[] = $subPriv;
566
+				$collected[] = $flat[$subPriv];
567
+			}
568
+
569
+		}
570
+
571
+		return array_values(array_unique($collected2));
572
+
573
+	}
574
+
575
+
576
+	/**
577
+	 * Returns a principal based on its uri.
578
+	 *
579
+	 * Returns null if the principal could not be found.
580
+	 *
581
+	 * @param string $uri
582
+	 * @return null|string
583
+	 */
584
+	public function getPrincipalByUri($uri) {
585
+
586
+		$result = null;
587
+		$collections = $this->principalCollectionSet;
588
+		foreach ($collections as $collection) {
589
+
590
+			$principalCollection = $this->server->tree->getNodeForPath($collection);
591
+			if (!$principalCollection instanceof IPrincipalCollection) {
592
+				// Not a principal collection, we're simply going to ignore
593
+				// this.
594
+				continue;
595
+			}
596
+
597
+			$result = $principalCollection->findByUri($uri);
598
+			if ($result) {
599
+				return $result;
600
+			}
601
+
602
+		}
603
+
604
+	}
605
+
606
+	/**
607
+	 * Principal property search
608
+	 *
609
+	 * This method can search for principals matching certain values in
610
+	 * properties.
611
+	 *
612
+	 * This method will return a list of properties for the matched properties.
613
+	 *
614
+	 * @param array $searchProperties    The properties to search on. This is a
615
+	 *                                   key-value list. The keys are property
616
+	 *                                   names, and the values the strings to
617
+	 *                                   match them on.
618
+	 * @param array $requestedProperties This is the list of properties to
619
+	 *                                   return for every match.
620
+	 * @param string $collectionUri      The principal collection to search on.
621
+	 *                                   If this is ommitted, the standard
622
+	 *                                   principal collection-set will be used.
623
+	 * @param string $test               "allof" to use AND to search the
624
+	 *                                   properties. 'anyof' for OR.
625
+	 * @return array     This method returns an array structure similar to
626
+	 *                  Sabre\DAV\Server::getPropertiesForPath. Returned
627
+	 *                  properties are index by a HTTP status code.
628
+	 */
629
+	public function principalSearch(array $searchProperties, array $requestedProperties, $collectionUri = null, $test = 'allof') {
630
+
631
+		if (!is_null($collectionUri)) {
632
+			$uris = [$collectionUri];
633
+		} else {
634
+			$uris = $this->principalCollectionSet;
635
+		}
636
+
637
+		$lookupResults = [];
638
+		foreach ($uris as $uri) {
639
+
640
+			$principalCollection = $this->server->tree->getNodeForPath($uri);
641
+			if (!$principalCollection instanceof IPrincipalCollection) {
642
+				// Not a principal collection, we're simply going to ignore
643
+				// this.
644
+				continue;
645
+			}
646
+
647
+			$results = $principalCollection->searchPrincipals($searchProperties, $test);
648
+			foreach ($results as $result) {
649
+				$lookupResults[] = rtrim($uri, '/') . '/' . $result;
650
+			}
651
+
652
+		}
653
+
654
+		$matches = [];
655
+
656
+		foreach ($lookupResults as $lookupResult) {
657
+
658
+			list($matches[]) = $this->server->getPropertiesForPath($lookupResult, $requestedProperties, 0);
659
+
660
+		}
661
+
662
+		return $matches;
663
+
664
+	}
665
+
666
+	/**
667
+	 * Sets up the plugin
668
+	 *
669
+	 * This method is automatically called by the server class.
670
+	 *
671
+	 * @param DAV\Server $server
672
+	 * @return void
673
+	 */
674
+	public function initialize(DAV\Server $server) {
675
+
676
+		$this->server = $server;
677
+		$server->on('propFind',            [$this, 'propFind'], 20);
678
+		$server->on('beforeMethod',        [$this, 'beforeMethod'], 20);
679
+		$server->on('beforeBind',          [$this, 'beforeBind'], 20);
680
+		$server->on('beforeUnbind',        [$this, 'beforeUnbind'], 20);
681
+		$server->on('propPatch',           [$this, 'propPatch']);
682
+		$server->on('beforeUnlock',        [$this, 'beforeUnlock'], 20);
683
+		$server->on('report',              [$this, 'report']);
684
+		$server->on('method:ACL',          [$this, 'httpAcl']);
685
+		$server->on('onHTMLActionsPanel',  [$this, 'htmlActionsPanel']);
686
+
687
+		array_push($server->protectedProperties,
688
+			'{DAV:}alternate-URI-set',
689
+			'{DAV:}principal-URL',
690
+			'{DAV:}group-membership',
691
+			'{DAV:}principal-collection-set',
692
+			'{DAV:}current-user-principal',
693
+			'{DAV:}supported-privilege-set',
694
+			'{DAV:}current-user-privilege-set',
695
+			'{DAV:}acl',
696
+			'{DAV:}acl-restrictions',
697
+			'{DAV:}inherited-acl-set',
698
+			'{DAV:}owner',
699
+			'{DAV:}group'
700
+		);
701
+
702
+		// Automatically mapping nodes implementing IPrincipal to the
703
+		// {DAV:}principal resourcetype.
704
+		$server->resourceTypeMapping['Sabre\\DAVACL\\IPrincipal'] = '{DAV:}principal';
705
+
706
+		// Mapping the group-member-set property to the HrefList property
707
+		// class.
708
+		$server->xml->elementMap['{DAV:}group-member-set'] = 'Sabre\\DAV\\Xml\\Property\\Href';
709
+		$server->xml->elementMap['{DAV:}acl'] = 'Sabre\\DAVACL\\Xml\\Property\\Acl';
710
+		$server->xml->elementMap['{DAV:}expand-property'] = 'Sabre\\DAVACL\\Xml\\Request\\ExpandPropertyReport';
711
+		$server->xml->elementMap['{DAV:}principal-property-search'] = 'Sabre\\DAVACL\\Xml\\Request\\PrincipalPropertySearchReport';
712
+		$server->xml->elementMap['{DAV:}principal-search-property-set'] = 'Sabre\\DAVACL\\Xml\\Request\\PrincipalSearchPropertySetReport';
713
+
714
+	}
715
+
716
+	/* {{{ Event handlers */
717
+
718
+	/**
719
+	 * Triggered before any method is handled
720
+	 *
721
+	 * @param RequestInterface $request
722
+	 * @param ResponseInterface $response
723
+	 * @return void
724
+	 */
725
+	public function beforeMethod(RequestInterface $request, ResponseInterface $response) {
726
+
727
+		$method = $request->getMethod();
728
+		$path = $request->getPath();
729
+
730
+		$exists = $this->server->tree->nodeExists($path);
731
+
732
+		// If the node doesn't exists, none of these checks apply
733
+		if (!$exists) return;
734
+
735
+		switch ($method) {
736
+
737
+			case 'GET' :
738
+			case 'HEAD' :
739
+			case 'OPTIONS' :
740
+				// For these 3 we only need to know if the node is readable.
741
+				$this->checkPrivileges($path, '{DAV:}read');
742
+				break;
743
+
744
+			case 'PUT' :
745
+			case 'LOCK' :
746
+			case 'UNLOCK' :
747
+				// This method requires the write-content priv if the node
748
+				// already exists, and bind on the parent if the node is being
749
+				// created.
750
+				// The bind privilege is handled in the beforeBind event.
751
+				$this->checkPrivileges($path, '{DAV:}write-content');
752
+				break;
753
+
754
+
755
+			case 'PROPPATCH' :
756
+				$this->checkPrivileges($path, '{DAV:}write-properties');
757
+				break;
758
+
759
+			case 'ACL' :
760
+				$this->checkPrivileges($path, '{DAV:}write-acl');
761
+				break;
762
+
763
+			case 'COPY' :
764
+			case 'MOVE' :
765
+				// Copy requires read privileges on the entire source tree.
766
+				// If the target exists write-content normally needs to be
767
+				// checked, however, we're deleting the node beforehand and
768
+				// creating a new one after, so this is handled by the
769
+				// beforeUnbind event.
770
+				//
771
+				// The creation of the new node is handled by the beforeBind
772
+				// event.
773
+				//
774
+				// If MOVE is used beforeUnbind will also be used to check if
775
+				// the sourcenode can be deleted.
776
+				$this->checkPrivileges($path, '{DAV:}read', self::R_RECURSIVE);
777
+
778
+				break;
779
+
780
+		}
781
+
782
+	}
783
+
784
+	/**
785
+	 * Triggered before a new node is created.
786
+	 *
787
+	 * This allows us to check permissions for any operation that creates a
788
+	 * new node, such as PUT, MKCOL, MKCALENDAR, LOCK, COPY and MOVE.
789
+	 *
790
+	 * @param string $uri
791
+	 * @return void
792
+	 */
793
+	public function beforeBind($uri) {
794
+
795
+		list($parentUri) = Uri\split($uri);
796
+		$this->checkPrivileges($parentUri, '{DAV:}bind');
797
+
798
+	}
799
+
800
+	/**
801
+	 * Triggered before a node is deleted
802
+	 *
803
+	 * This allows us to check permissions for any operation that will delete
804
+	 * an existing node.
805
+	 *
806
+	 * @param string $uri
807
+	 * @return void
808
+	 */
809
+	public function beforeUnbind($uri) {
810
+
811
+		list($parentUri) = Uri\split($uri);
812
+		$this->checkPrivileges($parentUri, '{DAV:}unbind', self::R_RECURSIVEPARENTS);
813
+
814
+	}
815
+
816
+	/**
817
+	 * Triggered before a node is unlocked.
818
+	 *
819
+	 * @param string $uri
820
+	 * @param DAV\Locks\LockInfo $lock
821
+	 * @return void
822
+	 */
823
+	public function beforeUnlock($uri, DAV\Locks\LockInfo $lock) {
824
+
825
+
826
+	}
827
+
828
+	/**
829
+	 * Triggered before properties are looked up in specific nodes.
830
+	 *
831
+	 * @param DAV\PropFind $propFind
832
+	 * @param DAV\INode $node
833
+	 * @param array $requestedProperties
834
+	 * @param array $returnedProperties
835
+	 * @return bool
836
+	 */
837
+	public function propFind(DAV\PropFind $propFind, DAV\INode $node) {
838
+
839
+		$path = $propFind->getPath();
840
+
841
+		// Checking the read permission
842
+		if (!$this->checkPrivileges($path, '{DAV:}read', self::R_PARENT, false)) {
843
+			// User is not allowed to read properties
844
+
845
+			// Returning false causes the property-fetching system to pretend
846
+			// that the node does not exist, and will cause it to be hidden
847
+			// from listings such as PROPFIND or the browser plugin.
848
+			if ($this->hideNodesFromListings) {
849
+				return false;
850
+			}
851
+
852
+			// Otherwise we simply mark every property as 403.
853
+			foreach ($propFind->getRequestedProperties() as $requestedProperty) {
854
+				$propFind->set($requestedProperty, null, 403);
855
+			}
856
+
857
+			return;
858
+
859
+		}
860
+
861
+		/* Adding principal properties */
862
+		if ($node instanceof IPrincipal) {
863
+
864
+			$propFind->handle('{DAV:}alternate-URI-set', function() use ($node) {
865
+				return new DAV\Xml\Property\Href($node->getAlternateUriSet());
866
+			});
867
+			$propFind->handle('{DAV:}principal-URL', function() use ($node) {
868
+				return new DAV\Xml\Property\Href($node->getPrincipalUrl() . '/');
869
+			});
870
+			$propFind->handle('{DAV:}group-member-set', function() use ($node) {
871
+				$members = $node->getGroupMemberSet();
872
+				foreach ($members as $k => $member) {
873
+					$members[$k] = rtrim($member, '/') . '/';
874
+				}
875
+				return new DAV\Xml\Property\Href($members);
876
+			});
877
+			$propFind->handle('{DAV:}group-membership', function() use ($node) {
878
+				$members = $node->getGroupMembership();
879
+				foreach ($members as $k => $member) {
880
+					$members[$k] = rtrim($member, '/') . '/';
881
+				}
882
+				return new DAV\Xml\Property\Href($members);
883
+			});
884
+			$propFind->handle('{DAV:}displayname', [$node, 'getDisplayName']);
885
+
886
+		}
887
+
888
+		$propFind->handle('{DAV:}principal-collection-set', function() {
889
+
890
+			$val = $this->principalCollectionSet;
891
+			// Ensuring all collections end with a slash
892
+			foreach ($val as $k => $v) $val[$k] = $v . '/';
893
+			return new DAV\Xml\Property\Href($val);
894
+
895
+		});
896
+		$propFind->handle('{DAV:}current-user-principal', function() {
897
+			if ($url = $this->getCurrentUserPrincipal()) {
898
+				return new Xml\Property\Principal(Xml\Property\Principal::HREF, $url . '/');
899
+			} else {
900
+				return new Xml\Property\Principal(Xml\Property\Principal::UNAUTHENTICATED);
901
+			}
902
+		});
903
+		$propFind->handle('{DAV:}supported-privilege-set', function() use ($node) {
904
+			return new Xml\Property\SupportedPrivilegeSet($this->getSupportedPrivilegeSet($node));
905
+		});
906
+		$propFind->handle('{DAV:}current-user-privilege-set', function() use ($node, $propFind, $path) {
907
+			if (!$this->checkPrivileges($path, '{DAV:}read-current-user-privilege-set', self::R_PARENT, false)) {
908
+				$propFind->set('{DAV:}current-user-privilege-set', null, 403);
909
+			} else {
910
+				$val = $this->getCurrentUserPrivilegeSet($node);
911
+				if (!is_null($val)) {
912
+					return new Xml\Property\CurrentUserPrivilegeSet($val);
913
+				}
914
+			}
915
+		});
916
+		$propFind->handle('{DAV:}acl', function() use ($node, $propFind, $path) {
917
+			/* The ACL property contains all the permissions */
918
+			if (!$this->checkPrivileges($path, '{DAV:}read-acl', self::R_PARENT, false)) {
919
+				$propFind->set('{DAV:}acl', null, 403);
920
+			} else {
921
+				$acl = $this->getACL($node);
922
+				if (!is_null($acl)) {
923
+					return new Xml\Property\Acl($this->getACL($node));
924
+				}
925
+			}
926
+		});
927
+		$propFind->handle('{DAV:}acl-restrictions', function() {
928
+			return new Xml\Property\AclRestrictions();
929
+		});
930
+
931
+		/* Adding ACL properties */
932
+		if ($node instanceof IACL) {
933
+			$propFind->handle('{DAV:}owner', function() use ($node) {
934
+				return new DAV\Xml\Property\Href($node->getOwner() . '/');
935
+			});
936
+		}
937
+
938
+	}
939
+
940
+	/**
941
+	 * This method intercepts PROPPATCH methods and make sure the
942
+	 * group-member-set is updated correctly.
943
+	 *
944
+	 * @param string $path
945
+	 * @param DAV\PropPatch $propPatch
946
+	 * @return void
947
+	 */
948
+	public function propPatch($path, DAV\PropPatch $propPatch) {
949
+
950
+		$propPatch->handle('{DAV:}group-member-set', function($value) use ($path) {
951
+			if (is_null($value)) {
952
+				$memberSet = [];
953
+			} elseif ($value instanceof DAV\Xml\Property\Href) {
954
+				$memberSet = array_map(
955
+					[$this->server, 'calculateUri'],
956
+					$value->getHrefs()
957
+				);
958
+			} else {
959
+				throw new DAV\Exception('The group-member-set property MUST be an instance of Sabre\DAV\Property\HrefList or null');
960
+			}
961
+			$node = $this->server->tree->getNodeForPath($path);
962
+			if (!($node instanceof IPrincipal)) {
963
+				// Fail
964
+				return false;
965
+			}
966
+
967
+			$node->setGroupMemberSet($memberSet);
968
+			// We must also clear our cache, just in case
969
+
970
+			$this->principalMembershipCache = [];
971
+
972
+			return true;
973
+		});
974
+
975
+	}
976
+
977
+	/**
978
+	 * This method handles HTTP REPORT requests
979
+	 *
980
+	 * @param string $reportName
981
+	 * @param mixed $report
982
+	 * @param mixed $path
983
+	 * @return bool
984
+	 */
985
+	public function report($reportName, $report, $path) {
986
+
987
+		switch ($reportName) {
988
+
989
+			case '{DAV:}principal-property-search' :
990
+				$this->server->transactionType = 'report-principal-property-search';
991
+				$this->principalPropertySearchReport($report);
992
+				return false;
993
+			case '{DAV:}principal-search-property-set' :
994
+				$this->server->transactionType = 'report-principal-search-property-set';
995
+				$this->principalSearchPropertySetReport($report);
996
+				return false;
997
+			case '{DAV:}expand-property' :
998
+				$this->server->transactionType = 'report-expand-property';
999
+				$this->expandPropertyReport($report);
1000
+				return false;
1001
+
1002
+		}
1003
+
1004
+	}
1005
+
1006
+	/**
1007
+	 * This method is responsible for handling the 'ACL' event.
1008
+	 *
1009
+	 * @param RequestInterface $request
1010
+	 * @param ResponseInterface $response
1011
+	 * @return bool
1012
+	 */
1013
+	public function httpAcl(RequestInterface $request, ResponseInterface $response) {
1014
+
1015
+		$path = $request->getPath();
1016
+		$body = $request->getBodyAsString();
1017
+
1018
+		if (!$body) {
1019
+			throw new DAV\Exception\BadRequest('XML body expected in ACL request');
1020
+		}
1021
+
1022
+		$acl = $this->server->xml->expect('{DAV:}acl', $body);
1023
+		$newAcl = $acl->getPrivileges();
1024
+
1025
+		// Normalizing urls
1026
+		foreach ($newAcl as $k => $newAce) {
1027
+			$newAcl[$k]['principal'] = $this->server->calculateUri($newAce['principal']);
1028
+		}
1029
+		$node = $this->server->tree->getNodeForPath($path);
1030
+
1031
+		if (!$node instanceof IACL) {
1032
+			throw new DAV\Exception\MethodNotAllowed('This node does not support the ACL method');
1033
+		}
1034
+
1035
+		$oldAcl = $this->getACL($node);
1036
+
1037
+		$supportedPrivileges = $this->getFlatPrivilegeSet($node);
1038
+
1039
+		/* Checking if protected principals from the existing principal set are
1040 1040
            not overwritten. */
1041
-        foreach ($oldAcl as $oldAce) {
1042
-
1043
-            if (!isset($oldAce['protected']) || !$oldAce['protected']) continue;
1044
-
1045
-            $found = false;
1046
-            foreach ($newAcl as $newAce) {
1047
-                if (
1048
-                    $newAce['privilege'] === $oldAce['privilege'] &&
1049
-                    $newAce['principal'] === $oldAce['principal'] &&
1050
-                    $newAce['protected']
1051
-                )
1052
-                $found = true;
1053
-            }
1054
-
1055
-            if (!$found)
1056
-                throw new Exception\AceConflict('This resource contained a protected {DAV:}ace, but this privilege did not occur in the ACL request');
1057
-
1058
-        }
1041
+		foreach ($oldAcl as $oldAce) {
1042
+
1043
+			if (!isset($oldAce['protected']) || !$oldAce['protected']) continue;
1044
+
1045
+			$found = false;
1046
+			foreach ($newAcl as $newAce) {
1047
+				if (
1048
+					$newAce['privilege'] === $oldAce['privilege'] &&
1049
+					$newAce['principal'] === $oldAce['principal'] &&
1050
+					$newAce['protected']
1051
+				)
1052
+				$found = true;
1053
+			}
1054
+
1055
+			if (!$found)
1056
+				throw new Exception\AceConflict('This resource contained a protected {DAV:}ace, but this privilege did not occur in the ACL request');
1057
+
1058
+		}
1059 1059
 
1060
-        foreach ($newAcl as $newAce) {
1061
-
1062
-            // Do we recognize the privilege
1063
-            if (!isset($supportedPrivileges[$newAce['privilege']])) {
1064
-                throw new Exception\NotSupportedPrivilege('The privilege you specified (' . $newAce['privilege'] . ') is not recognized by this server');
1065
-            }
1066
-
1067
-            if ($supportedPrivileges[$newAce['privilege']]['abstract']) {
1068
-                throw new Exception\NoAbstract('The privilege you specified (' . $newAce['privilege'] . ') is an abstract privilege');
1069
-            }
1070
-
1071
-            // Looking up the principal
1072
-            try {
1073
-                $principal = $this->server->tree->getNodeForPath($newAce['principal']);
1074
-            } catch (DAV\Exception\NotFound $e) {
1075
-                throw new Exception\NotRecognizedPrincipal('The specified principal (' . $newAce['principal'] . ') does not exist');
1076
-            }
1077
-            if (!($principal instanceof IPrincipal)) {
1078
-                throw new Exception\NotRecognizedPrincipal('The specified uri (' . $newAce['principal'] . ') is not a principal');
1079
-            }
1060
+		foreach ($newAcl as $newAce) {
1061
+
1062
+			// Do we recognize the privilege
1063
+			if (!isset($supportedPrivileges[$newAce['privilege']])) {
1064
+				throw new Exception\NotSupportedPrivilege('The privilege you specified (' . $newAce['privilege'] . ') is not recognized by this server');
1065
+			}
1066
+
1067
+			if ($supportedPrivileges[$newAce['privilege']]['abstract']) {
1068
+				throw new Exception\NoAbstract('The privilege you specified (' . $newAce['privilege'] . ') is an abstract privilege');
1069
+			}
1070
+
1071
+			// Looking up the principal
1072
+			try {
1073
+				$principal = $this->server->tree->getNodeForPath($newAce['principal']);
1074
+			} catch (DAV\Exception\NotFound $e) {
1075
+				throw new Exception\NotRecognizedPrincipal('The specified principal (' . $newAce['principal'] . ') does not exist');
1076
+			}
1077
+			if (!($principal instanceof IPrincipal)) {
1078
+				throw new Exception\NotRecognizedPrincipal('The specified uri (' . $newAce['principal'] . ') is not a principal');
1079
+			}
1080 1080
 
1081
-        }
1082
-        $node->setACL($newAcl);
1081
+		}
1082
+		$node->setACL($newAcl);
1083 1083
 
1084
-        $response->setStatus(200);
1085
-
1086
-        // Breaking the event chain, because we handled this method.
1087
-        return false;
1088
-
1089
-    }
1090
-
1091
-    /* }}} */
1092
-
1093
-    /* Reports {{{ */
1094
-
1095
-    /**
1096
-     * The expand-property report is defined in RFC3253 section 3-8.
1097
-     *
1098
-     * This report is very similar to a standard PROPFIND. The difference is
1099
-     * that it has the additional ability to look at properties containing a
1100
-     * {DAV:}href element, follow that property and grab additional elements
1101
-     * there.
1102
-     *
1103
-     * Other rfc's, such as ACL rely on this report, so it made sense to put
1104
-     * it in this plugin.
1105
-     *
1106
-     * @param Xml\Request\ExpandPropertyReport $report
1107
-     * @return void
1108
-     */
1109
-    protected function expandPropertyReport($report) {
1084
+		$response->setStatus(200);
1085
+
1086
+		// Breaking the event chain, because we handled this method.
1087
+		return false;
1088
+
1089
+	}
1090
+
1091
+	/* }}} */
1092
+
1093
+	/* Reports {{{ */
1094
+
1095
+	/**
1096
+	 * The expand-property report is defined in RFC3253 section 3-8.
1097
+	 *
1098
+	 * This report is very similar to a standard PROPFIND. The difference is
1099
+	 * that it has the additional ability to look at properties containing a
1100
+	 * {DAV:}href element, follow that property and grab additional elements
1101
+	 * there.
1102
+	 *
1103
+	 * Other rfc's, such as ACL rely on this report, so it made sense to put
1104
+	 * it in this plugin.
1105
+	 *
1106
+	 * @param Xml\Request\ExpandPropertyReport $report
1107
+	 * @return void
1108
+	 */
1109
+	protected function expandPropertyReport($report) {
1110 1110
 
1111
-        $depth = $this->server->getHTTPDepth(0);
1112
-        $requestUri = $this->server->getRequestUri();
1111
+		$depth = $this->server->getHTTPDepth(0);
1112
+		$requestUri = $this->server->getRequestUri();
1113 1113
 
1114
-        $result = $this->expandProperties($requestUri, $report->properties, $depth);
1114
+		$result = $this->expandProperties($requestUri, $report->properties, $depth);
1115 1115
 
1116
-        $xml = $this->server->xml->write(
1117
-            '{DAV:}multistatus',
1118
-            new DAV\Xml\Response\MultiStatus($result),
1119
-            $this->server->getBaseUri()
1120
-        );
1121
-        $this->server->httpResponse->setHeader('Content-Type', 'application/xml; charset=utf-8');
1122
-        $this->server->httpResponse->setStatus(207);
1123
-        $this->server->httpResponse->setBody($xml);
1116
+		$xml = $this->server->xml->write(
1117
+			'{DAV:}multistatus',
1118
+			new DAV\Xml\Response\MultiStatus($result),
1119
+			$this->server->getBaseUri()
1120
+		);
1121
+		$this->server->httpResponse->setHeader('Content-Type', 'application/xml; charset=utf-8');
1122
+		$this->server->httpResponse->setStatus(207);
1123
+		$this->server->httpResponse->setBody($xml);
1124 1124
 
1125
-    }
1125
+	}
1126 1126
 
1127
-    /**
1128
-     * This method expands all the properties and returns
1129
-     * a list with property values
1130
-     *
1131
-     * @param array $path
1132
-     * @param array $requestedProperties the list of required properties
1133
-     * @param int $depth
1134
-     * @return array
1135
-     */
1136
-    protected function expandProperties($path, array $requestedProperties, $depth) {
1127
+	/**
1128
+	 * This method expands all the properties and returns
1129
+	 * a list with property values
1130
+	 *
1131
+	 * @param array $path
1132
+	 * @param array $requestedProperties the list of required properties
1133
+	 * @param int $depth
1134
+	 * @return array
1135
+	 */
1136
+	protected function expandProperties($path, array $requestedProperties, $depth) {
1137 1137
 
1138
-        $foundProperties = $this->server->getPropertiesForPath($path, array_keys($requestedProperties), $depth);
1138
+		$foundProperties = $this->server->getPropertiesForPath($path, array_keys($requestedProperties), $depth);
1139 1139
 
1140
-        $result = [];
1140
+		$result = [];
1141 1141
 
1142
-        foreach ($foundProperties as $node) {
1143
-
1144
-            foreach ($requestedProperties as $propertyName => $childRequestedProperties) {
1145
-
1146
-                // We're only traversing if sub-properties were requested
1147
-                if (count($childRequestedProperties) === 0) continue;
1148
-
1149
-                // We only have to do the expansion if the property was found
1150
-                // and it contains an href element.
1151
-                if (!array_key_exists($propertyName, $node[200])) continue;
1152
-
1153
-                if (!$node[200][$propertyName] instanceof DAV\Xml\Property\Href) {
1154
-                    continue;
1155
-                }
1156
-
1157
-                $childHrefs = $node[200][$propertyName]->getHrefs();
1158
-                $childProps = [];
1159
-
1160
-                foreach ($childHrefs as $href) {
1161
-                    // Gathering the result of the children
1162
-                    $childProps[] = [
1163
-                        'name'  => '{DAV:}response',
1164
-                        'value' => $this->expandProperties($href, $childRequestedProperties, 0)[0]
1165
-                    ];
1166
-                }
1167
-
1168
-                // Replacing the property with its expannded form.
1169
-                $node[200][$propertyName] = $childProps;
1170
-
1171
-            }
1172
-            $result[] = new DAV\Xml\Element\Response($node['href'], $node);
1173
-
1174
-        }
1175
-
1176
-        return $result;
1177
-
1178
-    }
1179
-
1180
-    /**
1181
-     * principalSearchPropertySetReport
1182
-     *
1183
-     * This method responsible for handing the
1184
-     * {DAV:}principal-search-property-set report. This report returns a list
1185
-     * of properties the client may search on, using the
1186
-     * {DAV:}principal-property-search report.
1187
-     *
1188
-     * @param Xml\Request\PrincipalSearchPropertySetReport $report
1189
-     * @return void
1190
-     */
1191
-    protected function principalSearchPropertySetReport($report) {
1192
-
1193
-        $httpDepth = $this->server->getHTTPDepth(0);
1194
-        if ($httpDepth !== 0) {
1195
-            throw new DAV\Exception\BadRequest('This report is only defined when Depth: 0');
1196
-        }
1197
-
1198
-        $writer = $this->server->xml->getWriter();
1199
-        $writer->openMemory();
1200
-        $writer->startDocument();
1201
-
1202
-        $writer->startElement('{DAV:}principal-search-property-set');
1203
-
1204
-        foreach ($this->principalSearchPropertySet as $propertyName => $description) {
1205
-
1206
-            $writer->startElement('{DAV:}principal-search-property');
1207
-            $writer->startElement('{DAV:}prop');
1208
-
1209
-            $writer->writeElement($propertyName);
1210
-
1211
-            $writer->endElement(); // prop
1212
-
1213
-            if ($description) {
1214
-                $writer->write([[
1215
-                    'name'       => '{DAV:}description',
1216
-                    'value'      => $description,
1217
-                    'attributes' => ['xml:lang' => 'en']
1218
-                ]]);
1219
-            }
1220
-
1221
-            $writer->endElement(); // principal-search-property
1222
-
1223
-
1224
-        }
1225
-
1226
-        $writer->endElement(); // principal-search-property-set
1227
-
1228
-        $this->server->httpResponse->setHeader('Content-Type', 'application/xml; charset=utf-8');
1229
-        $this->server->httpResponse->setStatus(200);
1230
-        $this->server->httpResponse->setBody($writer->outputMemory());
1231
-
1232
-    }
1142
+		foreach ($foundProperties as $node) {
1143
+
1144
+			foreach ($requestedProperties as $propertyName => $childRequestedProperties) {
1145
+
1146
+				// We're only traversing if sub-properties were requested
1147
+				if (count($childRequestedProperties) === 0) continue;
1148
+
1149
+				// We only have to do the expansion if the property was found
1150
+				// and it contains an href element.
1151
+				if (!array_key_exists($propertyName, $node[200])) continue;
1152
+
1153
+				if (!$node[200][$propertyName] instanceof DAV\Xml\Property\Href) {
1154
+					continue;
1155
+				}
1156
+
1157
+				$childHrefs = $node[200][$propertyName]->getHrefs();
1158
+				$childProps = [];
1159
+
1160
+				foreach ($childHrefs as $href) {
1161
+					// Gathering the result of the children
1162
+					$childProps[] = [
1163
+						'name'  => '{DAV:}response',
1164
+						'value' => $this->expandProperties($href, $childRequestedProperties, 0)[0]
1165
+					];
1166
+				}
1167
+
1168
+				// Replacing the property with its expannded form.
1169
+				$node[200][$propertyName] = $childProps;
1170
+
1171
+			}
1172
+			$result[] = new DAV\Xml\Element\Response($node['href'], $node);
1173
+
1174
+		}
1175
+
1176
+		return $result;
1177
+
1178
+	}
1179
+
1180
+	/**
1181
+	 * principalSearchPropertySetReport
1182
+	 *
1183
+	 * This method responsible for handing the
1184
+	 * {DAV:}principal-search-property-set report. This report returns a list
1185
+	 * of properties the client may search on, using the
1186
+	 * {DAV:}principal-property-search report.
1187
+	 *
1188
+	 * @param Xml\Request\PrincipalSearchPropertySetReport $report
1189
+	 * @return void
1190
+	 */
1191
+	protected function principalSearchPropertySetReport($report) {
1192
+
1193
+		$httpDepth = $this->server->getHTTPDepth(0);
1194
+		if ($httpDepth !== 0) {
1195
+			throw new DAV\Exception\BadRequest('This report is only defined when Depth: 0');
1196
+		}
1197
+
1198
+		$writer = $this->server->xml->getWriter();
1199
+		$writer->openMemory();
1200
+		$writer->startDocument();
1201
+
1202
+		$writer->startElement('{DAV:}principal-search-property-set');
1203
+
1204
+		foreach ($this->principalSearchPropertySet as $propertyName => $description) {
1205
+
1206
+			$writer->startElement('{DAV:}principal-search-property');
1207
+			$writer->startElement('{DAV:}prop');
1208
+
1209
+			$writer->writeElement($propertyName);
1210
+
1211
+			$writer->endElement(); // prop
1212
+
1213
+			if ($description) {
1214
+				$writer->write([[
1215
+					'name'       => '{DAV:}description',
1216
+					'value'      => $description,
1217
+					'attributes' => ['xml:lang' => 'en']
1218
+				]]);
1219
+			}
1220
+
1221
+			$writer->endElement(); // principal-search-property
1222
+
1223
+
1224
+		}
1225
+
1226
+		$writer->endElement(); // principal-search-property-set
1227
+
1228
+		$this->server->httpResponse->setHeader('Content-Type', 'application/xml; charset=utf-8');
1229
+		$this->server->httpResponse->setStatus(200);
1230
+		$this->server->httpResponse->setBody($writer->outputMemory());
1231
+
1232
+	}
1233 1233
 
1234
-    /**
1235
-     * principalPropertySearchReport
1236
-     *
1237
-     * This method is responsible for handing the
1238
-     * {DAV:}principal-property-search report. This report can be used for
1239
-     * clients to search for groups of principals, based on the value of one
1240
-     * or more properties.
1241
-     *
1242
-     * @param Xml\Request\PrincipalPropertySearchReport $report
1243
-     * @return void
1244
-     */
1245
-    protected function principalPropertySearchReport($report) {
1246
-
1247
-        $uri = null;
1248
-        if (!$report->applyToPrincipalCollectionSet) {
1249
-            $uri = $this->server->httpRequest->getPath();
1250
-        }
1251
-        if ($this->server->getHttpDepth('0') !== 0) {
1252
-            throw new BadRequest('Depth must be 0');
1253
-        }
1254
-        $result = $this->principalSearch(
1255
-            $report->searchProperties,
1256
-            $report->properties,
1257
-            $uri,
1258
-            $report->test
1259
-        );
1260
-
1261
-        $prefer = $this->server->getHTTPPrefer();
1262
-
1263
-        $this->server->httpResponse->setStatus(207);
1264
-        $this->server->httpResponse->setHeader('Content-Type', 'application/xml; charset=utf-8');
1265
-        $this->server->httpResponse->setHeader('Vary', 'Brief,Prefer');
1266
-        $this->server->httpResponse->setBody($this->server->generateMultiStatus($result, $prefer['return'] === 'minimal'));
1267
-
1268
-    }
1269
-
1270
-    /* }}} */
1271
-
1272
-    /**
1273
-     * This method is used to generate HTML output for the
1274
-     * DAV\Browser\Plugin. This allows us to generate an interface users
1275
-     * can use to create new calendars.
1276
-     *
1277
-     * @param DAV\INode $node
1278
-     * @param string $output
1279
-     * @return bool
1280
-     */
1281
-    public function htmlActionsPanel(DAV\INode $node, &$output) {
1282
-
1283
-        if (!$node instanceof PrincipalCollection)
1284
-            return;
1285
-
1286
-        $output .= '<tr><td colspan="2"><form method="post" action="">
1234
+	/**
1235
+	 * principalPropertySearchReport
1236
+	 *
1237
+	 * This method is responsible for handing the
1238
+	 * {DAV:}principal-property-search report. This report can be used for
1239
+	 * clients to search for groups of principals, based on the value of one
1240
+	 * or more properties.
1241
+	 *
1242
+	 * @param Xml\Request\PrincipalPropertySearchReport $report
1243
+	 * @return void
1244
+	 */
1245
+	protected function principalPropertySearchReport($report) {
1246
+
1247
+		$uri = null;
1248
+		if (!$report->applyToPrincipalCollectionSet) {
1249
+			$uri = $this->server->httpRequest->getPath();
1250
+		}
1251
+		if ($this->server->getHttpDepth('0') !== 0) {
1252
+			throw new BadRequest('Depth must be 0');
1253
+		}
1254
+		$result = $this->principalSearch(
1255
+			$report->searchProperties,
1256
+			$report->properties,
1257
+			$uri,
1258
+			$report->test
1259
+		);
1260
+
1261
+		$prefer = $this->server->getHTTPPrefer();
1262
+
1263
+		$this->server->httpResponse->setStatus(207);
1264
+		$this->server->httpResponse->setHeader('Content-Type', 'application/xml; charset=utf-8');
1265
+		$this->server->httpResponse->setHeader('Vary', 'Brief,Prefer');
1266
+		$this->server->httpResponse->setBody($this->server->generateMultiStatus($result, $prefer['return'] === 'minimal'));
1267
+
1268
+	}
1269
+
1270
+	/* }}} */
1271
+
1272
+	/**
1273
+	 * This method is used to generate HTML output for the
1274
+	 * DAV\Browser\Plugin. This allows us to generate an interface users
1275
+	 * can use to create new calendars.
1276
+	 *
1277
+	 * @param DAV\INode $node
1278
+	 * @param string $output
1279
+	 * @return bool
1280
+	 */
1281
+	public function htmlActionsPanel(DAV\INode $node, &$output) {
1282
+
1283
+		if (!$node instanceof PrincipalCollection)
1284
+			return;
1285
+
1286
+		$output .= '<tr><td colspan="2"><form method="post" action="">
1287 1287
             <h3>Create new principal</h3>
1288 1288
             <input type="hidden" name="sabreAction" value="mkcol" />
1289 1289
             <input type="hidden" name="resourceType" value="{DAV:}principal" />
@@ -1294,28 +1294,28 @@  discard block
 block discarded – undo
1294 1294
             </form>
1295 1295
             </td></tr>';
1296 1296
 
1297
-        return false;
1298
-
1299
-    }
1300
-
1301
-    /**
1302
-     * Returns a bunch of meta-data about the plugin.
1303
-     *
1304
-     * Providing this information is optional, and is mainly displayed by the
1305
-     * Browser plugin.
1306
-     *
1307
-     * The description key in the returned array may contain html and will not
1308
-     * be sanitized.
1309
-     *
1310
-     * @return array
1311
-     */
1312
-    public function getPluginInfo() {
1313
-
1314
-        return [
1315
-            'name'        => $this->getPluginName(),
1316
-            'description' => 'Adds support for WebDAV ACL (rfc3744)',
1317
-            'link'        => 'http://sabre.io/dav/acl/',
1318
-        ];
1319
-
1320
-    }
1297
+		return false;
1298
+
1299
+	}
1300
+
1301
+	/**
1302
+	 * Returns a bunch of meta-data about the plugin.
1303
+	 *
1304
+	 * Providing this information is optional, and is mainly displayed by the
1305
+	 * Browser plugin.
1306
+	 *
1307
+	 * The description key in the returned array may contain html and will not
1308
+	 * be sanitized.
1309
+	 *
1310
+	 * @return array
1311
+	 */
1312
+	public function getPluginInfo() {
1313
+
1314
+		return [
1315
+			'name'        => $this->getPluginName(),
1316
+			'description' => 'Adds support for WebDAV ACL (rfc3744)',
1317
+			'link'        => 'http://sabre.io/dav/acl/',
1318
+		];
1319
+
1320
+	}
1321 1321
 }
Please login to merge, or discard this patch.
libraries/SabreDAV/DAVACL/Principal.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -39,7 +39,7 @@
 block discarded – undo
39 39
     /**
40 40
      * Creates the principal object
41 41
      *
42
-     * @param IPrincipalBackend $principalBackend
42
+     * @param PrincipalBackend\BackendInterface $principalBackend
43 43
      * @param array $principalProperties
44 44
      */
45 45
     function __construct(PrincipalBackend\BackendInterface $principalBackend, array $principalProperties = []) {
Please login to merge, or discard this patch.
Indentation   +262 added lines, -262 removed lines patch added patch discarded remove patch
@@ -22,267 +22,267 @@
 block discarded – undo
22 22
  */
23 23
 class Principal extends DAV\Node implements IPrincipal, DAV\IProperties, IACL {
24 24
 
25
-    /**
26
-     * Struct with principal information.
27
-     *
28
-     * @var array
29
-     */
30
-    protected $principalProperties;
31
-
32
-    /**
33
-     * Principal backend
34
-     *
35
-     * @var PrincipalBackend\BackendInterface
36
-     */
37
-    protected $principalBackend;
38
-
39
-    /**
40
-     * Creates the principal object
41
-     *
42
-     * @param IPrincipalBackend $principalBackend
43
-     * @param array $principalProperties
44
-     */
45
-    public function __construct(PrincipalBackend\BackendInterface $principalBackend, array $principalProperties = []) {
46
-
47
-        if (!isset($principalProperties['uri'])) {
48
-            throw new DAV\Exception('The principal properties must at least contain the \'uri\' key');
49
-        }
50
-        $this->principalBackend = $principalBackend;
51
-        $this->principalProperties = $principalProperties;
52
-
53
-    }
54
-
55
-    /**
56
-     * Returns the full principal url
57
-     *
58
-     * @return string
59
-     */
60
-    public function getPrincipalUrl() {
61
-
62
-        return $this->principalProperties['uri'];
63
-
64
-    }
65
-
66
-    /**
67
-     * Returns a list of alternative urls for a principal
68
-     *
69
-     * This can for example be an email address, or ldap url.
70
-     *
71
-     * @return array
72
-     */
73
-    public function getAlternateUriSet() {
74
-
75
-        $uris = [];
76
-        if (isset($this->principalProperties['{DAV:}alternate-URI-set'])) {
77
-
78
-            $uris = $this->principalProperties['{DAV:}alternate-URI-set'];
79
-
80
-        }
81
-
82
-        if (isset($this->principalProperties['{http://sabredav.org/ns}email-address'])) {
83
-            $uris[] = 'mailto:' . $this->principalProperties['{http://sabredav.org/ns}email-address'];
84
-        }
85
-
86
-        return array_unique($uris);
87
-
88
-    }
89
-
90
-    /**
91
-     * Returns the list of group members
92
-     *
93
-     * If this principal is a group, this function should return
94
-     * all member principal uri's for the group.
95
-     *
96
-     * @return array
97
-     */
98
-    public function getGroupMemberSet() {
99
-
100
-        return $this->principalBackend->getGroupMemberSet($this->principalProperties['uri']);
101
-
102
-    }
103
-
104
-    /**
105
-     * Returns the list of groups this principal is member of
106
-     *
107
-     * If this principal is a member of a (list of) groups, this function
108
-     * should return a list of principal uri's for it's members.
109
-     *
110
-     * @return array
111
-     */
112
-    public function getGroupMembership() {
113
-
114
-        return $this->principalBackend->getGroupMemberShip($this->principalProperties['uri']);
115
-
116
-    }
117
-
118
-    /**
119
-     * Sets a list of group members
120
-     *
121
-     * If this principal is a group, this method sets all the group members.
122
-     * The list of members is always overwritten, never appended to.
123
-     *
124
-     * This method should throw an exception if the members could not be set.
125
-     *
126
-     * @param array $groupMembers
127
-     * @return void
128
-     */
129
-    public function setGroupMemberSet(array $groupMembers) {
130
-
131
-        $this->principalBackend->setGroupMemberSet($this->principalProperties['uri'], $groupMembers);
132
-
133
-    }
134
-
135
-    /**
136
-     * Returns this principals name.
137
-     *
138
-     * @return string
139
-     */
140
-    public function getName() {
141
-
142
-        $uri = $this->principalProperties['uri'];
143
-        list(, $name) = URLUtil::splitPath($uri);
144
-        return $name;
145
-
146
-    }
147
-
148
-    /**
149
-     * Returns the name of the user
150
-     *
151
-     * @return string
152
-     */
153
-    public function getDisplayName() {
154
-
155
-        if (isset($this->principalProperties['{DAV:}displayname'])) {
156
-            return $this->principalProperties['{DAV:}displayname'];
157
-        } else {
158
-            return $this->getName();
159
-        }
160
-
161
-    }
162
-
163
-    /**
164
-     * Returns a list of properties
165
-     *
166
-     * @param array $requestedProperties
167
-     * @return array
168
-     */
169
-    public function getProperties($requestedProperties) {
170
-
171
-        $newProperties = [];
172
-        foreach ($requestedProperties as $propName) {
173
-
174
-            if (isset($this->principalProperties[$propName])) {
175
-                $newProperties[$propName] = $this->principalProperties[$propName];
176
-            }
177
-
178
-        }
179
-
180
-        return $newProperties;
181
-
182
-    }
183
-
184
-    /**
185
-     * Updates properties on this node.
186
-     *
187
-     * This method received a PropPatch object, which contains all the
188
-     * information about the update.
189
-     *
190
-     * To update specific properties, call the 'handle' method on this object.
191
-     * Read the PropPatch documentation for more information.
192
-     *
193
-     * @param DAV\PropPatch $propPatch
194
-     * @return void
195
-     */
196
-    public function propPatch(DAV\PropPatch $propPatch) {
197
-
198
-        return $this->principalBackend->updatePrincipal(
199
-            $this->principalProperties['uri'],
200
-            $propPatch
201
-        );
202
-
203
-    }
204
-
205
-    /**
206
-     * Returns the owner principal
207
-     *
208
-     * This must be a url to a principal, or null if there's no owner
209
-     *
210
-     * @return string|null
211
-     */
212
-    public function getOwner() {
213
-
214
-        return $this->principalProperties['uri'];
215
-
216
-
217
-    }
218
-
219
-    /**
220
-     * Returns a group principal
221
-     *
222
-     * This must be a url to a principal, or null if there's no owner
223
-     *
224
-     * @return string|null
225
-     */
226
-    public function getGroup() {
227
-
228
-        return null;
229
-
230
-    }
231
-
232
-    /**
233
-     * Returns a list of ACE's for this node.
234
-     *
235
-     * Each ACE has the following properties:
236
-     *   * 'privilege', a string such as {DAV:}read or {DAV:}write. These are
237
-     *     currently the only supported privileges
238
-     *   * 'principal', a url to the principal who owns the node
239
-     *   * 'protected' (optional), indicating that this ACE is not allowed to
240
-     *      be updated.
241
-     *
242
-     * @return array
243
-     */
244
-    public function getACL() {
245
-
246
-        return [
247
-            [
248
-                'privilege' => '{DAV:}read',
249
-                'principal' => '{DAV:}authenticated',
250
-                'protected' => true,
251
-            ],
252
-        ];
253
-
254
-    }
255
-
256
-    /**
257
-     * Updates the ACL
258
-     *
259
-     * This method will receive a list of new ACE's.
260
-     *
261
-     * @param array $acl
262
-     * @return void
263
-     */
264
-    public function setACL(array $acl) {
265
-
266
-        throw new DAV\Exception\MethodNotAllowed('Updating ACLs is not allowed here');
267
-
268
-    }
269
-
270
-    /**
271
-     * Returns the list of supported privileges for this node.
272
-     *
273
-     * The returned data structure is a list of nested privileges.
274
-     * See Sabre\DAVACL\Plugin::getDefaultSupportedPrivilegeSet for a simple
275
-     * standard structure.
276
-     *
277
-     * If null is returned from this method, the default privilege set is used,
278
-     * which is fine for most common usecases.
279
-     *
280
-     * @return array|null
281
-     */
282
-    public function getSupportedPrivilegeSet() {
283
-
284
-        return null;
285
-
286
-    }
25
+	/**
26
+	 * Struct with principal information.
27
+	 *
28
+	 * @var array
29
+	 */
30
+	protected $principalProperties;
31
+
32
+	/**
33
+	 * Principal backend
34
+	 *
35
+	 * @var PrincipalBackend\BackendInterface
36
+	 */
37
+	protected $principalBackend;
38
+
39
+	/**
40
+	 * Creates the principal object
41
+	 *
42
+	 * @param IPrincipalBackend $principalBackend
43
+	 * @param array $principalProperties
44
+	 */
45
+	public function __construct(PrincipalBackend\BackendInterface $principalBackend, array $principalProperties = []) {
46
+
47
+		if (!isset($principalProperties['uri'])) {
48
+			throw new DAV\Exception('The principal properties must at least contain the \'uri\' key');
49
+		}
50
+		$this->principalBackend = $principalBackend;
51
+		$this->principalProperties = $principalProperties;
52
+
53
+	}
54
+
55
+	/**
56
+	 * Returns the full principal url
57
+	 *
58
+	 * @return string
59
+	 */
60
+	public function getPrincipalUrl() {
61
+
62
+		return $this->principalProperties['uri'];
63
+
64
+	}
65
+
66
+	/**
67
+	 * Returns a list of alternative urls for a principal
68
+	 *
69
+	 * This can for example be an email address, or ldap url.
70
+	 *
71
+	 * @return array
72
+	 */
73
+	public function getAlternateUriSet() {
74
+
75
+		$uris = [];
76
+		if (isset($this->principalProperties['{DAV:}alternate-URI-set'])) {
77
+
78
+			$uris = $this->principalProperties['{DAV:}alternate-URI-set'];
79
+
80
+		}
81
+
82
+		if (isset($this->principalProperties['{http://sabredav.org/ns}email-address'])) {
83
+			$uris[] = 'mailto:' . $this->principalProperties['{http://sabredav.org/ns}email-address'];
84
+		}
85
+
86
+		return array_unique($uris);
87
+
88
+	}
89
+
90
+	/**
91
+	 * Returns the list of group members
92
+	 *
93
+	 * If this principal is a group, this function should return
94
+	 * all member principal uri's for the group.
95
+	 *
96
+	 * @return array
97
+	 */
98
+	public function getGroupMemberSet() {
99
+
100
+		return $this->principalBackend->getGroupMemberSet($this->principalProperties['uri']);
101
+
102
+	}
103
+
104
+	/**
105
+	 * Returns the list of groups this principal is member of
106
+	 *
107
+	 * If this principal is a member of a (list of) groups, this function
108
+	 * should return a list of principal uri's for it's members.
109
+	 *
110
+	 * @return array
111
+	 */
112
+	public function getGroupMembership() {
113
+
114
+		return $this->principalBackend->getGroupMemberShip($this->principalProperties['uri']);
115
+
116
+	}
117
+
118
+	/**
119
+	 * Sets a list of group members
120
+	 *
121
+	 * If this principal is a group, this method sets all the group members.
122
+	 * The list of members is always overwritten, never appended to.
123
+	 *
124
+	 * This method should throw an exception if the members could not be set.
125
+	 *
126
+	 * @param array $groupMembers
127
+	 * @return void
128
+	 */
129
+	public function setGroupMemberSet(array $groupMembers) {
130
+
131
+		$this->principalBackend->setGroupMemberSet($this->principalProperties['uri'], $groupMembers);
132
+
133
+	}
134
+
135
+	/**
136
+	 * Returns this principals name.
137
+	 *
138
+	 * @return string
139
+	 */
140
+	public function getName() {
141
+
142
+		$uri = $this->principalProperties['uri'];
143
+		list(, $name) = URLUtil::splitPath($uri);
144
+		return $name;
145
+
146
+	}
147
+
148
+	/**
149
+	 * Returns the name of the user
150
+	 *
151
+	 * @return string
152
+	 */
153
+	public function getDisplayName() {
154
+
155
+		if (isset($this->principalProperties['{DAV:}displayname'])) {
156
+			return $this->principalProperties['{DAV:}displayname'];
157
+		} else {
158
+			return $this->getName();
159
+		}
160
+
161
+	}
162
+
163
+	/**
164
+	 * Returns a list of properties
165
+	 *
166
+	 * @param array $requestedProperties
167
+	 * @return array
168
+	 */
169
+	public function getProperties($requestedProperties) {
170
+
171
+		$newProperties = [];
172
+		foreach ($requestedProperties as $propName) {
173
+
174
+			if (isset($this->principalProperties[$propName])) {
175
+				$newProperties[$propName] = $this->principalProperties[$propName];
176
+			}
177
+
178
+		}
179
+
180
+		return $newProperties;
181
+
182
+	}
183
+
184
+	/**
185
+	 * Updates properties on this node.
186
+	 *
187
+	 * This method received a PropPatch object, which contains all the
188
+	 * information about the update.
189
+	 *
190
+	 * To update specific properties, call the 'handle' method on this object.
191
+	 * Read the PropPatch documentation for more information.
192
+	 *
193
+	 * @param DAV\PropPatch $propPatch
194
+	 * @return void
195
+	 */
196
+	public function propPatch(DAV\PropPatch $propPatch) {
197
+
198
+		return $this->principalBackend->updatePrincipal(
199
+			$this->principalProperties['uri'],
200
+			$propPatch
201
+		);
202
+
203
+	}
204
+
205
+	/**
206
+	 * Returns the owner principal
207
+	 *
208
+	 * This must be a url to a principal, or null if there's no owner
209
+	 *
210
+	 * @return string|null
211
+	 */
212
+	public function getOwner() {
213
+
214
+		return $this->principalProperties['uri'];
215
+
216
+
217
+	}
218
+
219
+	/**
220
+	 * Returns a group principal
221
+	 *
222
+	 * This must be a url to a principal, or null if there's no owner
223
+	 *
224
+	 * @return string|null
225
+	 */
226
+	public function getGroup() {
227
+
228
+		return null;
229
+
230
+	}
231
+
232
+	/**
233
+	 * Returns a list of ACE's for this node.
234
+	 *
235
+	 * Each ACE has the following properties:
236
+	 *   * 'privilege', a string such as {DAV:}read or {DAV:}write. These are
237
+	 *     currently the only supported privileges
238
+	 *   * 'principal', a url to the principal who owns the node
239
+	 *   * 'protected' (optional), indicating that this ACE is not allowed to
240
+	 *      be updated.
241
+	 *
242
+	 * @return array
243
+	 */
244
+	public function getACL() {
245
+
246
+		return [
247
+			[
248
+				'privilege' => '{DAV:}read',
249
+				'principal' => '{DAV:}authenticated',
250
+				'protected' => true,
251
+			],
252
+		];
253
+
254
+	}
255
+
256
+	/**
257
+	 * Updates the ACL
258
+	 *
259
+	 * This method will receive a list of new ACE's.
260
+	 *
261
+	 * @param array $acl
262
+	 * @return void
263
+	 */
264
+	public function setACL(array $acl) {
265
+
266
+		throw new DAV\Exception\MethodNotAllowed('Updating ACLs is not allowed here');
267
+
268
+	}
269
+
270
+	/**
271
+	 * Returns the list of supported privileges for this node.
272
+	 *
273
+	 * The returned data structure is a list of nested privileges.
274
+	 * See Sabre\DAVACL\Plugin::getDefaultSupportedPrivilegeSet for a simple
275
+	 * standard structure.
276
+	 *
277
+	 * If null is returned from this method, the default privilege set is used,
278
+	 * which is fine for most common usecases.
279
+	 *
280
+	 * @return array|null
281
+	 */
282
+	public function getSupportedPrivilegeSet() {
283
+
284
+		return null;
285
+
286
+	}
287 287
 
288 288
 }
Please login to merge, or discard this patch.
libraries/SabreDAV/DAVACL/PrincipalBackend/PDO.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -65,7 +65,7 @@
 block discarded – undo
65 65
     /**
66 66
      * Sets up the backend.
67 67
      *
68
-     * @param PDO $pdo
68
+     * @param \PDO $pdo
69 69
      */
70 70
     function __construct(\PDO $pdo) {
71 71
 
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -240,7 +240,7 @@  discard block
 block discarded – undo
240 240
      * @return array
241 241
      */
242 242
     function searchPrincipals($prefixPath, array $searchProperties, $test = 'allof') {
243
-        if (count($searchProperties) == 0) return [];    //No criteria
243
+        if (count($searchProperties) == 0) return []; //No criteria
244 244
 
245 245
         $query = sprintf('SELECT uri FROM %s WHERE ', $this->tableName);
246 246
         $values = [];
@@ -303,11 +303,11 @@  discard block
 block discarded – undo
303 303
         if ($value == null) return null;
304 304
 
305 305
         $uri = null;
306
-        switch ($scheme){
306
+        switch ($scheme) {
307 307
             case "mailto":
308 308
                 $query = sprintf('SELECT uri FROM %s WHERE lower(email)=lower(?)', $this->tableName);
309 309
                 $stmt = $this->pdo->prepare($query);
310
-                $stmt->execute([ $value ]);
310
+                $stmt->execute([$value]);
311 311
             
312 312
                 while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
313 313
                     // Checking if the principal is in the prefix
@@ -383,7 +383,7 @@  discard block
 block discarded – undo
383 383
     function setGroupMemberSet($principal, array $members) {
384 384
 
385 385
         // Grabbing the list of principal id's.
386
-        $stmt = $this->pdo->prepare(sprintf('SELECT id, uri FROM %s WHERE uri IN (? %s);',$this->tableName, str_repeat(', ? ', count($members))));
386
+        $stmt = $this->pdo->prepare(sprintf('SELECT id, uri FROM %s WHERE uri IN (? %s);', $this->tableName, str_repeat(', ? ', count($members))));
387 387
         $stmt->execute(array_merge([$principal], $members));
388 388
 
389 389
         $memberIds = [];
Please login to merge, or discard this patch.
Indentation   +405 added lines, -405 removed lines patch added patch discarded remove patch
@@ -19,415 +19,415 @@
 block discarded – undo
19 19
  */
20 20
 class PDO extends AbstractBackend implements CreatePrincipalSupport {
21 21
 
22
-    /**
23
-     * PDO table name for 'principals'
24
-     *
25
-     * @var string
26
-     */
27
-    public $tableName = 'principals';
28
-
29
-    /**
30
-     * PDO table name for 'group members'
31
-     *
32
-     * @var string
33
-     */
34
-    public $groupMembersTableName = 'groupmembers';
35
-
36
-    /**
37
-     * pdo
38
-     *
39
-     * @var PDO
40
-     */
41
-    protected $pdo;
42
-
43
-    /**
44
-     * A list of additional fields to support
45
-     *
46
-     * @var array
47
-     */
48
-    protected $fieldMap = [
49
-
50
-        /**
51
-         * This property can be used to display the users' real name.
52
-         */
53
-        '{DAV:}displayname' => [
54
-            'dbField' => 'displayname',
55
-        ],
56
-
57
-        /**
58
-         * This is the users' primary email-address.
59
-         */
60
-        '{http://sabredav.org/ns}email-address' => [
61
-            'dbField' => 'email',
62
-        ],
63
-    ];
64
-
65
-    /**
66
-     * Sets up the backend.
67
-     *
68
-     * @param PDO $pdo
69
-     */
70
-    public function __construct(\PDO $pdo) {
71
-
72
-        $this->pdo = $pdo;
73
-
74
-    }
75
-
76
-    /**
77
-     * Returns a list of principals based on a prefix.
78
-     *
79
-     * This prefix will often contain something like 'principals'. You are only
80
-     * expected to return principals that are in this base path.
81
-     *
82
-     * You are expected to return at least a 'uri' for every user, you can
83
-     * return any additional properties if you wish so. Common properties are:
84
-     *   {DAV:}displayname
85
-     *   {http://sabredav.org/ns}email-address - This is a custom SabreDAV
86
-     *     field that's actualy injected in a number of other properties. If
87
-     *     you have an email address, use this property.
88
-     *
89
-     * @param string $prefixPath
90
-     * @return array
91
-     */
92
-    public function getPrincipalsByPrefix($prefixPath) {
93
-
94
-        $fields = [
95
-            'uri',
96
-        ];
97
-
98
-        foreach ($this->fieldMap as $key => $value) {
99
-            $fields[] = $value['dbField'];
100
-        }
101
-        $result = $this->pdo->query(sprintf('SELECT %s FROM %s', implode(',', $fields), $this->tableName));
102
-
103
-        $principals = [];
104
-
105
-        while ($row = $result->fetch(\PDO::FETCH_ASSOC)) {
106
-
107
-            // Checking if the principal is in the prefix
108
-            list($rowPrefix) = URLUtil::splitPath($row['uri']);
109
-            if ($rowPrefix !== $prefixPath) continue;
110
-
111
-            $principal = [
112
-                'uri' => $row['uri'],
113
-            ];
114
-            foreach ($this->fieldMap as $key => $value) {
115
-                if ($row[$value['dbField']]) {
116
-                    $principal[$key] = $row[$value['dbField']];
117
-                }
118
-            }
119
-            $principals[] = $principal;
120
-
121
-        }
122
-
123
-        return $principals;
124
-
125
-    }
126
-
127
-    /**
128
-     * Returns a specific principal, specified by it's path.
129
-     * The returned structure should be the exact same as from
130
-     * getPrincipalsByPrefix.
131
-     *
132
-     * @param string $path
133
-     * @return array
134
-     */
135
-    public function getPrincipalByPath($path) {
136
-
137
-        $fields = [
138
-            'id',
139
-            'uri',
140
-        ];
141
-
142
-        foreach ($this->fieldMap as $key => $value) {
143
-            $fields[] = $value['dbField'];
144
-        }
145
-        $stmt = $this->pdo->prepare(sprintf('SELECT %s FROM %s WHERE uri = ?', implode(',', $fields), $this->tableName));
146
-        $stmt->execute([$path]);
147
-
148
-        $row = $stmt->fetch(\PDO::FETCH_ASSOC);
149
-        if (!$row) return;
150
-
151
-        $principal = [
152
-            'id'  => $row['id'],
153
-            'uri' => $row['uri'],
154
-        ];
155
-        foreach ($this->fieldMap as $key => $value) {
156
-            if ($row[$value['dbField']]) {
157
-                $principal[$key] = $row[$value['dbField']];
158
-            }
159
-        }
160
-        return $principal;
161
-
162
-    }
163
-
164
-    /**
165
-     * Updates one ore more webdav properties on a principal.
166
-     *
167
-     * The list of mutations is stored in a Sabre\DAV\PropPatch object.
168
-     * To do the actual updates, you must tell this object which properties
169
-     * you're going to process with the handle() method.
170
-     *
171
-     * Calling the handle method is like telling the PropPatch object "I
172
-     * promise I can handle updating this property".
173
-     *
174
-     * Read the PropPatch documenation for more info and examples.
175
-     *
176
-     * @param string $path
177
-     * @param DAV\PropPatch $propPatch
178
-     */
179
-    public function updatePrincipal($path, DAV\PropPatch $propPatch) {
180
-
181
-        $propPatch->handle(array_keys($this->fieldMap), function($properties) use ($path) {
182
-
183
-            $query = sprintf('UPDATE %s SET ', $this->tableName);
184
-            $first = true;
185
-
186
-            $values = [];
187
-
188
-            foreach ($properties as $key => $value) {
189
-
190
-                $dbField = $this->fieldMap[$key]['dbField'];
191
-
192
-                if (!$first) {
193
-                    $query .= ', ';
194
-                }
195
-                $first = false;
196
-                $query .= $dbField . ' = :' . $dbField;
197
-                $values[$dbField] = $value;
198
-
199
-            }
200
-
201
-            $query .= " WHERE uri = :uri";
202
-            $values['uri'] = $path;
203
-
204
-            $stmt = $this->pdo->prepare($query);
205
-            $stmt->execute($values);
206
-
207
-            return true;
208
-
209
-        });
210
-
211
-    }
212
-
213
-    /**
214
-     * This method is used to search for principals matching a set of
215
-     * properties.
216
-     *
217
-     * This search is specifically used by RFC3744's principal-property-search
218
-     * REPORT.
219
-     *
220
-     * The actual search should be a unicode-non-case-sensitive search. The
221
-     * keys in searchProperties are the WebDAV property names, while the values
222
-     * are the property values to search on.
223
-     *
224
-     * By default, if multiple properties are submitted to this method, the
225
-     * various properties should be combined with 'AND'. If $test is set to
226
-     * 'anyof', it should be combined using 'OR'.
227
-     *
228
-     * This method should simply return an array with full principal uri's.
229
-     *
230
-     * If somebody attempted to search on a property the backend does not
231
-     * support, you should simply return 0 results.
232
-     *
233
-     * You can also just return 0 results if you choose to not support
234
-     * searching at all, but keep in mind that this may stop certain features
235
-     * from working.
236
-     *
237
-     * @param string $prefixPath
238
-     * @param array $searchProperties
239
-     * @param string $test
240
-     * @return array
241
-     */
242
-    public function searchPrincipals($prefixPath, array $searchProperties, $test = 'allof') {
243
-        if (count($searchProperties) == 0) return [];    //No criteria
244
-
245
-        $query = sprintf('SELECT uri FROM %s WHERE ', $this->tableName);
246
-        $values = [];
247
-        foreach ($searchProperties as $property => $value) {
248
-            switch ($property) {
249
-                case '{DAV:}displayname' :
250
-                    $column = "displayname";
251
-                    break;
252
-                case '{http://sabredav.org/ns}email-address' :
253
-                    $column = "email";
254
-                    break;
255
-                default :
256
-                    // Unsupported property
257
-                    return [];
258
-            }
259
-            if (count($values) > 0) $query .= (strcmp($test, "anyof") == 0 ? " || " : " && ");
260
-            $query .= 'lower(' . $column . ') LIKE lower(?)';
261
-            $values[] = '%' . $value . '%';
262
-
263
-        }
264
-        $stmt = $this->pdo->prepare($query);
265
-        $stmt->execute($values);
266
-
267
-        $principals = [];
268
-        while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
269
-
270
-            // Checking if the principal is in the prefix
271
-            list($rowPrefix) = URLUtil::splitPath($row['uri']);
272
-            if ($rowPrefix !== $prefixPath) continue;
273
-
274
-            $principals[] = $row['uri'];
275
-
276
-        }
277
-
278
-        return $principals;
279
-
280
-    }
281
-
282
-    /**
283
-     * Finds a principal by its URI.
284
-     *
285
-     * This method may receive any type of uri, but mailto: addresses will be
286
-     * the most common.
287
-     *
288
-     * Implementation of this API is optional. It is currently used by the
289
-     * CalDAV system to find principals based on their email addresses. If this
290
-     * API is not implemented, some features may not work correctly.
291
-     *
292
-     * This method must return a relative principal path, or null, if the
293
-     * principal was not found or you refuse to find it.
294
-     *
295
-     * @param string $uri
296
-     * @param string $principalPrefix
297
-     * @return string
298
-     */
299
-    public function findByUri($uri, $principalPrefix) {
300
-        $value = null;
301
-        $scheme = null;
302
-        list($scheme, $value) = explode(":", $uri, 2);
303
-        if ($value === null) return null;
304
-
305
-        $uri = null;
306
-        switch ($scheme){
307
-            case "mailto":
308
-                $query = sprintf('SELECT uri FROM %s WHERE lower(email)=lower(?)', $this->tableName);
309
-                $stmt = $this->pdo->prepare($query);
310
-                $stmt->execute([ $value ]);
22
+	/**
23
+	 * PDO table name for 'principals'
24
+	 *
25
+	 * @var string
26
+	 */
27
+	public $tableName = 'principals';
28
+
29
+	/**
30
+	 * PDO table name for 'group members'
31
+	 *
32
+	 * @var string
33
+	 */
34
+	public $groupMembersTableName = 'groupmembers';
35
+
36
+	/**
37
+	 * pdo
38
+	 *
39
+	 * @var PDO
40
+	 */
41
+	protected $pdo;
42
+
43
+	/**
44
+	 * A list of additional fields to support
45
+	 *
46
+	 * @var array
47
+	 */
48
+	protected $fieldMap = [
49
+
50
+		/**
51
+		 * This property can be used to display the users' real name.
52
+		 */
53
+		'{DAV:}displayname' => [
54
+			'dbField' => 'displayname',
55
+		],
56
+
57
+		/**
58
+		 * This is the users' primary email-address.
59
+		 */
60
+		'{http://sabredav.org/ns}email-address' => [
61
+			'dbField' => 'email',
62
+		],
63
+	];
64
+
65
+	/**
66
+	 * Sets up the backend.
67
+	 *
68
+	 * @param PDO $pdo
69
+	 */
70
+	public function __construct(\PDO $pdo) {
71
+
72
+		$this->pdo = $pdo;
73
+
74
+	}
75
+
76
+	/**
77
+	 * Returns a list of principals based on a prefix.
78
+	 *
79
+	 * This prefix will often contain something like 'principals'. You are only
80
+	 * expected to return principals that are in this base path.
81
+	 *
82
+	 * You are expected to return at least a 'uri' for every user, you can
83
+	 * return any additional properties if you wish so. Common properties are:
84
+	 *   {DAV:}displayname
85
+	 *   {http://sabredav.org/ns}email-address - This is a custom SabreDAV
86
+	 *     field that's actualy injected in a number of other properties. If
87
+	 *     you have an email address, use this property.
88
+	 *
89
+	 * @param string $prefixPath
90
+	 * @return array
91
+	 */
92
+	public function getPrincipalsByPrefix($prefixPath) {
93
+
94
+		$fields = [
95
+			'uri',
96
+		];
97
+
98
+		foreach ($this->fieldMap as $key => $value) {
99
+			$fields[] = $value['dbField'];
100
+		}
101
+		$result = $this->pdo->query(sprintf('SELECT %s FROM %s', implode(',', $fields), $this->tableName));
102
+
103
+		$principals = [];
104
+
105
+		while ($row = $result->fetch(\PDO::FETCH_ASSOC)) {
106
+
107
+			// Checking if the principal is in the prefix
108
+			list($rowPrefix) = URLUtil::splitPath($row['uri']);
109
+			if ($rowPrefix !== $prefixPath) continue;
110
+
111
+			$principal = [
112
+				'uri' => $row['uri'],
113
+			];
114
+			foreach ($this->fieldMap as $key => $value) {
115
+				if ($row[$value['dbField']]) {
116
+					$principal[$key] = $row[$value['dbField']];
117
+				}
118
+			}
119
+			$principals[] = $principal;
120
+
121
+		}
122
+
123
+		return $principals;
124
+
125
+	}
126
+
127
+	/**
128
+	 * Returns a specific principal, specified by it's path.
129
+	 * The returned structure should be the exact same as from
130
+	 * getPrincipalsByPrefix.
131
+	 *
132
+	 * @param string $path
133
+	 * @return array
134
+	 */
135
+	public function getPrincipalByPath($path) {
136
+
137
+		$fields = [
138
+			'id',
139
+			'uri',
140
+		];
141
+
142
+		foreach ($this->fieldMap as $key => $value) {
143
+			$fields[] = $value['dbField'];
144
+		}
145
+		$stmt = $this->pdo->prepare(sprintf('SELECT %s FROM %s WHERE uri = ?', implode(',', $fields), $this->tableName));
146
+		$stmt->execute([$path]);
147
+
148
+		$row = $stmt->fetch(\PDO::FETCH_ASSOC);
149
+		if (!$row) return;
150
+
151
+		$principal = [
152
+			'id'  => $row['id'],
153
+			'uri' => $row['uri'],
154
+		];
155
+		foreach ($this->fieldMap as $key => $value) {
156
+			if ($row[$value['dbField']]) {
157
+				$principal[$key] = $row[$value['dbField']];
158
+			}
159
+		}
160
+		return $principal;
161
+
162
+	}
163
+
164
+	/**
165
+	 * Updates one ore more webdav properties on a principal.
166
+	 *
167
+	 * The list of mutations is stored in a Sabre\DAV\PropPatch object.
168
+	 * To do the actual updates, you must tell this object which properties
169
+	 * you're going to process with the handle() method.
170
+	 *
171
+	 * Calling the handle method is like telling the PropPatch object "I
172
+	 * promise I can handle updating this property".
173
+	 *
174
+	 * Read the PropPatch documenation for more info and examples.
175
+	 *
176
+	 * @param string $path
177
+	 * @param DAV\PropPatch $propPatch
178
+	 */
179
+	public function updatePrincipal($path, DAV\PropPatch $propPatch) {
180
+
181
+		$propPatch->handle(array_keys($this->fieldMap), function($properties) use ($path) {
182
+
183
+			$query = sprintf('UPDATE %s SET ', $this->tableName);
184
+			$first = true;
185
+
186
+			$values = [];
187
+
188
+			foreach ($properties as $key => $value) {
189
+
190
+				$dbField = $this->fieldMap[$key]['dbField'];
191
+
192
+				if (!$first) {
193
+					$query .= ', ';
194
+				}
195
+				$first = false;
196
+				$query .= $dbField . ' = :' . $dbField;
197
+				$values[$dbField] = $value;
198
+
199
+			}
200
+
201
+			$query .= " WHERE uri = :uri";
202
+			$values['uri'] = $path;
203
+
204
+			$stmt = $this->pdo->prepare($query);
205
+			$stmt->execute($values);
206
+
207
+			return true;
208
+
209
+		});
210
+
211
+	}
212
+
213
+	/**
214
+	 * This method is used to search for principals matching a set of
215
+	 * properties.
216
+	 *
217
+	 * This search is specifically used by RFC3744's principal-property-search
218
+	 * REPORT.
219
+	 *
220
+	 * The actual search should be a unicode-non-case-sensitive search. The
221
+	 * keys in searchProperties are the WebDAV property names, while the values
222
+	 * are the property values to search on.
223
+	 *
224
+	 * By default, if multiple properties are submitted to this method, the
225
+	 * various properties should be combined with 'AND'. If $test is set to
226
+	 * 'anyof', it should be combined using 'OR'.
227
+	 *
228
+	 * This method should simply return an array with full principal uri's.
229
+	 *
230
+	 * If somebody attempted to search on a property the backend does not
231
+	 * support, you should simply return 0 results.
232
+	 *
233
+	 * You can also just return 0 results if you choose to not support
234
+	 * searching at all, but keep in mind that this may stop certain features
235
+	 * from working.
236
+	 *
237
+	 * @param string $prefixPath
238
+	 * @param array $searchProperties
239
+	 * @param string $test
240
+	 * @return array
241
+	 */
242
+	public function searchPrincipals($prefixPath, array $searchProperties, $test = 'allof') {
243
+		if (count($searchProperties) == 0) return [];    //No criteria
244
+
245
+		$query = sprintf('SELECT uri FROM %s WHERE ', $this->tableName);
246
+		$values = [];
247
+		foreach ($searchProperties as $property => $value) {
248
+			switch ($property) {
249
+				case '{DAV:}displayname' :
250
+					$column = "displayname";
251
+					break;
252
+				case '{http://sabredav.org/ns}email-address' :
253
+					$column = "email";
254
+					break;
255
+				default :
256
+					// Unsupported property
257
+					return [];
258
+			}
259
+			if (count($values) > 0) $query .= (strcmp($test, "anyof") == 0 ? " || " : " && ");
260
+			$query .= 'lower(' . $column . ') LIKE lower(?)';
261
+			$values[] = '%' . $value . '%';
262
+
263
+		}
264
+		$stmt = $this->pdo->prepare($query);
265
+		$stmt->execute($values);
266
+
267
+		$principals = [];
268
+		while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
269
+
270
+			// Checking if the principal is in the prefix
271
+			list($rowPrefix) = URLUtil::splitPath($row['uri']);
272
+			if ($rowPrefix !== $prefixPath) continue;
273
+
274
+			$principals[] = $row['uri'];
275
+
276
+		}
277
+
278
+		return $principals;
279
+
280
+	}
281
+
282
+	/**
283
+	 * Finds a principal by its URI.
284
+	 *
285
+	 * This method may receive any type of uri, but mailto: addresses will be
286
+	 * the most common.
287
+	 *
288
+	 * Implementation of this API is optional. It is currently used by the
289
+	 * CalDAV system to find principals based on their email addresses. If this
290
+	 * API is not implemented, some features may not work correctly.
291
+	 *
292
+	 * This method must return a relative principal path, or null, if the
293
+	 * principal was not found or you refuse to find it.
294
+	 *
295
+	 * @param string $uri
296
+	 * @param string $principalPrefix
297
+	 * @return string
298
+	 */
299
+	public function findByUri($uri, $principalPrefix) {
300
+		$value = null;
301
+		$scheme = null;
302
+		list($scheme, $value) = explode(":", $uri, 2);
303
+		if ($value === null) return null;
304
+
305
+		$uri = null;
306
+		switch ($scheme){
307
+			case "mailto":
308
+				$query = sprintf('SELECT uri FROM %s WHERE lower(email)=lower(?)', $this->tableName);
309
+				$stmt = $this->pdo->prepare($query);
310
+				$stmt->execute([ $value ]);
311 311
             
312
-                while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
313
-                    // Checking if the principal is in the prefix
314
-                    list($rowPrefix) = URLUtil::splitPath($row['uri']);
315
-                    if ($rowPrefix !== $principalPrefix) continue;
312
+				while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
313
+					// Checking if the principal is in the prefix
314
+					list($rowPrefix) = URLUtil::splitPath($row['uri']);
315
+					if ($rowPrefix !== $principalPrefix) continue;
316 316
                     
317
-                    $uri = $row['uri'];
318
-                    break; //Stop on first match
319
-                }
320
-                break;
321
-            default:
322
-                //unsupported uri scheme
323
-                return null;
324
-        }
325
-        return $uri;
326
-    }
327
-
328
-    /**
329
-     * Returns the list of members for a group-principal
330
-     *
331
-     * @param string $principal
332
-     * @return array
333
-     */
334
-    public function getGroupMemberSet($principal) {
335
-
336
-        $principal = $this->getPrincipalByPath($principal);
337
-        if (!$principal) throw new DAV\Exception('Principal not found');
317
+					$uri = $row['uri'];
318
+					break; //Stop on first match
319
+				}
320
+				break;
321
+			default:
322
+				//unsupported uri scheme
323
+				return null;
324
+		}
325
+		return $uri;
326
+	}
327
+
328
+	/**
329
+	 * Returns the list of members for a group-principal
330
+	 *
331
+	 * @param string $principal
332
+	 * @return array
333
+	 */
334
+	public function getGroupMemberSet($principal) {
335
+
336
+		$principal = $this->getPrincipalByPath($principal);
337
+		if (!$principal) throw new DAV\Exception('Principal not found');
338 338
 
339 339
 		$query = 'SELECT principals.uri as uri FROM %s AS groupmembers LEFT JOIN %s AS principals ON groupmembers.member_id = principals.id WHERE groupmembers.principal_id = ?';
340
-        $query = sprintf($query, $this->groupMembersTableName, $this->tableName);
340
+		$query = sprintf($query, $this->groupMembersTableName, $this->tableName);
341 341
 		$stmt = $this->pdo->prepare($query);
342
-        $stmt->execute([$principal['id']]);
343
-
344
-        $result = [];
345
-        while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
346
-            $result[] = $row['uri'];
347
-        }
348
-        return $result;
349
-
350
-    }
351
-
352
-    /**
353
-     * Returns the list of groups a principal is a member of
354
-     *
355
-     * @param string $principal
356
-     * @return array
357
-     */
358
-    public function getGroupMembership($principal) {
359
-
360
-        $principal = $this->getPrincipalByPath($principal);
361
-        if (!$principal) throw new DAV\Exception('Principal not found');
362
-
363
-        $stmt = $this->pdo->prepare(sprintf('SELECT principals.uri as uri FROM %s AS groupmembers LEFT JOIN %s AS principals ON groupmembers.principal_id = principals.id WHERE groupmembers.member_id = ?', $this->groupMembersTableName, $this->tableName));
364
-        $stmt->execute([$principal['id']]);
365
-
366
-        $result = [];
367
-        while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
368
-            $result[] = $row['uri'];
369
-        }
370
-        return $result;
371
-
372
-    }
373
-
374
-    /**
375
-     * Updates the list of group members for a group principal.
376
-     *
377
-     * The principals should be passed as a list of uri's.
378
-     *
379
-     * @param string $principal
380
-     * @param array $members
381
-     * @return void
382
-     */
383
-    public function setGroupMemberSet($principal, array $members) {
384
-
385
-        // Grabbing the list of principal id's.
386
-        $stmt = $this->pdo->prepare(sprintf('SELECT id, uri FROM %s WHERE uri IN (? %s);',$this->tableName, str_repeat(', ? ', count($members))));
387
-        $stmt->execute(array_merge([$principal], $members));
388
-
389
-        $memberIds = [];
390
-        $principalId = null;
391
-
392
-        while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
393
-            if ($row['uri'] == $principal) {
394
-                $principalId = $row['id'];
395
-            } else {
396
-                $memberIds[] = $row['id'];
397
-            }
398
-        }
399
-        if (!$principalId) throw new DAV\Exception('Principal not found');
400
-
401
-        // Wiping out old members
402
-        $stmt = $this->pdo->prepare(sprintf('DELETE FROM %s WHERE principal_id = ?;', $this->groupMembersTableName));
403
-        $stmt->execute([$principalId]);
404
-
405
-        foreach ($memberIds as $memberId) {
406
-
407
-            $stmt = $this->pdo->prepare('INSERT INTO ' . $this->groupMembersTableName . ' (principal_id, member_id) VALUES (?, ?);');
408
-            $stmt->execute([$principalId, $memberId]);
409
-
410
-        }
411
-
412
-    }
413
-
414
-    /**
415
-     * Creates a new principal.
416
-     *
417
-     * This method receives a full path for the new principal. The mkCol object
418
-     * contains any additional webdav properties specified during the creation
419
-     * of the principal.
420
-     *
421
-     * @param string $path
422
-     * @param MkCol $mkCol
423
-     * @return void
424
-     */
425
-    public function createPrincipal($path, MkCol $mkCol) {
426
-
427
-        $stmt = $this->pdo->prepare('INSERT INTO ' . $this->tableName . ' (uri) VALUES (?)');
428
-        $stmt->execute([$path]);
429
-        $this->updatePrincipal($path, $mkCol);
430
-
431
-    }
342
+		$stmt->execute([$principal['id']]);
343
+
344
+		$result = [];
345
+		while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
346
+			$result[] = $row['uri'];
347
+		}
348
+		return $result;
349
+
350
+	}
351
+
352
+	/**
353
+	 * Returns the list of groups a principal is a member of
354
+	 *
355
+	 * @param string $principal
356
+	 * @return array
357
+	 */
358
+	public function getGroupMembership($principal) {
359
+
360
+		$principal = $this->getPrincipalByPath($principal);
361
+		if (!$principal) throw new DAV\Exception('Principal not found');
362
+
363
+		$stmt = $this->pdo->prepare(sprintf('SELECT principals.uri as uri FROM %s AS groupmembers LEFT JOIN %s AS principals ON groupmembers.principal_id = principals.id WHERE groupmembers.member_id = ?', $this->groupMembersTableName, $this->tableName));
364
+		$stmt->execute([$principal['id']]);
365
+
366
+		$result = [];
367
+		while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
368
+			$result[] = $row['uri'];
369
+		}
370
+		return $result;
371
+
372
+	}
373
+
374
+	/**
375
+	 * Updates the list of group members for a group principal.
376
+	 *
377
+	 * The principals should be passed as a list of uri's.
378
+	 *
379
+	 * @param string $principal
380
+	 * @param array $members
381
+	 * @return void
382
+	 */
383
+	public function setGroupMemberSet($principal, array $members) {
384
+
385
+		// Grabbing the list of principal id's.
386
+		$stmt = $this->pdo->prepare(sprintf('SELECT id, uri FROM %s WHERE uri IN (? %s);',$this->tableName, str_repeat(', ? ', count($members))));
387
+		$stmt->execute(array_merge([$principal], $members));
388
+
389
+		$memberIds = [];
390
+		$principalId = null;
391
+
392
+		while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
393
+			if ($row['uri'] == $principal) {
394
+				$principalId = $row['id'];
395
+			} else {
396
+				$memberIds[] = $row['id'];
397
+			}
398
+		}
399
+		if (!$principalId) throw new DAV\Exception('Principal not found');
400
+
401
+		// Wiping out old members
402
+		$stmt = $this->pdo->prepare(sprintf('DELETE FROM %s WHERE principal_id = ?;', $this->groupMembersTableName));
403
+		$stmt->execute([$principalId]);
404
+
405
+		foreach ($memberIds as $memberId) {
406
+
407
+			$stmt = $this->pdo->prepare('INSERT INTO ' . $this->groupMembersTableName . ' (principal_id, member_id) VALUES (?, ?);');
408
+			$stmt->execute([$principalId, $memberId]);
409
+
410
+		}
411
+
412
+	}
413
+
414
+	/**
415
+	 * Creates a new principal.
416
+	 *
417
+	 * This method receives a full path for the new principal. The mkCol object
418
+	 * contains any additional webdav properties specified during the creation
419
+	 * of the principal.
420
+	 *
421
+	 * @param string $path
422
+	 * @param MkCol $mkCol
423
+	 * @return void
424
+	 */
425
+	public function createPrincipal($path, MkCol $mkCol) {
426
+
427
+		$stmt = $this->pdo->prepare('INSERT INTO ' . $this->tableName . ' (uri) VALUES (?)');
428
+		$stmt->execute([$path]);
429
+		$this->updatePrincipal($path, $mkCol);
430
+
431
+	}
432 432
 
433 433
 }
Please login to merge, or discard this patch.
Braces   +31 added lines, -10 removed lines patch added patch discarded remove patch
@@ -106,7 +106,9 @@  discard block
 block discarded – undo
106 106
 
107 107
             // Checking if the principal is in the prefix
108 108
             list($rowPrefix) = URLUtil::splitPath($row['uri']);
109
-            if ($rowPrefix !== $prefixPath) continue;
109
+            if ($rowPrefix !== $prefixPath) {
110
+            	continue;
111
+            }
110 112
 
111 113
             $principal = [
112 114
                 'uri' => $row['uri'],
@@ -146,7 +148,9 @@  discard block
 block discarded – undo
146 148
         $stmt->execute([$path]);
147 149
 
148 150
         $row = $stmt->fetch(\PDO::FETCH_ASSOC);
149
-        if (!$row) return;
151
+        if (!$row) {
152
+        	return;
153
+        }
150 154
 
151 155
         $principal = [
152 156
             'id'  => $row['id'],
@@ -240,7 +244,10 @@  discard block
 block discarded – undo
240 244
      * @return array
241 245
      */
242 246
     public function searchPrincipals($prefixPath, array $searchProperties, $test = 'allof') {
243
-        if (count($searchProperties) == 0) return [];    //No criteria
247
+        if (count($searchProperties) == 0) {
248
+        	return [];
249
+        }
250
+        //No criteria
244 251
 
245 252
         $query = sprintf('SELECT uri FROM %s WHERE ', $this->tableName);
246 253
         $values = [];
@@ -256,7 +263,9 @@  discard block
 block discarded – undo
256 263
                     // Unsupported property
257 264
                     return [];
258 265
             }
259
-            if (count($values) > 0) $query .= (strcmp($test, "anyof") == 0 ? " || " : " && ");
266
+            if (count($values) > 0) {
267
+            	$query .= (strcmp($test, "anyof") == 0 ? " || " : " && ");
268
+            }
260 269
             $query .= 'lower(' . $column . ') LIKE lower(?)';
261 270
             $values[] = '%' . $value . '%';
262 271
 
@@ -269,7 +278,9 @@  discard block
 block discarded – undo
269 278
 
270 279
             // Checking if the principal is in the prefix
271 280
             list($rowPrefix) = URLUtil::splitPath($row['uri']);
272
-            if ($rowPrefix !== $prefixPath) continue;
281
+            if ($rowPrefix !== $prefixPath) {
282
+            	continue;
283
+            }
273 284
 
274 285
             $principals[] = $row['uri'];
275 286
 
@@ -300,7 +311,9 @@  discard block
 block discarded – undo
300 311
         $value = null;
301 312
         $scheme = null;
302 313
         list($scheme, $value) = explode(":", $uri, 2);
303
-        if ($value === null) return null;
314
+        if ($value === null) {
315
+        	return null;
316
+        }
304 317
 
305 318
         $uri = null;
306 319
         switch ($scheme){
@@ -312,7 +325,9 @@  discard block
 block discarded – undo
312 325
                 while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
313 326
                     // Checking if the principal is in the prefix
314 327
                     list($rowPrefix) = URLUtil::splitPath($row['uri']);
315
-                    if ($rowPrefix !== $principalPrefix) continue;
328
+                    if ($rowPrefix !== $principalPrefix) {
329
+                    	continue;
330
+                    }
316 331
                     
317 332
                     $uri = $row['uri'];
318 333
                     break; //Stop on first match
@@ -334,7 +349,9 @@  discard block
 block discarded – undo
334 349
     public function getGroupMemberSet($principal) {
335 350
 
336 351
         $principal = $this->getPrincipalByPath($principal);
337
-        if (!$principal) throw new DAV\Exception('Principal not found');
352
+        if (!$principal) {
353
+        	throw new DAV\Exception('Principal not found');
354
+        }
338 355
 
339 356
 		$query = 'SELECT principals.uri as uri FROM %s AS groupmembers LEFT JOIN %s AS principals ON groupmembers.member_id = principals.id WHERE groupmembers.principal_id = ?';
340 357
         $query = sprintf($query, $this->groupMembersTableName, $this->tableName);
@@ -358,7 +375,9 @@  discard block
 block discarded – undo
358 375
     public function getGroupMembership($principal) {
359 376
 
360 377
         $principal = $this->getPrincipalByPath($principal);
361
-        if (!$principal) throw new DAV\Exception('Principal not found');
378
+        if (!$principal) {
379
+        	throw new DAV\Exception('Principal not found');
380
+        }
362 381
 
363 382
         $stmt = $this->pdo->prepare(sprintf('SELECT principals.uri as uri FROM %s AS groupmembers LEFT JOIN %s AS principals ON groupmembers.principal_id = principals.id WHERE groupmembers.member_id = ?', $this->groupMembersTableName, $this->tableName));
364 383
         $stmt->execute([$principal['id']]);
@@ -396,7 +415,9 @@  discard block
 block discarded – undo
396 415
                 $memberIds[] = $row['id'];
397 416
             }
398 417
         }
399
-        if (!$principalId) throw new DAV\Exception('Principal not found');
418
+        if (!$principalId) {
419
+        	throw new DAV\Exception('Principal not found');
420
+        }
400 421
 
401 422
         // Wiping out old members
402 423
         $stmt = $this->pdo->prepare(sprintf('DELETE FROM %s WHERE principal_id = ?;', $this->groupMembersTableName));
Please login to merge, or discard this patch.