@@ -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 | } |
@@ -37,10 +37,10 @@ discard block |
||
| 37 | 37 | * @param $priorityHeader |
| 38 | 38 | * @return |
| 39 | 39 | */ |
| 40 | - public function __construct($capacity = -1, $priorityHeader = NULL){ |
|
| 40 | + public function __construct($capacity = -1, $priorityHeader = NULL) { |
|
| 41 | 41 | $this->setCapacity((int)$capacity); |
| 42 | 42 | $this->queue = new SplPriorityQueue(); |
| 43 | - if($priorityHeader){ |
|
| 43 | + if ($priorityHeader) { |
|
| 44 | 44 | $this->priorityHeader = $priorityHeader; |
| 45 | 45 | } |
| 46 | 46 | } |
@@ -51,10 +51,10 @@ discard block |
||
| 51 | 51 | * @param $message |
| 52 | 52 | * @return |
| 53 | 53 | */ |
| 54 | - protected function doSend(\PEIP\INF\Message\Message $message){ |
|
| 55 | - if($this->capacity < 1 || $this->getMessageCount() <= $this->getCapacity()){ |
|
| 54 | + protected function doSend(\PEIP\INF\Message\Message $message) { |
|
| 55 | + if ($this->capacity < 1 || $this->getMessageCount() <= $this->getCapacity()) { |
|
| 56 | 56 | $this->queue->insert($message, $message->getHeader($this->priorityHeader)); |
| 57 | - }else{ |
|
| 57 | + }else { |
|
| 58 | 58 | throw new \Exception('Not implemented yet.'); |
| 59 | 59 | } |
| 60 | 60 | } |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | * @access public |
| 29 | 29 | * @return |
| 30 | 30 | */ |
| 31 | - public function getName(){ |
|
| 31 | + public function getName() { |
|
| 32 | 32 | |
| 33 | 33 | } |
| 34 | 34 | |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | * @param $timeout |
| 41 | 41 | * @return |
| 42 | 42 | */ |
| 43 | - public function send(\PEIP\INF\Message\Message $message, $timeout = -1){ |
|
| 43 | + public function send(\PEIP\INF\Message\Message $message, $timeout = -1) { |
|
| 44 | 44 | |
| 45 | 45 | } |
| 46 | 46 | |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | * @param $name |
| 61 | 61 | * @return |
| 62 | 62 | */ |
| 63 | - public function setName($name){ |
|
| 63 | + public function setName($name) { |
|
| 64 | 64 | $this->name = $name; |
| 65 | 65 | } |
| 66 | 66 | |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | * @access public |
| 70 | 70 | * @return |
| 71 | 71 | */ |
| 72 | - public function getName(){ |
|
| 72 | + public function getName() { |
|
| 73 | 73 | return $this->name; |
| 74 | 74 | } |
| 75 | 75 | |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | * @param $timeout |
| 81 | 81 | * @return |
| 82 | 82 | */ |
| 83 | - public function send(\PEIP\INF\Message\Message $message, $timeout = -1){ |
|
| 83 | + public function send(\PEIP\INF\Message\Message $message, $timeout = -1) { |
|
| 84 | 84 | return $this->handle($message); |
| 85 | 85 | } |
| 86 | 86 | |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | * @param $message |
| 91 | 91 | * @return |
| 92 | 92 | */ |
| 93 | - protected function doSend(\PEIP\INF\Message\Message $message){ |
|
| 93 | + protected function doSend(\PEIP\INF\Message\Message $message) { |
|
| 94 | 94 | $this->doFireEvent(self::EVENT_PRE_PUBLISH, array(self::HEADER_MESSAGE=>$message)); |
| 95 | 95 | $this->getMessageDispatcher()->notify($message); |
| 96 | 96 | $this->doFireEvent(self::EVENT_POST_PUBLISH, array(self::HEADER_MESSAGE=>$message)); |
@@ -103,12 +103,12 @@ discard block |
||
| 103 | 103 | * @param $content |
| 104 | 104 | * @return |
| 105 | 105 | */ |
| 106 | - protected function replyMessage($message){ |
|
| 106 | + protected function replyMessage($message) { |
|
| 107 | 107 | $message = $this->ensureMessage($message); |
| 108 | 108 | //if(\PEIP\Util\Test::assertMessage($message)){ |
| 109 | - if($this->getOutputChannel()){ |
|
| 109 | + if ($this->getOutputChannel()) { |
|
| 110 | 110 | $this->getOutputChannel()->send($message); |
| 111 | - }else{ |
|
| 111 | + }else { |
|
| 112 | 112 | $this->doSend($message); |
| 113 | 113 | } |
| 114 | 114 | //} |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | * @param $message |
| 121 | 121 | * @return |
| 122 | 122 | */ |
| 123 | - protected function doReply(\PEIP\INF\Message\Message $message){ |
|
| 123 | + protected function doReply(\PEIP\INF\Message\Message $message) { |
|
| 124 | 124 | $this->replyMessage($message); |
| 125 | 125 | } |
| 126 | 126 | |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | * @param $handler |
| 131 | 131 | * @return |
| 132 | 132 | */ |
| 133 | - public function subscribe($handler){ |
|
| 133 | + public function subscribe($handler) { |
|
| 134 | 134 | Test::ensureHandler($handler); |
| 135 | 135 | $this->getMessageDispatcher()->connect($handler); |
| 136 | 136 | $this->doFireEvent(self::EVENT_SUBSCRIBE, array(self::HEADER_SUBSCRIBER=>$handler)); |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | * @param $handler e |
| 143 | 143 | * @return |
| 144 | 144 | */ |
| 145 | - public function unsubscribe($handler){ |
|
| 145 | + public function unsubscribe($handler) { |
|
| 146 | 146 | Test::ensureHandler($handler); |
| 147 | 147 | $this->getMessageDispatcher()->disconnect($handler); |
| 148 | 148 | $this->doFireEvent( |
@@ -160,9 +160,9 @@ discard block |
||
| 160 | 160 | * @param $transferListeners |
| 161 | 161 | * @return |
| 162 | 162 | */ |
| 163 | - public function setMessageDispatcher(\PEIP\INF\Dispatcher\Dispatcher $dispatcher, $transferListeners = true){ |
|
| 164 | - if(isset($this->dispatcher) && $transferListeners){ |
|
| 165 | - foreach($this->dispatcher->getListeners() as $listener){ |
|
| 163 | + public function setMessageDispatcher(\PEIP\INF\Dispatcher\Dispatcher $dispatcher, $transferListeners = true) { |
|
| 164 | + if (isset($this->dispatcher) && $transferListeners) { |
|
| 165 | + foreach ($this->dispatcher->getListeners() as $listener) { |
|
| 166 | 166 | $dispatcher->connect($listener); |
| 167 | 167 | $this->dispatcher->disconnect($listener); |
| 168 | 168 | } |
@@ -176,7 +176,7 @@ discard block |
||
| 176 | 176 | * @access public |
| 177 | 177 | * @return |
| 178 | 178 | */ |
| 179 | - public function getMessageDispatcher(){ |
|
| 179 | + public function getMessageDispatcher() { |
|
| 180 | 180 | $defaultDispatcher = self::DEFAULT_CLASS_MESSAGE_DISPATCHER; |
| 181 | 181 | return isset($this->dispatcher) ? $this->dispatcher : $this->dispatcher = new $defaultDispatcher; |
| 182 | 182 | } |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | * @param $callable |
| 189 | 189 | * @return |
| 190 | 190 | */ |
| 191 | - protected function registerCommand($commandName, $callable){ |
|
| 191 | + protected function registerCommand($commandName, $callable) { |
|
| 192 | 192 | $this->commands[$commandName] = $callable; |
| 193 | 193 | } |
| 194 | 194 | |
@@ -198,10 +198,10 @@ discard block |
||
| 198 | 198 | * @param $cmdMessage |
| 199 | 199 | * @return |
| 200 | 200 | */ |
| 201 | - public function command(\PEIP\INF\Message\Message $cmdMessage){ |
|
| 201 | + public function command(\PEIP\INF\Message\Message $cmdMessage) { |
|
| 202 | 202 | $this->doFireEvent(self::EVENT_PRE_COMMAND, array(self::HEADER_MESSAGE=>$cmdMessage)); |
| 203 | 203 | $commandName = trim((string)$cmdMessage->getHeader('COMMAND')); |
| 204 | - if($commandName != '' && array_key_exists($commandName, $this->commands)){ |
|
| 204 | + if ($commandName != '' && array_key_exists($commandName, $this->commands)) { |
|
| 205 | 205 | call_user_func($this->commands[$commandName], $cmdMessage->getContent()); |
| 206 | 206 | } |
| 207 | 207 | $this->doFireEvent(self::EVENT_POST_COMMAND, array(self::HEADER_MESSAGE=>$cmdMessage)); |
@@ -31,10 +31,10 @@ discard block |
||
| 31 | 31 | * @param $inputChannel |
| 32 | 32 | * @return |
| 33 | 33 | */ |
| 34 | - public function setInputChannel(\PEIP\INF\Channel\Channel $inputChannel){ |
|
| 35 | - if(isset($this->eventName)){ |
|
| 34 | + public function setInputChannel(\PEIP\INF\Channel\Channel $inputChannel) { |
|
| 35 | + if (isset($this->eventName)) { |
|
| 36 | 36 | $this->connectChannel($inputChannel); |
| 37 | - }else{ |
|
| 37 | + }else { |
|
| 38 | 38 | $this->inputChannel = $inputChannel; |
| 39 | 39 | } |
| 40 | 40 | } |
@@ -45,10 +45,10 @@ discard block |
||
| 45 | 45 | * @param $eventName |
| 46 | 46 | * @return |
| 47 | 47 | */ |
| 48 | - public function setEventName($eventName){ |
|
| 49 | - if(!isset($this->eventName)){ |
|
| 48 | + public function setEventName($eventName) { |
|
| 49 | + if (!isset($this->eventName)) { |
|
| 50 | 50 | $this->eventName = $eventName; |
| 51 | - if($this->inputChannel){ |
|
| 51 | + if ($this->inputChannel) { |
|
| 52 | 52 | $this->inputChannel->connect($this->eventName, $this); |
| 53 | 53 | } |
| 54 | 54 | } |
@@ -33,7 +33,7 @@ |
||
| 33 | 33 | * @param $outputChannel |
| 34 | 34 | * @return |
| 35 | 35 | */ |
| 36 | - public function __construct($eventName, \PEIP\INF\Channel\Channel $inputChannel, \PEIP\INF\Channel\Channel $outputChannel){ |
|
| 36 | + public function __construct($eventName, \PEIP\INF\Channel\Channel $inputChannel, \PEIP\INF\Channel\Channel $outputChannel) { |
|
| 37 | 37 | $this->setEventName($eventName); |
| 38 | 38 | $this->setInputChannel($inputChannel); |
| 39 | 39 | $this->setOutputChannel($outputChannel); |
@@ -34,7 +34,7 @@ |
||
| 34 | 34 | * @param $content |
| 35 | 35 | * @return |
| 36 | 36 | */ |
| 37 | - protected function replyMessage($content){ |
|
| 37 | + protected function replyMessage($content) { |
|
| 38 | 38 | $message = $this->ensureMessage($content); |
| 39 | 39 | $this->getOutputChannel()->command($message); |
| 40 | 40 | } |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | protected |
| 30 | 30 | $eventName; |
| 31 | 31 | |
| 32 | - public function connectChannel(\PEIP\INF\Channel\Channel $inputChannel){ |
|
| 32 | + public function connectChannel(\PEIP\INF\Channel\Channel $inputChannel) { |
|
| 33 | 33 | $this->inputChannel = $inputChannel; |
| 34 | 34 | |
| 35 | 35 | } |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | * @param \PEIP\INF\Channel\Channel $inputChannel the input-channel to listen for events. |
| 45 | 45 | * @return |
| 46 | 46 | */ |
| 47 | - public function setInputChannel(\PEIP\INF\Channel\Channel $inputChannel){ |
|
| 47 | + public function setInputChannel(\PEIP\INF\Channel\Channel $inputChannel) { |
|
| 48 | 48 | $this->connectChannel($inputChannel); |
| 49 | 49 | } |
| 50 | 50 | |
@@ -60,9 +60,9 @@ discard block |
||
| 60 | 60 | * @access protected |
| 61 | 61 | * @param \PEIP\INF\Message\Message $message the message to reply with |
| 62 | 62 | */ |
| 63 | - protected function doReply(\PEIP\INF\Message\Message $message){ |
|
| 63 | + protected function doReply(\PEIP\INF\Message\Message $message) { |
|
| 64 | 64 | $headerMessage = $message->getHeader('MESSAGE'); |
| 65 | - if($headerMessage instanceof \PEIP\INF\Message\Message){ |
|
| 65 | + if ($headerMessage instanceof \PEIP\INF\Message\Message) { |
|
| 66 | 66 | return $this->replyMessage($headerMessage); |
| 67 | 67 | } |
| 68 | 68 | } |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | * @param \PEIP\INF\Event\Connectable $connectable the connectable to listen to |
| 76 | 76 | * @return |
| 77 | 77 | */ |
| 78 | - public function listen(\PEIP\INF\Event\Connectable $connectable){ |
|
| 78 | + public function listen(\PEIP\INF\Event\Connectable $connectable) { |
|
| 79 | 79 | return $this->doListen($this->eventName, $connectable); |
| 80 | 80 | } |
| 81 | 81 | |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | * @param \PEIP\INF\Event\Connectable $connectable the connectable to unlisten |
| 88 | 88 | * @return |
| 89 | 89 | */ |
| 90 | - public function unlisten(\PEIP\INF\Event\Connectable $connectable){ |
|
| 90 | + public function unlisten(\PEIP\INF\Event\Connectable $connectable) { |
|
| 91 | 91 | return $this->doUnlisten($this->eventName, $connectable); |
| 92 | 92 | } |
| 93 | 93 | |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | * @access public |
| 98 | 98 | * @return array array of \PEIP\INF\Event\Connectable instances |
| 99 | 99 | */ |
| 100 | - public function getConnected(){ |
|
| 100 | + public function getConnected() { |
|
| 101 | 101 | return $this->doGetConnected(); |
| 102 | 102 | } |
| 103 | 103 | |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | * @param \PEIP\INF\Channel\Channel $channel \PEIP\INF\Channel\Channel instance to disconnect from |
| 109 | 109 | * @return |
| 110 | 110 | */ |
| 111 | - public function disconnectChannel(\PEIP\INF\Channel\Channel $channel){ |
|
| 111 | + public function disconnectChannel(\PEIP\INF\Channel\Channel $channel) { |
|
| 112 | 112 | $this->disconnectInputChannel(); |
| 113 | 113 | $this->inputChannel = $channel; |
| 114 | 114 | $this->connectInputChannel(); |
@@ -121,8 +121,8 @@ discard block |
||
| 121 | 121 | * @access protected |
| 122 | 122 | * @return |
| 123 | 123 | */ |
| 124 | - protected function connectInputChannel(){ |
|
| 125 | - if($this->inputChannel && $this->eventName){ |
|
| 124 | + protected function connectInputChannel() { |
|
| 125 | + if ($this->inputChannel && $this->eventName) { |
|
| 126 | 126 | $this->inputChannel->connect($this->eventName, $this); |
| 127 | 127 | } |
| 128 | 128 | } |
@@ -134,8 +134,8 @@ discard block |
||
| 134 | 134 | * @access protected |
| 135 | 135 | * @return |
| 136 | 136 | */ |
| 137 | - protected function disconnectInputChannel(){ |
|
| 138 | - if($this->inputChannel && $this->eventName){ |
|
| 137 | + protected function disconnectInputChannel() { |
|
| 138 | + if ($this->inputChannel && $this->eventName) { |
|
| 139 | 139 | $this->inputChannel->disconnect($this->eventName, $this); |
| 140 | 140 | } |
| 141 | 141 | } |
@@ -147,7 +147,7 @@ discard block |
||
| 147 | 147 | * @param $eventName |
| 148 | 148 | * @return |
| 149 | 149 | */ |
| 150 | - public function setEventName($eventName){ |
|
| 150 | + public function setEventName($eventName) { |
|
| 151 | 151 | $this->disconnectInputChannel(); |
| 152 | 152 | $this->eventName = $eventName; |
| 153 | 153 | $this->connectInputChannel(); |