@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | * @param $type |
| 48 | 48 | * @return |
| 49 | 49 | */ |
| 50 | - public function __construct($type){
|
|
| 50 | + public function __construct($type) {
|
|
| 51 | 51 | $this->type = $type; |
| 52 | 52 | } |
| 53 | 53 | |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | * @param $message |
| 58 | 58 | * @return |
| 59 | 59 | */ |
| 60 | - public function acceptMessage(\PEIP\INF\Message\Message $message){
|
|
| 60 | + public function acceptMessage(\PEIP\INF\Message\Message $message) {
|
|
| 61 | 61 | return call_user_func(self::$types[$this->type], $message->getContent()); |
| 62 | 62 | } |
| 63 | 63 | |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | * @param $discardChannel |
| 34 | 34 | * @return |
| 35 | 35 | */ |
| 36 | - public function setDiscardChannel(\PEIP\INF\Channel\Channel $discardChannel){
|
|
| 36 | + public function setDiscardChannel(\PEIP\INF\Channel\Channel $discardChannel) {
|
|
| 37 | 37 | $this->discardChannel = $discardChannel; |
| 38 | 38 | } |
| 39 | 39 | |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | * @access public |
| 43 | 43 | * @return |
| 44 | 44 | */ |
| 45 | - public function getDiscardChannel(){
|
|
| 45 | + public function getDiscardChannel() {
|
|
| 46 | 46 | return $this->discardChannel; |
| 47 | 47 | } |
| 48 | 48 | |
@@ -52,8 +52,8 @@ discard block |
||
| 52 | 52 | * @param $message |
| 53 | 53 | * @return |
| 54 | 54 | */ |
| 55 | - protected function discardMessage(\PEIP\INF\Message\Message $message){
|
|
| 56 | - if(isset($this->discardChannel)){
|
|
| 55 | + protected function discardMessage(\PEIP\INF\Message\Message $message) {
|
|
| 56 | + if (isset($this->discardChannel)) {
|
|
| 57 | 57 | $this->discardChannel->send($message); |
| 58 | 58 | } |
| 59 | 59 | } |
@@ -38,12 +38,12 @@ discard block |
||
| 38 | 38 | * @param \PEIP\INF\Message\Message $message message to handle/reply for |
| 39 | 39 | * @return |
| 40 | 40 | */ |
| 41 | - public function doReply(\PEIP\INF\Message\Message $message){
|
|
| 41 | + public function doReply(\PEIP\INF\Message\Message $message) {
|
|
| 42 | 42 | $res = $this->callService($message); |
| 43 | 43 | $out = (bool)$message->hasHeader('REPLY_CHANNEL')
|
| 44 | 44 | ? $message->getHeader('REPLY_CHANNEL')
|
| 45 | 45 | : $this->outputChannel; |
| 46 | - if($out){
|
|
| 46 | + if ($out) {
|
|
| 47 | 47 | $this->replyMessage($res, $res); |
| 48 | 48 | } |
| 49 | 49 | } |
@@ -56,12 +56,12 @@ discard block |
||
| 56 | 56 | * @param \PEIP\INF\Message\Message $message message to call the service with it�s content/payload |
| 57 | 57 | * @return mixed result of calling the registered service callable with message content/payload |
| 58 | 58 | */ |
| 59 | - protected function callService(\PEIP\INF\Message\Message $message){
|
|
| 59 | + protected function callService(\PEIP\INF\Message\Message $message) {
|
|
| 60 | 60 | $res = NULL; |
| 61 | - if(is_callable($this->serviceCallable)){
|
|
| 61 | + if (is_callable($this->serviceCallable)) {
|
|
| 62 | 62 | $res = call_user_func($this->serviceCallable, $message->getContent()); |
| 63 | - }else{
|
|
| 64 | - if(is_object($this->serviceCallable) && method_exists($this->serviceCallable, 'handle')){
|
|
| 63 | + }else {
|
|
| 64 | + if (is_object($this->serviceCallable) && method_exists($this->serviceCallable, 'handle')) {
|
|
| 65 | 65 | $res = $this->serviceCallable->handle($message->getContent()); |
| 66 | 66 | } |
| 67 | 67 | } |
@@ -22,43 +22,43 @@ discard block |
||
| 22 | 22 | |
| 23 | 23 | class XMLArrayTranslator {
|
| 24 | 24 | |
| 25 | - public static function translate($content){
|
|
| 25 | + public static function translate($content) {
|
|
| 26 | 26 | $array = array(); |
| 27 | 27 | try {
|
| 28 | 28 | $node = simplexml_load_string($content); |
| 29 | 29 | // fix for hhvm |
| 30 | - if(!($node instanceof \SimpleXMLElement)){
|
|
| 30 | + if (!($node instanceof \SimpleXMLElement)) {
|
|
| 31 | 31 | throw new \Exception('loading XML failed');
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | } |
| 35 | - catch(\Exception $e){
|
|
| 35 | + catch (\Exception $e) {
|
|
| 36 | 36 | return false; |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | return self::doTranslate($node); |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | - protected static function doTranslate(\SimpleXMLElement $node){
|
|
| 42 | + protected static function doTranslate(\SimpleXMLElement $node) {
|
|
| 43 | 43 | |
| 44 | 44 | $array = array(); |
| 45 | 45 | $array['type'] = $node['type'] |
| 46 | 46 | ? (string)$node['type'] |
| 47 | 47 | : (string)$node->getName(); |
| 48 | 48 | $value = (string)$node; |
| 49 | - if($value != ''){
|
|
| 49 | + if ($value != '') {
|
|
| 50 | 50 | $array['value'] = $value; |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | - foreach($node->attributes() as $name=>$value){
|
|
| 53 | + foreach ($node->attributes() as $name=>$value) {
|
|
| 54 | 54 | $array[$name] = (string)$value; |
| 55 | 55 | } |
| 56 | - foreach($node->children() as $nr=>$child){
|
|
| 56 | + foreach ($node->children() as $nr=>$child) {
|
|
| 57 | 57 | $name = $child->getName(); |
| 58 | 58 | $res = self::doTranslate($child); |
| 59 | 59 | |
| 60 | - if(isset($array[$name])){
|
|
| 61 | - if(is_string($array[$name])){
|
|
| 60 | + if (isset($array[$name])) {
|
|
| 61 | + if (is_string($array[$name])) {
|
|
| 62 | 62 | $array[$name] = array( |
| 63 | 63 | array( |
| 64 | 64 | 'type'=>$name, |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | ) |
| 67 | 67 | ); |
| 68 | 68 | } |
| 69 | - }else{
|
|
| 69 | + }else {
|
|
| 70 | 70 | $array[$name] = array(); |
| 71 | 71 | } |
| 72 | 72 | $array[$name][] = $res; |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | * @param $name |
| 65 | 65 | * @return |
| 66 | 66 | */ |
| 67 | - public function setName($name){
|
|
| 67 | + public function setName($name) {
|
|
| 68 | 68 | $this->name = $name; |
| 69 | 69 | } |
| 70 | 70 | |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | * @access public |
| 74 | 74 | * @return |
| 75 | 75 | */ |
| 76 | - public function getName(){
|
|
| 76 | + public function getName() {
|
|
| 77 | 77 | return $this->name; |
| 78 | 78 | } |
| 79 | 79 | |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | * @param $timeout |
| 85 | 85 | * @return |
| 86 | 86 | */ |
| 87 | - public function send(\PEIP\INF\Message\Message $message, $timeout = -1){
|
|
| 87 | + public function send(\PEIP\INF\Message\Message $message, $timeout = -1) {
|
|
| 88 | 88 | return $this->handle($message); |
| 89 | 89 | } |
| 90 | 90 | |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | * @param $message |
| 95 | 95 | * @return |
| 96 | 96 | */ |
| 97 | - protected function doSend(\PEIP\INF\Message\Message $message){
|
|
| 97 | + protected function doSend(\PEIP\INF\Message\Message $message) {
|
|
| 98 | 98 | $this->doFireEvent(self::EVENT_PRE_PUBLISH, array(self::HEADER_MESSAGE=>$message)); |
| 99 | 99 | $this->getMessageDispatcher()->notify($message); |
| 100 | 100 | $this->doFireEvent(self::EVENT_POST_PUBLISH, array(self::HEADER_MESSAGE=>$message)); |
@@ -107,12 +107,12 @@ discard block |
||
| 107 | 107 | * @param $content |
| 108 | 108 | * @return |
| 109 | 109 | */ |
| 110 | - protected function replyMessage($message){
|
|
| 110 | + protected function replyMessage($message) {
|
|
| 111 | 111 | $message = $this->ensureMessage($message); |
| 112 | 112 | //if(\PEIP\Util\Test::assertMessage($message)){
|
| 113 | - if($this->getOutputChannel()){
|
|
| 113 | + if ($this->getOutputChannel()) {
|
|
| 114 | 114 | $this->getOutputChannel()->send($message); |
| 115 | - }else{
|
|
| 115 | + }else {
|
|
| 116 | 116 | $this->doSend($message); |
| 117 | 117 | } |
| 118 | 118 | //} |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | * @param $message |
| 125 | 125 | * @return |
| 126 | 126 | */ |
| 127 | - protected function doReply(\PEIP\INF\Message\Message $message){
|
|
| 127 | + protected function doReply(\PEIP\INF\Message\Message $message) {
|
|
| 128 | 128 | $this->replyMessage($message); |
| 129 | 129 | } |
| 130 | 130 | |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | * @param $handler |
| 135 | 135 | * @return |
| 136 | 136 | */ |
| 137 | - public function subscribe($handler){
|
|
| 137 | + public function subscribe($handler) {
|
|
| 138 | 138 | Test::ensureHandler($handler); |
| 139 | 139 | $this->getMessageDispatcher()->connect($handler); |
| 140 | 140 | $this->doFireEvent(self::EVENT_SUBSCRIBE, array(self::HEADER_SUBSCRIBER=>$handler)); |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | * @param $handler e |
| 147 | 147 | * @return |
| 148 | 148 | */ |
| 149 | - public function unsubscribe($handler){
|
|
| 149 | + public function unsubscribe($handler) {
|
|
| 150 | 150 | Test::ensureHandler($handler); |
| 151 | 151 | $this->getMessageDispatcher()->disconnect($handler); |
| 152 | 152 | $this->doFireEvent( |
@@ -164,9 +164,9 @@ discard block |
||
| 164 | 164 | * @param $transferListeners |
| 165 | 165 | * @return |
| 166 | 166 | */ |
| 167 | - public function setMessageDispatcher(\PEIP\INF\Dispatcher\Dispatcher $dispatcher, $transferListeners = true){
|
|
| 168 | - if(isset($this->dispatcher) && $transferListeners){
|
|
| 169 | - foreach($this->dispatcher->getListeners() as $listener){
|
|
| 167 | + public function setMessageDispatcher(\PEIP\INF\Dispatcher\Dispatcher $dispatcher, $transferListeners = true) {
|
|
| 168 | + if (isset($this->dispatcher) && $transferListeners) {
|
|
| 169 | + foreach ($this->dispatcher->getListeners() as $listener) {
|
|
| 170 | 170 | $dispatcher->connect($listener); |
| 171 | 171 | $this->dispatcher->disconnect($listener); |
| 172 | 172 | } |
@@ -180,7 +180,7 @@ discard block |
||
| 180 | 180 | * @access public |
| 181 | 181 | * @return |
| 182 | 182 | */ |
| 183 | - public function getMessageDispatcher(){
|
|
| 183 | + public function getMessageDispatcher() {
|
|
| 184 | 184 | $defaultDispatcher = self::DEFAULT_CLASS_MESSAGE_DISPATCHER; |
| 185 | 185 | return isset($this->dispatcher) ? $this->dispatcher : $this->dispatcher = new $defaultDispatcher; |
| 186 | 186 | } |
@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | * @param $callable |
| 193 | 193 | * @return |
| 194 | 194 | */ |
| 195 | - protected function registerCommand($commandName, $callable){
|
|
| 195 | + protected function registerCommand($commandName, $callable) {
|
|
| 196 | 196 | $this->commands[$commandName] = $callable; |
| 197 | 197 | } |
| 198 | 198 | |
@@ -202,10 +202,10 @@ discard block |
||
| 202 | 202 | * @param $cmdMessage |
| 203 | 203 | * @return |
| 204 | 204 | */ |
| 205 | - public function command(\PEIP\INF\Message\Message $cmdMessage){
|
|
| 205 | + public function command(\PEIP\INF\Message\Message $cmdMessage) {
|
|
| 206 | 206 | $this->doFireEvent(self::EVENT_PRE_COMMAND, array(self::HEADER_MESSAGE=>$cmdMessage)); |
| 207 | 207 | $commandName = trim((string)$cmdMessage->getHeader('COMMAND'));
|
| 208 | - if($commandName != '' && array_key_exists($commandName, $this->commands)){
|
|
| 208 | + if ($commandName != '' && array_key_exists($commandName, $this->commands)) {
|
|
| 209 | 209 | call_user_func($this->commands[$commandName], $cmdMessage->getContent()); |
| 210 | 210 | } |
| 211 | 211 | $this->doFireEvent(self::EVENT_POST_COMMAND, array(self::HEADER_MESSAGE=>$cmdMessage)); |
@@ -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 = isset($config["class"]) ? trim((string)$config["class"]) : (string)$defaultClass; |
| 49 | - if($cls != ''){
|
|
| 49 | + if ($cls != '') {
|
|
| 50 | 50 | try {
|
| 51 | - $constructor = isset($config["constructor"])?(string)$config["constructor"]:""; |
|
| 52 | - if($constructor != '' && Test::assertMethod($cls, $constructor)){
|
|
| 51 | + $constructor = isset($config["constructor"]) ? (string)$config["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 = ""){
|
|
| 130 | - if((isset($config["class"]) && "" != (string)$config["class"]) || $defaultClass !== ""){
|
|
| 129 | + public static function buildAndModify($config, $arguments, $defaultClass = "") {
|
|
| 130 | + if ((isset($config["class"]) && "" != (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(isset($config["ref_property"])){
|
|
| 135 | + if (isset($config["ref_property"])) {
|
|
| 136 | 136 | $service = $service->{(string)$config["ref_property"]};
|
| 137 | - }elseif(isset($config["ref_method"])){
|
|
| 137 | + }elseif (isset($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,30 +166,30 @@ 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 | $config = is_array($config) ? new \ArrayObject($config) : $config; |
| 171 | 171 | $reflection = GenericBuilder::getInstance(get_class($service))->getReflectionClass(); |
| 172 | 172 | // set instance properties |
| 173 | - if(isset($config->property)){
|
|
| 174 | - foreach($config->property as $property){
|
|
| 173 | + if (isset($config->property)) {
|
|
| 174 | + foreach ($config->property as $property) {
|
|
| 175 | 175 | $arg = self::buildArg($property); |
| 176 | - if($arg){
|
|
| 176 | + if ($arg) {
|
|
| 177 | 177 | $setter = self::getSetter($property); |
| 178 | - if($setter && self::hasPublicProperty($service, 'Method', $setter)){
|
|
| 178 | + if ($setter && self::hasPublicProperty($service, 'Method', $setter)) {
|
|
| 179 | 179 | $service->{$setter}($arg);
|
| 180 | - }elseif(in_array($property, self::hasPublicProperty($service, 'Property', $setter))){
|
|
| 180 | + }elseif (in_array($property, self::hasPublicProperty($service, 'Property', $setter))) {
|
|
| 181 | 181 | $service->$setter = $arg; |
| 182 | 182 | } |
| 183 | 183 | } |
| 184 | 184 | } |
| 185 | 185 | } |
| 186 | 186 | // call instance methods |
| 187 | - if(isset($config->action)){
|
|
| 188 | - foreach($config->action as $action){
|
|
| 187 | + if (isset($config->action)) {
|
|
| 188 | + foreach ($config->action as $action) {
|
|
| 189 | 189 | $method = (string)$action['method'] != '' ? (string)$action['method'] : NULL; |
| 190 | - if($method && self::hasPublicProperty($service, 'Method', $method)){
|
|
| 190 | + if ($method && self::hasPublicProperty($service, 'Method', $method)) {
|
|
| 191 | 191 | $args = array(); |
| 192 | - foreach($action->children() as $argument){
|
|
| 192 | + foreach ($action->children() as $argument) {
|
|
| 193 | 193 | $args[] = $this->buildArg($argument); |
| 194 | 194 | } |
| 195 | 195 | call_user_func_array(array($service, (string)$action['method']), $args); |
@@ -197,9 +197,9 @@ discard block |
||
| 197 | 197 | } |
| 198 | 198 | } |
| 199 | 199 | // register instance listeners |
| 200 | - if($service instanceof \PEIP\INF\Event\Connectable){
|
|
| 201 | - if(isset($config->listener)){
|
|
| 202 | - foreach($config->listener as $listenerConf){
|
|
| 200 | + if ($service instanceof \PEIP\INF\Event\Connectable) {
|
|
| 201 | + if (isset($config->listener)) {
|
|
| 202 | + foreach ($config->listener as $listenerConf) {
|
|
| 203 | 203 | $event = (string)$listenerConf['event']; |
| 204 | 204 | $listener = $this->provideService($listenerConf); |
| 205 | 205 | $service->connect($event, $listener); |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | * @param string $eventClass the event-class the builder shall create instances for |
| 38 | 38 | * @param array $defaultHeaders default headers for the created events |
| 39 | 39 | */ |
| 40 | - public function __construct($eventClass = '\PEIP\Event\Event', array $defaultHeaders = array()){
|
|
| 40 | + public function __construct($eventClass = '\PEIP\Event\Event', array $defaultHeaders = array()) {
|
|
| 41 | 41 | $this->eventClass = $eventClass; |
| 42 | 42 | $this->defaultParameters = $defaultHeaders; |
| 43 | 43 | } |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | * @param string $eventClass the event-class the builder shall create instances for |
| 50 | 50 | * @return EventBuilder the instance of EventBuilder for the given event-class |
| 51 | 51 | */ |
| 52 | - public static function getInstance($eventClass = '\PEIP\Event\Event'){
|
|
| 52 | + public static function getInstance($eventClass = '\PEIP\Event\Event') {
|
|
| 53 | 53 | |
| 54 | 54 | return isset(self::$instances[$eventClass]) |
| 55 | 55 | ? self::$instances[$eventClass] |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | * @param array $headers the headers for the event |
| 68 | 68 | * @return object event instance |
| 69 | 69 | */ |
| 70 | - public function build($subject, $name, array $headers = array()){
|
|
| 70 | + public function build($subject, $name, array $headers = array()) {
|
|
| 71 | 71 | |
| 72 | 72 | return new $this->eventClass( |
| 73 | 73 | $subject, |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | * @param array $parameters the headers for the event |
| 87 | 87 | * @return |
| 88 | 88 | */ |
| 89 | - public function buildAndDispatch(ObjectEventDispatcher $dispatcher, $subject, $name, array $headers = array()){
|
|
| 89 | + public function buildAndDispatch(ObjectEventDispatcher $dispatcher, $subject, $name, array $headers = array()) {
|
|
| 90 | 90 | |
| 91 | 91 | return $dispatcher->notify( |
| 92 | 92 | $name, |
@@ -15,11 +15,11 @@ discard block |
||
| 15 | 15 | class Test {
|
| 16 | 16 | |
| 17 | 17 | |
| 18 | - public static function assertClassHasConstructor($className){
|
|
| 19 | - return (boolean) ReflectionPool::getInstance($className)->getConstructor(); |
|
| 18 | + public static function assertClassHasConstructor($className) {
|
|
| 19 | + return (boolean)ReflectionPool::getInstance($className)->getConstructor(); |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | - public static function assertRequiredConstructorParameters($className, $parameters){
|
|
| 22 | + public static function assertRequiredConstructorParameters($className, $parameters) {
|
|
| 23 | 23 | return (boolean) |
| 24 | 24 | !self::assertClassHasConstructor($className) || |
| 25 | 25 | count($parameters) >= ReflectionPool::getInstance($className) |
@@ -27,55 +27,55 @@ discard block |
||
| 27 | 27 | ->getNumberOfRequiredParameters(); |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | - public static function assertInstanceOf($className, $object){
|
|
| 31 | - return (boolean) ReflectionPool::getInstance($className) |
|
| 30 | + public static function assertInstanceOf($className, $object) {
|
|
| 31 | + return (boolean)ReflectionPool::getInstance($className) |
|
| 32 | 32 | ->isInstance($object); |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | - public static function assertClassOrInterfaceExists($className){
|
|
| 36 | - return (boolean) class_exists($className) || interface_exists($className); |
|
| 35 | + public static function assertClassOrInterfaceExists($className) {
|
|
| 36 | + return (boolean)class_exists($className) || interface_exists($className); |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | - public static function assertImplements($className, $interfaceName){
|
|
| 39 | + public static function assertImplements($className, $interfaceName) {
|
|
| 40 | 40 | $className = is_object($className) ? get_class($className) : $className; |
| 41 | - $res = false;//throw new \Exception(); |
|
| 41 | + $res = false; //throw new \Exception(); |
|
| 42 | 42 | try {
|
| 43 | 43 | class_exists($className); |
| 44 | - $res = ReflectionPool::getInstance($className) |
|
| 44 | + $res = ReflectionPool::getInstance($className) |
|
| 45 | 45 | ->implementsInterface($interfaceName); |
| 46 | - } catch (\Exception $e){
|
|
| 46 | + } catch (\Exception $e) {
|
|
| 47 | 47 | $res = false; |
| 48 | 48 | } |
| 49 | - return $res;; |
|
| 49 | + return $res; ; |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | - public static function assertMessage($message){
|
|
| 52 | + public static function assertMessage($message) {
|
|
| 53 | 53 | return self::assertImplements($message, '\PEIP\INF\Message\Message'); |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | - public static function assertEvent($event){
|
|
| 56 | + public static function assertEvent($event) {
|
|
| 57 | 57 | return self::assertImplements($event, '\PEIP\INF\Event\Event'); |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | - public static function assertEventSubject($event){
|
|
| 60 | + public static function assertEventSubject($event) {
|
|
| 61 | 61 | return self::assertImplements($event, '\PEIP\INF\Event\Event') |
| 62 | 62 | && $event->getSubject(); |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | - public static function assertEventObjectSubject($event){
|
|
| 65 | + public static function assertEventObjectSubject($event) {
|
|
| 66 | 66 | return self::assertEventSubject($event) |
| 67 | 67 | && is_object($event->getSubject()); |
| 68 | 68 | } |
| 69 | - public static function assertArrayAccess($var){
|
|
| 70 | - return (boolean) is_array($var) || $var instanceof \ArrayAccess; |
|
| 69 | + public static function assertArrayAccess($var) {
|
|
| 70 | + return (boolean)is_array($var) || $var instanceof \ArrayAccess; |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | - public static function assertHandler($var){
|
|
| 74 | - return (boolean) is_callable($var) || $var instanceof \PEIP\INF\Handler\Handler; |
|
| 73 | + public static function assertHandler($var) {
|
|
| 74 | + return (boolean)is_callable($var) || $var instanceof \PEIP\INF\Handler\Handler; |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - public static function castType($var, $type){
|
|
| 78 | - switch($type){
|
|
| 77 | + public static function castType($var, $type) {
|
|
| 78 | + switch ($type) {
|
|
| 79 | 79 | case 'string': |
| 80 | 80 | $var = (string)$var; |
| 81 | 81 | break; |
@@ -99,8 +99,8 @@ discard block |
||
| 99 | 99 | return $var; |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | - public static function ensureArrayAccess($var){
|
|
| 103 | - if(!Test::assertArrayAccess($var)){
|
|
| 102 | + public static function ensureArrayAccess($var) {
|
|
| 103 | + if (!Test::assertArrayAccess($var)) {
|
|
| 104 | 104 | throw new \InvalidArgumentException( |
| 105 | 105 | 'Value is not an array nor an instance of ArrayAccess' |
| 106 | 106 | ); |
@@ -109,8 +109,8 @@ discard block |
||
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | |
| 112 | - public static function ensureHandler($var){
|
|
| 113 | - if(!Test::assertHandler($var)){
|
|
| 112 | + public static function ensureHandler($var) {
|
|
| 113 | + if (!Test::assertHandler($var)) {
|
|
| 114 | 114 | throw new \InvalidArgumentException( |
| 115 | 115 | 'Value is not an callable nor an instance of \PEIP\INF\Handler\Handler' |
| 116 | 116 | ); |
@@ -118,8 +118,8 @@ discard block |
||
| 118 | 118 | return $var; |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | - public static function ensureImplements($className, $interfaceName){
|
|
| 122 | - if(!Test::assertImplements($className, $interfaceName)){
|
|
| 121 | + public static function ensureImplements($className, $interfaceName) {
|
|
| 122 | + if (!Test::assertImplements($className, $interfaceName)) {
|
|
| 123 | 123 | throw new \InvalidArgumentException( |
| 124 | 124 | 'Class "'.$className.'" is not an instanceof "'.$interfaceName.'"' |
| 125 | 125 | ); |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | return $className; |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | - public static function assertMethod($className, $methodname){
|
|
| 130 | + public static function assertMethod($className, $methodname) {
|
|
| 131 | 131 | return ReflectionPool::getInstance($className)->hasMethod($methodname); |
| 132 | 132 | } |
| 133 | 133 | |
@@ -43,10 +43,10 @@ discard block |
||
| 43 | 43 | * @param boolean $storeRef wether to store a reference for new instance. default: true |
| 44 | 44 | * @return |
| 45 | 45 | */ |
| 46 | - public function __construct($className, \ReflectionClass $reflectionClass = NULL, $storeRef = true){
|
|
| 47 | - if($reflectionClass ){
|
|
| 46 | + public function __construct($className, \ReflectionClass $reflectionClass = NULL, $storeRef = true) {
|
|
| 47 | + if ($reflectionClass) {
|
|
| 48 | 48 | |
| 49 | - if($reflectionClass->getName() != $className){
|
|
| 49 | + if ($reflectionClass->getName() != $className) {
|
|
| 50 | 50 | throw new \Exception( |
| 51 | 51 | 'Constructing GenericBuilder with wrong ReflectionClass' |
| 52 | 52 | ); |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | $this->reflectionClass = $reflectionClass; |
| 57 | 57 | } |
| 58 | 58 | $this->className = $className; |
| 59 | - if($storeRef){
|
|
| 59 | + if ($storeRef) {
|
|
| 60 | 60 | self::$instances[$this->className] = $this; |
| 61 | 61 | } |
| 62 | 62 | } |
@@ -68,8 +68,8 @@ discard block |
||
| 68 | 68 | * @param string $className class-name to return builder instance for |
| 69 | 69 | * @return GenericBuilder builder instance for class |
| 70 | 70 | */ |
| 71 | - public static function getInstance($className){
|
|
| 72 | - if(!array_key_exists((string)$className, self::$instances)) {
|
|
| 71 | + public static function getInstance($className) {
|
|
| 72 | + if (!array_key_exists((string)$className, self::$instances)) {
|
|
| 73 | 73 | new GenericBuilder($className); |
| 74 | 74 | } |
| 75 | 75 | return self::$instances[$className]; |
@@ -82,9 +82,9 @@ discard block |
||
| 82 | 82 | * @param array $arguments array of constructore arguments |
| 83 | 83 | * @return object the created object instance |
| 84 | 84 | */ |
| 85 | - public function build(array $arguments = array()){
|
|
| 86 | - if(Test::assertClassHasConstructor($this->className)){
|
|
| 87 | - if(!Test::assertRequiredConstructorParameters($this->className, $arguments)){
|
|
| 85 | + public function build(array $arguments = array()) {
|
|
| 86 | + if (Test::assertClassHasConstructor($this->className)) {
|
|
| 87 | + if (!Test::assertRequiredConstructorParameters($this->className, $arguments)) {
|
|
| 88 | 88 | throw new \Exception('Missing Argument '.(count($arguments) + 1).' for '.$this->className.'::__construct');
|
| 89 | 89 | } |
| 90 | 90 | return $this->getReflectionClass()->newInstanceArgs($arguments); |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | * @access public |
| 99 | 99 | * @return ReflectionClass |
| 100 | 100 | */ |
| 101 | - public function getReflectionClass(){
|
|
| 101 | + public function getReflectionClass() {
|
|
| 102 | 102 | return ReflectionPool::getInstance($this->className); |
| 103 | 103 | } |
| 104 | 104 | |