@@ -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 | |
@@ -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, |
@@ -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 | } |
@@ -22,6 +22,6 @@ |
||
| 22 | 22 | |
| 23 | 23 | interface Singleton { |
| 24 | 24 | |
| 25 | - public static function getInstance (); |
|
| 25 | + public static function getInstance(); |
|
| 26 | 26 | |
| 27 | 27 | } |
@@ -12,7 +12,6 @@ |
||
| 12 | 12 | * @author timo |
| 13 | 13 | */ |
| 14 | 14 | use PEIP\Context\XMLContext; |
| 15 | -use PEIP\Plugins\BasePlugin; |
|
| 16 | 15 | |
| 17 | 16 | class ServiceProvider extends \PEIP\Service\ServiceContainer { |
| 18 | 17 | |
@@ -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,16 +83,16 @@ discard block |
||
| 83 | 83 | * @see XMLContext::includeContext |
| 84 | 84 | * @access protected |
| 85 | 85 | */ |
| 86 | - protected function initNodeBuilders(){ |
|
| 86 | + protected function initNodeBuilders() { |
|
| 87 | 87 | $builders = array( |
| 88 | 88 | 'service' => 'initService' |
| 89 | 89 | ); |
| 90 | - foreach($builders as $nodeName => $method){ |
|
| 90 | + foreach ($builders as $nodeName => $method) { |
|
| 91 | 91 | $this->registerNodeBuilder($nodeName, array($this, $method)); |
| 92 | 92 | } |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | - public function addConfig($config){ |
|
| 95 | + public function addConfig($config) { |
|
| 96 | 96 | $this->doFireEvent( |
| 97 | 97 | self::EVENT_BEFORE_ADD_CONFIG, |
| 98 | 98 | array( |
@@ -111,15 +111,15 @@ discard block |
||
| 111 | 111 | ); |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | - public function provideService($key){ |
|
| 114 | + public function provideService($key) { |
|
| 115 | 115 | $this->doFireEvent(self::EVENT_BEFORE_PROVIDE_SERVICE, array( |
| 116 | 116 | self::HEADER_KEY=>$key) |
| 117 | 117 | ); |
| 118 | 118 | |
| 119 | - if($this->hasService($key)){ |
|
| 120 | - $service = $this->getService($key); |
|
| 121 | - }else{ |
|
| 122 | - $service = $this->createService($key); |
|
| 119 | + if ($this->hasService($key)) { |
|
| 120 | + $service = $this->getService($key); |
|
| 121 | + }else { |
|
| 122 | + $service = $this->createService($key); |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | $this->doFireEvent(self::EVENT_AFTER_PROVIDE_SERVICE, array( |
@@ -130,16 +130,16 @@ discard block |
||
| 130 | 130 | return $service; |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | - protected function createService($key){ |
|
| 133 | + protected function createService($key) { |
|
| 134 | 134 | $this->doFireEvent(self::EVENT_BEFORE_CREATE_SERVICE, array( |
| 135 | 135 | self::HEADER_KEY=>$key) |
| 136 | 136 | ); |
| 137 | 137 | $errorMessage = ''; |
| 138 | 138 | $config = $this->getServiceConfig($key); |
| 139 | 139 | |
| 140 | - if($config){ |
|
| 140 | + if ($config) { |
|
| 141 | 141 | $node = $this->buildNode($config); |
| 142 | - if($node){ |
|
| 142 | + if ($node) { |
|
| 143 | 143 | $this->setService( |
| 144 | 144 | $key, |
| 145 | 145 | $node |
@@ -150,11 +150,11 @@ discard block |
||
| 150 | 150 | )); |
| 151 | 151 | |
| 152 | 152 | return $node; |
| 153 | - }else{ |
|
| 153 | + }else { |
|
| 154 | 154 | $errorMessage = 'COULD NOT BUILD NODE FOR KEY: '.$key; |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | - }else{ |
|
| 157 | + }else { |
|
| 158 | 158 | $errorMessage = 'NO CONFIG FOR KEY: '.$key; |
| 159 | 159 | } |
| 160 | 160 | $this->doFireEvent(self::EVENT_CREATE_SERVICE_ERROR, array( |
@@ -164,8 +164,8 @@ discard block |
||
| 164 | 164 | return NULL; |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | - public function getServiceConfig($key){ |
|
| 168 | - if(!isset($this->ids[$key])){ |
|
| 167 | + public function getServiceConfig($key) { |
|
| 168 | + if (!isset($this->ids[$key])) { |
|
| 169 | 169 | return false; |
| 170 | 170 | } |
| 171 | 171 | return $this->config[$this->ids[$key]]; |
@@ -180,7 +180,7 @@ discard block |
||
| 180 | 180 | * @param object $config configuration-node |
| 181 | 181 | * @return void |
| 182 | 182 | */ |
| 183 | - protected function buildNode($config){ |
|
| 183 | + protected function buildNode($config) { |
|
| 184 | 184 | $nodeName = (string)$config['type']; |
| 185 | 185 | |
| 186 | 186 | $this->doFireEvent(self::EVENT_BEFORE_BUILD_NODE, array( |
@@ -188,20 +188,20 @@ discard block |
||
| 188 | 188 | self::HEADER_NODE_NAME=> $nodeName |
| 189 | 189 | )); |
| 190 | 190 | // call the builder method registered for the node. |
| 191 | - if(array_key_exists($nodeName, $this->nodeBuilders)){ |
|
| 191 | + if (array_key_exists($nodeName, $this->nodeBuilders)) { |
|
| 192 | 192 | |
| 193 | 193 | $nodeInstance = call_user_func($this->nodeBuilders[$nodeName], $config); |
| 194 | - if(is_object($nodeInstance)){ |
|
| 194 | + if (is_object($nodeInstance)) { |
|
| 195 | 195 | $this->doFireEvent(self::EVENT_BUILD_NODE_SUCCESS, array( |
| 196 | 196 | self::HEADER_NODE_CONFIG=>$config, |
| 197 | 197 | self::HEADER_NODE_NAME=> $nodeName, |
| 198 | 198 | self::HEADER_NODE => $nodeInstance |
| 199 | 199 | )); |
| 200 | 200 | return $nodeInstance; |
| 201 | - }else{ |
|
| 201 | + }else { |
|
| 202 | 202 | $errorMessage = 'BUILDER RETURNED NO OBJECT FOR NODE-TYPE: '.$nodeName; |
| 203 | 203 | } |
| 204 | - }else{ |
|
| 204 | + }else { |
|
| 205 | 205 | $errorMessage = 'NO BUILDER FOUND FOR NODE-TYPE: '.$nodeName; |
| 206 | 206 | } |
| 207 | 207 | |
@@ -212,27 +212,27 @@ discard block |
||
| 212 | 212 | )); |
| 213 | 213 | } |
| 214 | 214 | |
| 215 | - protected function getIdFromConfig($config){ |
|
| 215 | + protected function getIdFromConfig($config) { |
|
| 216 | 216 | $id = ''; |
| 217 | - if(isset($config[$this->idAttribute])){ |
|
| 217 | + if (isset($config[$this->idAttribute])) { |
|
| 218 | 218 | $id = trim((string)($config[$this->idAttribute])); |
| 219 | 219 | } |
| 220 | 220 | return $id; |
| 221 | 221 | } |
| 222 | 222 | |
| 223 | - protected function getCountConfig(){ |
|
| 223 | + protected function getCountConfig() { |
|
| 224 | 224 | return count($this->config); |
| 225 | 225 | } |
| 226 | 226 | |
| 227 | - protected function doAddConfig($config){ |
|
| 227 | + protected function doAddConfig($config) { |
|
| 228 | 228 | $countConfig = $this->getCountConfig(); |
| 229 | 229 | $this->config[$countConfig] = $config; |
| 230 | 230 | return $countConfig; |
| 231 | 231 | } |
| 232 | 232 | |
| 233 | - protected function doRegisterConfig($config){ |
|
| 234 | - $id = $this->getIdFromConfig($config); |
|
| 235 | - if($id != ''){ |
|
| 233 | + protected function doRegisterConfig($config) { |
|
| 234 | + $id = $this->getIdFromConfig($config); |
|
| 235 | + if ($id != '') { |
|
| 236 | 236 | $this->ids[$id] = $this->getCountConfig() - 1; |
| 237 | 237 | } |
| 238 | 238 | return $id; |
@@ -23,11 +23,11 @@ discard block |
||
| 23 | 23 | * @param $config configuration of the service |
| 24 | 24 | * @return object the initialized service instance |
| 25 | 25 | */ |
| 26 | - public static function createService(array $config){ |
|
| 26 | + public static function createService(array $config) { |
|
| 27 | 27 | $args = array(); |
| 28 | 28 | //build arguments for constructor |
| 29 | - if(isset($config['constructor_arg'])){ |
|
| 30 | - foreach($config['constructor_arg'] as $arg){ |
|
| 29 | + if (isset($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 function buildArg($config){ |
|
| 90 | - if(trim((string)$config['value']) != ''){ |
|
| 89 | + protected 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 = $this->buildArg($config->list); |
| 111 | - }elseif($config->service){ |
|
| 111 | + }elseif ($config->service) { |
|
| 112 | 112 | $arg = $this->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(array $config, $arguments, $defaultClass = ""){ |
|
| 130 | - if((isset($config["class"]) && "" != (string)$config["class"]) || $defaultClass !== ""){ |
|
| 129 | + public static function buildAndModify(array $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(isset($config['argument'])){ |
|
| 140 | - foreach($config['argument'] as $arg){ |
|
| 139 | + if (isset($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); |
@@ -165,29 +165,29 @@ discard block |
||
| 165 | 165 | * @param object $config configuration to get the modification instructions from. |
| 166 | 166 | * @return object the modificated service |
| 167 | 167 | */ |
| 168 | - protected function modifyService($service, $config){ |
|
| 168 | + protected function modifyService($service, $config) { |
|
| 169 | 169 | $config = is_array($config) ? new \ArrayObject($config) : $config; |
| 170 | 170 | // set instance properties |
| 171 | - if(isset($config->property)){ |
|
| 172 | - foreach($config->property as $property){ |
|
| 171 | + if (isset($config->property)) { |
|
| 172 | + foreach ($config->property as $property) { |
|
| 173 | 173 | $arg = $this->buildArg($property); |
| 174 | - if($arg){ |
|
| 174 | + if ($arg) { |
|
| 175 | 175 | $setter = self::getSetter($property); |
| 176 | - if($setter && self::hasPublicProperty($service, 'Method', $setter)){ |
|
| 176 | + if ($setter && self::hasPublicProperty($service, 'Method', $setter)) { |
|
| 177 | 177 | $service->{$setter}($arg); |
| 178 | - }elseif(in_array($property, self::hasPublicProperty($service, 'Property', $setter))){ |
|
| 178 | + }elseif (in_array($property, self::hasPublicProperty($service, 'Property', $setter))) { |
|
| 179 | 179 | $service->$setter = $arg; |
| 180 | 180 | } |
| 181 | 181 | } |
| 182 | 182 | } |
| 183 | 183 | } |
| 184 | 184 | // call instance methods |
| 185 | - if(isset($config->action)){ |
|
| 186 | - foreach($config->action as $action){ |
|
| 185 | + if (isset($config->action)) { |
|
| 186 | + foreach ($config->action as $action) { |
|
| 187 | 187 | $method = (string)$action['method'] != '' ? (string)$action['method'] : NULL; |
| 188 | - if($method && self::hasPublicProperty($service, 'Method', $method)){ |
|
| 188 | + if ($method && self::hasPublicProperty($service, 'Method', $method)) { |
|
| 189 | 189 | $args = array(); |
| 190 | - foreach($action->children() as $argument){ |
|
| 190 | + foreach ($action->children() as $argument) { |
|
| 191 | 191 | $args[] = $this->buildArg($argument); |
| 192 | 192 | } |
| 193 | 193 | call_user_func_array(array($service, (string)$action['method']), $args); |
@@ -195,9 +195,9 @@ discard block |
||
| 195 | 195 | } |
| 196 | 196 | } |
| 197 | 197 | // register instance listeners |
| 198 | - if($service instanceof \PEIP\INF\Event\Connectable){ |
|
| 199 | - if(isset($config->listener)){ |
|
| 200 | - foreach($config->listener as $listenerConf){ |
|
| 198 | + if ($service instanceof \PEIP\INF\Event\Connectable) { |
|
| 199 | + if (isset($config->listener)) { |
|
| 200 | + foreach ($config->listener as $listenerConf) { |
|
| 201 | 201 | $event = (string)$listenerConf['event']; |
| 202 | 202 | $listener = $this->provideService($listenerConf); |
| 203 | 203 | $service->connect($event, $listener); |
@@ -38,16 +38,16 @@ discard block |
||
| 38 | 38 | * @param $parameters |
| 39 | 39 | * @return |
| 40 | 40 | */ |
| 41 | - protected function __construct($callable ,array $parameters = array()){ |
|
| 41 | + protected function __construct($callable, array $parameters = array()) { |
|
| 42 | 42 | $this->callable = $callable; |
| 43 | 43 | $this->setParameters($parameters); |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | - public static function getfromClass($class, array $parameters = array()){ |
|
| 46 | + public static function getfromClass($class, array $parameters = array()) { |
|
| 47 | 47 | return new DedicatedFactory(array($class, '__construct'), $parameters); |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | - public static function getfromCallable($callable, array $parameters = array()){ |
|
| 50 | + public static function getfromCallable($callable, array $parameters = array()) { |
|
| 51 | 51 | return new DedicatedFactory($callable, $parameters); |
| 52 | 52 | } |
| 53 | 53 | |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | * @param $arguments |
| 58 | 58 | * @return |
| 59 | 59 | */ |
| 60 | - public function build(array $arguments = array()){ |
|
| 60 | + public function build(array $arguments = array()) { |
|
| 61 | 61 | $arguments = count($arguments) > 0 ? $arguments : $this->getParameters(); |
| 62 | 62 | return (is_array($this->callable) && $this->callable[1] == '__construct') |
| 63 | 63 | ? GenericBuilder::GetInstance($this->callable[0])->build($arguments) |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | * @param $method |
| 71 | 71 | * @return |
| 72 | 72 | */ |
| 73 | - public function setConstructor($method){ |
|
| 73 | + public function setConstructor($method) { |
|
| 74 | 74 | $this->constructor = (string)$method; |
| 75 | 75 | return $this; |
| 76 | 76 | } |
@@ -22,42 +22,42 @@ discard block |
||
| 22 | 22 | |
| 23 | 23 | class XMLArrayTranslator { |
| 24 | 24 | |
| 25 | - public static function translate($content){ |
|
| 25 | + public static function translate($content) { |
|
| 26 | 26 | try { |
| 27 | 27 | $node = simplexml_load_string($content); |
| 28 | 28 | // fix for hhvm |
| 29 | - if(!($node instanceof \SimpleXMLElement)){ |
|
| 29 | + if (!($node instanceof \SimpleXMLElement)) { |
|
| 30 | 30 | throw new \Exception('loading XML failed'); |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | } |
| 34 | - catch(\Exception $e){ |
|
| 34 | + catch (\Exception $e) { |
|
| 35 | 35 | return false; |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | return self::doTranslate($node); |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | - protected static function doTranslate(\SimpleXMLElement $node){ |
|
| 41 | + protected static function doTranslate(\SimpleXMLElement $node) { |
|
| 42 | 42 | |
| 43 | 43 | $array = array(); |
| 44 | 44 | $array['type'] = $node['type'] |
| 45 | 45 | ? (string)$node['type'] |
| 46 | 46 | : (string)$node->getName(); |
| 47 | 47 | $value = (string)$node; |
| 48 | - if($value != ''){ |
|
| 48 | + if ($value != '') { |
|
| 49 | 49 | $array['value'] = $value; |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | - foreach($node->attributes() as $name=>$value){ |
|
| 52 | + foreach ($node->attributes() as $name=>$value) { |
|
| 53 | 53 | $array[$name] = (string)$value; |
| 54 | 54 | } |
| 55 | - foreach($node->children() as $nr=>$child){ |
|
| 55 | + foreach ($node->children() as $nr=>$child) { |
|
| 56 | 56 | $name = $child->getName(); |
| 57 | 57 | $res = self::doTranslate($child); |
| 58 | 58 | |
| 59 | - if(isset($array[$name])){ |
|
| 60 | - if(is_string($array[$name])){ |
|
| 59 | + if (isset($array[$name])) { |
|
| 60 | + if (is_string($array[$name])) { |
|
| 61 | 61 | $array[$name] = array( |
| 62 | 62 | array( |
| 63 | 63 | 'type'=>$name, |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | ) |
| 66 | 66 | ); |
| 67 | 67 | } |
| 68 | - }else{ |
|
| 68 | + }else { |
|
| 69 | 69 | $array[$name] = array(); |
| 70 | 70 | } |
| 71 | 71 | $array[$name][] = $res; |
@@ -50,24 +50,24 @@ discard block |
||
| 50 | 50 | * @param string $string the configuration string |
| 51 | 51 | * @return |
| 52 | 52 | */ |
| 53 | - public function __construct($string){ |
|
| 53 | + public function __construct($string) { |
|
| 54 | 54 | $this->initNodeBuilders(); |
| 55 | 55 | $reader = new XMLContextReader($string); |
| 56 | 56 | |
| 57 | 57 | |
| 58 | 58 | $serviceActivator = new HeaderServiceActivator(array($this, 'addConfig'), 'NODE'); |
| 59 | 59 | |
| 60 | - $reader->connect('read_node', $serviceActivator); |
|
| 60 | + $reader->connect('read_node', $serviceActivator); |
|
| 61 | 61 | $reader->read(); |
| 62 | 62 | |
| 63 | 63 | |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | - public function addConfig($config){ |
|
| 66 | + public function addConfig($config) { |
|
| 67 | 67 | return $this->getServiceProvider()->addConfig($config); |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | - public function handleReadConfig(\PEIP\INF\Event\Event $event){ |
|
| 70 | + public function handleReadConfig(\PEIP\INF\Event\Event $event) { |
|
| 71 | 71 | $this->addConfig($event->getHeader('NODE')); |
| 72 | 72 | } |
| 73 | 73 | |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | * @return XMLContext the context instance |
| 80 | 80 | * @throws RuntimeException |
| 81 | 81 | */ |
| 82 | - public static function createFromString($string){ |
|
| 82 | + public static function createFromString($string) { |
|
| 83 | 83 | return new XMLContext($string); |
| 84 | 84 | } |
| 85 | 85 | |
@@ -91,10 +91,10 @@ discard block |
||
| 91 | 91 | * @return XMLContext the context instance |
| 92 | 92 | * @throws RuntimeException |
| 93 | 93 | */ |
| 94 | - public static function createFromFile($file){ |
|
| 95 | - if(file_exists($file)){ |
|
| 94 | + public static function createFromFile($file) { |
|
| 95 | + if (file_exists($file)) { |
|
| 96 | 96 | return self::createFromString(file_get_contents($file)); |
| 97 | - }else{ |
|
| 97 | + }else { |
|
| 98 | 98 | throw new \RuntimeException('Cannot open file "'.$file.'".'); |
| 99 | 99 | } |
| 100 | 100 | } |
@@ -105,15 +105,15 @@ discard block |
||
| 105 | 105 | * @access protected |
| 106 | 106 | * @return void |
| 107 | 107 | */ |
| 108 | - protected function init(){ |
|
| 108 | + protected function init() { |
|
| 109 | 109 | $xml = $this->simpleXML; |
| 110 | 110 | $this->channelRegistry = ChannelRegistry::getInstance(); |
| 111 | 111 | // register this context as a service if id is set. |
| 112 | - if($xml['id']){ |
|
| 112 | + if ($xml['id']) { |
|
| 113 | 113 | $this->services[(string)$xml['id']] = $this; |
| 114 | 114 | } |
| 115 | 115 | // build services |
| 116 | - foreach($xml->children() as $entry){ |
|
| 116 | + foreach ($xml->children() as $entry) { |
|
| 117 | 117 | $this->buildNode($entry); |
| 118 | 118 | } |
| 119 | 119 | } |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | * @param string $nodeName the name of the node |
| 127 | 127 | * @param callable $callable a callable which creates instances for node-name |
| 128 | 128 | */ |
| 129 | - public function registerNodeBuilder($nodeName, $callable){ |
|
| 129 | + public function registerNodeBuilder($nodeName, $callable) { |
|
| 130 | 130 | return $this->getServiceProvider()->registerNodeBuilder($nodeName, $callable); |
| 131 | 131 | } |
| 132 | 132 | |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | * @access public |
| 138 | 138 | * @param \PEIP\INF\Context\Context_Plugin $plugin a plugin instance |
| 139 | 139 | */ |
| 140 | - public function addPlugin(\PEIP\INF\Context\ContextPlugin $plugin){ |
|
| 140 | + public function addPlugin(\PEIP\INF\Context\ContextPlugin $plugin) { |
|
| 141 | 141 | $plugin->init($this); |
| 142 | 142 | } |
| 143 | 143 | |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | * @param object $config configuration object for the plugin |
| 149 | 149 | * @return |
| 150 | 150 | */ |
| 151 | - public function createPlugin($config){ |
|
| 151 | + public function createPlugin($config) { |
|
| 152 | 152 | $plugin = $this->createService($config); |
| 153 | 153 | $this->addPlugin($plugin); |
| 154 | 154 | } |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | * @access public |
| 170 | 170 | * @param XMLContext $config the config to include |
| 171 | 171 | */ |
| 172 | - public function includeContext(XMLContext $context){ |
|
| 172 | + public function includeContext(XMLContext $context) { |
|
| 173 | 173 | $this->services = array_merge($this->services, $context->getServices()); |
| 174 | 174 | } |
| 175 | 175 | |
@@ -180,8 +180,8 @@ discard block |
||
| 180 | 180 | * @access public |
| 181 | 181 | * @param XMLContext $context the config to include |
| 182 | 182 | */ |
| 183 | - public function includeContextFromFile($filePath){ |
|
| 184 | - if(file_exists($filePath)){ |
|
| 183 | + public function includeContextFromFile($filePath) { |
|
| 184 | + if (file_exists($filePath)) { |
|
| 185 | 185 | $this->includeContextFromString(file_get_contents($filePath)); |
| 186 | 186 | } |
| 187 | 187 | } |
@@ -193,7 +193,7 @@ discard block |
||
| 193 | 193 | * @access public |
| 194 | 194 | * @param string $configString the config to include |
| 195 | 195 | */ |
| 196 | - public function includeContextFromString($configString){ |
|
| 196 | + public function includeContextFromString($configString) { |
|
| 197 | 197 | $context = new XMLContext($configString); |
| 198 | 198 | $this->includeContext($context); |
| 199 | 199 | } |
@@ -205,14 +205,14 @@ discard block |
||
| 205 | 205 | * @access protected |
| 206 | 206 | * @param object $config the configuration for the context |
| 207 | 207 | */ |
| 208 | - protected function createContext($config){ |
|
| 209 | - if((string)$config['file'] != ''){ |
|
| 208 | + protected function createContext($config) { |
|
| 209 | + if ((string)$config['file'] != '') { |
|
| 210 | 210 | $this->includeContextFromFile((string)$config['file']); |
| 211 | 211 | } |
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | |
| 215 | - public function getServiceProvider(){ |
|
| 215 | + public function getServiceProvider() { |
|
| 216 | 216 | return isset($this->serviceProvider) |
| 217 | 217 | ? $this->serviceProvider |
| 218 | 218 | : $this->serviceProvider = new ServiceProvider(); |
@@ -228,7 +228,7 @@ discard block |
||
| 228 | 228 | * @see XMLContext::includeContext |
| 229 | 229 | * @access protected |
| 230 | 230 | */ |
| 231 | - protected function initNodeBuilders(){ |
|
| 231 | + protected function initNodeBuilders() { |
|
| 232 | 232 | $builders = array( |
| 233 | 233 | 'include' => 'createContext', |
| 234 | 234 | 'plugin' => 'createPlugin', |
@@ -246,7 +246,7 @@ discard block |
||
| 246 | 246 | ); |
| 247 | 247 | $plugin = new BasePlugin(); |
| 248 | 248 | $this->addPlugin($plugin); |
| 249 | - foreach($builders as $nodeName => $method){ |
|
| 249 | + foreach ($builders as $nodeName => $method) { |
|
| 250 | 250 | $this->registerNodeBuilder($nodeName, array($this, $method)); |
| 251 | 251 | } |
| 252 | 252 | } |
@@ -260,10 +260,10 @@ discard block |
||
| 260 | 260 | * @param object $node configuration-node |
| 261 | 261 | * @return void |
| 262 | 262 | */ |
| 263 | - protected function buildNode($node){ |
|
| 263 | + protected function buildNode($node) { |
|
| 264 | 264 | $nodeName = $node->getName(); |
| 265 | 265 | // call the builder method registered for the node. |
| 266 | - if(array_key_exists($nodeName, $this->nodeBuilders)){ |
|
| 266 | + if (array_key_exists($nodeName, $this->nodeBuilders)) { |
|
| 267 | 267 | call_user_func($this->nodeBuilders[$nodeName], $node); |
| 268 | 268 | } |
| 269 | 269 | } |
@@ -282,7 +282,7 @@ discard block |
||
| 282 | 282 | * @param string $channelName the name/id of the channel to return |
| 283 | 283 | * @return \PEIP\INF\Channel\Channel |
| 284 | 284 | */ |
| 285 | - public function resolveChannelName($channelName){ |
|
| 285 | + public function resolveChannelName($channelName) { |
|
| 286 | 286 | return $this->channelRegistry->get($channelName); |
| 287 | 287 | } |
| 288 | 288 | |
@@ -294,7 +294,7 @@ discard block |
||
| 294 | 294 | * @param mixed $id the id for the service |
| 295 | 295 | * @return object the service instance if found |
| 296 | 296 | */ |
| 297 | - public function getService($id){ |
|
| 297 | + public function getService($id) { |
|
| 298 | 298 | return $this->getServiceProvider()->provideService($id); |
| 299 | 299 | } |
| 300 | 300 | |
@@ -304,7 +304,7 @@ discard block |
||
| 304 | 304 | * @access public |
| 305 | 305 | * @return array registered services |
| 306 | 306 | */ |
| 307 | - public function getServices(){ |
|
| 307 | + public function getServices() { |
|
| 308 | 308 | return $this->getServiceProvider()->getServices(); |
| 309 | 309 | } |
| 310 | 310 | |
@@ -315,7 +315,7 @@ discard block |
||
| 315 | 315 | * @param mixed $id the id for the service |
| 316 | 316 | * @return boolean wether service is registered |
| 317 | 317 | */ |
| 318 | - public function hasService($id){ |
|
| 318 | + public function hasService($id) { |
|
| 319 | 319 | return isset($this->services[$id]); |
| 320 | 320 | } |
| 321 | 321 | |
@@ -329,9 +329,9 @@ discard block |
||
| 329 | 329 | * @return object the service instance if found |
| 330 | 330 | * |
| 331 | 331 | */ |
| 332 | - protected function requestService($id){ |
|
| 332 | + protected function requestService($id) { |
|
| 333 | 333 | $service = $this->getService($id); |
| 334 | - if($service === NULL){ |
|
| 334 | + if ($service === NULL) { |
|
| 335 | 335 | throw new \RuntimeException('Service "'.$id.'" not found.'); |
| 336 | 336 | } |
| 337 | 337 | return $service; |
@@ -345,9 +345,9 @@ discard block |
||
| 345 | 345 | * @param object $config |
| 346 | 346 | * @return object the initialized service instance |
| 347 | 347 | */ |
| 348 | - protected function initService($config){ |
|
| 348 | + protected function initService($config) { |
|
| 349 | 349 | $id = trim((string)$config['id']); |
| 350 | - if($id != ''){ |
|
| 350 | + if ($id != '') { |
|
| 351 | 351 | return $this->services[$id] = $this->createService($config); |
| 352 | 352 | } |
| 353 | 353 | } |
@@ -359,7 +359,7 @@ discard block |
||
| 359 | 359 | * @param $config |
| 360 | 360 | * @return object the initialized service instance |
| 361 | 361 | */ |
| 362 | - public function createService($config){ |
|
| 362 | + public function createService($config) { |
|
| 363 | 363 | return ServiceFactory::createService($config); |
| 364 | 364 | } |
| 365 | 365 | |
@@ -376,28 +376,28 @@ discard block |
||
| 376 | 376 | * @param object $config configuration to get the modification instructions from. |
| 377 | 377 | * @return object the modificated service |
| 378 | 378 | */ |
| 379 | - protected function modifyService($service, $config){ |
|
| 379 | + protected function modifyService($service, $config) { |
|
| 380 | 380 | // set instance properties |
| 381 | - if($config->property){ |
|
| 382 | - foreach($config->property as $property){ |
|
| 381 | + if ($config->property) { |
|
| 382 | + foreach ($config->property as $property) { |
|
| 383 | 383 | $arg = $this->buildArg($property); |
| 384 | - if($arg){ |
|
| 384 | + if ($arg) { |
|
| 385 | 385 | $setter = self::getSetter($property); |
| 386 | - if($setter && self::hasPublicProperty($service, 'Method', $setter)){ |
|
| 386 | + if ($setter && self::hasPublicProperty($service, 'Method', $setter)) { |
|
| 387 | 387 | $service->{$setter}($arg); |
| 388 | - }elseif(in_array($property, self::hasPublicProperty($service, 'Property', $setter))){ |
|
| 388 | + }elseif (in_array($property, self::hasPublicProperty($service, 'Property', $setter))) { |
|
| 389 | 389 | $service->$setter = $arg; |
| 390 | 390 | } |
| 391 | 391 | } |
| 392 | 392 | } |
| 393 | 393 | } |
| 394 | 394 | // call instance methods |
| 395 | - if($config->action){ |
|
| 396 | - foreach($config->action as $action){ |
|
| 395 | + if ($config->action) { |
|
| 396 | + foreach ($config->action as $action) { |
|
| 397 | 397 | $method = (string)$action['method'] != '' ? (string)$action['method'] : NULL; |
| 398 | - if($method && self::hasPublicProperty($service, 'Method', $method)){ |
|
| 398 | + if ($method && self::hasPublicProperty($service, 'Method', $method)) { |
|
| 399 | 399 | $args = array(); |
| 400 | - foreach($action->children() as $argument){ |
|
| 400 | + foreach ($action->children() as $argument) { |
|
| 401 | 401 | $args[] = $this->buildArg($argument); |
| 402 | 402 | } |
| 403 | 403 | call_user_func_array(array($service, (string)$action['method']), $args); |
@@ -405,9 +405,9 @@ discard block |
||
| 405 | 405 | } |
| 406 | 406 | } |
| 407 | 407 | // register instance listeners |
| 408 | - if($service instanceof \PEIP\INF\Event\Connectable){ |
|
| 409 | - if($config->listener){ |
|
| 410 | - foreach($config->listener as $listenerConf){ |
|
| 408 | + if ($service instanceof \PEIP\INF\Event\Connectable) { |
|
| 409 | + if ($config->listener) { |
|
| 410 | + foreach ($config->listener as $listenerConf) { |
|
| 411 | 411 | $event = (string)$listenerConf['event']; |
| 412 | 412 | $listener = $this->provideService($listenerConf); |
| 413 | 413 | $service->connect($event, $listener); |
@@ -426,7 +426,7 @@ discard block |
||
| 426 | 426 | * @param mixed $id the id ofthe gateway |
| 427 | 427 | * @return object the gateway instance |
| 428 | 428 | */ |
| 429 | - public function getGateway($id){ |
|
| 429 | + public function getGateway($id) { |
|
| 430 | 430 | return $this->getServiceProvider()->provideService($id); |
| 431 | 431 | } |
| 432 | 432 | |
@@ -438,7 +438,7 @@ discard block |
||
| 438 | 438 | * @param object $config configuration object for the pollable channel. |
| 439 | 439 | * @return \PEIP\INF\Channel\Channel the created pollable channel instance |
| 440 | 440 | */ |
| 441 | - public function createChannel($config){ |
|
| 441 | + public function createChannel($config) { |
|
| 442 | 442 | return $this->doCreateChannel($config, 'PollableChannel'); |
| 443 | 443 | } |
| 444 | 444 | |
@@ -450,7 +450,7 @@ discard block |
||
| 450 | 450 | * @param object $config configuration object for the subscribable channel. |
| 451 | 451 | * @return \PEIP\INF\Channel\Channel the created subscribable channel instance |
| 452 | 452 | */ |
| 453 | - public function createSubscribableChannel($config){ |
|
| 453 | + public function createSubscribableChannel($config) { |
|
| 454 | 454 | return $this->doCreateChannel($config, 'PublishSubscribeChannel'); |
| 455 | 455 | } |
| 456 | 456 | |
@@ -463,9 +463,9 @@ discard block |
||
| 463 | 463 | * @param $additionalArguments additional arguments for the channel constructor (without first arg = id) |
| 464 | 464 | * @return \PEIP\INF\Channel\Channel the created channel instance |
| 465 | 465 | */ |
| 466 | - public function doCreateChannel($config, $defaultChannelClass, array $additionalArguments = array()){ |
|
| 466 | + public function doCreateChannel($config, $defaultChannelClass, array $additionalArguments = array()) { |
|
| 467 | 467 | $id = (string)$config['id']; |
| 468 | - if($id != ''){ |
|
| 468 | + if ($id != '') { |
|
| 469 | 469 | array_unshift($additionalArguments, $id); |
| 470 | 470 | $channel = $this->buildAndModify($config, $additionalArguments, $defaultChannelClass); |
| 471 | 471 | $this->channelRegistry->register($channel); |
@@ -482,7 +482,7 @@ discard block |
||
| 482 | 482 | * @param string $defaultClass the class to use if none is set in config. |
| 483 | 483 | * @return object the gateway instance |
| 484 | 484 | */ |
| 485 | - public function createGateway($config, $defaultClass = false){ |
|
| 485 | + public function createGateway($config, $defaultClass = false) { |
|
| 486 | 486 | $args = array( |
| 487 | 487 | $this->getRequestChannel($config), |
| 488 | 488 | $this->getReplyChannel($config) |
@@ -506,7 +506,7 @@ discard block |
||
| 506 | 506 | * @param string $defaultClass the class to use if none is set in config. |
| 507 | 507 | * @return object the router instance |
| 508 | 508 | */ |
| 509 | - public function createRouter($config, $defaultClass = false){ |
|
| 509 | + public function createRouter($config, $defaultClass = false) { |
|
| 510 | 510 | $resolver = $config['channel_resolver'] ? (string)$config['channel_resolver'] : $this->channelRegistry; |
| 511 | 511 | return $this->buildAndModify($config, array( |
| 512 | 512 | $resolver, |
@@ -523,7 +523,7 @@ discard block |
||
| 523 | 523 | * @param object $config configuration object for the splitter. |
| 524 | 524 | * @return object the splitter instance |
| 525 | 525 | */ |
| 526 | - public function createSplitter($config){ |
|
| 526 | + public function createSplitter($config) { |
|
| 527 | 527 | return $this->createReplyMessageHandler($config); |
| 528 | 528 | } |
| 529 | 529 | |
@@ -536,7 +536,7 @@ discard block |
||
| 536 | 536 | * @param object $config configuration object for the transformer. |
| 537 | 537 | * @return object the transformer instance |
| 538 | 538 | */ |
| 539 | - public function createTransformer($config){ |
|
| 539 | + public function createTransformer($config) { |
|
| 540 | 540 | return $this->createReplyMessageHandler($config); |
| 541 | 541 | } |
| 542 | 542 | |
@@ -549,7 +549,7 @@ discard block |
||
| 549 | 549 | * @param object $config configuration object for the aggregator. |
| 550 | 550 | * @return object the aggregator instance |
| 551 | 551 | */ |
| 552 | - public function createAggregator($config){ |
|
| 552 | + public function createAggregator($config) { |
|
| 553 | 553 | return $this->createReplyMessageHandler($config); |
| 554 | 554 | } |
| 555 | 555 | |
@@ -562,7 +562,7 @@ discard block |
||
| 562 | 562 | * @param object $config configuration object for the wiretap. |
| 563 | 563 | * @return object the wiretap instance |
| 564 | 564 | */ |
| 565 | - public function createWiretap($config){ |
|
| 565 | + public function createWiretap($config) { |
|
| 566 | 566 | return $this->createReplyMessageHandler($config, 'Wiretap'); |
| 567 | 567 | } |
| 568 | 568 | |
@@ -575,7 +575,7 @@ discard block |
||
| 575 | 575 | * @param string $defaultClass the class to use if none is set in config. |
| 576 | 576 | * @return object the reply-message-handler instance |
| 577 | 577 | */ |
| 578 | - public function createReplyMessageHandler($config, $defaultClass = false){ |
|
| 578 | + public function createReplyMessageHandler($config, $defaultClass = false) { |
|
| 579 | 579 | return $this->buildAndModify($config, $this->getReplyHandlerArguments($config), $defaultClass); |
| 580 | 580 | } |
| 581 | 581 | |
@@ -588,12 +588,12 @@ discard block |
||
| 588 | 588 | * @param string $defaultClass the class to use if none is set in config. |
| 589 | 589 | * @return object the service-activator instance |
| 590 | 590 | */ |
| 591 | - public function createServiceActivator($config, $defaultClass = false){ |
|
| 591 | + public function createServiceActivator($config, $defaultClass = false) { |
|
| 592 | 592 | $method = (string)$config['method']; |
| 593 | 593 | $service = $this->getService((string)$config['ref']); |
| 594 | - if($method && $service){ |
|
| 594 | + if ($method && $service) { |
|
| 595 | 595 | $args = $this->getReplyHandlerArguments($config); |
| 596 | - array_unshift($args,array( |
|
| 596 | + array_unshift($args, array( |
|
| 597 | 597 | $service, |
| 598 | 598 | $method |
| 599 | 599 | )); |
@@ -614,11 +614,11 @@ discard block |
||
| 614 | 614 | * @param object $config configuration object for the service. |
| 615 | 615 | * @return |
| 616 | 616 | */ |
| 617 | - protected function provideService($config){ |
|
| 617 | + protected function provideService($config) { |
|
| 618 | 618 | $ref = trim((string)$config['ref']); |
| 619 | - if($ref != ''){ |
|
| 619 | + if ($ref != '') { |
|
| 620 | 620 | $service = $this->getService($ref); |
| 621 | - }else{ |
|
| 621 | + }else { |
|
| 622 | 622 | $service = $this->createService($config); |
| 623 | 623 | } |
| 624 | 624 | return $service; |
@@ -635,10 +635,10 @@ discard block |
||
| 635 | 635 | * @param object $config configuration object for the setter-method. |
| 636 | 636 | * @return string camel-cased |
| 637 | 637 | */ |
| 638 | - protected static function getSetter($config){ |
|
| 639 | - if($config['setter']){ |
|
| 638 | + protected static function getSetter($config) { |
|
| 639 | + if ($config['setter']) { |
|
| 640 | 640 | $setter = (string)$config['setter']; |
| 641 | - }elseif($config['name']){ |
|
| 641 | + }elseif ($config['name']) { |
|
| 642 | 642 | $setter = 'set'.ucfirst((string)$config['name']); |
| 643 | 643 | } |
| 644 | 644 | return $setter; |
@@ -651,29 +651,29 @@ discard block |
||
| 651 | 651 | * @param object $config configuration object to create argument from. |
| 652 | 652 | * @return mixed build argument |
| 653 | 653 | */ |
| 654 | - protected function buildArg($config){ |
|
| 655 | - if(trim((string)$config['value']) != ''){ |
|
| 654 | + protected function buildArg($config) { |
|
| 655 | + if (trim((string)$config['value']) != '') { |
|
| 656 | 656 | $arg = (string)$config['value']; |
| 657 | - }elseif($config->getName() == 'value'){ |
|
| 657 | + }elseif ($config->getName() == 'value') { |
|
| 658 | 658 | $arg = (string)$config; |
| 659 | - }elseif($config->getName() == 'list'){ |
|
| 659 | + }elseif ($config->getName() == 'list') { |
|
| 660 | 660 | $arg = array(); |
| 661 | - foreach($config->children() as $entry){ |
|
| 662 | - if($entry->getName() == 'value'){ |
|
| 663 | - if($entry['key']){ |
|
| 661 | + foreach ($config->children() as $entry) { |
|
| 662 | + if ($entry->getName() == 'value') { |
|
| 663 | + if ($entry['key']) { |
|
| 664 | 664 | $arg[(string)$entry['key']] = (string)$entry; |
| 665 | - }else{ |
|
| 665 | + }else { |
|
| 666 | 666 | $arg[] = (string)$entry; |
| 667 | 667 | } |
| 668 | - }elseif($entry->getName() == 'service'){ |
|
| 668 | + }elseif ($entry->getName() == 'service') { |
|
| 669 | 669 | $arg[] = $this->provideService($entry); |
| 670 | 670 | } |
| 671 | 671 | } |
| 672 | - }elseif($config->getName() == 'service'){ |
|
| 672 | + }elseif ($config->getName() == 'service') { |
|
| 673 | 673 | $arg = $this->provideService($config); |
| 674 | - }elseif($config->list){ |
|
| 674 | + }elseif ($config->list) { |
|
| 675 | 675 | $arg = $this->buildArg($config->list); |
| 676 | - }elseif($config->service){ |
|
| 676 | + }elseif ($config->service) { |
|
| 677 | 677 | $arg = $this->buildArg($config->service); |
| 678 | 678 | } |
| 679 | 679 | return $arg; |
@@ -687,12 +687,12 @@ discard block |
||
| 687 | 687 | * @param object $config configuration object to create arguments from. |
| 688 | 688 | * @return mixed build arguments |
| 689 | 689 | */ |
| 690 | - protected function getReplyHandlerArguments($config){ |
|
| 690 | + protected function getReplyHandlerArguments($config) { |
|
| 691 | 691 | $args = array( |
| 692 | 692 | $this->doGetChannel('input', $config), |
| 693 | 693 | $this->doGetChannel('output', $config) |
| 694 | 694 | ); |
| 695 | - if($args[0] == NULL){ |
|
| 695 | + if ($args[0] == NULL) { |
|
| 696 | 696 | throw new \RuntimeException('Could not receive input channel.'); |
| 697 | 697 | } |
| 698 | 698 | return $args; |
@@ -707,7 +707,7 @@ discard block |
||
| 707 | 707 | * @param object $config configuration object to return request-channel from. |
| 708 | 708 | * @return \PEIP\INF\Channel\Channel request-channel |
| 709 | 709 | */ |
| 710 | - protected function getRequestChannel($config){ |
|
| 710 | + protected function getRequestChannel($config) { |
|
| 711 | 711 | return $this->doGetChannel('request', $config); |
| 712 | 712 | } |
| 713 | 713 | |
@@ -720,7 +720,7 @@ discard block |
||
| 720 | 720 | * @param object $config configuration object to return reply-channel from. |
| 721 | 721 | * @return \PEIP\INF\Channel\Channel reply-channel |
| 722 | 722 | */ |
| 723 | - protected function getReplyChannel($config){ |
|
| 723 | + protected function getReplyChannel($config) { |
|
| 724 | 724 | return $this->doGetChannel('reply', $config); |
| 725 | 725 | } |
| 726 | 726 | |
@@ -733,7 +733,7 @@ discard block |
||
| 733 | 733 | * @param object $config configuration object to return channel from. |
| 734 | 734 | * @return \PEIP\INF\Channel\Channel reply-channel |
| 735 | 735 | */ |
| 736 | - public function doGetChannel($type, $config){ |
|
| 736 | + public function doGetChannel($type, $config) { |
|
| 737 | 737 | $channelName = $config[$type."_channel"] |
| 738 | 738 | ? $config[$type."_channel"] |
| 739 | 739 | : $config["default_".$type."_channel"]; |
@@ -753,7 +753,7 @@ discard block |
||
| 753 | 753 | * @param string $defaultClass class to create instance for if none is set in config |
| 754 | 754 | * @return object build and modified srvice instance |
| 755 | 755 | */ |
| 756 | - public function buildAndModify($config, $arguments, $defaultClass = false){ |
|
| 756 | + public function buildAndModify($config, $arguments, $defaultClass = false) { |
|
| 757 | 757 | return ServiceFactory::buildAndModify($config, $arguments, $defaultClass); |
| 758 | 758 | } |
| 759 | 759 | |
@@ -767,21 +767,21 @@ 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 | - protected static function doBuild($config, $arguments, $defaultClass = false){ |
|
| 770 | + protected static function doBuild($config, $arguments, $defaultClass = false) { |
|
| 771 | 771 | $cls = $config["class"] ? trim((string)$config["class"]) : (string)$defaultClass; |
| 772 | - if($cls != ''){ |
|
| 772 | + if ($cls != '') { |
|
| 773 | 773 | try { |
| 774 | 774 | $constructor = (string)$config["constructor"]; |
| 775 | - if($constructor != ''){ |
|
| 775 | + if ($constructor != '') { |
|
| 776 | 776 | $service = call_user_func_array(array($cls, $constructor), $arguments); |
| 777 | - }else{ |
|
| 777 | + }else { |
|
| 778 | 778 | $service = self::build($cls, $arguments); |
| 779 | 779 | } |
| 780 | - }catch(\Exception $e){ |
|
| 780 | + } catch (\Exception $e) { |
|
| 781 | 781 | throw new \RuntimeException('Could not create Service "'.$cls.'" -> '.$e->getMessage()); |
| 782 | 782 | } |
| 783 | 783 | } |
| 784 | - if(is_object($service)){ |
|
| 784 | + if (is_object($service)) { |
|
| 785 | 785 | return $service; |
| 786 | 786 | } |
| 787 | 787 | throw new \RuntimeException('Could not create Service "'.$cls.'". Class does not exist.'); |
@@ -797,13 +797,13 @@ discard block |
||
| 797 | 797 | * @param array $arguments arguments for the constructor |
| 798 | 798 | * @return object build and modified srvice instance |
| 799 | 799 | */ |
| 800 | - protected static function build($className, $arguments){ |
|
| 800 | + protected static function build($className, $arguments) { |
|
| 801 | 801 | return GenericBuilder::getInstance($className)->build($arguments); |
| 802 | 802 | } |
| 803 | 803 | |
| 804 | - protected static function hasPublicProperty($service, $type, $name){ |
|
| 804 | + protected static function hasPublicProperty($service, $type, $name) { |
|
| 805 | 805 | $reflection = GenericBuilder::getInstance(get_class($service))->getReflectionClass(); |
| 806 | - if($reflection->{'has'.$type}($name) && $reflection->{'get'.$type}($name)->isPublic()){ |
|
| 806 | + if ($reflection->{'has'.$type}($name) && $reflection->{'get'.$type}($name)->isPublic()) { |
|
| 807 | 807 | return true; |
| 808 | 808 | } |
| 809 | 809 | return false; |