@@ -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 |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | * @param $title |
| 35 | 35 | * @return |
| 36 | 36 | */ |
| 37 | - public function __construct($content, $title){
|
|
| 37 | + public function __construct($content, $title) {
|
|
| 38 | 38 | $this->setContent((string)$content); |
| 39 | 39 | } |
| 40 | 40 | |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | * @param $title |
| 45 | 45 | * @return |
| 46 | 46 | */ |
| 47 | - public function setTitle($title){
|
|
| 47 | + public function setTitle($title) {
|
|
| 48 | 48 | $this->title = (string)$title; |
| 49 | 49 | } |
| 50 | 50 | |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | * @access public |
| 54 | 54 | * @return |
| 55 | 55 | */ |
| 56 | - public function getTitle(){
|
|
| 56 | + public function getTitle() {
|
|
| 57 | 57 | return $this->title; |
| 58 | 58 | } |
| 59 | 59 | |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | * @param string $name the name of the header |
| 68 | 68 | * @return boolean wether the header is set |
| 69 | 69 | */ |
| 70 | - public static function build(array $arguments = array()){
|
|
| 70 | + public static function build(array $arguments = array()) {
|
|
| 71 | 71 | return GenericBuilder::getInstance('\PEIP\Message\StringMessage')->build($arguments);
|
| 72 | 72 | } |
| 73 | 73 | |
@@ -36,7 +36,7 @@ |
||
| 36 | 36 | * @param $headers |
| 37 | 37 | * @return |
| 38 | 38 | */ |
| 39 | - public function __construct(\Exception $payload, array $headers = array()){
|
|
| 39 | + public function __construct(\Exception $payload, array $headers = array()) {
|
|
| 40 | 40 | $this->payload = $payload; |
| 41 | 41 | $this->headers = $headers; |
| 42 | 42 | } |
@@ -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 | } |
@@ -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 | } |
@@ -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 | |
@@ -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 | } |
@@ -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 | |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | * @param $timeout |
| 37 | 37 | * @return |
| 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 | |
| 41 | 41 | $sent = $this->doSend($message); |
| 42 | 42 | |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | * @param $message |
| 50 | 50 | * @return |
| 51 | 51 | */ |
| 52 | - protected function doSend(\PEIP\INF\Message\Message $message){
|
|
| 52 | + protected function doSend(\PEIP\INF\Message\Message $message) {
|
|
| 53 | 53 | $this->getMessageDispatcher()->notify($message); |
| 54 | 54 | return true; |
| 55 | 55 | } |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | * @access public |
| 60 | 60 | * @return |
| 61 | 61 | */ |
| 62 | - public function getMessageDispatcher(){
|
|
| 62 | + public function getMessageDispatcher() {
|
|
| 63 | 63 | return isset($this->dispatcher) ? $this->dispatcher : $this->dispatcher = new IteratingDispatcher; |
| 64 | 64 | } |
| 65 | 65 | |