@@ -35,9 +35,9 @@ discard block |
||
| 35 | 35 | * @param \PEIP\INF\Channel\Channel $outputChannel the outputs-channel |
| 36 | 36 | * @return |
| 37 | 37 | */ |
| 38 | - public function __construct(\PEIP\INF\Channel\Channel $inputChannel, \PEIP\INF\Channel\Channel $outputChannel = NULL){ |
|
| 38 | + public function __construct(\PEIP\INF\Channel\Channel $inputChannel, \PEIP\INF\Channel\Channel $outputChannel = NULL) { |
|
| 39 | 39 | $this->setInputChannel($inputChannel); |
| 40 | - if(is_object($outputChannel)){ |
|
| 40 | + if (is_object($outputChannel)) { |
|
| 41 | 41 | $this->setOutputChannel($outputChannel); |
| 42 | 42 | } |
| 43 | 43 | } |
@@ -49,13 +49,13 @@ discard block |
||
| 49 | 49 | * @param \PEIP\INF\Message\Message $message message to split |
| 50 | 50 | * @return |
| 51 | 51 | */ |
| 52 | - public function doReply(\PEIP\INF\Message\Message $message){ |
|
| 52 | + public function doReply(\PEIP\INF\Message\Message $message) { |
|
| 53 | 53 | $res = $this->split($message); |
| 54 | - if(is_array($res)){ |
|
| 55 | - foreach($res as $msg){ |
|
| 54 | + if (is_array($res)) { |
|
| 55 | + foreach ($res as $msg) { |
|
| 56 | 56 | $this->replyMessage($msg); |
| 57 | 57 | } |
| 58 | - }else{ |
|
| 58 | + }else { |
|
| 59 | 59 | $this->replyMessage($res); |
| 60 | 60 | } |
| 61 | 61 | } |
@@ -44,9 +44,9 @@ discard block |
||
| 44 | 44 | * @param Callable|PEIP\INF\Handler\Handler $listener listener to connect |
| 45 | 45 | * @return |
| 46 | 46 | */ |
| 47 | - public function connect($name, $listener){ |
|
| 47 | + public function connect($name, $listener) { |
|
| 48 | 48 | Test::ensureHandler($listener); |
| 49 | - if (!$this->hasListeners($name)){ |
|
| 49 | + if (!$this->hasListeners($name)) { |
|
| 50 | 50 | $this->listeners[$name] = array(); |
| 51 | 51 | } |
| 52 | 52 | $this->listeners[$name][] = $listener; |
@@ -61,13 +61,13 @@ discard block |
||
| 61 | 61 | * @param Callable|PEIP\INF\Handler\Handler $listener listener to connect |
| 62 | 62 | * @return |
| 63 | 63 | */ |
| 64 | - public function disconnect($name, $listener){ |
|
| 65 | - if (!$this->hasListeners($name)){ |
|
| 64 | + public function disconnect($name, $listener) { |
|
| 65 | + if (!$this->hasListeners($name)) { |
|
| 66 | 66 | return false; |
| 67 | 67 | } |
| 68 | 68 | $res = false; |
| 69 | - foreach ($this->listeners[$name] as $i => $callable){ |
|
| 70 | - if ($listener === $callable){ |
|
| 69 | + foreach ($this->listeners[$name] as $i => $callable) { |
|
| 70 | + if ($listener === $callable) { |
|
| 71 | 71 | unset($this->listeners[$name][$i]); |
| 72 | 72 | $res = true; |
| 73 | 73 | } |
@@ -83,8 +83,8 @@ discard block |
||
| 83 | 83 | * @param Callable|PEIP\INF\Handler\Handler $listener listener to connect |
| 84 | 84 | * @return |
| 85 | 85 | */ |
| 86 | - public function disconnectAll($name){ |
|
| 87 | - if (!isset($this->listeners[$name])){ |
|
| 86 | + public function disconnectAll($name) { |
|
| 87 | + if (!isset($this->listeners[$name])) { |
|
| 88 | 88 | return false; |
| 89 | 89 | } |
| 90 | 90 | $this->listeners[$name] = array(); |
@@ -98,11 +98,11 @@ discard block |
||
| 98 | 98 | * @param string $name name of the event |
| 99 | 99 | * @return boolean wether any listener is registered for event-name |
| 100 | 100 | */ |
| 101 | - public function hasListeners($name){ |
|
| 102 | - if (!isset($this->listeners[$name])){ |
|
| 101 | + public function hasListeners($name) { |
|
| 102 | + if (!isset($this->listeners[$name])) { |
|
| 103 | 103 | return false; |
| 104 | 104 | } |
| 105 | - return (boolean) count($this->listeners[$name]); |
|
| 105 | + return (boolean)count($this->listeners[$name]); |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | /** |
@@ -113,8 +113,8 @@ discard block |
||
| 113 | 113 | * @param mixed $subject the subject |
| 114 | 114 | * @return boolean success |
| 115 | 115 | */ |
| 116 | - public function notify($name, $subject){ |
|
| 117 | - if($this->hasListeners($name)){ |
|
| 116 | + public function notify($name, $subject) { |
|
| 117 | + if ($this->hasListeners($name)) { |
|
| 118 | 118 | self::doNotify($this->getListeners($name), $subject); |
| 119 | 119 | return true; |
| 120 | 120 | } |
@@ -129,8 +129,8 @@ discard block |
||
| 129 | 129 | * @param mixed $subject the subject |
| 130 | 130 | * @return \PEIP\INF\Handler\Handler listener which returned a boolean true value |
| 131 | 131 | */ |
| 132 | - public function notifyUntil($name, $subject){ |
|
| 133 | - if($this->hasListeners($name)){ |
|
| 132 | + public function notifyUntil($name, $subject) { |
|
| 133 | + if ($this->hasListeners($name)) { |
|
| 134 | 134 | return self::doNotifyUntil($this->getListeners($name), $subject); |
| 135 | 135 | } |
| 136 | 136 | return NULL; |
@@ -143,8 +143,8 @@ discard block |
||
| 143 | 143 | * @param $name |
| 144 | 144 | * @return array array of \PEIP\INF\Handler\Handler instances |
| 145 | 145 | */ |
| 146 | - public function getListeners($name){ |
|
| 147 | - if (!isset($this->listeners[$name])){ |
|
| 146 | + public function getListeners($name) { |
|
| 147 | + if (!isset($this->listeners[$name])) { |
|
| 148 | 148 | return array(); |
| 149 | 149 | } |
| 150 | 150 | return $this->listeners[$name]; |
@@ -33,16 +33,16 @@ discard block |
||
| 33 | 33 | * @param mixed $subject subject to notify the listeners of |
| 34 | 34 | * @return void |
| 35 | 35 | */ |
| 36 | - protected static function doNotify(array $listeners, $subject){ |
|
| 37 | - foreach($listeners as $listener){ |
|
| 36 | + protected static function doNotify(array $listeners, $subject) { |
|
| 37 | + foreach ($listeners as $listener) { |
|
| 38 | 38 | self::doNotifyOne($listener, $subject); |
| 39 | 39 | } |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | - protected static function doNotifyOne($listener, $subject){ |
|
| 43 | - if(is_callable($listener)){ |
|
| 42 | + protected static function doNotifyOne($listener, $subject) { |
|
| 43 | + if (is_callable($listener)) { |
|
| 44 | 44 | $res = call_user_func($listener, $subject); |
| 45 | - }else{ |
|
| 45 | + }else { |
|
| 46 | 46 | $res = $listener->handle($subject); |
| 47 | 47 | } |
| 48 | 48 | return $res; |
@@ -58,9 +58,9 @@ discard block |
||
| 58 | 58 | * @param mixed $subject subject to notify the listeners of |
| 59 | 59 | * @return \PEIP\INF\Handler\Handler listener that returned a boolean true value |
| 60 | 60 | */ |
| 61 | - protected static function doNotifyUntil(array $listeners, $subject){ |
|
| 62 | - foreach ($listeners as $listener){ |
|
| 63 | - if (self::doNotifyOne($listener, $subject)){ |
|
| 61 | + protected static function doNotifyUntil(array $listeners, $subject) { |
|
| 62 | + foreach ($listeners as $listener) { |
|
| 63 | + if (self::doNotifyOne($listener, $subject)) { |
|
| 64 | 64 | return $listener; |
| 65 | 65 | } |
| 66 | 66 | } |
@@ -9,22 +9,22 @@ |
||
| 9 | 9 | protected $channel; |
| 10 | 10 | protected $handler; |
| 11 | 11 | |
| 12 | - public function __construct(\PEIP\ABS\Handler\MessageHandler $handler, $channel){ |
|
| 12 | + public function __construct(\PEIP\ABS\Handler\MessageHandler $handler, $channel) { |
|
| 13 | 13 | $this->channel = $channel; |
| 14 | 14 | $this->handler = $handler; |
| 15 | 15 | } |
| 16 | 16 | |
| 17 | - protected function getMessage($object){ |
|
| 18 | - if($this->channel instanceof \PEIP\INF\Channel\SubscribableChannel){ |
|
| 17 | + protected function getMessage($object) { |
|
| 18 | + if ($this->channel instanceof \PEIP\INF\Channel\SubscribableChannel) { |
|
| 19 | 19 | return $object; |
| 20 | - }else{ |
|
| 20 | + }else { |
|
| 21 | 21 | return $object->getContent()->receive(); |
| 22 | 22 | } |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | - public function handle($object){ |
|
| 25 | + public function handle($object) { |
|
| 26 | 26 | $message = $this->getMessage($object); |
| 27 | - if(!is_object($message)){ |
|
| 27 | + if (!is_object($message)) { |
|
| 28 | 28 | throw new \Exception('Could not get Message from Channel'); |
| 29 | 29 | } |
| 30 | 30 | $this->handler->handle($message); |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | * @param $name |
| 34 | 34 | * @return |
| 35 | 35 | */ |
| 36 | - public static function getInstance(){ |
|
| 36 | + public static function getInstance() { |
|
| 37 | 37 | return self::$instance ? self::$instance : self::$instance = new ChannelRegistry; |
| 38 | 38 | } |
| 39 | 39 | |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | * @param $channel |
| 44 | 44 | * @return |
| 45 | 45 | */ |
| 46 | - public function register($channel){ |
|
| 46 | + public function register($channel) { |
|
| 47 | 47 | $this->channels[$channel->getName()] = $channel; |
| 48 | 48 | } |
| 49 | 49 | |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | * @param $name |
| 56 | 56 | * @return |
| 57 | 57 | */ |
| 58 | - public function get($name){ |
|
| 58 | + public function get($name) { |
|
| 59 | 59 | return $this->channels[$name]; |
| 60 | 60 | } |
| 61 | 61 | |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | * @param $channelName |
| 66 | 66 | * @return |
| 67 | 67 | */ |
| 68 | - public function resolveChannelName($channelName){ |
|
| 68 | + public function resolveChannelName($channelName) { |
|
| 69 | 69 | return $this->get($channelName); |
| 70 | 70 | } |
| 71 | 71 | |
@@ -35,7 +35,7 @@ |
||
| 35 | 35 | * @param $message |
| 36 | 36 | * @return |
| 37 | 37 | */ |
| 38 | - protected function doSend(\PEIP\INF\Message\Message $message){ |
|
| 38 | + protected function doSend(\PEIP\INF\Message\Message $message) { |
|
| 39 | 39 | $this->doFireEvent('prePublish', array('MESSAGE'=>$message)); |
| 40 | 40 | $this->getMessageDispatcher()->notify($message); |
| 41 | 41 | $this->doFireEvent('postPublish', array('MESSAGE'=>$message)); |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | * @param $timeout |
| 37 | 37 | * @return boolean wether message was sent successfully |
| 38 | 38 | */ |
| 39 | - public function send(\PEIP\INF\Message\Message $message, $timeout = -1){ |
|
| 39 | + public function send(\PEIP\INF\Message\Message $message, $timeout = -1) { |
|
| 40 | 40 | return $this->doSend($message); |
| 41 | 41 | } |
| 42 | 42 | |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | * @param $message |
| 48 | 48 | * @return |
| 49 | 49 | */ |
| 50 | - protected function doSend(\PEIP\INF\Message\Message $message){ |
|
| 50 | + protected function doSend(\PEIP\INF\Message\Message $message) { |
|
| 51 | 51 | $this->getMessageDispatcher()->notify($message); |
| 52 | 52 | return true; |
| 53 | 53 | } |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | * @access public |
| 58 | 58 | * @return |
| 59 | 59 | */ |
| 60 | - public function getMessageDispatcher(){ |
|
| 60 | + public function getMessageDispatcher() { |
|
| 61 | 61 | return isset($this->dispatcher) ? $this->dispatcher : $this->dispatcher = new IteratingDispatcher; |
| 62 | 62 | } |
| 63 | 63 | |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | * @param $capacity |
| 38 | 38 | * @return |
| 39 | 39 | */ |
| 40 | - public function __construct($capacity = -1){ |
|
| 40 | + public function __construct($capacity = -1) { |
|
| 41 | 41 | $this->setCapacity((int)$capacity); |
| 42 | 42 | $this->queue = new SplQueue(); |
| 43 | 43 | } |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | * @access public |
| 48 | 48 | * @return |
| 49 | 49 | */ |
| 50 | - public function getMessageCount(){ |
|
| 50 | + public function getMessageCount() { |
|
| 51 | 51 | return count($this->messages); |
| 52 | 52 | } |
| 53 | 53 | |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | * @access public |
| 57 | 57 | * @return |
| 58 | 58 | */ |
| 59 | - public function getCapacity(){ |
|
| 59 | + public function getCapacity() { |
|
| 60 | 60 | return $this->capacity; |
| 61 | 61 | } |
| 62 | 62 | |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | * @param $capacity |
| 67 | 67 | * @return |
| 68 | 68 | */ |
| 69 | - public function setCapacity($capacity){ |
|
| 69 | + public function setCapacity($capacity) { |
|
| 70 | 70 | $this->capacity = $capacity; |
| 71 | 71 | } |
| 72 | 72 | |
@@ -76,10 +76,10 @@ discard block |
||
| 76 | 76 | * @param $message |
| 77 | 77 | * @return |
| 78 | 78 | */ |
| 79 | - protected function doSend(\PEIP\INF\Message\Message $message){ |
|
| 80 | - if($this->capacity < 1 || $this->getMessageCount() <= $this->getCapacity()){ |
|
| 79 | + protected function doSend(\PEIP\INF\Message\Message $message) { |
|
| 80 | + if ($this->capacity < 1 || $this->getMessageCount() <= $this->getCapacity()) { |
|
| 81 | 81 | $this->queue->enqueque($message); |
| 82 | - }else{ |
|
| 82 | + }else { |
|
| 83 | 83 | throw new \Exception('Not implemented yet.'); |
| 84 | 84 | } |
| 85 | 85 | } |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | * @param \PEIP\INF\Message\Message $message the message to send |
| 42 | 42 | * @return |
| 43 | 43 | */ |
| 44 | - protected function doSend(\PEIP\INF\Message\Message $message){ |
|
| 44 | + protected function doSend(\PEIP\INF\Message\Message $message) { |
|
| 45 | 45 | $this->messages[] = $message; |
| 46 | 46 | return true; |
| 47 | 47 | } |
@@ -55,18 +55,18 @@ discard block |
||
| 55 | 55 | * @param integer $timeout timout for receiving a message |
| 56 | 56 | * @return |
| 57 | 57 | */ |
| 58 | - public function receive($timeout = 0){ |
|
| 58 | + public function receive($timeout = 0) { |
|
| 59 | 59 | $this->doFireEvent(self::EVENT_PRE_RECEIVE); |
| 60 | 60 | $message = NULL; |
| 61 | - if($timeout == 0){ |
|
| 61 | + if ($timeout == 0) { |
|
| 62 | 62 | $message = $this->getMessage(); |
| 63 | - }elseif($timeout < 0){ |
|
| 64 | - while(!$message = $this->getMessage()){ |
|
| 63 | + }elseif ($timeout < 0) { |
|
| 64 | + while (!$message = $this->getMessage()) { |
|
| 65 | 65 | |
| 66 | 66 | } |
| 67 | - }else{ |
|
| 67 | + }else { |
|
| 68 | 68 | $time = time() + $timeout; |
| 69 | - while(($time > time()) && !$message = $this->getMessage()){ |
|
| 69 | + while (($time > time()) && !$message = $this->getMessage()) { |
|
| 70 | 70 | |
| 71 | 71 | } |
| 72 | 72 | } |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | * @access protected |
| 85 | 85 | * @return \PEIP\INF\Message\Message message from top of the message stack |
| 86 | 86 | */ |
| 87 | - protected function getMessage(){ |
|
| 87 | + protected function getMessage() { |
|
| 88 | 88 | return array_shift($this->messages); |
| 89 | 89 | } |
| 90 | 90 | |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | * @access public |
| 95 | 95 | * @return |
| 96 | 96 | */ |
| 97 | - public function clear(){ |
|
| 97 | + public function clear() { |
|
| 98 | 98 | $this->messages = array(); |
| 99 | 99 | } |
| 100 | 100 | |
@@ -105,9 +105,9 @@ discard block |
||
| 105 | 105 | * @param \PEIP\INF\Message\Message_Selector $selector the selector to accept messages |
| 106 | 106 | * @return array accepted messages |
| 107 | 107 | */ |
| 108 | - public function purge(\PEIP\INF\Selector\MessageSelector $selector){ |
|
| 109 | - foreach($this->messages as $key=>$message){ |
|
| 110 | - if(!$selector->acceptMessage($message)){ |
|
| 108 | + public function purge(\PEIP\INF\Selector\MessageSelector $selector) { |
|
| 109 | + foreach ($this->messages as $key=>$message) { |
|
| 110 | + if (!$selector->acceptMessage($message)) { |
|
| 111 | 111 | unset($this->messages[$key]); |
| 112 | 112 | } |
| 113 | 113 | } |