@@ -22,17 +22,17 @@ |
||
| 22 | 22 | */ |
| 23 | 23 | |
| 24 | 24 | |
| 25 | -use PEIP\Handler\CallableHandler; |
|
| 26 | -use PEIP\Service\HeaderServiceActivator; |
|
| 27 | -use PEIP\Channel\ChannelRegistry; |
|
| 28 | -use PEIP\Service\ServiceProvider; |
|
| 29 | -use PEIP\Plugins\BasePlugin; |
|
| 30 | -use PEIP\Factory\ServiceFactory; |
|
| 31 | -use PEIP\Base\GenericBuilder; |
|
| 32 | -use PEIP\Channel\PollableChannel; |
|
| 33 | -use PEIP\Channel\PublishSubscribeChannel; |
|
| 34 | -use PEIP\Gateway\SimpleMessagingGateway; |
|
| 35 | -use PEIP\Listener\Wiretap; |
|
| 25 | +use PEIP\Handler\CallableHandler; |
|
| 26 | +use PEIP\Service\HeaderServiceActivator; |
|
| 27 | +use PEIP\Channel\ChannelRegistry; |
|
| 28 | +use PEIP\Service\ServiceProvider; |
|
| 29 | +use PEIP\Plugins\BasePlugin; |
|
| 30 | +use PEIP\Factory\ServiceFactory; |
|
| 31 | +use PEIP\Base\GenericBuilder; |
|
| 32 | +use PEIP\Channel\PollableChannel; |
|
| 33 | +use PEIP\Channel\PublishSubscribeChannel; |
|
| 34 | +use PEIP\Gateway\SimpleMessagingGateway; |
|
| 35 | +use PEIP\Listener\Wiretap; |
|
| 36 | 36 | use PEIP\Service\ServiceActivator; |
| 37 | 37 | |
| 38 | 38 | class XMLContext |
@@ -55,26 +55,26 @@ discard block |
||
| 55 | 55 | * @param string $string the configuration string |
| 56 | 56 | * @return |
| 57 | 57 | */ |
| 58 | - public function __construct($string){
|
|
| 58 | + public function __construct($string) {
|
|
| 59 | 59 | $this->initNodeBuilders(); |
| 60 | 60 | $reader = new XMLContext_Reader($string); |
| 61 | 61 | $provider = $this->getServiceProvider(); |
| 62 | 62 | |
| 63 | - $handler = new CallableHandler($callable); |
|
| 63 | + $handler = new CallableHandler($callable); |
|
| 64 | 64 | |
| 65 | 65 | $serviceActivator = new HeaderServiceActivator(array($this, 'addConfig'), 'NODE'); |
| 66 | 66 | |
| 67 | - $reader->connect('read_node', $serviceActivator);
|
|
| 67 | + $reader->connect('read_node', $serviceActivator);
|
|
| 68 | 68 | $reader->read(); |
| 69 | 69 | |
| 70 | 70 | |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | - public function addConfig($config){
|
|
| 73 | + public function addConfig($config) {
|
|
| 74 | 74 | return $this->getServiceProvider()->addConfig($config); |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - public function handleReadConfig(\PEIP\INF\Event\Event $event){
|
|
| 77 | + public function handleReadConfig(\PEIP\INF\Event\Event $event) {
|
|
| 78 | 78 | $this->addConfig($event->getHeader('NODE'));
|
| 79 | 79 | } |
| 80 | 80 | |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | * @return XMLContext the context instance |
| 87 | 87 | * @throws RuntimeException |
| 88 | 88 | */ |
| 89 | - public static function createFromString($string){
|
|
| 89 | + public static function createFromString($string) {
|
|
| 90 | 90 | return new XMLContext($string); |
| 91 | 91 | } |
| 92 | 92 | |
@@ -98,10 +98,10 @@ discard block |
||
| 98 | 98 | * @return XMLContext the context instance |
| 99 | 99 | * @throws RuntimeException |
| 100 | 100 | */ |
| 101 | - public static function createFromFile($file){
|
|
| 102 | - if(file_exists($file)){
|
|
| 101 | + public static function createFromFile($file) {
|
|
| 102 | + if (file_exists($file)) {
|
|
| 103 | 103 | return self::createFromString(file_get_contents($file)); |
| 104 | - }else{
|
|
| 104 | + }else {
|
|
| 105 | 105 | throw new \RuntimeException('Cannot open file "'.$file.'".');
|
| 106 | 106 | } |
| 107 | 107 | } |
@@ -112,15 +112,15 @@ discard block |
||
| 112 | 112 | * @access protected |
| 113 | 113 | * @return void |
| 114 | 114 | */ |
| 115 | - protected function init(){
|
|
| 115 | + protected function init() {
|
|
| 116 | 116 | $xml = $this->simpleXML; |
| 117 | 117 | $this->channelRegistry = ChannelRegistry::getInstance(); |
| 118 | 118 | // register this context as a service if id is set. |
| 119 | - if($xml['id']){
|
|
| 119 | + if ($xml['id']) {
|
|
| 120 | 120 | $this->services[(string)$xml['id']] = $this; |
| 121 | 121 | } |
| 122 | 122 | // build services |
| 123 | - foreach($xml->children() as $entry){
|
|
| 123 | + foreach ($xml->children() as $entry) {
|
|
| 124 | 124 | $this->buildNode($entry); |
| 125 | 125 | } |
| 126 | 126 | } |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | * @param string $nodeName the name of the node |
| 134 | 134 | * @param callable $callable a callable which creates instances for node-name |
| 135 | 135 | */ |
| 136 | - public function registerNodeBuilder($nodeName, $callable){
|
|
| 136 | + public function registerNodeBuilder($nodeName, $callable) {
|
|
| 137 | 137 | return $this->getServiceProvider()->registerNodeBuilder($nodeName, $callable); |
| 138 | 138 | } |
| 139 | 139 | |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | * @access public |
| 145 | 145 | * @param \PEIP\INF\Context\Context_Plugin $plugin a plugin instance |
| 146 | 146 | */ |
| 147 | - public function addPlugin(\PEIP\INF\Context\Context_Plugin $plugin){
|
|
| 147 | + public function addPlugin(\PEIP\INF\Context\Context_Plugin $plugin) {
|
|
| 148 | 148 | $plugin->init($this); |
| 149 | 149 | } |
| 150 | 150 | |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | * @param object $config configuration object for the plugin |
| 156 | 156 | * @return |
| 157 | 157 | */ |
| 158 | - public function createPlugin($config){
|
|
| 158 | + public function createPlugin($config) {
|
|
| 159 | 159 | $plugin = $this->createService($config); |
| 160 | 160 | $this->addPlugin($plugin); |
| 161 | 161 | } |
@@ -176,7 +176,7 @@ discard block |
||
| 176 | 176 | * @access public |
| 177 | 177 | * @param XMLContext $config the config to include |
| 178 | 178 | */ |
| 179 | - public function includeContext(XMLContext $context){
|
|
| 179 | + public function includeContext(XMLContext $context) {
|
|
| 180 | 180 | $this->services = array_merge($this->services, $context->getServices()); |
| 181 | 181 | } |
| 182 | 182 | |
@@ -187,8 +187,8 @@ discard block |
||
| 187 | 187 | * @access public |
| 188 | 188 | * @param XMLContext $context the config to include |
| 189 | 189 | */ |
| 190 | - public function includeContextFromFile($filePath){
|
|
| 191 | - if(file_exists($filePath)){
|
|
| 190 | + public function includeContextFromFile($filePath) {
|
|
| 191 | + if (file_exists($filePath)) {
|
|
| 192 | 192 | $this->includeContextFromString(file_get_contents($filePath)); |
| 193 | 193 | } |
| 194 | 194 | } |
@@ -200,7 +200,7 @@ discard block |
||
| 200 | 200 | * @access public |
| 201 | 201 | * @param string $configString the config to include |
| 202 | 202 | */ |
| 203 | - public function includeContextFromString($configString){
|
|
| 203 | + public function includeContextFromString($configString) {
|
|
| 204 | 204 | $context = new XMLContext($configString); |
| 205 | 205 | $this->includeContext($context); |
| 206 | 206 | } |
@@ -212,14 +212,14 @@ discard block |
||
| 212 | 212 | * @access protected |
| 213 | 213 | * @param object $config the configuration for the context |
| 214 | 214 | */ |
| 215 | - protected function createContext($config){
|
|
| 216 | - if((string)$config['file'] != ''){
|
|
| 215 | + protected function createContext($config) {
|
|
| 216 | + if ((string)$config['file'] != '') {
|
|
| 217 | 217 | $this->includeContextFromFile((string)$config['file']); |
| 218 | 218 | } |
| 219 | 219 | } |
| 220 | 220 | |
| 221 | 221 | |
| 222 | - public function getServiceProvider(){
|
|
| 222 | + public function getServiceProvider() {
|
|
| 223 | 223 | return isset($this->serviceProvider) |
| 224 | 224 | ? $this->serviceProvider |
| 225 | 225 | : $this->serviceProvider = new ServiceProvider(); |
@@ -235,7 +235,7 @@ discard block |
||
| 235 | 235 | * @see XMLContext::includeContext |
| 236 | 236 | * @access protected |
| 237 | 237 | */ |
| 238 | - protected function initNodeBuilders(){
|
|
| 238 | + protected function initNodeBuilders() {
|
|
| 239 | 239 | $builders = array( |
| 240 | 240 | 'include' => 'createContext', |
| 241 | 241 | 'plugin' => 'createPlugin', |
@@ -253,7 +253,7 @@ discard block |
||
| 253 | 253 | ); |
| 254 | 254 | $plugin = new BasePlugin(); |
| 255 | 255 | $this->addPlugin($plugin); return; |
| 256 | - foreach($builders as $nodeName => $method){
|
|
| 256 | + foreach ($builders as $nodeName => $method) {
|
|
| 257 | 257 | $this->registerNodeBuilder($nodeName, array($this, $method)); |
| 258 | 258 | } |
| 259 | 259 | } |
@@ -267,10 +267,10 @@ discard block |
||
| 267 | 267 | * @param object $node configuration-node |
| 268 | 268 | * @return void |
| 269 | 269 | */ |
| 270 | - protected function buildNode($node){
|
|
| 270 | + protected function buildNode($node) {
|
|
| 271 | 271 | $nodeName = $node->getName(); |
| 272 | 272 | // call the builder method registered for the node. |
| 273 | - if(array_key_exists($nodeName, $this->nodeBuilders)){
|
|
| 273 | + if (array_key_exists($nodeName, $this->nodeBuilders)) {
|
|
| 274 | 274 | call_user_func($this->nodeBuilders[$nodeName], $node); |
| 275 | 275 | } |
| 276 | 276 | } |
@@ -289,7 +289,7 @@ discard block |
||
| 289 | 289 | * @param string $channelName the name/id of the channel to return |
| 290 | 290 | * @return \PEIP\INF\Channel\Channel |
| 291 | 291 | */ |
| 292 | - public function resolveChannelName($channelName){
|
|
| 292 | + public function resolveChannelName($channelName) {
|
|
| 293 | 293 | return $this->channelRegistry->get($channelName); |
| 294 | 294 | } |
| 295 | 295 | |
@@ -301,7 +301,7 @@ discard block |
||
| 301 | 301 | * @param mixed $id the id for the service |
| 302 | 302 | * @return object the service instance if found |
| 303 | 303 | */ |
| 304 | - public function getService($id){
|
|
| 304 | + public function getService($id) {
|
|
| 305 | 305 | return $this->getServiceProvider()->provideService($id); |
| 306 | 306 | } |
| 307 | 307 | |
@@ -311,7 +311,7 @@ discard block |
||
| 311 | 311 | * @access public |
| 312 | 312 | * @return array registered services |
| 313 | 313 | */ |
| 314 | - public function getServices(){
|
|
| 314 | + public function getServices() {
|
|
| 315 | 315 | return $this->getServiceProvider()->getServices(); |
| 316 | 316 | } |
| 317 | 317 | |
@@ -322,7 +322,7 @@ discard block |
||
| 322 | 322 | * @param mixed $id the id for the service |
| 323 | 323 | * @return boolean wether service is registered |
| 324 | 324 | */ |
| 325 | - public function hasService($id){
|
|
| 325 | + public function hasService($id) {
|
|
| 326 | 326 | return isset($this->services[$id]); |
| 327 | 327 | } |
| 328 | 328 | |
@@ -336,9 +336,9 @@ discard block |
||
| 336 | 336 | * @return object the service instance if found |
| 337 | 337 | * |
| 338 | 338 | */ |
| 339 | - protected function requestService($id){
|
|
| 339 | + protected function requestService($id) {
|
|
| 340 | 340 | $service = $this->getService($id); |
| 341 | - if($service === NULL){
|
|
| 341 | + if ($service === NULL) {
|
|
| 342 | 342 | throw new \RuntimeException('Service "'.$id.'" not found.');
|
| 343 | 343 | } |
| 344 | 344 | return $service; |
@@ -352,9 +352,9 @@ discard block |
||
| 352 | 352 | * @param object $config |
| 353 | 353 | * @return object the initialized service instance |
| 354 | 354 | */ |
| 355 | - protected function initService($config){
|
|
| 355 | + protected function initService($config) {
|
|
| 356 | 356 | $id = trim((string)$config['id']); |
| 357 | - if($id != ''){
|
|
| 357 | + if ($id != '') {
|
|
| 358 | 358 | return $this->services[$id] = $this->createService($config); |
| 359 | 359 | } |
| 360 | 360 | } |
@@ -366,7 +366,7 @@ discard block |
||
| 366 | 366 | * @param $config |
| 367 | 367 | * @return object the initialized service instance |
| 368 | 368 | */ |
| 369 | - public function createService($config){
|
|
| 369 | + public function createService($config) {
|
|
| 370 | 370 | return ServiceFactory::createService($config); |
| 371 | 371 | } |
| 372 | 372 | |
@@ -383,29 +383,29 @@ discard block |
||
| 383 | 383 | * @param object $config configuration to get the modification instructions from. |
| 384 | 384 | * @return object the modificated service |
| 385 | 385 | */ |
| 386 | - protected function modifyService($service, $config){
|
|
| 386 | + protected function modifyService($service, $config) {
|
|
| 387 | 387 | $reflection = GenericBuilder::getInstance(get_class($service))->getReflectionClass(); |
| 388 | 388 | // set instance properties |
| 389 | - if($config->property){
|
|
| 390 | - foreach($config->property as $property){
|
|
| 389 | + if ($config->property) {
|
|
| 390 | + foreach ($config->property as $property) {
|
|
| 391 | 391 | $arg = $this->buildArg($property); |
| 392 | - if($arg){
|
|
| 392 | + if ($arg) {
|
|
| 393 | 393 | $setter = self::getSetter($property); |
| 394 | - if($setter && self::hasPublicProperty($service, 'Method', $setter)){
|
|
| 394 | + if ($setter && self::hasPublicProperty($service, 'Method', $setter)) {
|
|
| 395 | 395 | $service->{$setter}($arg);
|
| 396 | - }elseif(in_array($property, self::hasPublicProperty($service, 'Property', $setter))){
|
|
| 396 | + }elseif (in_array($property, self::hasPublicProperty($service, 'Property', $setter))) {
|
|
| 397 | 397 | $service->$setter = $arg; |
| 398 | 398 | } |
| 399 | 399 | } |
| 400 | 400 | } |
| 401 | 401 | } |
| 402 | 402 | // call instance methods |
| 403 | - if($config->action){
|
|
| 404 | - foreach($config->action as $action){
|
|
| 403 | + if ($config->action) {
|
|
| 404 | + foreach ($config->action as $action) {
|
|
| 405 | 405 | $method = (string)$action['method'] != '' ? (string)$action['method'] : NULL; |
| 406 | - if($method && self::hasPublicProperty($service, 'Method', $method)){
|
|
| 406 | + if ($method && self::hasPublicProperty($service, 'Method', $method)) {
|
|
| 407 | 407 | $args = array(); |
| 408 | - foreach($action->children() as $argument){
|
|
| 408 | + foreach ($action->children() as $argument) {
|
|
| 409 | 409 | $args[] = $this->buildArg($argument); |
| 410 | 410 | } |
| 411 | 411 | call_user_func_array(array($service, (string)$action['method']), $args); |
@@ -413,9 +413,9 @@ discard block |
||
| 413 | 413 | } |
| 414 | 414 | } |
| 415 | 415 | // register instance listeners |
| 416 | - if($service instanceof \PEIP\INF\Event\Connectable){
|
|
| 417 | - if($config->listener){
|
|
| 418 | - foreach($config->listener as $listenerConf){
|
|
| 416 | + if ($service instanceof \PEIP\INF\Event\Connectable) {
|
|
| 417 | + if ($config->listener) {
|
|
| 418 | + foreach ($config->listener as $listenerConf) {
|
|
| 419 | 419 | $event = (string)$listenerConf['event']; |
| 420 | 420 | $listener = $this->provideService($listenerConf); |
| 421 | 421 | $service->connect($event, $listener); |
@@ -434,7 +434,7 @@ discard block |
||
| 434 | 434 | * @param mixed $id the id ofthe gateway |
| 435 | 435 | * @return object the gateway instance |
| 436 | 436 | */ |
| 437 | - public function getGateway($id){
|
|
| 437 | + public function getGateway($id) {
|
|
| 438 | 438 | return $this->services[$id]; |
| 439 | 439 | } |
| 440 | 440 | |
@@ -446,7 +446,7 @@ discard block |
||
| 446 | 446 | * @param object $config configuration object for the pollable channel. |
| 447 | 447 | * @return \PEIP\INF\Channel\Channel the created pollable channel instance |
| 448 | 448 | */ |
| 449 | - public function createChannel($config){
|
|
| 449 | + public function createChannel($config) {
|
|
| 450 | 450 | return $this->doCreateChannel($config, 'PollableChannel'); |
| 451 | 451 | } |
| 452 | 452 | |
@@ -458,7 +458,7 @@ discard block |
||
| 458 | 458 | * @param object $config configuration object for the subscribable channel. |
| 459 | 459 | * @return \PEIP\INF\Channel\Channel the created subscribable channel instance |
| 460 | 460 | */ |
| 461 | - public function createSubscribableChannel($config){
|
|
| 461 | + public function createSubscribableChannel($config) {
|
|
| 462 | 462 | return $this->doCreateChannel($config, 'PublishSubscribeChannel'); |
| 463 | 463 | } |
| 464 | 464 | |
@@ -471,9 +471,9 @@ discard block |
||
| 471 | 471 | * @param $additionalArguments additional arguments for the channel constructor (without first arg = id) |
| 472 | 472 | * @return \PEIP\INF\Channel\Channel the created channel instance |
| 473 | 473 | */ |
| 474 | - public function doCreateChannel($config, $defaultChannelClass, array $additionalArguments = array()){
|
|
| 474 | + public function doCreateChannel($config, $defaultChannelClass, array $additionalArguments = array()) {
|
|
| 475 | 475 | $id = (string)$config['id']; |
| 476 | - if($id != ''){
|
|
| 476 | + if ($id != '') {
|
|
| 477 | 477 | array_unshift($additionalArguments, $id); |
| 478 | 478 | $channel = $this->buildAndModify($config, $additionalArguments, $defaultChannelClass); |
| 479 | 479 | $this->channelRegistry->register($channel); |
@@ -490,7 +490,7 @@ discard block |
||
| 490 | 490 | * @param string $defaultClass the class to use if none is set in config. |
| 491 | 491 | * @return object the gateway instance |
| 492 | 492 | */ |
| 493 | - public function createGateway($config, $defaultClass = false){
|
|
| 493 | + public function createGateway($config, $defaultClass = false) {
|
|
| 494 | 494 | $args = array( |
| 495 | 495 | $this->getRequestChannel($config), |
| 496 | 496 | $this->getReplyChannel($config) |
@@ -514,7 +514,7 @@ discard block |
||
| 514 | 514 | * @param string $defaultClass the class to use if none is set in config. |
| 515 | 515 | * @return object the router instance |
| 516 | 516 | */ |
| 517 | - public function createRouter($config, $defaultClass = false){
|
|
| 517 | + public function createRouter($config, $defaultClass = false) {
|
|
| 518 | 518 | $resolver = $config['channel_resolver'] ? (string)$config['channel_resolver'] : $this->channelRegistry; |
| 519 | 519 | return $this->buildAndModify($config, array( |
| 520 | 520 | $resolver, |
@@ -531,7 +531,7 @@ discard block |
||
| 531 | 531 | * @param object $config configuration object for the splitter. |
| 532 | 532 | * @return object the splitter instance |
| 533 | 533 | */ |
| 534 | - public function createSplitter($config){
|
|
| 534 | + public function createSplitter($config) {
|
|
| 535 | 535 | return $this->createReplyMessageHandler($config); |
| 536 | 536 | } |
| 537 | 537 | |
@@ -544,7 +544,7 @@ discard block |
||
| 544 | 544 | * @param object $config configuration object for the transformer. |
| 545 | 545 | * @return object the transformer instance |
| 546 | 546 | */ |
| 547 | - public function createTransformer($config){
|
|
| 547 | + public function createTransformer($config) {
|
|
| 548 | 548 | return $this->createReplyMessageHandler($config); |
| 549 | 549 | } |
| 550 | 550 | |
@@ -557,7 +557,7 @@ discard block |
||
| 557 | 557 | * @param object $config configuration object for the aggregator. |
| 558 | 558 | * @return object the aggregator instance |
| 559 | 559 | */ |
| 560 | - public function createAggregator($config){
|
|
| 560 | + public function createAggregator($config) {
|
|
| 561 | 561 | return $this->createReplyMessageHandler($config); |
| 562 | 562 | } |
| 563 | 563 | |
@@ -570,7 +570,7 @@ discard block |
||
| 570 | 570 | * @param object $config configuration object for the wiretap. |
| 571 | 571 | * @return object the wiretap instance |
| 572 | 572 | */ |
| 573 | - public function createWiretap($config){
|
|
| 573 | + public function createWiretap($config) {
|
|
| 574 | 574 | return $this->createReplyMessageHandler($config, 'Wiretap'); |
| 575 | 575 | } |
| 576 | 576 | |
@@ -583,7 +583,7 @@ discard block |
||
| 583 | 583 | * @param string $defaultClass the class to use if none is set in config. |
| 584 | 584 | * @return object the reply-message-handler instance |
| 585 | 585 | */ |
| 586 | - public function createReplyMessageHandler($config, $defaultClass = false){
|
|
| 586 | + public function createReplyMessageHandler($config, $defaultClass = false) {
|
|
| 587 | 587 | return $this->buildAndModify($config, $this->getReplyHandlerArguments($config), $defaultClass); |
| 588 | 588 | } |
| 589 | 589 | |
@@ -596,12 +596,12 @@ discard block |
||
| 596 | 596 | * @param string $defaultClass the class to use if none is set in config. |
| 597 | 597 | * @return object the service-activator instance |
| 598 | 598 | */ |
| 599 | - public function createServiceActivator($config, $defaultClass = false){
|
|
| 599 | + public function createServiceActivator($config, $defaultClass = false) {
|
|
| 600 | 600 | $method = (string)$config['method']; |
| 601 | 601 | $service = $this->getService((string)$config['ref']); |
| 602 | - if($method && $service){
|
|
| 602 | + if ($method && $service) {
|
|
| 603 | 603 | $args = $this->getReplyHandlerArguments($config); |
| 604 | - array_unshift($args,array( |
|
| 604 | + array_unshift($args, array( |
|
| 605 | 605 | $service, |
| 606 | 606 | $method |
| 607 | 607 | )); |
@@ -622,11 +622,11 @@ discard block |
||
| 622 | 622 | * @param object $config configuration object for the service. |
| 623 | 623 | * @return |
| 624 | 624 | */ |
| 625 | - protected function provideService($config){
|
|
| 625 | + protected function provideService($config) {
|
|
| 626 | 626 | $ref = trim((string)$config['ref']); |
| 627 | - if($ref != ''){
|
|
| 627 | + if ($ref != '') {
|
|
| 628 | 628 | $service = $this->getService($ref); |
| 629 | - }else{
|
|
| 629 | + }else {
|
|
| 630 | 630 | $service = $this->createService($config); |
| 631 | 631 | } |
| 632 | 632 | return $service; |
@@ -643,10 +643,10 @@ discard block |
||
| 643 | 643 | * @param object $config configuration object for the setter-method. |
| 644 | 644 | * @return string camel-cased |
| 645 | 645 | */ |
| 646 | - protected static function getSetter($config){
|
|
| 647 | - if($config['setter']){
|
|
| 646 | + protected static function getSetter($config) {
|
|
| 647 | + if ($config['setter']) {
|
|
| 648 | 648 | $setter = (string)$config['setter']; |
| 649 | - }elseif($config['name']){
|
|
| 649 | + }elseif ($config['name']) {
|
|
| 650 | 650 | $setter = 'set'.ucfirst((string)$config['name']); |
| 651 | 651 | } |
| 652 | 652 | return $setter; |
@@ -659,29 +659,29 @@ discard block |
||
| 659 | 659 | * @param object $config configuration object to create argument from. |
| 660 | 660 | * @return mixed build argument |
| 661 | 661 | */ |
| 662 | - protected function buildArg($config){
|
|
| 663 | - if(trim((string)$config['value']) != ''){
|
|
| 662 | + protected function buildArg($config) {
|
|
| 663 | + if (trim((string)$config['value']) != '') {
|
|
| 664 | 664 | $arg = (string)$config['value']; |
| 665 | - }elseif($config->getName() == 'value'){
|
|
| 665 | + }elseif ($config->getName() == 'value') {
|
|
| 666 | 666 | $arg = (string)$config; |
| 667 | - }elseif($config->getName() == 'list'){
|
|
| 667 | + }elseif ($config->getName() == 'list') {
|
|
| 668 | 668 | $arg = array(); |
| 669 | - foreach($config->children() as $entry){
|
|
| 670 | - if($entry->getName() == 'value'){
|
|
| 671 | - if($entry['key']){
|
|
| 669 | + foreach ($config->children() as $entry) {
|
|
| 670 | + if ($entry->getName() == 'value') {
|
|
| 671 | + if ($entry['key']) {
|
|
| 672 | 672 | $arg[(string)$entry['key']] = (string)$entry; |
| 673 | - }else{
|
|
| 673 | + }else {
|
|
| 674 | 674 | $arg[] = (string)$entry; |
| 675 | 675 | } |
| 676 | - }elseif($entry->getName() == 'service'){
|
|
| 676 | + }elseif ($entry->getName() == 'service') {
|
|
| 677 | 677 | $arg[] = $this->provideService($entry); |
| 678 | 678 | } |
| 679 | 679 | } |
| 680 | - }elseif($config->getName() == 'service'){
|
|
| 680 | + }elseif ($config->getName() == 'service') {
|
|
| 681 | 681 | $arg = $this->provideService($config); |
| 682 | - }elseif($config->list){
|
|
| 682 | + }elseif ($config->list) {
|
|
| 683 | 683 | $arg = $this->buildArg($config->list); |
| 684 | - }elseif($config->service){
|
|
| 684 | + }elseif ($config->service) {
|
|
| 685 | 685 | $arg = $this->buildArg($config->service); |
| 686 | 686 | } |
| 687 | 687 | return $arg; |
@@ -695,12 +695,12 @@ discard block |
||
| 695 | 695 | * @param object $config configuration object to create arguments from. |
| 696 | 696 | * @return mixed build arguments |
| 697 | 697 | */ |
| 698 | - protected function getReplyHandlerArguments($config){
|
|
| 698 | + protected function getReplyHandlerArguments($config) {
|
|
| 699 | 699 | $args = array( |
| 700 | 700 | $this->doGetChannel('input', $config),
|
| 701 | 701 | $this->doGetChannel('output', $config)
|
| 702 | 702 | ); |
| 703 | - if($args[0] == NULL){
|
|
| 703 | + if ($args[0] == NULL) {
|
|
| 704 | 704 | throw new \RuntimeException('Could not receive input channel.');
|
| 705 | 705 | } |
| 706 | 706 | return $args; |
@@ -715,7 +715,7 @@ discard block |
||
| 715 | 715 | * @param object $config configuration object to return request-channel from. |
| 716 | 716 | * @return \PEIP\INF\Channel\Channel request-channel |
| 717 | 717 | */ |
| 718 | - protected function getRequestChannel($config){
|
|
| 718 | + protected function getRequestChannel($config) {
|
|
| 719 | 719 | return $this->doGetChannel('request', $config);
|
| 720 | 720 | } |
| 721 | 721 | |
@@ -728,7 +728,7 @@ discard block |
||
| 728 | 728 | * @param object $config configuration object to return reply-channel from. |
| 729 | 729 | * @return \PEIP\INF\Channel\Channel reply-channel |
| 730 | 730 | */ |
| 731 | - protected function getReplyChannel($config){
|
|
| 731 | + protected function getReplyChannel($config) {
|
|
| 732 | 732 | return $this->doGetChannel('reply', $config);
|
| 733 | 733 | } |
| 734 | 734 | |
@@ -741,15 +741,15 @@ discard block |
||
| 741 | 741 | * @param object $config configuration object to return channel from. |
| 742 | 742 | * @return \PEIP\INF\Channel\Channel reply-channel |
| 743 | 743 | */ |
| 744 | - public function doGetChannel($type, $config){
|
|
| 744 | + public function doGetChannel($type, $config) {
|
|
| 745 | 745 | $channelName = $config[$type."_channel"] |
| 746 | 746 | ? $config[$type."_channel"] |
| 747 | 747 | : $config["default_".$type."_channel"]; |
| 748 | 748 | return $this->serviceProvider->provideService(trim((string)$channelName)); |
| 749 | - $channel = $this->services[trim((string)$channelName)]; |
|
| 750 | - if($channel instanceof \PEIP\INF\Channel\Channel){
|
|
| 749 | + $channel = $this->services[trim((string)$channelName)]; |
|
| 750 | + if ($channel instanceof \PEIP\INF\Channel\Channel) {
|
|
| 751 | 751 | return $channel; |
| 752 | - }else{
|
|
| 752 | + }else {
|
|
| 753 | 753 | return NULL; |
| 754 | 754 | } |
| 755 | 755 | } |
@@ -767,31 +767,31 @@ discard block |
||
| 767 | 767 | * @param string $defaultClass class to create instance for if none is set in config |
| 768 | 768 | * @return object build and modified srvice instance |
| 769 | 769 | */ |
| 770 | - public function buildAndModify($config, $arguments, $defaultClass = false){
|
|
| 771 | - if("" != (string)$config["class"] || $defaultClass){
|
|
| 770 | + public function buildAndModify($config, $arguments, $defaultClass = false) {
|
|
| 771 | + if ("" != (string)$config["class"] || $defaultClass) {
|
|
| 772 | 772 | $service = ServiceFactory::doBuild($config, $arguments, $defaultClass); |
| 773 | - }elseif($config["ref"]){
|
|
| 773 | + }elseif ($config["ref"]) {
|
|
| 774 | 774 | $service = $this->getService((string)$config['ref']); |
| 775 | - }else{
|
|
| 775 | + }else {
|
|
| 776 | 776 | throw new \RuntimeException('Could not create Service. no class or reference given.');
|
| 777 | 777 | } |
| 778 | - if($config["ref_property"]){
|
|
| 778 | + if ($config["ref_property"]) {
|
|
| 779 | 779 | $service = $service->{(string)$config["ref_property"]};
|
| 780 | - }elseif($config["ref_method"]){
|
|
| 780 | + }elseif ($config["ref_method"]) {
|
|
| 781 | 781 | $args = array(); |
| 782 | - if($config->argument){
|
|
| 783 | - foreach($config->argument as $arg){
|
|
| 782 | + if ($config->argument) {
|
|
| 783 | + foreach ($config->argument as $arg) {
|
|
| 784 | 784 | $args[] = $this->buildArg($arg); |
| 785 | 785 | } |
| 786 | 786 | } |
| 787 | 787 | $service = call_user_func_array(array($service, (string)$config["ref_method"]), $args); |
| 788 | 788 | } |
| 789 | - if(!is_object($service)){
|
|
| 789 | + if (!is_object($service)) {
|
|
| 790 | 790 | throw new \RuntimeException('Could not create Service.');
|
| 791 | 791 | } |
| 792 | 792 | $service = $this->modifyService($service, $config); |
| 793 | 793 | $id = trim((string)$config['id']); |
| 794 | - if($service && $id != ''){
|
|
| 794 | + if ($service && $id != '') {
|
|
| 795 | 795 | $this->services[$id] = $service; |
| 796 | 796 | } |
| 797 | 797 | return $service; |
@@ -807,21 +807,21 @@ discard block |
||
| 807 | 807 | * @param string $defaultClass class to create instance for if none is set in config |
| 808 | 808 | * @return object build and modified srvice instance |
| 809 | 809 | */ |
| 810 | - protected static function doBuild($config, $arguments, $defaultClass = false){
|
|
| 810 | + protected static function doBuild($config, $arguments, $defaultClass = false) {
|
|
| 811 | 811 | $cls = $config["class"] ? trim((string)$config["class"]) : (string)$defaultClass; |
| 812 | - if($cls != ''){
|
|
| 812 | + if ($cls != '') {
|
|
| 813 | 813 | try {
|
| 814 | 814 | $constructor = (string)$config["constructor"]; |
| 815 | - if($constructor != ''){
|
|
| 815 | + if ($constructor != '') {
|
|
| 816 | 816 | $service = call_user_func_array(array($cls, $constructor), $arguments); |
| 817 | - }else{
|
|
| 817 | + }else {
|
|
| 818 | 818 | $service = self::build($cls, $arguments); |
| 819 | 819 | } |
| 820 | - }catch(\Exception $e){
|
|
| 820 | + } catch (\Exception $e) {
|
|
| 821 | 821 | throw new \RuntimeException('Could not create Service "'.$cls.'" -> '.$e->getMessage());
|
| 822 | 822 | } |
| 823 | 823 | } |
| 824 | - if(is_object($service)){
|
|
| 824 | + if (is_object($service)) {
|
|
| 825 | 825 | return $service; |
| 826 | 826 | } |
| 827 | 827 | throw new \RuntimeException('Could not create Service "'.$cls.'". Class does not exist.');
|
@@ -837,13 +837,13 @@ discard block |
||
| 837 | 837 | * @param array $arguments arguments for the constructor |
| 838 | 838 | * @return object build and modified srvice instance |
| 839 | 839 | */ |
| 840 | - protected static function build($className, $arguments){
|
|
| 840 | + protected static function build($className, $arguments) {
|
|
| 841 | 841 | return GenericBuilder::getInstance($className)->build($arguments); |
| 842 | 842 | } |
| 843 | 843 | |
| 844 | - protected static function hasPublicProperty($service, $type, $name){
|
|
| 844 | + protected static function hasPublicProperty($service, $type, $name) {
|
|
| 845 | 845 | $reflection = GenericBuilder::getInstance(get_class($service))->getReflectionClass(); |
| 846 | - if($reflection->{'has'.$type}($name) && $reflection->{'get'.$type}($name)->isPublic()){
|
|
| 846 | + if ($reflection->{'has'.$type}($name) && $reflection->{'get'.$type}($name)->isPublic()) {
|
|
| 847 | 847 | return true; |
| 848 | 848 | } |
| 849 | 849 | return false; |
@@ -11,8 +11,7 @@ |
||
| 11 | 11 | * |
| 12 | 12 | * @author timo |
| 13 | 13 | */ |
| 14 | -use PEIP\Util\Reflection; |
|
| 15 | -use PEIP\Util\ReflectionPool; |
|
| 14 | +use PEIP\Util\Reflection; |
|
| 16 | 15 | use PEIP\Event\EventBuilder; |
| 17 | 16 | |
| 18 | 17 | class ClassEventDispatcher extends \PEIP\Dispatcher\ObjectEventDispatcher {
|
@@ -27,9 +27,9 @@ discard block |
||
| 27 | 27 | * @param Callable|PEIP\INF\Handler\Handler $listener event-handler |
| 28 | 28 | * @return boolean |
| 29 | 29 | */ |
| 30 | - public function connect($name, $object, $listener){
|
|
| 30 | + public function connect($name, $object, $listener) {
|
|
| 31 | 31 | $class = is_object($object) ? get_class($object) : (string)$object; |
| 32 | - foreach(Reflection::getImplementedClassesAndInterfaces($object) as $cls){
|
|
| 32 | + foreach (Reflection::getImplementedClassesAndInterfaces($object) as $cls) {
|
|
| 33 | 33 | $reflection = Reflection_Pool::getInstance($class); |
| 34 | 34 | parent::connect($name, $reflection, $listener); |
| 35 | 35 | } |
@@ -37,13 +37,13 @@ discard block |
||
| 37 | 37 | return true; |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | - public function disconnect($name, $object, $listener){
|
|
| 40 | + public function disconnect($name, $object, $listener) {
|
|
| 41 | 41 | $class = is_object($object) ? get_class($object) : (string)$object; |
| 42 | 42 | $res = true; |
| 43 | - foreach(Reflection::getImplementedClassesAndInterfaces($object) as $cls){
|
|
| 43 | + foreach (Reflection::getImplementedClassesAndInterfaces($object) as $cls) {
|
|
| 44 | 44 | $reflection = Reflection_Pool::getInstance($class); |
| 45 | 45 | $r = parent::disconnect($name, $reflection, $listener); |
| 46 | - if(!$r){
|
|
| 46 | + if (!$r) {
|
|
| 47 | 47 | $res = false; |
| 48 | 48 | } |
| 49 | 49 | } |
@@ -58,9 +58,9 @@ discard block |
||
| 58 | 58 | * @param \PEIP\INF\Event\Event $object an event object |
| 59 | 59 | * @return boolean |
| 60 | 60 | */ |
| 61 | - public function notify($name, $object){
|
|
| 62 | - if($object instanceof \PEIP\INF\Event\Event){
|
|
| 63 | - if(is_object($object->getContent())){
|
|
| 61 | + public function notify($name, $object) {
|
|
| 62 | + if ($object instanceof \PEIP\INF\Event\Event) {
|
|
| 63 | + if (is_object($object->getContent())) {
|
|
| 64 | 64 | return self::doNotify( |
| 65 | 65 | $this->getListeners( |
| 66 | 66 | $name, |
@@ -70,10 +70,10 @@ discard block |
||
| 70 | 70 | ), |
| 71 | 71 | $object |
| 72 | 72 | ); |
| 73 | - }else{
|
|
| 73 | + }else {
|
|
| 74 | 74 | throw new \InvalidArgumentException('instance of \PEIP\INF\Event\Event must contain subject');
|
| 75 | 75 | } |
| 76 | - }else{
|
|
| 76 | + }else {
|
|
| 77 | 77 | throw new \InvalidArgumentException('object must be instance of \PEIP\INF\Event\Event');
|
| 78 | 78 | } |
| 79 | 79 | } //put your code here |
@@ -90,8 +90,8 @@ discard block |
||
| 90 | 90 | * @return |
| 91 | 91 | * @see EventBuilder |
| 92 | 92 | */ |
| 93 | - public function buildAndNotify($name, $object, array $headers = array(), $eventClass = false, $type = false){
|
|
| 94 | - if(!$this->hasListeners($name, ($object))){
|
|
| 93 | + public function buildAndNotify($name, $object, array $headers = array(), $eventClass = false, $type = false) {
|
|
| 94 | + if (!$this->hasListeners($name, ($object))) {
|
|
| 95 | 95 | return false; |
| 96 | 96 | } |
| 97 | 97 | |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | * @param object $object object to check for listeners |
| 115 | 115 | * @return boolean |
| 116 | 116 | */ |
| 117 | - public function hasListeners($name, $object){
|
|
| 117 | + public function hasListeners($name, $object) {
|
|
| 118 | 118 | return parent::hasListeners( |
| 119 | 119 | $name, |
| 120 | 120 | Reflection_Pool::getInstance($object) |
@@ -11,7 +11,7 @@ |
||
| 11 | 11 | * |
| 12 | 12 | * @author timo |
| 13 | 13 | */ |
| 14 | -use PEIP\Event\EventBuilder; |
|
| 14 | +use PEIP\Event\EventBuilder; |
|
| 15 | 15 | use PEIP\Util\ReflectionPool; |
| 16 | 16 | |
| 17 | 17 | class EventClassDispatcher |
@@ -25,9 +25,9 @@ discard block |
||
| 25 | 25 | * @param \PEIP\INF\Event\Event $object an event object |
| 26 | 26 | * @return boolean |
| 27 | 27 | */ |
| 28 | - public function notify($name, $object){
|
|
| 29 | - if($object instanceof \PEIP\INF\Event\Event){
|
|
| 30 | - if(is_object($object->getContent())){
|
|
| 28 | + public function notify($name, $object) {
|
|
| 29 | + if ($object instanceof \PEIP\INF\Event\Event) {
|
|
| 30 | + if (is_object($object->getContent())) {
|
|
| 31 | 31 | return self::doNotify( |
| 32 | 32 | $this->getListeners( |
| 33 | 33 | $name, |
@@ -35,10 +35,10 @@ discard block |
||
| 35 | 35 | ), |
| 36 | 36 | $object->getContent() |
| 37 | 37 | ); |
| 38 | - }else{
|
|
| 38 | + }else {
|
|
| 39 | 39 | throw new \InvalidArgumentException('instance of \PEIP\INF\Event\Event must contain subject');
|
| 40 | 40 | } |
| 41 | - }else{
|
|
| 41 | + }else {
|
|
| 42 | 42 | throw new \InvalidArgumentException('object must be instance of \PEIP\INF\Event\Event');
|
| 43 | 43 | } |
| 44 | 44 | } //put your code here |
@@ -55,8 +55,8 @@ discard block |
||
| 55 | 55 | * @return |
| 56 | 56 | * @see EventBuilder |
| 57 | 57 | */ |
| 58 | - public function buildAndNotify($name, $object, array $headers = array(), $eventClass = false, $type = false){
|
|
| 59 | - if(!$this->hasListeners($name, ($object))){
|
|
| 58 | + public function buildAndNotify($name, $object, array $headers = array(), $eventClass = false, $type = false) {
|
|
| 59 | + if (!$this->hasListeners($name, ($object))) {
|
|
| 60 | 60 | return false; |
| 61 | 61 | } |
| 62 | 62 | |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | * @param object $object object to check for listeners |
| 80 | 80 | * @return boolean |
| 81 | 81 | */ |
| 82 | - public function hasListeners($name, $object){
|
|
| 82 | + public function hasListeners($name, $object) {
|
|
| 83 | 83 | return parent::hasListeners( |
| 84 | 84 | $name, |
| 85 | 85 | ReflectionPool::getInstance($object) |
@@ -11,8 +11,8 @@ |
||
| 11 | 11 | * |
| 12 | 12 | * @author timo |
| 13 | 13 | */ |
| 14 | -use PEIP\Util\Test; |
|
| 15 | -use PEIP\Base\GenericBuilder; |
|
| 14 | +use PEIP\Util\Test; |
|
| 15 | +use PEIP\Base\GenericBuilder; |
|
| 16 | 16 | use PEIP\Context\XMLContext; |
| 17 | 17 | |
| 18 | 18 | class ServiceFactory {
|
@@ -23,11 +23,11 @@ discard block |
||
| 23 | 23 | * @param $config |
| 24 | 24 | * @return object the initialized service instance |
| 25 | 25 | */ |
| 26 | - public static function createService($config){
|
|
| 26 | + public static function createService($config) {
|
|
| 27 | 27 | $args = array(); |
| 28 | 28 | //build arguments for constructor |
| 29 | - if($config->constructor_arg){
|
|
| 30 | - foreach($config->constructor_arg as $arg){
|
|
| 29 | + if ($config->constructor_arg) {
|
|
| 30 | + foreach ($config->constructor_arg as $arg) {
|
|
| 31 | 31 | $args[] = self::buildArg($arg); |
| 32 | 32 | } |
| 33 | 33 | } |
@@ -44,21 +44,21 @@ discard block |
||
| 44 | 44 | * @param string $defaultClass class to create instance for if none is set in config |
| 45 | 45 | * @return object build and modified srvice instance |
| 46 | 46 | */ |
| 47 | - public static function doBuild($config, $arguments, $defaultClass = false){
|
|
| 47 | + public static function doBuild($config, $arguments, $defaultClass = false) {
|
|
| 48 | 48 | $cls = $config["class"] ? trim((string)$config["class"]) : (string)$defaultClass; |
| 49 | - if($cls != ''){
|
|
| 49 | + if ($cls != '') {
|
|
| 50 | 50 | try {
|
| 51 | 51 | $constructor = (string)$config["constructor"]; |
| 52 | - if($constructor != '' && Test::assertMethod($cls, $constructor)){
|
|
| 52 | + if ($constructor != '' && Test::assertMethod($cls, $constructor)) {
|
|
| 53 | 53 | $service = call_user_func_array(array($cls, $constructor), $arguments); |
| 54 | - }else{
|
|
| 54 | + }else {
|
|
| 55 | 55 | $service = self::build($cls, $arguments); |
| 56 | 56 | } |
| 57 | - }catch(\Exception $e){
|
|
| 57 | + } catch (\Exception $e) {
|
|
| 58 | 58 | throw new \RuntimeException('Could not create Service "'.$cls.'" -> '.$e->getMessage());
|
| 59 | 59 | } |
| 60 | 60 | } |
| 61 | - if(is_object($service)){
|
|
| 61 | + if (is_object($service)) {
|
|
| 62 | 62 | return $service; |
| 63 | 63 | } |
| 64 | 64 | throw new \RuntimeException('Could not create Service "'.$cls.'". Class does not exist.');
|
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | * @param array $arguments arguments for the constructor |
| 76 | 76 | * @return object build and modified srvice instance |
| 77 | 77 | */ |
| 78 | - public static function build($className, $arguments){
|
|
| 78 | + public static function build($className, $arguments) {
|
|
| 79 | 79 | return GenericBuilder::getInstance($className)->build($arguments); |
| 80 | 80 | } |
| 81 | 81 | |
@@ -86,29 +86,29 @@ discard block |
||
| 86 | 86 | * @param object $config configuration object to create argument from. |
| 87 | 87 | * @return mixed build argument |
| 88 | 88 | */ |
| 89 | - protected static function buildArg($config){
|
|
| 90 | - if(trim((string)$config['value']) != ''){
|
|
| 89 | + protected static function buildArg($config) {
|
|
| 90 | + if (trim((string)$config['value']) != '') {
|
|
| 91 | 91 | $arg = (string)$config['value']; |
| 92 | - }elseif($config->getName() == 'value'){
|
|
| 92 | + }elseif ($config->getName() == 'value') {
|
|
| 93 | 93 | $arg = (string)$config; |
| 94 | - }elseif($config->getName() == 'list'){
|
|
| 94 | + }elseif ($config->getName() == 'list') {
|
|
| 95 | 95 | $arg = array(); |
| 96 | - foreach($config->children() as $entry){
|
|
| 97 | - if($entry->getName() == 'value'){
|
|
| 98 | - if($entry['key']){
|
|
| 96 | + foreach ($config->children() as $entry) {
|
|
| 97 | + if ($entry->getName() == 'value') {
|
|
| 98 | + if ($entry['key']) {
|
|
| 99 | 99 | $arg[(string)$entry['key']] = (string)$entry; |
| 100 | - }else{
|
|
| 100 | + }else {
|
|
| 101 | 101 | $arg[] = (string)$entry; |
| 102 | 102 | } |
| 103 | - }elseif($entry->getName() == 'service'){
|
|
| 103 | + }elseif ($entry->getName() == 'service') {
|
|
| 104 | 104 | $arg[] = $this->provideService($entry); |
| 105 | 105 | } |
| 106 | 106 | } |
| 107 | - }elseif($config->getName() == 'service'){
|
|
| 107 | + }elseif ($config->getName() == 'service') {
|
|
| 108 | 108 | $arg = self::provideService($config); |
| 109 | - }elseif($config->list){
|
|
| 109 | + }elseif ($config->list) {
|
|
| 110 | 110 | $arg = self::buildArg($config->list); |
| 111 | - }elseif($config->service){
|
|
| 111 | + }elseif ($config->service) {
|
|
| 112 | 112 | $arg = self::buildArg($config->service); |
| 113 | 113 | } |
| 114 | 114 | return $arg; |
@@ -126,24 +126,24 @@ discard block |
||
| 126 | 126 | * @param string $defaultClass class to create instance for if none is set in config |
| 127 | 127 | * @return object build and modified srvice instance |
| 128 | 128 | */ |
| 129 | - public static function buildAndModify($config, $arguments, $defaultClass = false){
|
|
| 130 | - if("" != (string)$config["class"] || $defaultClass){
|
|
| 129 | + public static function buildAndModify($config, $arguments, $defaultClass = false) {
|
|
| 130 | + if ("" != (string)$config["class"] || $defaultClass) {
|
|
| 131 | 131 | $service = ServiceFactory::doBuild($config, $arguments, $defaultClass); |
| 132 | - }else{
|
|
| 132 | + }else {
|
|
| 133 | 133 | throw new \RuntimeException('Could not create Service. no class or reference given.');
|
| 134 | 134 | } |
| 135 | - if($config["ref_property"]){
|
|
| 135 | + if ($config["ref_property"]) {
|
|
| 136 | 136 | $service = $service->{(string)$config["ref_property"]};
|
| 137 | - }elseif($config["ref_method"]){
|
|
| 137 | + }elseif ($config["ref_method"]) {
|
|
| 138 | 138 | $args = array(); |
| 139 | - if($config->argument){
|
|
| 140 | - foreach($config->argument as $arg){
|
|
| 139 | + if ($config->argument) {
|
|
| 140 | + foreach ($config->argument as $arg) {
|
|
| 141 | 141 | $args[] = $this->buildArg($arg); |
| 142 | 142 | } |
| 143 | 143 | } |
| 144 | 144 | $service = call_user_func_array(array($service, (string)$config["ref_method"]), $args); |
| 145 | 145 | } |
| 146 | - if(!is_object($service)){
|
|
| 146 | + if (!is_object($service)) {
|
|
| 147 | 147 | throw new \RuntimeException('Could not create Service.');
|
| 148 | 148 | } |
| 149 | 149 | $service = self::modifyService($service, $config); |
@@ -166,29 +166,29 @@ discard block |
||
| 166 | 166 | * @param object $config configuration to get the modification instructions from. |
| 167 | 167 | * @return object the modificated service |
| 168 | 168 | */ |
| 169 | - protected function modifyService($service, $config){
|
|
| 169 | + protected function modifyService($service, $config) {
|
|
| 170 | 170 | $reflection = GenericBuilder::getInstance(get_class($service))->getReflectionClass(); |
| 171 | 171 | // set instance properties |
| 172 | - if($config->property){
|
|
| 173 | - foreach($config->property as $property){
|
|
| 172 | + if ($config->property) {
|
|
| 173 | + foreach ($config->property as $property) {
|
|
| 174 | 174 | $arg = self::buildArg($property); |
| 175 | - if($arg){
|
|
| 175 | + if ($arg) {
|
|
| 176 | 176 | $setter = self::getSetter($property); |
| 177 | - if($setter && self::hasPublicProperty($service, 'Method', $setter)){
|
|
| 177 | + if ($setter && self::hasPublicProperty($service, 'Method', $setter)) {
|
|
| 178 | 178 | $service->{$setter}($arg);
|
| 179 | - }elseif(in_array($property, self::hasPublicProperty($service, 'Property', $setter))){
|
|
| 179 | + }elseif (in_array($property, self::hasPublicProperty($service, 'Property', $setter))) {
|
|
| 180 | 180 | $service->$setter = $arg; |
| 181 | 181 | } |
| 182 | 182 | } |
| 183 | 183 | } |
| 184 | 184 | } |
| 185 | 185 | // call instance methods |
| 186 | - if($config->action){
|
|
| 187 | - foreach($config->action as $action){
|
|
| 186 | + if ($config->action) {
|
|
| 187 | + foreach ($config->action as $action) {
|
|
| 188 | 188 | $method = (string)$action['method'] != '' ? (string)$action['method'] : NULL; |
| 189 | - if($method && self::hasPublicProperty($service, 'Method', $method)){
|
|
| 189 | + if ($method && self::hasPublicProperty($service, 'Method', $method)) {
|
|
| 190 | 190 | $args = array(); |
| 191 | - foreach($action->children() as $argument){
|
|
| 191 | + foreach ($action->children() as $argument) {
|
|
| 192 | 192 | $args[] = $this->buildArg($argument); |
| 193 | 193 | } |
| 194 | 194 | call_user_func_array(array($service, (string)$action['method']), $args); |
@@ -196,9 +196,9 @@ discard block |
||
| 196 | 196 | } |
| 197 | 197 | } |
| 198 | 198 | // register instance listeners |
| 199 | - if($service instanceof \PEIP\INF\Event\Connectable){
|
|
| 200 | - if($config->listener){
|
|
| 201 | - foreach($config->listener as $listenerConf){
|
|
| 199 | + if ($service instanceof \PEIP\INF\Event\Connectable) {
|
|
| 200 | + if ($config->listener) {
|
|
| 201 | + foreach ($config->listener as $listenerConf) {
|
|
| 202 | 202 | $event = (string)$listenerConf['event']; |
| 203 | 203 | $listener = $this->provideService($listenerConf); |
| 204 | 204 | $service->connect($event, $listener); |
@@ -20,7 +20,7 @@ |
||
| 20 | 20 | * @implements \PEIP\INF\Gateway\MessagingGateway, \PEIP\INF\Message\MessageBuilder |
| 21 | 21 | */ |
| 22 | 22 | |
| 23 | -use PEIP\Message\GenericMessage; |
|
| 23 | +use PEIP\Message\GenericMessage; |
|
| 24 | 24 | use PEIP\Message\MessageBuilder; |
| 25 | 25 | |
| 26 | 26 | class SimpleMessagingGateway |
@@ -43,9 +43,9 @@ discard block |
||
| 43 | 43 | * @param \PEIP\INF\Channel\PollableChannel $replyChannel The default channel to receive requests from the gateway |
| 44 | 44 | * @param array $defaultHeaders The default headers to apply to request messages |
| 45 | 45 | */ |
| 46 | - public function __construct(\PEIP\INF\Channel\Channel $requestChannel, \PEIP\INF\Channel\Channel $replyChannel = NULL, array $defaultHeaders = array()){
|
|
| 46 | + public function __construct(\PEIP\INF\Channel\Channel $requestChannel, \PEIP\INF\Channel\Channel $replyChannel = NULL, array $defaultHeaders = array()) {
|
|
| 47 | 47 | $this->setRequestChannel($requestChannel); |
| 48 | - if($replyChannel){
|
|
| 48 | + if ($replyChannel) {
|
|
| 49 | 49 | $this->setReplyChannel($replyChannel); |
| 50 | 50 | } |
| 51 | 51 | $this->defaultHeaders = $defaultHeaders; |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | * @param \PEIP\INF\Channel\Channel $replyChannel The default channel to receive requests from the gateway |
| 60 | 60 | * @return |
| 61 | 61 | */ |
| 62 | - public function setRequestChannel(\PEIP\INF\Channel\Channel $requestChannel){
|
|
| 62 | + public function setRequestChannel(\PEIP\INF\Channel\Channel $requestChannel) {
|
|
| 63 | 63 | $this->requestChannel = $requestChannel; |
| 64 | 64 | } |
| 65 | 65 | |
@@ -70,8 +70,8 @@ discard block |
||
| 70 | 70 | * @param \PEIP\INF\Channel\PollableChannel $replyChannel The default channel to receive requests from the gateway |
| 71 | 71 | * @return |
| 72 | 72 | */ |
| 73 | - public function setReplyChannel(\PEIP\INF\Channel\Channel $replyChannel){
|
|
| 74 | - if(!($replyChannel instanceof \PEIP\INF\Channel\PollableChannel)){
|
|
| 73 | + public function setReplyChannel(\PEIP\INF\Channel\Channel $replyChannel) {
|
|
| 74 | + if (!($replyChannel instanceof \PEIP\INF\Channel\PollableChannel)) {
|
|
| 75 | 75 | throw new \InvalidArgumentException('reply channel must be instance of \PEIP\INF\Channel\PollableChannel.');
|
| 76 | 76 | } |
| 77 | 77 | $this->replyChannel = $replyChannel; |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | * @param mixed $content the content/payload for the message to send |
| 85 | 85 | * @return |
| 86 | 86 | */ |
| 87 | - public function send($content){
|
|
| 87 | + public function send($content) {
|
|
| 88 | 88 | return $this->requestChannel->send($this->buildMessage($content)); |
| 89 | 89 | } |
| 90 | 90 | |
@@ -94,12 +94,12 @@ discard block |
||
| 94 | 94 | * @access public |
| 95 | 95 | * @return mixed content/payload of the received message |
| 96 | 96 | */ |
| 97 | - public function receive(){
|
|
| 98 | - if(!isset($this->replyChannel)){
|
|
| 97 | + public function receive() {
|
|
| 98 | + if (!isset($this->replyChannel)) {
|
|
| 99 | 99 | throw new \LogicException('No replyChannel set.');
|
| 100 | 100 | } |
| 101 | 101 | $message = $this->replyChannel->receive(); |
| 102 | - if($message){
|
|
| 102 | + if ($message) {
|
|
| 103 | 103 | return $message->getContent(); |
| 104 | 104 | } |
| 105 | 105 | return NULL; |
@@ -112,12 +112,12 @@ discard block |
||
| 112 | 112 | * @param mixed $content the content/payload for the message to send |
| 113 | 113 | * @return mixed content/payload of the received message |
| 114 | 114 | */ |
| 115 | - public function sendAndReceive($content){
|
|
| 115 | + public function sendAndReceive($content) {
|
|
| 116 | 116 | $this->send($content); |
| 117 | 117 | try {
|
| 118 | 118 | $res = $this->receive(); |
| 119 | 119 | } |
| 120 | - catch(\Exception $e){
|
|
| 120 | + catch (\Exception $e) {
|
|
| 121 | 121 | return NULL; |
| 122 | 122 | } |
| 123 | 123 | return $res; |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | * @param mixed $content the content/payload for the message to send |
| 131 | 131 | * @return \PEIP\INF\Message\Message the built message |
| 132 | 132 | */ |
| 133 | - protected function buildMessage($content){
|
|
| 133 | + protected function buildMessage($content) {
|
|
| 134 | 134 | return $this->getMessageBuilder()->setContent($content)->build(); |
| 135 | 135 | } |
| 136 | 136 | |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | * @access protected |
| 141 | 141 | * @return MessageBuilder message builder instance for the registerd message class |
| 142 | 142 | */ |
| 143 | - protected function getMessageBuilder(){
|
|
| 143 | + protected function getMessageBuilder() {
|
|
| 144 | 144 | return isset($this->messageBuilder) && ($this->messageBuilder->getMessageClass() == $this->getMessageClass()) |
| 145 | 145 | ? $this->messageBuilder |
| 146 | 146 | : $this->messageBuilder = MessageBuilder::getInstance($this->messageClass)->setHeaders($this->defaultHeaders); |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | * @param string $messageClass message class to create instances from |
| 154 | 154 | * @return |
| 155 | 155 | */ |
| 156 | - public function setMessageClass($messageClass){
|
|
| 156 | + public function setMessageClass($messageClass) {
|
|
| 157 | 157 | $this->messageClass = $messageClass; |
| 158 | 158 | } |
| 159 | 159 | |
@@ -163,7 +163,7 @@ discard block |
||
| 163 | 163 | * @access public |
| 164 | 164 | * @return string message class to create instances from |
| 165 | 165 | */ |
| 166 | - public function getMessageClass(){
|
|
| 166 | + public function getMessageClass() {
|
|
| 167 | 167 | return $this->messageClass; |
| 168 | 168 | } |
| 169 | 169 | |
@@ -20,7 +20,7 @@ |
||
| 20 | 20 | * @implements \PEIP\INF\Base\Container, \PEIP\INF\Message\Message, \PEIP\INF\Base\Buildable |
| 21 | 21 | */ |
| 22 | 22 | |
| 23 | -use PEIP\Util\Test; |
|
| 23 | +use PEIP\Util\Test; |
|
| 24 | 24 | use PEIP\Base\GenericBuilder; |
| 25 | 25 | |
| 26 | 26 | class GenericMessage |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | * @param mixed $content The content/payload of the message |
| 42 | 42 | * @param array|ArrayAccess $headers headers as key/value pairs |
| 43 | 43 | */ |
| 44 | - public function __construct($content, $headers = array()){
|
|
| 44 | + public function __construct($content, $headers = array()) {
|
|
| 45 | 45 | $this->doSetContent($content); |
| 46 | 46 | $this->doSetHeaders($headers); |
| 47 | 47 | } |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | * @access public |
| 54 | 54 | * @return |
| 55 | 55 | */ |
| 56 | - public function getContent(){
|
|
| 56 | + public function getContent() {
|
|
| 57 | 57 | return $this->content; |
| 58 | 58 | } |
| 59 | 59 | |
@@ -63,13 +63,13 @@ discard block |
||
| 63 | 63 | * @access protected |
| 64 | 64 | * @param mixed $content The content/payload of the message |
| 65 | 65 | */ |
| 66 | - protected function doSetContent($content){
|
|
| 66 | + protected function doSetContent($content) {
|
|
| 67 | 67 | $this->content = Test::castType($content, self::CONTENT_CAST_TYPE); |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | - protected function doSetHeaders($headers){
|
|
| 70 | + protected function doSetHeaders($headers) {
|
|
| 71 | 71 | $headers = Test::ensureArrayAccess($headers); |
| 72 | - if(is_array($headers)){
|
|
| 72 | + if (is_array($headers)) {
|
|
| 73 | 73 | $headers = new \ArrayObject($headers); |
| 74 | 74 | } |
| 75 | 75 | $this->headers = $headers; |
@@ -81,8 +81,8 @@ discard block |
||
| 81 | 81 | * @access public |
| 82 | 82 | * @return ArrayAccess ArrayAccess object of headers |
| 83 | 83 | */ |
| 84 | - public function getHeaders(){
|
|
| 85 | - return (array) $this->headers; |
|
| 84 | + public function getHeaders() {
|
|
| 85 | + return (array)$this->headers; |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | /** |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | * @param string $name the name of the header |
| 93 | 93 | * @return mixed the value of the header |
| 94 | 94 | */ |
| 95 | - public function getHeader($name){
|
|
| 95 | + public function getHeader($name) {
|
|
| 96 | 96 | $name = (string)$name; |
| 97 | 97 | return isset($this->headers[$name]) ? $this->headers[$name] : NULL; |
| 98 | 98 | } |
@@ -105,8 +105,8 @@ discard block |
||
| 105 | 105 | * @param string $name the name of the header |
| 106 | 106 | * @return boolean wether the header has been successfully set |
| 107 | 107 | */ |
| 108 | - public function addHeader($name, $value){
|
|
| 109 | - if(!$this->hasHeader($name)){
|
|
| 108 | + public function addHeader($name, $value) {
|
|
| 109 | + if (!$this->hasHeader($name)) {
|
|
| 110 | 110 | $this->headers[$name] = $value; |
| 111 | 111 | return true; |
| 112 | 112 | } |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | * @param string $name the name of the header |
| 121 | 121 | * @return boolean wether the header is set |
| 122 | 122 | */ |
| 123 | - public function hasHeader($name){
|
|
| 123 | + public function hasHeader($name) {
|
|
| 124 | 124 | return isset($this->headers[$name]); |
| 125 | 125 | } |
| 126 | 126 | |
@@ -130,16 +130,16 @@ discard block |
||
| 130 | 130 | * @access public |
| 131 | 131 | * @return string content/payload of the message |
| 132 | 132 | */ |
| 133 | - public function __toString(){
|
|
| 133 | + public function __toString() {
|
|
| 134 | 134 | $res = false; |
| 135 | 135 | try {
|
| 136 | 136 | $res = (string)$this->getContent(); |
| 137 | 137 | } |
| 138 | - catch(\Exception $e){
|
|
| 138 | + catch (\Exception $e) {
|
|
| 139 | 139 | try {
|
| 140 | 140 | $res = get_class($this->getContent()); |
| 141 | 141 | } |
| 142 | - catch(\Exception $e){
|
|
| 142 | + catch (\Exception $e) {
|
|
| 143 | 143 | |
| 144 | 144 | } |
| 145 | 145 | } |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | * @param array $arguments argumends for the constructor |
| 160 | 160 | * @return GenericMessage new class instance |
| 161 | 161 | */ |
| 162 | - public static function build(array $arguments = array()){
|
|
| 162 | + public static function build(array $arguments = array()) {
|
|
| 163 | 163 | return GenericBuilder::getInstance(__CLASS__)->build($arguments); |
| 164 | 164 | } |
| 165 | 165 | } |
| 166 | 166 | \ No newline at end of file |
@@ -24,8 +24,8 @@ |
||
| 24 | 24 | */ |
| 25 | 25 | |
| 26 | 26 | |
| 27 | -use PEIP\Dispatcher\Dispatcher; |
|
| 28 | -use PEIP\Event\Event; |
|
| 27 | +use PEIP\Dispatcher\Dispatcher; |
|
| 28 | +use PEIP\Event\Event; |
|
| 29 | 29 | use PEIP\Util\Test; |
| 30 | 30 | |
| 31 | 31 | class Pipe |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | * @param $name |
| 64 | 64 | * @return |
| 65 | 65 | */ |
| 66 | - public function setName($name){
|
|
| 66 | + public function setName($name) {
|
|
| 67 | 67 | $this->name = $name; |
| 68 | 68 | } |
| 69 | 69 | |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | * @access public |
| 73 | 73 | * @return |
| 74 | 74 | */ |
| 75 | - public function getName(){
|
|
| 75 | + public function getName() {
|
|
| 76 | 76 | return $this->name; |
| 77 | 77 | } |
| 78 | 78 | |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | * @param $timeout |
| 84 | 84 | * @return |
| 85 | 85 | */ |
| 86 | - public function send(\PEIP\INF\Message\Message $message, $timeout = -1){
|
|
| 86 | + public function send(\PEIP\INF\Message\Message $message, $timeout = -1) {
|
|
| 87 | 87 | return $this->handle($message); |
| 88 | 88 | } |
| 89 | 89 | |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | * @param $message |
| 94 | 94 | * @return |
| 95 | 95 | */ |
| 96 | - protected function doSend(\PEIP\INF\Message\Message $message){
|
|
| 96 | + protected function doSend(\PEIP\INF\Message\Message $message) {
|
|
| 97 | 97 | $this->doFireEvent(self::EVENT_PRE_PUBLISH, array(self::HEADER_MESSAGE=>$message)); |
| 98 | 98 | $this->getMessageDispatcher()->notify($message); |
| 99 | 99 | $this->doFireEvent(self::EVENT_POST_PUBLISH, array(self::HEADER_MESSAGE=>$message)); |
@@ -106,11 +106,11 @@ discard block |
||
| 106 | 106 | * @param $content |
| 107 | 107 | * @return |
| 108 | 108 | */ |
| 109 | - protected function replyMessage($message){
|
|
| 110 | - if(\PEIP\Util\Test::assertMessage($message)){
|
|
| 111 | - if($this->getOutputChannel()){
|
|
| 109 | + protected function replyMessage($message) {
|
|
| 110 | + if (\PEIP\Util\Test::assertMessage($message)) {
|
|
| 111 | + if ($this->getOutputChannel()) {
|
|
| 112 | 112 | $this->getOutputChannel()->send($message); |
| 113 | - }else{
|
|
| 113 | + }else {
|
|
| 114 | 114 | $this->doSend($message); |
| 115 | 115 | } |
| 116 | 116 | } |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | * @param $message |
| 123 | 123 | * @return |
| 124 | 124 | */ |
| 125 | - protected function doReply(\PEIP\INF\Message\Message $message){
|
|
| 125 | + protected function doReply(\PEIP\INF\Message\Message $message) {
|
|
| 126 | 126 | $this->replyMessage($message); |
| 127 | 127 | } |
| 128 | 128 | |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | * @param $handler |
| 133 | 133 | * @return |
| 134 | 134 | */ |
| 135 | - public function subscribe($handler){
|
|
| 135 | + public function subscribe($handler) {
|
|
| 136 | 136 | Test::ensureHandler($handler); |
| 137 | 137 | $this->getMessageDispatcher()->connect($handler); |
| 138 | 138 | $this->doFireEvent(self::EVENT_SUBSCRIBE, array(self::HEADER_SUBSCRIBER=>$handler)); |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | * @param $handler e |
| 145 | 145 | * @return |
| 146 | 146 | */ |
| 147 | - public function unsubscribe($handler){
|
|
| 147 | + public function unsubscribe($handler) {
|
|
| 148 | 148 | Test::ensureHandler($handler); |
| 149 | 149 | $this->getMessageDispatcher()->disconnect($handler); |
| 150 | 150 | $this->doFireEvent( |
@@ -162,9 +162,9 @@ discard block |
||
| 162 | 162 | * @param $transferListeners |
| 163 | 163 | * @return |
| 164 | 164 | */ |
| 165 | - public function setMessageDispatcher(\PEIP\INF\Dispatcher\Dispatcher $dispatcher, $transferListeners = true){
|
|
| 166 | - if(isset($this->dispatcher) && $transferListeners){
|
|
| 167 | - foreach($this->dispatcher->getListeners() as $listener){
|
|
| 165 | + public function setMessageDispatcher(\PEIP\INF\Dispatcher\Dispatcher $dispatcher, $transferListeners = true) {
|
|
| 166 | + if (isset($this->dispatcher) && $transferListeners) {
|
|
| 167 | + foreach ($this->dispatcher->getListeners() as $listener) {
|
|
| 168 | 168 | $dispatcher->connect($listener); |
| 169 | 169 | $this->dispatcher->disconnect($listener); |
| 170 | 170 | } |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | * @access public |
| 179 | 179 | * @return |
| 180 | 180 | */ |
| 181 | - public function getMessageDispatcher(){
|
|
| 181 | + public function getMessageDispatcher() {
|
|
| 182 | 182 | $defaultDispatcher = self::DEFAULT_CLASS_MESSAGE_DISPATCHER; |
| 183 | 183 | return isset($this->dispatcher) ? $this->dispatcher : $this->dispatcher = new $defaultDispatcher; |
| 184 | 184 | } |
@@ -190,7 +190,7 @@ discard block |
||
| 190 | 190 | * @param $callable |
| 191 | 191 | * @return |
| 192 | 192 | */ |
| 193 | - protected function registerCommand($commandName, $callable){
|
|
| 193 | + protected function registerCommand($commandName, $callable) {
|
|
| 194 | 194 | $this->commands[$commandName] = $callable; |
| 195 | 195 | } |
| 196 | 196 | |
@@ -200,10 +200,10 @@ discard block |
||
| 200 | 200 | * @param $cmdMessage |
| 201 | 201 | * @return |
| 202 | 202 | */ |
| 203 | - public function command(\PEIP\INF\Message\Message $cmdMessage){
|
|
| 203 | + public function command(\PEIP\INF\Message\Message $cmdMessage) {
|
|
| 204 | 204 | $this->doFireEvent(self::EVENT_PRE_COMMAND, array(self::HEADER_MESSAGE=>$cmdMessage)); |
| 205 | 205 | $commandName = trim((string)$cmdMessage->getHeader('COMMAND'));
|
| 206 | - if($commandName != '' && array_key_exists($commandName, $this->commands)){
|
|
| 206 | + if ($commandName != '' && array_key_exists($commandName, $this->commands)) {
|
|
| 207 | 207 | call_user_func($this->commands[$commandName], $cmdMessage->getContent()); |
| 208 | 208 | } |
| 209 | 209 | $this->doFireEvent(self::EVENT_POST_COMMAND, array(self::HEADER_MESSAGE=>$cmdMessage)); |
@@ -11,11 +11,11 @@ |
||
| 11 | 11 | * |
| 12 | 12 | * @author timo |
| 13 | 13 | */ |
| 14 | -use PEIP\Context\XMLContext; |
|
| 15 | -use PEIP\Channel\PollableChannel; |
|
| 16 | -use PEIP\Channel\PublishSubscribeChannel; |
|
| 17 | -use PEIP\Gateway\SimpleMessagingGateway; |
|
| 18 | -use PEIP\Listener\Wiretap; |
|
| 14 | +use PEIP\Context\XMLContext; |
|
| 15 | +use PEIP\Channel\PollableChannel; |
|
| 16 | +use PEIP\Channel\PublishSubscribeChannel; |
|
| 17 | +use PEIP\Gateway\SimpleMessagingGateway; |
|
| 18 | +use PEIP\Listener\Wiretap; |
|
| 19 | 19 | use PEIP\Service\ServiceActivator; |
| 20 | 20 | |
| 21 | 21 | class BasePlugin extends \PEIP\ABS\Context\ContextPlugin {
|
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | * @param object $config configuration object for the pollable channel. |
| 47 | 47 | * @return \PEIP\INF\Channel\Channel the created pollable channel instance |
| 48 | 48 | */ |
| 49 | - public function createChannel($config){
|
|
| 49 | + public function createChannel($config) {
|
|
| 50 | 50 | return $this->doCreateChannel($config, 'PollableChannel'); |
| 51 | 51 | } |
| 52 | 52 | |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | * @param object $config configuration object for the subscribable channel. |
| 59 | 59 | * @return \PEIP\INF\Channel\Channel the created subscribable channel instance |
| 60 | 60 | */ |
| 61 | - public function createSubscribableChannel($config){
|
|
| 61 | + public function createSubscribableChannel($config) {
|
|
| 62 | 62 | return $this->doCreateChannel($config, 'PublishSubscribeChannel'); |
| 63 | 63 | } |
| 64 | 64 | |
@@ -71,9 +71,9 @@ discard block |
||
| 71 | 71 | * @param $additionalArguments additional arguments for the channel constructor (without first arg = id) |
| 72 | 72 | * @return \PEIP\INF\Channel\Channel the created channel instance |
| 73 | 73 | */ |
| 74 | - public function doCreateChannel($config, $defaultChannelClass, array $additionalArguments = array()){
|
|
| 74 | + public function doCreateChannel($config, $defaultChannelClass, array $additionalArguments = array()) {
|
|
| 75 | 75 | $id = (string)$config['id']; |
| 76 | - if($id != ''){
|
|
| 76 | + if ($id != '') {
|
|
| 77 | 77 | array_unshift($additionalArguments, $id); |
| 78 | 78 | $channel = $this->buildAndModify($config, $additionalArguments, $defaultChannelClass); |
| 79 | 79 | //$this->channelRegistry->register($channel); |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | * @param string $defaultClass the class to use if none is set in config. |
| 92 | 92 | * @return object the gateway instance |
| 93 | 93 | */ |
| 94 | - public function createGateway($config, $defaultClass = false){
|
|
| 94 | + public function createGateway($config, $defaultClass = false) {
|
|
| 95 | 95 | $args = array( |
| 96 | 96 | $this->getRequestChannel($config), |
| 97 | 97 | $this->getReplyChannel($config) |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | * @param string $defaultClass the class to use if none is set in config. |
| 116 | 116 | * @return object the router instance |
| 117 | 117 | */ |
| 118 | - public function createRouter($config, $defaultClass = false){
|
|
| 118 | + public function createRouter($config, $defaultClass = false) {
|
|
| 119 | 119 | $resolver = $config['channel_resolver'] ? (string)$config['channel_resolver'] : $this->channelRegistry; |
| 120 | 120 | return $this->buildAndModify($config, array( |
| 121 | 121 | $resolver, |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | * @param object $config configuration object for the splitter. |
| 133 | 133 | * @return object the splitter instance |
| 134 | 134 | */ |
| 135 | - public function createSplitter($config){
|
|
| 135 | + public function createSplitter($config) {
|
|
| 136 | 136 | return $this->createReplyMessageHandler($config); |
| 137 | 137 | } |
| 138 | 138 | |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | * @param object $config configuration object for the transformer. |
| 146 | 146 | * @return object the transformer instance |
| 147 | 147 | */ |
| 148 | - public function createTransformer($config){
|
|
| 148 | + public function createTransformer($config) {
|
|
| 149 | 149 | return $this->createReplyMessageHandler($config); |
| 150 | 150 | } |
| 151 | 151 | |
@@ -158,7 +158,7 @@ discard block |
||
| 158 | 158 | * @param object $config configuration object for the aggregator. |
| 159 | 159 | * @return object the aggregator instance |
| 160 | 160 | */ |
| 161 | - public function createAggregator($config){
|
|
| 161 | + public function createAggregator($config) {
|
|
| 162 | 162 | return $this->createReplyMessageHandler($config); |
| 163 | 163 | } |
| 164 | 164 | |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | * @param object $config configuration object for the wiretap. |
| 172 | 172 | * @return object the wiretap instance |
| 173 | 173 | */ |
| 174 | - public function createWiretap($config){
|
|
| 174 | + public function createWiretap($config) {
|
|
| 175 | 175 | return $this->createReplyMessageHandler($config, 'Wiretap'); |
| 176 | 176 | } |
| 177 | 177 | |
@@ -184,7 +184,7 @@ discard block |
||
| 184 | 184 | * @param string $defaultClass the class to use if none is set in config. |
| 185 | 185 | * @return object the reply-message-handler instance |
| 186 | 186 | */ |
| 187 | - public function createReplyMessageHandler($config, $defaultClass = false){
|
|
| 187 | + public function createReplyMessageHandler($config, $defaultClass = false) {
|
|
| 188 | 188 | return $this->buildAndModify($config, $this->getReplyHandlerArguments($config), $defaultClass); |
| 189 | 189 | } |
| 190 | 190 | |
@@ -197,12 +197,12 @@ discard block |
||
| 197 | 197 | * @param string $defaultClass the class to use if none is set in config. |
| 198 | 198 | * @return object the service-activator instance |
| 199 | 199 | */ |
| 200 | - public function createServiceActivator($config, $defaultClass = false){
|
|
| 200 | + public function createServiceActivator($config, $defaultClass = false) {
|
|
| 201 | 201 | $method = (string)$config['method']; |
| 202 | 202 | $service = $this->context->getServiceProvider()->provideService((string)$config['ref']); |
| 203 | - if($method && $service){
|
|
| 203 | + if ($method && $service) {
|
|
| 204 | 204 | $args = $this->getReplyHandlerArguments($config); |
| 205 | - array_unshift($args,array( |
|
| 205 | + array_unshift($args, array( |
|
| 206 | 206 | $service, |
| 207 | 207 | $method |
| 208 | 208 | )); |
@@ -219,12 +219,12 @@ discard block |
||
| 219 | 219 | * @param object $config configuration object to create arguments from. |
| 220 | 220 | * @return mixed build arguments |
| 221 | 221 | */ |
| 222 | - protected function getReplyHandlerArguments($config){
|
|
| 222 | + protected function getReplyHandlerArguments($config) {
|
|
| 223 | 223 | $args = array( |
| 224 | 224 | $this->doGetChannel('input', $config),
|
| 225 | 225 | $this->doGetChannel('output', $config)
|
| 226 | 226 | ); |
| 227 | - if($args[0] == NULL){
|
|
| 227 | + if ($args[0] == NULL) {
|
|
| 228 | 228 | throw new \RuntimeException('Could not receive input channel.');
|
| 229 | 229 | } |
| 230 | 230 | return $args; |
@@ -239,7 +239,7 @@ discard block |
||
| 239 | 239 | * @param object $config configuration object to return request-channel from. |
| 240 | 240 | * @return \PEIP\INF\Channel\Channel request-channel |
| 241 | 241 | */ |
| 242 | - protected function getRequestChannel($config){
|
|
| 242 | + protected function getRequestChannel($config) {
|
|
| 243 | 243 | return $this->doGetChannel('request', $config);
|
| 244 | 244 | } |
| 245 | 245 | |
@@ -252,7 +252,7 @@ discard block |
||
| 252 | 252 | * @param object $config configuration object to return reply-channel from. |
| 253 | 253 | * @return \PEIP\INF\Channel\Channel reply-channel |
| 254 | 254 | */ |
| 255 | - protected function getReplyChannel($config){
|
|
| 255 | + protected function getReplyChannel($config) {
|
|
| 256 | 256 | return $this->doGetChannel('reply', $config);
|
| 257 | 257 | } |
| 258 | 258 | |
@@ -265,15 +265,15 @@ discard block |
||
| 265 | 265 | * @param object $config configuration object to return channel from. |
| 266 | 266 | * @return \PEIP\INF\Channel\Channel reply-channel |
| 267 | 267 | */ |
| 268 | - public function doGetChannel($type, $config){
|
|
| 268 | + public function doGetChannel($type, $config) {
|
|
| 269 | 269 | $channelName = $config[$type."_channel"] |
| 270 | 270 | ? $config[$type."_channel"] |
| 271 | 271 | : $config["default_".$type."_channel"]; |
| 272 | 272 | return $this->context->getServiceProvider()->provideService(trim((string)$channelName)); |
| 273 | - $channel = $this->services[trim((string)$channelName)]; |
|
| 274 | - if($channel instanceof \PEIP\INF\Channel\Channel){
|
|
| 273 | + $channel = $this->services[trim((string)$channelName)]; |
|
| 274 | + if ($channel instanceof \PEIP\INF\Channel\Channel) {
|
|
| 275 | 275 | return $channel; |
| 276 | - }else{
|
|
| 276 | + }else {
|
|
| 277 | 277 | return NULL; |
| 278 | 278 | } |
| 279 | 279 | } |
@@ -11,7 +11,7 @@ |
||
| 11 | 11 | * |
| 12 | 12 | * @author timo |
| 13 | 13 | */ |
| 14 | -use PEIP\Context\XMLContext; |
|
| 14 | +use PEIP\Context\XMLContext; |
|
| 15 | 15 | use PEIP\Plugins\BasePlugin; |
| 16 | 16 | |
| 17 | 17 | class ServiceProvider extends \PEIP\Service\ServiceContainer {
|
@@ -14,7 +14,7 @@ discard block |
||
| 14 | 14 | use PEIP\Context\XMLContext; |
| 15 | 15 | use PEIP\Plugins\BasePlugin; |
| 16 | 16 | |
| 17 | -class ServiceProvider extends \PEIP\Service\ServiceContainer {
|
|
| 17 | +class ServiceProvider extends \PEIP\Service\ServiceContainer {
|
|
| 18 | 18 | |
| 19 | 19 | const |
| 20 | 20 | /* Headers */ |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | public function __construct(array $config = array(), $idAttribute = 'id') {
|
| 48 | 48 | $this->idAttribute = $idAttribute; |
| 49 | 49 | $this->initNodeBuilders(); |
| 50 | - foreach($config as $serviceConfig){
|
|
| 50 | + foreach ($config as $serviceConfig) {
|
|
| 51 | 51 | $this->addConfig($serviceConfig); |
| 52 | 52 | } |
| 53 | 53 | |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | * @access public |
| 59 | 59 | * @return array registered services |
| 60 | 60 | */ |
| 61 | - public function getServices(){
|
|
| 61 | + public function getServices() {
|
|
| 62 | 62 | return $this->services; |
| 63 | 63 | } |
| 64 | 64 | |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | * @param string $nodeName the name of the node |
| 71 | 71 | * @param callable $callable a callable which creates instances for node-name |
| 72 | 72 | */ |
| 73 | - public function registerNodeBuilder($nodeName, $callable){
|
|
| 73 | + public function registerNodeBuilder($nodeName, $callable) {
|
|
| 74 | 74 | $this->nodeBuilders[$nodeName] = $callable; |
| 75 | 75 | } |
| 76 | 76 | /** |
@@ -83,17 +83,17 @@ discard block |
||
| 83 | 83 | * @see XMLContext::includeContext |
| 84 | 84 | * @access protected |
| 85 | 85 | */ |
| 86 | - protected function initNodeBuilders(){ return;
|
|
| 86 | + protected function initNodeBuilders() { return;
|
|
| 87 | 87 | $builders = array( |
| 88 | 88 | 'service' => 'initService' |
| 89 | 89 | ); |
| 90 | 90 | $plugin = new BasePlugin(); |
| 91 | - foreach($builders as $nodeName => $method){
|
|
| 91 | + foreach ($builders as $nodeName => $method) {
|
|
| 92 | 92 | $this->registerNodeBuilder($nodeName, array($this, $method)); |
| 93 | 93 | } |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | - public function addConfig($config){
|
|
| 96 | + public function addConfig($config) {
|
|
| 97 | 97 | $this->doFireEvent( |
| 98 | 98 | self::EVENT_BEFORE_ADD_CONFIG, |
| 99 | 99 | array( |
@@ -112,15 +112,15 @@ discard block |
||
| 112 | 112 | ); |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | - public function provideService($key){
|
|
| 115 | + public function provideService($key) {
|
|
| 116 | 116 | $this->doFireEvent(self::EVENT_BEFORE_PROVIDE_SERVICE, array( |
| 117 | 117 | self::HEADER_KEY=>$key) |
| 118 | 118 | ); |
| 119 | 119 | |
| 120 | - if($this->hasService($key)){
|
|
| 121 | - $service = $this->getService($key); |
|
| 122 | - }else{
|
|
| 123 | - $service = $this->createService($key); |
|
| 120 | + if ($this->hasService($key)) {
|
|
| 121 | + $service = $this->getService($key); |
|
| 122 | + }else {
|
|
| 123 | + $service = $this->createService($key); |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | $this->doFireEvent(self::EVENT_AFTER_PROVIDE_SERVICE, array( |
@@ -131,16 +131,16 @@ discard block |
||
| 131 | 131 | return $service; |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | - protected function createService($key){
|
|
| 134 | + protected function createService($key) {
|
|
| 135 | 135 | $this->doFireEvent(self::EVENT_BEFORE_CREATE_SERVICE, array( |
| 136 | 136 | self::HEADER_KEY=>$key) |
| 137 | 137 | ); |
| 138 | 138 | $errorMessage = ''; |
| 139 | 139 | $config = $this->getServiceConfig($key); |
| 140 | 140 | |
| 141 | - if($config){
|
|
| 141 | + if ($config) {
|
|
| 142 | 142 | $node = $this->buildNode($config); |
| 143 | - if($node){
|
|
| 143 | + if ($node) {
|
|
| 144 | 144 | $this->setService( |
| 145 | 145 | $key, |
| 146 | 146 | $node |
@@ -151,11 +151,11 @@ discard block |
||
| 151 | 151 | )); |
| 152 | 152 | |
| 153 | 153 | return $node; |
| 154 | - }else{
|
|
| 154 | + }else {
|
|
| 155 | 155 | $errorMessage = 'COULD NOT BUILD NODE FOR KEY: '.$key; |
| 156 | 156 | } |
| 157 | 157 | |
| 158 | - }else{
|
|
| 158 | + }else {
|
|
| 159 | 159 | $errorMessage = 'NO CONFIG FOR KEY: '.$key; |
| 160 | 160 | } |
| 161 | 161 | $this->doFireEvent(self::EVENT_CREATE_SERVICE_ERROR, array( |
@@ -165,8 +165,8 @@ discard block |
||
| 165 | 165 | return NULL; |
| 166 | 166 | } |
| 167 | 167 | |
| 168 | - public function getServiceConfig($key){
|
|
| 169 | - if(!isset($this->ids[$key])){
|
|
| 168 | + public function getServiceConfig($key) {
|
|
| 169 | + if (!isset($this->ids[$key])) {
|
|
| 170 | 170 | return false; |
| 171 | 171 | } |
| 172 | 172 | return $this->config[$this->ids[$key]]; |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | * @param object $config configuration-node |
| 182 | 182 | * @return void |
| 183 | 183 | */ |
| 184 | - protected function buildNode($config){
|
|
| 184 | + protected function buildNode($config) {
|
|
| 185 | 185 | $nodeName = (string)$config['type']; |
| 186 | 186 | |
| 187 | 187 | $this->doFireEvent(self::EVENT_BEFORE_BUILD_NODE, array( |
@@ -189,20 +189,20 @@ discard block |
||
| 189 | 189 | self::HEADER_NODE_NAME=> $nodeName |
| 190 | 190 | )); |
| 191 | 191 | // call the builder method registered for the node. |
| 192 | - if(array_key_exists($nodeName, $this->nodeBuilders)){
|
|
| 192 | + if (array_key_exists($nodeName, $this->nodeBuilders)) {
|
|
| 193 | 193 | |
| 194 | 194 | $nodeInstance = call_user_func($this->nodeBuilders[$nodeName], $config); |
| 195 | - if(is_object($nodeInstance)){
|
|
| 195 | + if (is_object($nodeInstance)) {
|
|
| 196 | 196 | $this->doFireEvent(self::EVENT_BUILD_NODE_SUCCESS, array( |
| 197 | 197 | self::HEADER_NODE_CONFIG=>$config, |
| 198 | 198 | self::HEADER_NODE_NAME=> $nodeName, |
| 199 | 199 | self::HEADER_NODE => $nodeInstance |
| 200 | 200 | )); |
| 201 | 201 | return $nodeInstance; |
| 202 | - }else{
|
|
| 202 | + }else {
|
|
| 203 | 203 | $errorMessage = 'BUILDER RETURNED NO OBJECT FOR NODE-TYPE: '.$nodeName; |
| 204 | 204 | } |
| 205 | - }else{
|
|
| 205 | + }else {
|
|
| 206 | 206 | $errorMessage = 'NO BUILDER FOUND FOR NODE-TYPE: '.$nodeName; |
| 207 | 207 | } |
| 208 | 208 | |
@@ -213,27 +213,27 @@ discard block |
||
| 213 | 213 | )); |
| 214 | 214 | } |
| 215 | 215 | |
| 216 | - protected function getIdFromConfig($config){
|
|
| 216 | + protected function getIdFromConfig($config) {
|
|
| 217 | 217 | $id = ''; |
| 218 | - if(isset($config[$this->idAttribute])){
|
|
| 218 | + if (isset($config[$this->idAttribute])) {
|
|
| 219 | 219 | $id = trim((string)($config[$this->idAttribute])); |
| 220 | 220 | } |
| 221 | 221 | return $id; |
| 222 | 222 | } |
| 223 | 223 | |
| 224 | - protected function getCountConfig(){
|
|
| 224 | + protected function getCountConfig() {
|
|
| 225 | 225 | return count($this->config); |
| 226 | 226 | } |
| 227 | 227 | |
| 228 | - protected function doAddConfig($config){
|
|
| 228 | + protected function doAddConfig($config) {
|
|
| 229 | 229 | $countConfig = $this->getCountConfig(); |
| 230 | 230 | $this->config[$countConfig] = $config; |
| 231 | 231 | return $countConfig; |
| 232 | 232 | } |
| 233 | 233 | |
| 234 | - protected function doRegisterConfig($config){
|
|
| 235 | - $id = $this->getIdFromConfig($config); |
|
| 236 | - if($id != ''){
|
|
| 234 | + protected function doRegisterConfig($config) {
|
|
| 235 | + $id = $this->getIdFromConfig($config); |
|
| 236 | + if ($id != '') {
|
|
| 237 | 237 | $this->ids[$id] = $this->getCountConfig() - 1; |
| 238 | 238 | } |
| 239 | 239 | return $id; |