@@ -77,18 +77,19 @@ discard block |
||
| 77 | 77 | { |
| 78 | 78 | if(is_array($config)) |
| 79 | 79 | { |
| 80 | - foreach($config as $id => $feed) |
|
| 81 | - $this->_feeds[$id] = $feed; |
|
| 80 | + foreach($config as $id => $feed) { |
|
| 81 | + $this->_feeds[$id] = $feed; |
|
| 82 | + } |
|
| 82 | 83 | } |
| 83 | - } |
|
| 84 | - else |
|
| 84 | + } else |
|
| 85 | 85 | { |
| 86 | 86 | foreach($config->getElementsByTagName('feed') as $feed) |
| 87 | 87 | { |
| 88 | - if(($id = $feed->getAttributes()->remove('id')) !== null) |
|
| 89 | - $this->_feeds[$id] = $feed; |
|
| 90 | - else |
|
| 91 | - throw new TConfigurationException('feedservice_id_required'); |
|
| 88 | + if(($id = $feed->getAttributes()->remove('id')) !== null) { |
|
| 89 | + $this->_feeds[$id] = $feed; |
|
| 90 | + } else { |
|
| 91 | + throw new TConfigurationException('feedservice_id_required'); |
|
| 92 | + } |
|
| 92 | 93 | } |
| 93 | 94 | } |
| 94 | 95 | } |
@@ -118,38 +119,40 @@ discard block |
||
| 118 | 119 | if(isset($feedConfig['class'])) |
| 119 | 120 | { |
| 120 | 121 | $feed = Prado::createComponent($feedConfig['class']); |
| 121 | - if($service instanceof IFeedContentProvider) |
|
| 122 | - $properties = isset($feedConfig['properties'])?$feedConfig['properties']:[]; |
|
| 123 | - else |
|
| 124 | - throw new TConfigurationException('jsonservice_response_type_invalid', $id); |
|
| 122 | + if($service instanceof IFeedContentProvider) { |
|
| 123 | + $properties = isset($feedConfig['properties'])?$feedConfig['properties']:[]; |
|
| 124 | + } else { |
|
| 125 | + throw new TConfigurationException('jsonservice_response_type_invalid', $id); |
|
| 126 | + } |
|
| 127 | + } else { |
|
| 128 | + throw new TConfigurationException('jsonservice_class_required', $id); |
|
| 125 | 129 | } |
| 126 | - else |
|
| 127 | - throw new TConfigurationException('jsonservice_class_required', $id); |
|
| 128 | - } |
|
| 129 | - else |
|
| 130 | + } else |
|
| 130 | 131 | { |
| 131 | 132 | $properties = $feedConfig->getAttributes(); |
| 132 | 133 | if(($class = $properties->remove('class')) !== null) |
| 133 | 134 | { |
| 134 | 135 | $feed = Prado::createComponent($class); |
| 135 | - if(!($feed instanceof IFeedContentProvider)) |
|
| 136 | - throw new TConfigurationException('feedservice_feedtype_invalid', $id); |
|
| 136 | + if(!($feed instanceof IFeedContentProvider)) { |
|
| 137 | + throw new TConfigurationException('feedservice_feedtype_invalid', $id); |
|
| 138 | + } |
|
| 139 | + } else { |
|
| 140 | + throw new TConfigurationException('feedservice_class_required', $id); |
|
| 137 | 141 | } |
| 138 | - else |
|
| 139 | - throw new TConfigurationException('feedservice_class_required', $id); |
|
| 140 | 142 | } |
| 141 | 143 | |
| 142 | 144 | // init feed properties |
| 143 | - foreach($properties as $name => $value) |
|
| 144 | - $feed->setSubproperty($name, $value); |
|
| 145 | + foreach($properties as $name => $value) { |
|
| 146 | + $feed->setSubproperty($name, $value); |
|
| 147 | + } |
|
| 145 | 148 | $feed->init($feedConfig); |
| 146 | 149 | |
| 147 | 150 | $content = $feed->getFeedContent(); |
| 148 | 151 | //$this->getResponse()->setContentType('application/rss+xml'); |
| 149 | 152 | $this->getResponse()->setContentType($feed->getContentType()); |
| 150 | 153 | $this->getResponse()->write($content); |
| 154 | + } else { |
|
| 155 | + throw new THttpException(404, 'feedservice_feed_unknown', $id); |
|
| 151 | 156 | } |
| 152 | - else |
|
| 153 | - throw new THttpException(404, 'feedservice_feed_unknown', $id); |
|
| 154 | 157 | } |
| 155 | 158 | } |
| 156 | 159 | \ No newline at end of file |
@@ -126,9 +126,9 @@ discard block |
||
| 126 | 126 | $dom = new TXmlDocument; |
| 127 | 127 | $dom->loadFromFile($this->_configFile); |
| 128 | 128 | $this->loadConfig($dom); |
| 129 | + } else { |
|
| 130 | + throw new TConfigurationException('soapservice_configfile_invalid', $this->_configFile); |
|
| 129 | 131 | } |
| 130 | - else |
|
| 131 | - throw new TConfigurationException('soapservice_configfile_invalid', $this->_configFile); |
|
| 132 | 132 | } |
| 133 | 133 | $this->loadConfig($config); |
| 134 | 134 | |
@@ -149,12 +149,13 @@ discard block |
||
| 149 | 149 | { |
| 150 | 150 | $serverID = substr($serverID, 0, $pos); |
| 151 | 151 | $this->_wsdlRequest = true; |
| 152 | + } else { |
|
| 153 | + $this->_wsdlRequest = false; |
|
| 152 | 154 | } |
| 153 | - else |
|
| 154 | - $this->_wsdlRequest = false; |
|
| 155 | 155 | $this->_serverID = $serverID; |
| 156 | - if(!isset($this->_servers[$serverID])) |
|
| 157 | - throw new THttpException(400, 'soapservice_request_invalid', $serverID); |
|
| 156 | + if(!isset($this->_servers[$serverID])) { |
|
| 157 | + throw new THttpException(400, 'soapservice_request_invalid', $serverID); |
|
| 158 | + } |
|
| 158 | 159 | } |
| 159 | 160 | |
| 160 | 161 | /** |
@@ -171,21 +172,23 @@ discard block |
||
| 171 | 172 | foreach($config['soap'] as $id => $server) |
| 172 | 173 | { |
| 173 | 174 | $properties = isset($server['properties'])?$server['properties']:[]; |
| 174 | - if(isset($this->_servers[$id])) |
|
| 175 | - throw new TConfigurationException('soapservice_serverid_duplicated', $id); |
|
| 175 | + if(isset($this->_servers[$id])) { |
|
| 176 | + throw new TConfigurationException('soapservice_serverid_duplicated', $id); |
|
| 177 | + } |
|
| 176 | 178 | $this->_servers[$id] = $properties; |
| 177 | 179 | } |
| 178 | 180 | } |
| 179 | - } |
|
| 180 | - else |
|
| 181 | + } else |
|
| 181 | 182 | { |
| 182 | 183 | foreach($config->getElementsByTagName('soap') as $serverXML) |
| 183 | 184 | { |
| 184 | 185 | $properties = $serverXML->getAttributes(); |
| 185 | - if(($id = $properties->remove('id')) === null) |
|
| 186 | - throw new TConfigurationException('soapservice_serverid_required'); |
|
| 187 | - if(isset($this->_servers[$id])) |
|
| 188 | - throw new TConfigurationException('soapservice_serverid_duplicated', $id); |
|
| 186 | + if(($id = $properties->remove('id')) === null) { |
|
| 187 | + throw new TConfigurationException('soapservice_serverid_required'); |
|
| 188 | + } |
|
| 189 | + if(isset($this->_servers[$id])) { |
|
| 190 | + throw new TConfigurationException('soapservice_serverid_duplicated', $id); |
|
| 191 | + } |
|
| 189 | 192 | $this->_servers[$id] = $properties; |
| 190 | 193 | } |
| 191 | 194 | } |
@@ -206,8 +209,9 @@ discard block |
||
| 206 | 209 | */ |
| 207 | 210 | public function setConfigFile($value) |
| 208 | 211 | { |
| 209 | - if(($this->_configFile = Prado::getPathOfNamespace($value, Prado::getApplication()->getConfigurationFileExt())) === null) |
|
| 210 | - throw new TConfigurationException('soapservice_configfile_invalid', $value); |
|
| 212 | + if(($this->_configFile = Prado::getPathOfNamespace($value, Prado::getApplication()->getConfigurationFileExt())) === null) { |
|
| 213 | + throw new TConfigurationException('soapservice_configfile_invalid', $value); |
|
| 214 | + } |
|
| 211 | 215 | } |
| 212 | 216 | |
| 213 | 217 | /** |
@@ -249,20 +253,24 @@ discard block |
||
| 249 | 253 | { |
| 250 | 254 | $properties = $this->_servers[$this->_serverID]; |
| 251 | 255 | $serverClass = null; |
| 252 | - if($this->getApplication()->getConfigurationType() == TApplication::CONFIG_TYPE_PHP && isset($config['class'])) |
|
| 253 | - $serverClass = $config['class']; |
|
| 254 | - elseif($this->getApplication()->getConfigurationType() == TApplication::CONFIG_TYPE_XML) |
|
| 255 | - $serverClass = $properties->remove('class'); |
|
| 256 | - if($serverClass === null) |
|
| 257 | - $serverClass = self::DEFAULT_SOAP_SERVER; |
|
| 256 | + if($this->getApplication()->getConfigurationType() == TApplication::CONFIG_TYPE_PHP && isset($config['class'])) { |
|
| 257 | + $serverClass = $config['class']; |
|
| 258 | + } elseif($this->getApplication()->getConfigurationType() == TApplication::CONFIG_TYPE_XML) { |
|
| 259 | + $serverClass = $properties->remove('class'); |
|
| 260 | + } |
|
| 261 | + if($serverClass === null) { |
|
| 262 | + $serverClass = self::DEFAULT_SOAP_SERVER; |
|
| 263 | + } |
|
| 258 | 264 | Prado::using($serverClass); |
| 259 | 265 | $className = ($pos = strrpos($serverClass, '.')) !== false?substr($serverClass, $pos + 1):$serverClass; |
| 260 | - if($className !== self::DEFAULT_SOAP_SERVER && !is_subclass_of($className, self::DEFAULT_SOAP_SERVER)) |
|
| 261 | - throw new TConfigurationException('soapservice_server_invalid', $serverClass); |
|
| 266 | + if($className !== self::DEFAULT_SOAP_SERVER && !is_subclass_of($className, self::DEFAULT_SOAP_SERVER)) { |
|
| 267 | + throw new TConfigurationException('soapservice_server_invalid', $serverClass); |
|
| 268 | + } |
|
| 262 | 269 | $server = new $className; |
| 263 | 270 | $server->setID($this->_serverID); |
| 264 | - foreach($properties as $name => $value) |
|
| 265 | - $server->setSubproperty($name, $value); |
|
| 271 | + foreach($properties as $name => $value) { |
|
| 272 | + $server->setSubproperty($name, $value); |
|
| 273 | + } |
|
| 266 | 274 | return $server; |
| 267 | 275 | } |
| 268 | 276 | |
@@ -284,8 +292,7 @@ discard block |
||
| 284 | 292 | Prado::trace("Generating WSDL", 'Prado\Web\Services\TSoapService'); |
| 285 | 293 | $this->getResponse()->clear(); |
| 286 | 294 | $this->getResponse()->write($server->getWsdl()); |
| 287 | - } |
|
| 288 | - else |
|
| 295 | + } else |
|
| 289 | 296 | { |
| 290 | 297 | // provide SOAP service |
| 291 | 298 | Prado::trace("Handling SOAP request", 'Prado\Web\Services\TSoapService'); |
@@ -85,14 +85,17 @@ |
||
| 85 | 85 | */ |
| 86 | 86 | public function callApiMethod($methodName, $parameters) |
| 87 | 87 | { |
| 88 | - if(!isset($this->rpcMethods[$methodName])) |
|
| 89 | - throw new TRpcException('Method "' . $methodName . '" not found'); |
|
| 88 | + if(!isset($this->rpcMethods[$methodName])) { |
|
| 89 | + throw new TRpcException('Method "' . $methodName . '" not found'); |
|
| 90 | + } |
|
| 90 | 91 | |
| 91 | - if($parameters === null) |
|
| 92 | - $parameters = []; |
|
| 92 | + if($parameters === null) { |
|
| 93 | + $parameters = []; |
|
| 94 | + } |
|
| 93 | 95 | |
| 94 | - if(!is_array($parameters)) |
|
| 95 | - $parameters = [$parameters]; |
|
| 96 | + if(!is_array($parameters)) { |
|
| 97 | + $parameters = [$parameters]; |
|
| 98 | + } |
|
| 96 | 99 | return call_user_func_array($this->rpcMethods[$methodName]['method'], $parameters); |
| 97 | 100 | } |
| 98 | 101 | } |
| 99 | 102 | \ No newline at end of file |
@@ -118,10 +118,11 @@ discard block |
||
| 118 | 118 | { |
| 119 | 119 | $this->loadFromFile($path . DIRECTORY_SEPARATOR . $fileName, $configPagePath); |
| 120 | 120 | $path .= DIRECTORY_SEPARATOR . $p; |
| 121 | - if($configPagePath === '') |
|
| 122 | - $configPagePath = $p; |
|
| 123 | - else |
|
| 124 | - $configPagePath .= '.' . $p; |
|
| 121 | + if($configPagePath === '') { |
|
| 122 | + $configPagePath = $p; |
|
| 123 | + } else { |
|
| 124 | + $configPagePath .= '.' . $p; |
|
| 125 | + } |
|
| 125 | 126 | } |
| 126 | 127 | $this->loadFromFile($path . DIRECTORY_SEPARATOR . $fileName, $configPagePath); |
| 127 | 128 | $this->_rules = new TAuthorizationRuleCollection($this->_rules); |
@@ -135,21 +136,22 @@ discard block |
||
| 135 | 136 | public function loadFromFile($fname, $configPagePath) |
| 136 | 137 | { |
| 137 | 138 | Prado::trace("Loading page configuration file $fname", 'System.Web.Services.TPageService'); |
| 138 | - if(empty($fname) || !is_file($fname)) |
|
| 139 | - return; |
|
| 139 | + if(empty($fname) || !is_file($fname)) { |
|
| 140 | + return; |
|
| 141 | + } |
|
| 140 | 142 | |
| 141 | 143 | if(Prado::getApplication()->getConfigurationType() == TApplication::CONFIG_TYPE_PHP) |
| 142 | 144 | { |
| 143 | 145 | $fcontent = include $fname; |
| 144 | 146 | $this->loadFromPhp($fcontent, dirname($fname), $configPagePath); |
| 145 | - } |
|
| 146 | - else |
|
| 147 | + } else |
|
| 147 | 148 | { |
| 148 | 149 | $dom = new TXmlDocument; |
| 149 | - if($dom->loadFromFile($fname)) |
|
| 150 | - $this->loadFromXml($dom, dirname($fname), $configPagePath); |
|
| 151 | - else |
|
| 152 | - throw new TConfigurationException('pageserviceconf_file_invalid', $fname); |
|
| 150 | + if($dom->loadFromFile($fname)) { |
|
| 151 | + $this->loadFromXml($dom, dirname($fname), $configPagePath); |
|
| 152 | + } else { |
|
| 153 | + throw new TConfigurationException('pageserviceconf_file_invalid', $fname); |
|
| 154 | + } |
|
| 153 | 155 | } |
| 154 | 156 | } |
| 155 | 157 | |
@@ -202,27 +204,32 @@ discard block |
||
| 202 | 204 | { |
| 203 | 205 | $patterns = isset($authorization['pages'])?$authorization['pages']:''; |
| 204 | 206 | $ruleApplies = false; |
| 205 | - if(empty($patterns) || trim($patterns) === '*') // null or empty string |
|
| 207 | + if(empty($patterns) || trim($patterns) === '*') { |
|
| 208 | + // null or empty string |
|
| 206 | 209 | $ruleApplies = true; |
| 207 | - else |
|
| 210 | + } else |
|
| 208 | 211 | { |
| 209 | 212 | foreach(explode(',', $patterns) as $pattern) |
| 210 | 213 | { |
| 211 | 214 | if(($pattern = trim($pattern)) !== '') |
| 212 | 215 | { |
| 213 | 216 | // we know $configPagePath and $this->_pagePath |
| 214 | - if($configPagePath !== '') // prepend the pattern with ConfigPagePath |
|
| 217 | + if($configPagePath !== '') { |
|
| 218 | + // prepend the pattern with ConfigPagePath |
|
| 215 | 219 | $pattern = $configPagePath . '.' . $pattern; |
| 220 | + } |
|
| 216 | 221 | if(strcasecmp($pattern, $this->_pagePath) === 0) |
| 217 | 222 | { |
| 218 | 223 | $ruleApplies = true; |
| 219 | 224 | break; |
| 220 | 225 | } |
| 221 | - if($pattern[strlen($pattern) - 1] === '*') // try wildcard matching |
|
| 226 | + if($pattern[strlen($pattern) - 1] === '*') { |
|
| 227 | + // try wildcard matching |
|
| 222 | 228 | { |
| 223 | 229 | if(strncasecmp($this->_pagePath, $pattern, strlen($pattern) - 1) === 0) |
| 224 | 230 | { |
| 225 | 231 | $ruleApplies = true; |
| 232 | + } |
|
| 226 | 233 | break; |
| 227 | 234 | } |
| 228 | 235 | } |
@@ -259,12 +266,15 @@ discard block |
||
| 259 | 266 | } |
| 260 | 267 | $matching = false; |
| 261 | 268 | $id = ($configPagePath === '')?$id:$configPagePath . '.' . $id; |
| 262 | - if(strcasecmp($id, $this->_pagePath) === 0) |
|
| 263 | - $matching = true; |
|
| 264 | - elseif($id[strlen($id) - 1] === '*') // try wildcard matching |
|
| 269 | + if(strcasecmp($id, $this->_pagePath) === 0) { |
|
| 270 | + $matching = true; |
|
| 271 | + } elseif($id[strlen($id) - 1] === '*') { |
|
| 272 | + // try wildcard matching |
|
| 265 | 273 | $matching = strncasecmp($this->_pagePath, $id, strlen($id) - 1) === 0; |
| 266 | - if($matching) |
|
| 267 | - $this->_properties = array_merge($this->_properties, $properties); |
|
| 274 | + } |
|
| 275 | + if($matching) { |
|
| 276 | + $this->_properties = array_merge($this->_properties, $properties); |
|
| 277 | + } |
|
| 268 | 278 | } |
| 269 | 279 | } |
| 270 | 280 | |
@@ -274,13 +284,15 @@ discard block |
||
| 274 | 284 | foreach($config['includes'] as $include) |
| 275 | 285 | { |
| 276 | 286 | $when = isset($include['when'])?true:false; |
| 277 | - if(!isset($include['file'])) |
|
| 278 | - throw new TConfigurationException('pageserviceconf_includefile_required'); |
|
| 287 | + if(!isset($include['file'])) { |
|
| 288 | + throw new TConfigurationException('pageserviceconf_includefile_required'); |
|
| 289 | + } |
|
| 279 | 290 | $filePath = $include['file']; |
| 280 | - if(isset($this->_includes[$filePath])) |
|
| 281 | - $this->_includes[$filePath] = [$configPagePath,'(' . $this->_includes[$filePath][1] . ') || (' . $when . ')']; |
|
| 282 | - else |
|
| 283 | - $this->_includes[$filePath] = [$configPagePath,$when]; |
|
| 291 | + if(isset($this->_includes[$filePath])) { |
|
| 292 | + $this->_includes[$filePath] = [$configPagePath,'(' . $this->_includes[$filePath][1] . ') || (' . $when . ')']; |
|
| 293 | + } else { |
|
| 294 | + $this->_includes[$filePath] = [$configPagePath,$when]; |
|
| 295 | + } |
|
| 284 | 296 | } |
| 285 | 297 | } |
| 286 | 298 | } |
@@ -301,35 +313,41 @@ discard block |
||
| 301 | 313 | { |
| 302 | 314 | $patterns = $node->getAttribute('pages'); |
| 303 | 315 | $ruleApplies = false; |
| 304 | - if(empty($patterns) || trim($patterns) === '*') // null or empty string |
|
| 316 | + if(empty($patterns) || trim($patterns) === '*') { |
|
| 317 | + // null or empty string |
|
| 305 | 318 | $ruleApplies = true; |
| 306 | - else |
|
| 319 | + } else |
|
| 307 | 320 | { |
| 308 | 321 | foreach(explode(',', $patterns) as $pattern) |
| 309 | 322 | { |
| 310 | 323 | if(($pattern = trim($pattern)) !== '') |
| 311 | 324 | { |
| 312 | 325 | // we know $configPagePath and $this->_pagePath |
| 313 | - if($configPagePath !== '') // prepend the pattern with ConfigPagePath |
|
| 326 | + if($configPagePath !== '') { |
|
| 327 | + // prepend the pattern with ConfigPagePath |
|
| 314 | 328 | $pattern = $configPagePath . '.' . $pattern; |
| 329 | + } |
|
| 315 | 330 | if(strcasecmp($pattern, $this->_pagePath) === 0) |
| 316 | 331 | { |
| 317 | 332 | $ruleApplies = true; |
| 318 | 333 | break; |
| 319 | 334 | } |
| 320 | - if($pattern[strlen($pattern) - 1] === '*') // try wildcard matching |
|
| 335 | + if($pattern[strlen($pattern) - 1] === '*') { |
|
| 336 | + // try wildcard matching |
|
| 321 | 337 | { |
| 322 | 338 | if(strncasecmp($this->_pagePath, $pattern, strlen($pattern) - 1) === 0) |
| 323 | 339 | { |
| 324 | 340 | $ruleApplies = true; |
| 341 | + } |
|
| 325 | 342 | break; |
| 326 | 343 | } |
| 327 | 344 | } |
| 328 | 345 | } |
| 329 | 346 | } |
| 330 | 347 | } |
| 331 | - if($ruleApplies) |
|
| 332 | - $rules[] = new TAuthorizationRule($node->getTagName(), $node->getAttribute('users'), $node->getAttribute('roles'), $node->getAttribute('verb'), $node->getAttribute('ips')); |
|
| 348 | + if($ruleApplies) { |
|
| 349 | + $rules[] = new TAuthorizationRule($node->getTagName(), $node->getAttribute('users'), $node->getAttribute('roles'), $node->getAttribute('verb'), $node->getAttribute('ips')); |
|
| 350 | + } |
|
| 333 | 351 | } |
| 334 | 352 | $this->_rules = array_merge($rules, $this->_rules); |
| 335 | 353 | } |
@@ -343,30 +361,37 @@ discard block |
||
| 343 | 361 | { |
| 344 | 362 | $properties = $node->getAttributes(); |
| 345 | 363 | $id = $properties->remove('id'); |
| 346 | - if(empty($id)) |
|
| 347 | - throw new TConfigurationException('pageserviceconf_page_invalid', $configPath); |
|
| 364 | + if(empty($id)) { |
|
| 365 | + throw new TConfigurationException('pageserviceconf_page_invalid', $configPath); |
|
| 366 | + } |
|
| 348 | 367 | $matching = false; |
| 349 | 368 | $id = ($configPagePath === '')?$id:$configPagePath . '.' . $id; |
| 350 | - if(strcasecmp($id, $this->_pagePath) === 0) |
|
| 351 | - $matching = true; |
|
| 352 | - elseif($id[strlen($id) - 1] === '*') // try wildcard matching |
|
| 369 | + if(strcasecmp($id, $this->_pagePath) === 0) { |
|
| 370 | + $matching = true; |
|
| 371 | + } elseif($id[strlen($id) - 1] === '*') { |
|
| 372 | + // try wildcard matching |
|
| 353 | 373 | $matching = strncasecmp($this->_pagePath, $id, strlen($id) - 1) === 0; |
| 354 | - if($matching) |
|
| 355 | - $this->_properties = array_merge($this->_properties, $properties->toArray()); |
|
| 374 | + } |
|
| 375 | + if($matching) { |
|
| 376 | + $this->_properties = array_merge($this->_properties, $properties->toArray()); |
|
| 377 | + } |
|
| 356 | 378 | } |
| 357 | 379 | } |
| 358 | 380 | |
| 359 | 381 | // external configurations |
| 360 | 382 | foreach($dom->getElementsByTagName('include') as $node) |
| 361 | 383 | { |
| 362 | - if(($when = $node->getAttribute('when')) === null) |
|
| 363 | - $when = true; |
|
| 364 | - if(($filePath = $node->getAttribute('file')) === null) |
|
| 365 | - throw new TConfigurationException('pageserviceconf_includefile_required'); |
|
| 366 | - if(isset($this->_includes[$filePath])) |
|
| 367 | - $this->_includes[$filePath] = [$configPagePath,'(' . $this->_includes[$filePath][1] . ') || (' . $when . ')']; |
|
| 368 | - else |
|
| 369 | - $this->_includes[$filePath] = [$configPagePath,$when]; |
|
| 384 | + if(($when = $node->getAttribute('when')) === null) { |
|
| 385 | + $when = true; |
|
| 386 | + } |
|
| 387 | + if(($filePath = $node->getAttribute('file')) === null) { |
|
| 388 | + throw new TConfigurationException('pageserviceconf_includefile_required'); |
|
| 389 | + } |
|
| 390 | + if(isset($this->_includes[$filePath])) { |
|
| 391 | + $this->_includes[$filePath] = [$configPagePath,'(' . $this->_includes[$filePath][1] . ') || (' . $when . ')']; |
|
| 392 | + } else { |
|
| 393 | + $this->_includes[$filePath] = [$configPagePath,$when]; |
|
| 394 | + } |
|
| 370 | 395 | } |
| 371 | 396 | } |
| 372 | 397 | } |
| 373 | 398 | \ No newline at end of file |
@@ -174,8 +174,9 @@ discard block |
||
| 174 | 174 | protected function initPageContext($pageConfig) |
| 175 | 175 | { |
| 176 | 176 | $application = $this->getApplication(); |
| 177 | - foreach($pageConfig->getApplicationConfigurations() as $appConfig) |
|
| 178 | - $application->applyConfiguration($appConfig); |
|
| 177 | + foreach($pageConfig->getApplicationConfigurations() as $appConfig) { |
|
| 178 | + $application->applyConfiguration($appConfig); |
|
| 179 | + } |
|
| 179 | 180 | |
| 180 | 181 | $this->applyConfiguration($pageConfig); |
| 181 | 182 | } |
@@ -194,12 +195,14 @@ discard block |
||
| 194 | 195 | foreach($config->getExternalConfigurations() as $filePath => $params) |
| 195 | 196 | { |
| 196 | 197 | list($configPagePath, $condition) = $params; |
| 197 | - if($condition !== true) |
|
| 198 | - $condition = $this->evaluateExpression($condition); |
|
| 198 | + if($condition !== true) { |
|
| 199 | + $condition = $this->evaluateExpression($condition); |
|
| 200 | + } |
|
| 199 | 201 | if($condition) |
| 200 | 202 | { |
| 201 | - if(($path = Prado::getPathOfNamespace($filePath, Prado::getApplication()->getConfigurationFileExt())) === null || !is_file($path)) |
|
| 202 | - throw new TConfigurationException('pageservice_includefile_invalid', $filePath); |
|
| 203 | + if(($path = Prado::getPathOfNamespace($filePath, Prado::getApplication()->getConfigurationFileExt())) === null || !is_file($path)) { |
|
| 204 | + throw new TConfigurationException('pageservice_includefile_invalid', $filePath); |
|
| 205 | + } |
|
| 203 | 206 | $c = new TPageConfiguration($pagePath); |
| 204 | 207 | $c->loadFromFile($path, $configPagePath); |
| 205 | 208 | $this->applyConfiguration($c); |
@@ -215,8 +218,9 @@ discard block |
||
| 215 | 218 | protected function determineRequestedPagePath() |
| 216 | 219 | { |
| 217 | 220 | $pagePath = $this->getRequest()->getServiceParameter(); |
| 218 | - if(empty($pagePath)) |
|
| 219 | - $pagePath = $this->getDefaultPage(); |
|
| 221 | + if(empty($pagePath)) { |
|
| 222 | + $pagePath = $this->getDefaultPage(); |
|
| 223 | + } |
|
| 220 | 224 | return $pagePath; |
| 221 | 225 | } |
| 222 | 226 | |
@@ -234,14 +238,14 @@ discard block |
||
| 234 | 238 | $pageConfig = new TPageConfiguration($pagePath); |
| 235 | 239 | if($config !== null) |
| 236 | 240 | { |
| 237 | - if($application->getConfigurationType() == TApplication::CONFIG_TYPE_PHP) |
|
| 238 | - $pageConfig->loadPageConfigurationFromPhp($config, $application->getBasePath(), ''); |
|
| 239 | - else |
|
| 240 | - $pageConfig->loadPageConfigurationFromXml($config, $application->getBasePath(), ''); |
|
| 241 | + if($application->getConfigurationType() == TApplication::CONFIG_TYPE_PHP) { |
|
| 242 | + $pageConfig->loadPageConfigurationFromPhp($config, $application->getBasePath(), ''); |
|
| 243 | + } else { |
|
| 244 | + $pageConfig->loadPageConfigurationFromXml($config, $application->getBasePath(), ''); |
|
| 245 | + } |
|
| 241 | 246 | } |
| 242 | 247 | $pageConfig->loadFromFiles($this->getBasePath()); |
| 243 | - } |
|
| 244 | - else |
|
| 248 | + } else |
|
| 245 | 249 | { |
| 246 | 250 | $configCached = true; |
| 247 | 251 | $currentTimestamp = []; |
@@ -253,23 +257,25 @@ discard block |
||
| 253 | 257 | { |
| 254 | 258 | foreach($timestamps as $fileName => $timestamp) |
| 255 | 259 | { |
| 256 | - if($fileName === 0) // application config file |
|
| 260 | + if($fileName === 0) { |
|
| 261 | + // application config file |
|
| 257 | 262 | { |
| 258 | 263 | $appConfigFile = $application->getConfigurationFile(); |
| 259 | - $currentTimestamp[0] = $appConfigFile === null?0:@filemtime($appConfigFile); |
|
| 260 | - if($currentTimestamp[0] > $timestamp || ($timestamp > 0 && !$currentTimestamp[0])) |
|
| 261 | - $configCached = false; |
|
| 262 | 264 | } |
| 263 | - else |
|
| 265 | + $currentTimestamp[0] = $appConfigFile === null?0:@filemtime($appConfigFile); |
|
| 266 | + if($currentTimestamp[0] > $timestamp || ($timestamp > 0 && !$currentTimestamp[0])) { |
|
| 267 | + $configCached = false; |
|
| 268 | + } |
|
| 269 | + } else |
|
| 264 | 270 | { |
| 265 | 271 | $currentTimestamp[$fileName] = @filemtime($fileName); |
| 266 | - if($currentTimestamp[$fileName] > $timestamp || ($timestamp > 0 && !$currentTimestamp[$fileName])) |
|
| 267 | - $configCached = false; |
|
| 272 | + if($currentTimestamp[$fileName] > $timestamp || ($timestamp > 0 && !$currentTimestamp[$fileName])) { |
|
| 273 | + $configCached = false; |
|
| 274 | + } |
|
| 268 | 275 | } |
| 269 | 276 | } |
| 270 | 277 | } |
| 271 | - } |
|
| 272 | - else |
|
| 278 | + } else |
|
| 273 | 279 | { |
| 274 | 280 | $configCached = false; |
| 275 | 281 | $paths = explode('.', $pagePath); |
@@ -291,10 +297,11 @@ discard block |
||
| 291 | 297 | $pageConfig = new TPageConfiguration($pagePath); |
| 292 | 298 | if($config !== null) |
| 293 | 299 | { |
| 294 | - if($application->getConfigurationType() == TApplication::CONFIG_TYPE_PHP) |
|
| 295 | - $pageConfig->loadPageConfigurationFromPhp($config, $application->getBasePath(), ''); |
|
| 296 | - else |
|
| 297 | - $pageConfig->loadPageConfigurationFromXml($config, $application->getBasePath(), ''); |
|
| 300 | + if($application->getConfigurationType() == TApplication::CONFIG_TYPE_PHP) { |
|
| 301 | + $pageConfig->loadPageConfigurationFromPhp($config, $application->getBasePath(), ''); |
|
| 302 | + } else { |
|
| 303 | + $pageConfig->loadPageConfigurationFromXml($config, $application->getBasePath(), ''); |
|
| 304 | + } |
|
| 298 | 305 | } |
| 299 | 306 | $pageConfig->loadFromFiles($this->getBasePath()); |
| 300 | 307 | $cache->set(self::CONFIG_CACHE_PREFIX . $this->getID() . $pagePath, [$pageConfig,$currentTimestamp]); |
@@ -353,8 +360,9 @@ discard block |
||
| 353 | 360 | if($this->_pagePath === null) |
| 354 | 361 | { |
| 355 | 362 | $this->_pagePath = strtr($this->determineRequestedPagePath(), '/\\', '..'); |
| 356 | - if(empty($this->_pagePath)) |
|
| 357 | - throw new THttpException(404, 'pageservice_page_required'); |
|
| 363 | + if(empty($this->_pagePath)) { |
|
| 364 | + throw new THttpException(404, 'pageservice_page_required'); |
|
| 365 | + } |
|
| 358 | 366 | } |
| 359 | 367 | return $this->_pagePath; |
| 360 | 368 | } |
@@ -381,10 +389,11 @@ discard block |
||
| 381 | 389 | */ |
| 382 | 390 | public function setDefaultPage($value) |
| 383 | 391 | { |
| 384 | - if($this->_initialized) |
|
| 385 | - throw new TInvalidOperationException('pageservice_defaultpage_unchangeable'); |
|
| 386 | - else |
|
| 387 | - $this->_defaultPage = $value; |
|
| 392 | + if($this->_initialized) { |
|
| 393 | + throw new TInvalidOperationException('pageservice_defaultpage_unchangeable'); |
|
| 394 | + } else { |
|
| 395 | + $this->_defaultPage = $value; |
|
| 396 | + } |
|
| 388 | 397 | } |
| 389 | 398 | |
| 390 | 399 | /** |
@@ -406,8 +415,9 @@ discard block |
||
| 406 | 415 | if(($this->_basePath = realpath($basePath)) === false || !is_dir($this->_basePath)) |
| 407 | 416 | { |
| 408 | 417 | $basePath = $this->getApplication()->getBasePath() . DIRECTORY_SEPARATOR . self::FALLBACK_BASEPATH; |
| 409 | - if(($this->_basePath = realpath($basePath)) === false || !is_dir($this->_basePath)) |
|
| 410 | - throw new TConfigurationException('pageservice_basepath_invalid', $basePath); |
|
| 418 | + if(($this->_basePath = realpath($basePath)) === false || !is_dir($this->_basePath)) { |
|
| 419 | + throw new TConfigurationException('pageservice_basepath_invalid', $basePath); |
|
| 420 | + } |
|
| 411 | 421 | } |
| 412 | 422 | } |
| 413 | 423 | return $this->_basePath; |
@@ -419,10 +429,11 @@ discard block |
||
| 419 | 429 | */ |
| 420 | 430 | public function setBasePath($value) |
| 421 | 431 | { |
| 422 | - if($this->_initialized) |
|
| 423 | - throw new TInvalidOperationException('pageservice_basepath_unchangeable'); |
|
| 424 | - elseif(($path = Prado::getPathOfNamespace($value)) === null || !is_dir($path)) |
|
| 425 | - throw new TConfigurationException('pageservice_basepath_invalid', $value); |
|
| 432 | + if($this->_initialized) { |
|
| 433 | + throw new TInvalidOperationException('pageservice_basepath_unchangeable'); |
|
| 434 | + } elseif(($path = Prado::getPathOfNamespace($value)) === null || !is_dir($path)) { |
|
| 435 | + throw new TConfigurationException('pageservice_basepath_invalid', $value); |
|
| 436 | + } |
|
| 426 | 437 | $this->_basePath = realpath($path); |
| 427 | 438 | } |
| 428 | 439 | |
@@ -489,36 +500,41 @@ discard block |
||
| 489 | 500 | $hasTemplateFile = is_file($path . self::PAGE_FILE_EXT); |
| 490 | 501 | $hasClassFile = is_file($path . Prado::CLASS_FILE_EXT); |
| 491 | 502 | |
| 492 | - if(!$hasTemplateFile && !$hasClassFile) |
|
| 493 | - throw new THttpException(404, 'pageservice_page_unknown', $pagePath); |
|
| 503 | + if(!$hasTemplateFile && !$hasClassFile) { |
|
| 504 | + throw new THttpException(404, 'pageservice_page_unknown', $pagePath); |
|
| 505 | + } |
|
| 494 | 506 | |
| 495 | 507 | if($hasClassFile) |
| 496 | 508 | { |
| 497 | 509 | $className = basename($path); |
| 498 | 510 | $namespacedClassName = static::PAGE_NAMESPACE_PREFIX . str_replace('.', '\\', $pagePath); |
| 499 | 511 | |
| 500 | - if(!class_exists($className, false) && !class_exists($namespacedClassName, false)) |
|
| 501 | - include_once($path . Prado::CLASS_FILE_EXT); |
|
| 512 | + if(!class_exists($className, false) && !class_exists($namespacedClassName, false)) { |
|
| 513 | + include_once($path . Prado::CLASS_FILE_EXT); |
|
| 514 | + } |
|
| 502 | 515 | |
| 503 | - if(!class_exists($className, false)) |
|
| 504 | - $className = $namespacedClassName; |
|
| 505 | - } |
|
| 506 | - else |
|
| 516 | + if(!class_exists($className, false)) { |
|
| 517 | + $className = $namespacedClassName; |
|
| 518 | + } |
|
| 519 | + } else |
|
| 507 | 520 | { |
| 508 | 521 | $className = $this->getBasePageClass(); |
| 509 | 522 | Prado::using($className); |
| 510 | - if(($pos = strrpos($className, '.')) !== false) |
|
| 511 | - $className = substr($className, $pos + 1); |
|
| 523 | + if(($pos = strrpos($className, '.')) !== false) { |
|
| 524 | + $className = substr($className, $pos + 1); |
|
| 525 | + } |
|
| 512 | 526 | } |
| 513 | 527 | |
| 514 | - if($className !== '\Prado\Web\UI\TPage' && !is_subclass_of($className, '\Prado\Web\UI\TPage')) |
|
| 515 | - throw new THttpException(404, 'pageservice_page_unknown', $pagePath); |
|
| 528 | + if($className !== '\Prado\Web\UI\TPage' && !is_subclass_of($className, '\Prado\Web\UI\TPage')) { |
|
| 529 | + throw new THttpException(404, 'pageservice_page_unknown', $pagePath); |
|
| 530 | + } |
|
| 516 | 531 | |
| 517 | 532 | $page = Prado::createComponent($className); |
| 518 | 533 | $page->setPagePath($pagePath); |
| 519 | 534 | |
| 520 | - if($hasTemplateFile) |
|
| 521 | - $page->setTemplate($this->getTemplateManager()->getTemplateByFileName($path . self::PAGE_FILE_EXT)); |
|
| 535 | + if($hasTemplateFile) { |
|
| 536 | + $page->setTemplate($this->getTemplateManager()->getTemplateByFileName($path . self::PAGE_FILE_EXT)); |
|
| 537 | + } |
|
| 522 | 538 | |
| 523 | 539 | return $page; |
| 524 | 540 | } |
@@ -530,8 +546,9 @@ discard block |
||
| 530 | 546 | */ |
| 531 | 547 | protected function runPage($page, $properties) |
| 532 | 548 | { |
| 533 | - foreach($properties as $name => $value) |
|
| 534 | - $page->setSubProperty($name, $value); |
|
| 549 | + foreach($properties as $name => $value) { |
|
| 550 | + $page->setSubProperty($name, $value); |
|
| 551 | + } |
|
| 535 | 552 | $page->run($this->getResponse()->createHtmlWriter()); |
| 536 | 553 | } |
| 537 | 554 | |
@@ -43,23 +43,28 @@ discard block |
||
| 43 | 43 | if(isset($_request['jsonrpc'])) |
| 44 | 44 | { |
| 45 | 45 | $this->_specificationVersion = $_request['jsonrpc']; |
| 46 | - if($this->_specificationVersion > 2.0) |
|
| 47 | - throw new TRpcException('Unsupported specification version', '-32600'); |
|
| 46 | + if($this->_specificationVersion > 2.0) { |
|
| 47 | + throw new TRpcException('Unsupported specification version', '-32600'); |
|
| 48 | + } |
|
| 48 | 49 | } |
| 49 | 50 | |
| 50 | - if(isset($_request['id'])) |
|
| 51 | - $this->_id = $_request['id']; |
|
| 51 | + if(isset($_request['id'])) { |
|
| 52 | + $this->_id = $_request['id']; |
|
| 53 | + } |
|
| 52 | 54 | |
| 53 | - if(!isset($_request['method'])) |
|
| 54 | - throw new TRpcException('Missing request method', '-32600'); |
|
| 55 | + if(!isset($_request['method'])) { |
|
| 56 | + throw new TRpcException('Missing request method', '-32600'); |
|
| 57 | + } |
|
| 55 | 58 | |
| 56 | - if(!isset($_request['params'])) |
|
| 57 | - $parameters = []; |
|
| 58 | - else |
|
| 59 | - $parameters = $_request['params']; |
|
| 59 | + if(!isset($_request['params'])) { |
|
| 60 | + $parameters = []; |
|
| 61 | + } else { |
|
| 62 | + $parameters = $_request['params']; |
|
| 63 | + } |
|
| 60 | 64 | |
| 61 | - if(!is_array($parameters)) |
|
| 62 | - $parameters = [$parameters]; |
|
| 65 | + if(!is_array($parameters)) { |
|
| 66 | + $parameters = [$parameters]; |
|
| 67 | + } |
|
| 63 | 68 | |
| 64 | 69 | // a request without an id is a notification that doesn't need a response |
| 65 | 70 | if($this->_id !== null) |
@@ -79,16 +84,13 @@ discard block |
||
| 79 | 84 | ]); |
| 80 | 85 | } |
| 81 | 86 | } |
| 82 | - } |
|
| 83 | - catch(TRpcException $e) |
|
| 87 | + } catch(TRpcException $e) |
|
| 84 | 88 | { |
| 85 | 89 | return $this->createErrorResponse($e); |
| 86 | - } |
|
| 87 | - catch(THttpException $e) |
|
| 90 | + } catch(THttpException $e) |
|
| 88 | 91 | { |
| 89 | 92 | throw $e; |
| 90 | - } |
|
| 91 | - catch(\Exception $e) |
|
| 93 | + } catch(\Exception $e) |
|
| 92 | 94 | { |
| 93 | 95 | return $this->createErrorResponse(new TRpcException('An internal error occured', '-32603')); |
| 94 | 96 | } |
@@ -161,8 +163,9 @@ discard block |
||
| 161 | 163 | private static function checkJsonError() |
| 162 | 164 | { |
| 163 | 165 | $errnum = json_last_error(); |
| 164 | - if($errnum != JSON_ERROR_NONE) |
|
| 165 | - throw new \Exception("JSON error: $msg", $err); |
|
| 166 | + if($errnum != JSON_ERROR_NONE) { |
|
| 167 | + throw new \Exception("JSON error: $msg", $err); |
|
| 168 | + } |
|
| 166 | 169 | } |
| 167 | 170 | |
| 168 | 171 | /** |
@@ -174,8 +177,9 @@ discard block |
||
| 174 | 177 | */ |
| 175 | 178 | public function callApiMethod($methodName, $parameters) |
| 176 | 179 | { |
| 177 | - if(!isset($this->rpcMethods[$methodName])) |
|
| 178 | - throw new TRpcException('Method "' . $methodName . '" not found', '-32601'); |
|
| 180 | + if(!isset($this->rpcMethods[$methodName])) { |
|
| 181 | + throw new TRpcException('Method "' . $methodName . '" not found', '-32601'); |
|
| 182 | + } |
|
| 179 | 183 | |
| 180 | 184 | return call_user_func_array($this->rpcMethods[$methodName]['method'], $parameters); |
| 181 | 185 | } |
@@ -94,29 +94,34 @@ discard block |
||
| 94 | 94 | { |
| 95 | 95 | $_properties = $this->apiProviders[$providerId]; |
| 96 | 96 | |
| 97 | - if(($_providerClass = $_properties->remove('class')) === null) |
|
| 98 | - throw new TConfigurationException('rpcservice_apiprovider_required'); |
|
| 97 | + if(($_providerClass = $_properties->remove('class')) === null) { |
|
| 98 | + throw new TConfigurationException('rpcservice_apiprovider_required'); |
|
| 99 | + } |
|
| 99 | 100 | |
| 100 | 101 | Prado::using($_providerClass); |
| 101 | 102 | |
| 102 | 103 | $_providerClassName = ($_pos = strrpos($_providerClass, '.')) !== false ? substr($_providerClass, $_pos + 1) : $_providerClass; |
| 103 | - if(!is_subclass_of($_providerClassName, self::BASE_API_PROVIDER)) |
|
| 104 | - throw new TConfigurationException('rpcservice_apiprovider_invalid'); |
|
| 104 | + if(!is_subclass_of($_providerClassName, self::BASE_API_PROVIDER)) { |
|
| 105 | + throw new TConfigurationException('rpcservice_apiprovider_invalid'); |
|
| 106 | + } |
|
| 105 | 107 | |
| 106 | - if(($_rpcServerClass = $_properties->remove('server')) === null) |
|
| 107 | - $_rpcServerClass = self::BASE_RPC_SERVER; |
|
| 108 | + if(($_rpcServerClass = $_properties->remove('server')) === null) { |
|
| 109 | + $_rpcServerClass = self::BASE_RPC_SERVER; |
|
| 110 | + } |
|
| 108 | 111 | |
| 109 | 112 | Prado::using($_rpcServerClass); |
| 110 | 113 | |
| 111 | 114 | $_rpcServerClassName = ($_pos = strrpos($_rpcServerClass, '.')) !== false ? substr($_rpcServerClass, $_pos + 1) : $_rpcServerClass; |
| 112 | - if($_rpcServerClassName !== self::BASE_RPC_SERVER && !is_subclass_of($_rpcServerClassName, self::BASE_RPC_SERVER)) |
|
| 113 | - throw new TConfigurationException('rpcservice_rpcserver_invalid'); |
|
| 115 | + if($_rpcServerClassName !== self::BASE_RPC_SERVER && !is_subclass_of($_rpcServerClassName, self::BASE_RPC_SERVER)) { |
|
| 116 | + throw new TConfigurationException('rpcservice_rpcserver_invalid'); |
|
| 117 | + } |
|
| 114 | 118 | |
| 115 | 119 | $_apiProvider = new $_providerClassName(new $_rpcServerClassName($protocolHandler)); |
| 116 | 120 | $_apiProvider->setId($providerId); |
| 117 | 121 | |
| 118 | - foreach($_properties as $_key => $_value) |
|
| 119 | - $_apiProvider->setSubProperty($_key, $_value); |
|
| 122 | + foreach($_properties as $_key => $_value) { |
|
| 123 | + $_apiProvider->setSubProperty($_key, $_value); |
|
| 124 | + } |
|
| 120 | 125 | |
| 121 | 126 | return $_apiProvider; |
| 122 | 127 | } |
@@ -140,11 +145,13 @@ discard block |
||
| 140 | 145 | { |
| 141 | 146 | $_properties = $_apiProviderXml->getAttributes(); |
| 142 | 147 | |
| 143 | - if(($_id = $_properties->remove('id')) === null || $_id == "") |
|
| 144 | - throw new TConfigurationException('rpcservice_apiproviderid_required'); |
|
| 148 | + if(($_id = $_properties->remove('id')) === null || $_id == "") { |
|
| 149 | + throw new TConfigurationException('rpcservice_apiproviderid_required'); |
|
| 150 | + } |
|
| 145 | 151 | |
| 146 | - if(isset($this->apiProviders[$_id])) |
|
| 147 | - throw new TConfigurationException('rpcservice_apiproviderid_duplicated'); |
|
| 152 | + if(isset($this->apiProviders[$_id])) { |
|
| 153 | + throw new TConfigurationException('rpcservice_apiproviderid_duplicated'); |
|
| 154 | + } |
|
| 148 | 155 | |
| 149 | 156 | $this->apiProviders[$_id] = $_properties; |
| 150 | 157 | } |
@@ -157,17 +164,24 @@ discard block |
||
| 157 | 164 | { |
| 158 | 165 | $_request = $this->getRequest(); |
| 159 | 166 | |
| 160 | - if(($_providerId = $_request->getServiceParameter()) == "") |
|
| 161 | - throw new THttpException(400, 'RPC API-Provider id required'); |
|
| 167 | + if(($_providerId = $_request->getServiceParameter()) == "") { |
|
| 168 | + throw new THttpException(400, 'RPC API-Provider id required'); |
|
| 169 | + } |
|
| 162 | 170 | |
| 163 | - if(($_method = $_request->getRequestType()) != 'POST') |
|
| 164 | - throw new THttpException(405, 'Invalid request method "' . $_method . '"!'); // TODO Exception muss "Allow POST" Header setzen |
|
| 171 | + if(($_method = $_request->getRequestType()) != 'POST') { |
|
| 172 | + throw new THttpException(405, 'Invalid request method "' . $_method . '"!'); |
|
| 173 | + } |
|
| 174 | + // TODO Exception muss "Allow POST" Header setzen |
|
| 165 | 175 | |
| 166 | - if(($_mimeType = $_request->getContentType()) === null) |
|
| 167 | - throw new THttpException(406, 'Content-Type is missing!'); // TODO Exception muss gültige Content-Type werte zurück geben |
|
| 176 | + if(($_mimeType = $_request->getContentType()) === null) { |
|
| 177 | + throw new THttpException(406, 'Content-Type is missing!'); |
|
| 178 | + } |
|
| 179 | + // TODO Exception muss gültige Content-Type werte zurück geben |
|
| 168 | 180 | |
| 169 | - if(!in_array($_mimeType, array_keys($this->protocolHandlers))) |
|
| 170 | - throw new THttpException(406, 'Unsupported Content-Type!'); // TODO see previous |
|
| 181 | + if(!in_array($_mimeType, array_keys($this->protocolHandlers))) { |
|
| 182 | + throw new THttpException(406, 'Unsupported Content-Type!'); |
|
| 183 | + } |
|
| 184 | + // TODO see previous |
|
| 171 | 185 | |
| 172 | 186 | $_protocolHandlerClass = $this->protocolHandlers[$_mimeType]; |
| 173 | 187 | $_protocolHandler = new $_protocolHandlerClass; |
@@ -84,18 +84,19 @@ discard block |
||
| 84 | 84 | { |
| 85 | 85 | if(is_array($config)) |
| 86 | 86 | { |
| 87 | - foreach($config['json'] as $id => $json) |
|
| 88 | - $this->_services[$id] = $json; |
|
| 87 | + foreach($config['json'] as $id => $json) { |
|
| 88 | + $this->_services[$id] = $json; |
|
| 89 | + } |
|
| 89 | 90 | } |
| 90 | - } |
|
| 91 | - else |
|
| 91 | + } else |
|
| 92 | 92 | { |
| 93 | 93 | foreach($config->getElementsByTagName('json') as $json) |
| 94 | 94 | { |
| 95 | - if(($id = $json->getAttribute('id')) !== null) |
|
| 96 | - $this->_services[$id] = $json; |
|
| 97 | - else |
|
| 98 | - throw new TConfigurationException('jsonservice_id_required'); |
|
| 95 | + if(($id = $json->getAttribute('id')) !== null) { |
|
| 96 | + $this->_services[$id] = $json; |
|
| 97 | + } else { |
|
| 98 | + throw new TConfigurationException('jsonservice_id_required'); |
|
| 99 | + } |
|
| 99 | 100 | } |
| 100 | 101 | } |
| 101 | 102 | } |
@@ -119,30 +120,30 @@ discard block |
||
| 119 | 120 | { |
| 120 | 121 | $properties = isset($serviceConfig['properties'])?$serviceConfig['properties']:[]; |
| 121 | 122 | $this->createJsonResponse($service, $properties, $serviceConfig); |
| 123 | + } else { |
|
| 124 | + throw new TConfigurationException('jsonservice_response_type_invalid', $id); |
|
| 122 | 125 | } |
| 123 | - else |
|
| 124 | - throw new TConfigurationException('jsonservice_response_type_invalid', $id); |
|
| 126 | + } else { |
|
| 127 | + throw new TConfigurationException('jsonservice_class_required', $id); |
|
| 125 | 128 | } |
| 126 | - else |
|
| 127 | - throw new TConfigurationException('jsonservice_class_required', $id); |
|
| 128 | - } |
|
| 129 | - else |
|
| 129 | + } else |
|
| 130 | 130 | { |
| 131 | 131 | $properties = $serviceConfig->getAttributes(); |
| 132 | 132 | if(($class = $properties->remove('class')) !== null) |
| 133 | 133 | { |
| 134 | 134 | $service = Prado::createComponent($class); |
| 135 | - if($service instanceof TJsonResponse) |
|
| 136 | - $this->createJsonResponse($service, $properties, $serviceConfig); |
|
| 137 | - else |
|
| 138 | - throw new TConfigurationException('jsonservice_response_type_invalid', $id); |
|
| 135 | + if($service instanceof TJsonResponse) { |
|
| 136 | + $this->createJsonResponse($service, $properties, $serviceConfig); |
|
| 137 | + } else { |
|
| 138 | + throw new TConfigurationException('jsonservice_response_type_invalid', $id); |
|
| 139 | + } |
|
| 140 | + } else { |
|
| 141 | + throw new TConfigurationException('jsonservice_class_required', $id); |
|
| 139 | 142 | } |
| 140 | - else |
|
| 141 | - throw new TConfigurationException('jsonservice_class_required', $id); |
|
| 142 | 143 | } |
| 144 | + } else { |
|
| 145 | + throw new THttpException(404, 'jsonservice_provider_unknown', $id); |
|
| 143 | 146 | } |
| 144 | - else |
|
| 145 | - throw new THttpException(404, 'jsonservice_provider_unknown', $id); |
|
| 146 | 147 | } |
| 147 | 148 | |
| 148 | 149 | /** |
@@ -152,8 +153,9 @@ discard block |
||
| 152 | 153 | protected function createJsonResponse($service, $properties, $config) |
| 153 | 154 | { |
| 154 | 155 | // init service properties |
| 155 | - foreach($properties as $name => $value) |
|
| 156 | - $service->setSubproperty($name, $value); |
|
| 156 | + foreach($properties as $name => $value) { |
|
| 157 | + $service->setSubproperty($name, $value); |
|
| 158 | + } |
|
| 157 | 159 | $service->init($config); |
| 158 | 160 | |
| 159 | 161 | //send content if not null |
@@ -62,8 +62,9 @@ discard block |
||
| 62 | 62 | */ |
| 63 | 63 | public function setID($id) |
| 64 | 64 | { |
| 65 | - if(strrpos($this->_id, '.wsdl') === strlen($this->_id) - 5) |
|
| 66 | - throw new TInvalidDataValueException('soapserver_id_invalid', $id); |
|
| 65 | + if(strrpos($this->_id, '.wsdl') === strlen($this->_id) - 5) { |
|
| 66 | + throw new TInvalidDataValueException('soapserver_id_invalid', $id); |
|
| 67 | + } |
|
| 67 | 68 | $this->_id = $id; |
| 68 | 69 | } |
| 69 | 70 | |
@@ -79,21 +80,22 @@ discard block |
||
| 79 | 80 | $this->guessMethodCallRequested($providerClass); |
| 80 | 81 | $server = $this->createServer(); |
| 81 | 82 | $server->setClass($providerClass, $this); |
| 82 | - if($this->_persistent) |
|
| 83 | - $server->setPersistence(SOAP_PERSISTENCE_SESSION); |
|
| 83 | + if($this->_persistent) { |
|
| 84 | + $server->setPersistence(SOAP_PERSISTENCE_SESSION); |
|
| 85 | + } |
|
| 86 | + } else { |
|
| 87 | + $server = $this->createServer(); |
|
| 84 | 88 | } |
| 85 | - else |
|
| 86 | - $server = $this->createServer(); |
|
| 87 | 89 | try |
| 88 | 90 | { |
| 89 | 91 | $server->handle(); |
| 90 | - } |
|
| 91 | - catch (\Exception $e) |
|
| 92 | + } catch (\Exception $e) |
|
| 92 | 93 | { |
| 93 | - if($this->getApplication()->getMode() === TApplicationMode::Debug) |
|
| 94 | - $this->fault($e->getMessage(), $e->__toString()); |
|
| 95 | - else |
|
| 96 | - $this->fault($e->getMessage()); |
|
| 94 | + if($this->getApplication()->getMode() === TApplicationMode::Debug) { |
|
| 95 | + $this->fault($e->getMessage(), $e->__toString()); |
|
| 96 | + } else { |
|
| 97 | + $this->fault($e->getMessage()); |
|
| 98 | + } |
|
| 97 | 99 | } |
| 98 | 100 | } |
| 99 | 101 | |
@@ -147,8 +149,9 @@ discard block |
||
| 147 | 149 | { |
| 148 | 150 | if($this->_server === null) |
| 149 | 151 | { |
| 150 | - if($this->getApplication()->getMode() === TApplicationMode::Debug) |
|
| 151 | - ini_set("soap.wsdl_cache_enabled", 0); |
|
| 152 | + if($this->getApplication()->getMode() === TApplicationMode::Debug) { |
|
| 153 | + ini_set("soap.wsdl_cache_enabled", 0); |
|
| 154 | + } |
|
| 152 | 155 | $this->_server = new \SoapServer($this->getWsdlUri(), $this->getOptions()); |
| 153 | 156 | } |
| 154 | 157 | return $this->_server; |
@@ -160,20 +163,26 @@ discard block |
||
| 160 | 163 | protected function getOptions() |
| 161 | 164 | { |
| 162 | 165 | $options = []; |
| 163 | - if($this->_version === '1.1') |
|
| 164 | - $options['soap_version'] = SOAP_1_1; |
|
| 165 | - elseif($this->_version === '1.2') |
|
| 166 | - $options['soap_version'] = SOAP_1_2; |
|
| 167 | - if(!empty($this->_actor)) |
|
| 168 | - $options['actor'] = $this->_actor; |
|
| 169 | - if(!empty($this->_encoding)) |
|
| 170 | - $options['encoding'] = $this->_encoding; |
|
| 171 | - if(!empty($this->_uri)) |
|
| 172 | - $options['uri'] = $this->_uri; |
|
| 166 | + if($this->_version === '1.1') { |
|
| 167 | + $options['soap_version'] = SOAP_1_1; |
|
| 168 | + } elseif($this->_version === '1.2') { |
|
| 169 | + $options['soap_version'] = SOAP_1_2; |
|
| 170 | + } |
|
| 171 | + if(!empty($this->_actor)) { |
|
| 172 | + $options['actor'] = $this->_actor; |
|
| 173 | + } |
|
| 174 | + if(!empty($this->_encoding)) { |
|
| 175 | + $options['encoding'] = $this->_encoding; |
|
| 176 | + } |
|
| 177 | + if(!empty($this->_uri)) { |
|
| 178 | + $options['uri'] = $this->_uri; |
|
| 179 | + } |
|
| 173 | 180 | if(is_string($this->_classMap)) |
| 174 | 181 | { |
| 175 | - foreach(preg_split('/\s*,\s*/', $this->_classMap) as $className) |
|
| 176 | - $options['classmap'][$className] = $className; //complex type uses the class name in the wsdl |
|
| 182 | + foreach(preg_split('/\s*,\s*/', $this->_classMap) as $className) { |
|
| 183 | + $options['classmap'][$className] = $className; |
|
| 184 | + } |
|
| 185 | + //complex type uses the class name in the wsdl |
|
| 177 | 186 | } |
| 178 | 187 | return $options; |
| 179 | 188 | } |
@@ -195,19 +204,19 @@ discard block |
||
| 195 | 204 | if($this->getApplication()->getMode() === TApplicationMode::Performance && ($cache = $this->getApplication()->getCache()) !== null) |
| 196 | 205 | { |
| 197 | 206 | $wsdl = $cache->get(self::WSDL_CACHE_PREFIX . $providerClass); |
| 198 | - if(is_string($wsdl)) |
|
| 199 | - return $wsdl; |
|
| 207 | + if(is_string($wsdl)) { |
|
| 208 | + return $wsdl; |
|
| 209 | + } |
|
| 200 | 210 | $wsdl = WsdlGenerator::generate($providerClass, $this->getUri(), $this->getEncoding()); |
| 201 | 211 | $cache->set(self::WSDL_CACHE_PREFIX . $providerClass, $wsdl); |
| 202 | 212 | return $wsdl; |
| 203 | - } |
|
| 204 | - else |
|
| 213 | + } else |
|
| 205 | 214 | { |
| 206 | 215 | return WsdlGenerator::generate($providerClass, $this->getUri(), $this->getEncoding()); |
| 207 | 216 | } |
| 217 | + } else { |
|
| 218 | + return file_get_contents($this->_wsdlUri); |
|
| 208 | 219 | } |
| 209 | - else |
|
| 210 | - return file_get_contents($this->_wsdlUri); |
|
| 211 | 220 | } |
| 212 | 221 | |
| 213 | 222 | /** |
@@ -215,10 +224,11 @@ discard block |
||
| 215 | 224 | */ |
| 216 | 225 | public function getWsdlUri() |
| 217 | 226 | { |
| 218 | - if($this->_wsdlUri === '') |
|
| 219 | - return $this->getRequest()->getBaseUrl() . $this->getService()->constructUrl($this->getID() . '.wsdl', false); |
|
| 220 | - else |
|
| 221 | - return $this->_wsdlUri; |
|
| 227 | + if($this->_wsdlUri === '') { |
|
| 228 | + return $this->getRequest()->getBaseUrl() . $this->getService()->constructUrl($this->getID() . '.wsdl', false); |
|
| 229 | + } else { |
|
| 230 | + return $this->_wsdlUri; |
|
| 231 | + } |
|
| 222 | 232 | } |
| 223 | 233 | |
| 224 | 234 | /** |
@@ -234,10 +244,11 @@ discard block |
||
| 234 | 244 | */ |
| 235 | 245 | public function getUri() |
| 236 | 246 | { |
| 237 | - if($this->_uri === '') |
|
| 238 | - return $this->getRequest()->getBaseUrl() . $this->getService()->constructUrl($this->getID(), false); |
|
| 239 | - else |
|
| 240 | - return $this->_uri; |
|
| 247 | + if($this->_uri === '') { |
|
| 248 | + return $this->getRequest()->getBaseUrl() . $this->getService()->constructUrl($this->getID(), false); |
|
| 249 | + } else { |
|
| 250 | + return $this->_uri; |
|
| 251 | + } |
|
| 241 | 252 | } |
| 242 | 253 | |
| 243 | 254 | /** |
@@ -278,10 +289,11 @@ discard block |
||
| 278 | 289 | */ |
| 279 | 290 | public function setVersion($value) |
| 280 | 291 | { |
| 281 | - if($value === '1.1' || $value === '1.2' || $value === '') |
|
| 282 | - $this->_version = $value; |
|
| 283 | - else |
|
| 284 | - throw new TInvalidDataValueException('soapserver_version_invalid', $value); |
|
| 292 | + if($value === '1.1' || $value === '1.2' || $value === '') { |
|
| 293 | + $this->_version = $value; |
|
| 294 | + } else { |
|
| 295 | + throw new TInvalidDataValueException('soapserver_version_invalid', $value); |
|
| 296 | + } |
|
| 285 | 297 | } |
| 286 | 298 | |
| 287 | 299 | /** |