@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | class ServiceContainer |
| 28 | 28 | extends \PEIP\ABS\Base\Connectable |
| 29 | 29 | implements |
| 30 | - \PEIP\INF\Service\ServiceContainer{
|
|
| 30 | + \PEIP\INF\Service\ServiceContainer {
|
|
| 31 | 31 | |
| 32 | 32 | protected $services = array(); |
| 33 | 33 | |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | * @param $service |
| 46 | 46 | * @return |
| 47 | 47 | */ |
| 48 | - public function setService($key, $service){
|
|
| 48 | + public function setService($key, $service) {
|
|
| 49 | 49 | $this->services[$key] = $service; |
| 50 | 50 | } |
| 51 | 51 | |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | * @param $key |
| 56 | 56 | * @return |
| 57 | 57 | */ |
| 58 | - public function getService($key){
|
|
| 58 | + public function getService($key) {
|
|
| 59 | 59 | return $this->services[$key]; |
| 60 | 60 | } |
| 61 | 61 | |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | * @param $key |
| 66 | 66 | * @return |
| 67 | 67 | */ |
| 68 | - public function hasService($key){
|
|
| 68 | + public function hasService($key) {
|
|
| 69 | 69 | return array_key_exists($key, $this->services); |
| 70 | 70 | } |
| 71 | 71 | |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | * @param $key |
| 76 | 76 | * @return |
| 77 | 77 | */ |
| 78 | - public function deleteService($key){
|
|
| 78 | + public function deleteService($key) {
|
|
| 79 | 79 | unset($this->services[$key]); |
| 80 | 80 | } |
| 81 | 81 | |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | use \PEIP\Data\InternalStoreAbstract; |
| 26 | 26 | use PEIP\Factory\DedicatedFactory; |
| 27 | 27 | |
| 28 | -class ServiceContainerBuilder extends \PEIP\Data\InternalStoreAbstract{
|
|
| 28 | +class ServiceContainerBuilder extends \PEIP\Data\InternalStoreAbstract {
|
|
| 29 | 29 | |
| 30 | 30 | |
| 31 | 31 | |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | * @param $factory |
| 36 | 36 | * @return |
| 37 | 37 | */ |
| 38 | - public function setFactory($key, DedicatedFactory $factory){
|
|
| 38 | + public function setFactory($key, DedicatedFactory $factory) {
|
|
| 39 | 39 | $this->setInternalValue($key, $factory); |
| 40 | 40 | } |
| 41 | 41 | |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | * @param $key |
| 46 | 46 | * @return |
| 47 | 47 | */ |
| 48 | - public function getFactory($key){
|
|
| 48 | + public function getFactory($key) {
|
|
| 49 | 49 | $this->getInternalValue($key); |
| 50 | 50 | } |
| 51 | 51 | |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | * @param $key |
| 56 | 56 | * @return |
| 57 | 57 | */ |
| 58 | - public function hasFactory($key){
|
|
| 58 | + public function hasFactory($key) {
|
|
| 59 | 59 | $this->hasInternalValue($key); |
| 60 | 60 | } |
| 61 | 61 | |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | * @param $key |
| 66 | 66 | * @return |
| 67 | 67 | */ |
| 68 | - public function deleteFactory($key){
|
|
| 68 | + public function deleteFactory($key) {
|
|
| 69 | 69 | $this->deleteInternalValue($key); |
| 70 | 70 | } |
| 71 | 71 | |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | * @param $key |
| 76 | 76 | * @return |
| 77 | 77 | */ |
| 78 | - public function getService($key){
|
|
| 78 | + public function getService($key) {
|
|
| 79 | 79 | return isset($this->services[$key]) ? $this->services[$key] : $this->services[$key] = $this->getFactory($key)->build(); |
| 80 | 80 | } |
| 81 | 81 | |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | * @param $key |
| 87 | 87 | * @return |
| 88 | 88 | */ |
| 89 | - public function buildService($key){
|
|
| 89 | + public function buildService($key) {
|
|
| 90 | 90 | return $this->getFactory($key)->build(); |
| 91 | 91 | } |
| 92 | 92 | |
@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | * @author timo |
| 13 | 13 | */ |
| 14 | 14 | |
| 15 | -class HeaderServiceActivator extends \PEIP\Service\ServiceActivator{
|
|
| 15 | +class HeaderServiceActivator extends \PEIP\Service\ServiceActivator {
|
|
| 16 | 16 | |
| 17 | 17 | protected $headerName; |
| 18 | 18 | |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | * @param $outputChannel |
| 25 | 25 | * @return |
| 26 | 26 | */ |
| 27 | - public function __construct($serviceCallable, $headerName, \PEIP\INF\Channel\Channel $inputChannel = NULL, \PEIP\INF\Channel\Channel $outputChannel = NULL){
|
|
| 27 | + public function __construct($serviceCallable, $headerName, \PEIP\INF\Channel\Channel $inputChannel = NULL, \PEIP\INF\Channel\Channel $outputChannel = NULL) {
|
|
| 28 | 28 | $this->headerName = $headerName; |
| 29 | 29 | parent::__construct($serviceCallable, $inputChannel, $outputChannel); |
| 30 | 30 | } |
@@ -38,12 +38,12 @@ discard block |
||
| 38 | 38 | * @param \PEIP\INF\Message\Message $message message to call the service with it�s content/payload |
| 39 | 39 | * @return mixed result of calling the registered service callable with message content/payload |
| 40 | 40 | */ |
| 41 | - protected function callService(\PEIP\INF\Message\Message $message){
|
|
| 41 | + protected function callService(\PEIP\INF\Message\Message $message) {
|
|
| 42 | 42 | $res = NULL; |
| 43 | - if(is_callable($this->serviceCallable)){
|
|
| 43 | + if (is_callable($this->serviceCallable)) {
|
|
| 44 | 44 | $res = call_user_func($this->serviceCallable, $message->getHeader($this->headerName)); |
| 45 | - }else{
|
|
| 46 | - if(is_object($this->serviceCallable) && method_exists($this->serviceCallable, 'handle')){
|
|
| 45 | + }else {
|
|
| 46 | + if (is_object($this->serviceCallable) && method_exists($this->serviceCallable, 'handle')) {
|
|
| 47 | 47 | $res = $this->serviceCallable->handle($message->getHeader($this->headerName)); |
| 48 | 48 | } |
| 49 | 49 | } |
@@ -33,12 +33,12 @@ |
||
| 33 | 33 | * @param $outputChannel |
| 34 | 34 | * @return |
| 35 | 35 | */ |
| 36 | - public function __construct($serviceCallable, \PEIP\INF\Channel\Channel $inputChannel = NULL, \PEIP\INF\Channel\Channel $outputChannel = NULL){
|
|
| 36 | + public function __construct($serviceCallable, \PEIP\INF\Channel\Channel $inputChannel = NULL, \PEIP\INF\Channel\Channel $outputChannel = NULL) {
|
|
| 37 | 37 | $this->serviceCallable = $serviceCallable; |
| 38 | - if(is_object($inputChannel)){
|
|
| 38 | + if (is_object($inputChannel)) {
|
|
| 39 | 39 | $this->setInputChannel($inputChannel); |
| 40 | 40 | } |
| 41 | - if(is_object($outputChannel)){
|
|
| 41 | + if (is_object($outputChannel)) {
|
|
| 42 | 42 | $this->setOutputChannel($outputChannel); |
| 43 | 43 | } |
| 44 | 44 | } |
@@ -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,17 +83,17 @@ discard block |
||
| 83 | 83 | * @see XMLContext::includeContext |
| 84 | 84 | * @access protected |
| 85 | 85 | */ |
| 86 | - protected function initNodeBuilders(){ return;
|
|
| 86 | + protected function initNodeBuilders() { return;
|
|
| 87 | 87 | $builders = array( |
| 88 | 88 | 'service' => 'initService' |
| 89 | 89 | ); |
| 90 | 90 | $plugin = new BasePlugin(); |
| 91 | - foreach($builders as $nodeName => $method){
|
|
| 91 | + foreach ($builders as $nodeName => $method) {
|
|
| 92 | 92 | $this->registerNodeBuilder($nodeName, array($this, $method)); |
| 93 | 93 | } |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | - public function addConfig($config){
|
|
| 96 | + public function addConfig($config) {
|
|
| 97 | 97 | $this->doFireEvent( |
| 98 | 98 | self::EVENT_BEFORE_ADD_CONFIG, |
| 99 | 99 | array( |
@@ -112,15 +112,15 @@ discard block |
||
| 112 | 112 | ); |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | - public function provideService($key){
|
|
| 115 | + public function provideService($key) {
|
|
| 116 | 116 | $this->doFireEvent(self::EVENT_BEFORE_PROVIDE_SERVICE, array( |
| 117 | 117 | self::HEADER_KEY=>$key) |
| 118 | 118 | ); |
| 119 | 119 | |
| 120 | - if($this->hasService($key)){
|
|
| 121 | - $service = $this->getService($key); |
|
| 122 | - }else{
|
|
| 123 | - $service = $this->createService($key); |
|
| 120 | + if ($this->hasService($key)) {
|
|
| 121 | + $service = $this->getService($key); |
|
| 122 | + }else {
|
|
| 123 | + $service = $this->createService($key); |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | $this->doFireEvent(self::EVENT_AFTER_PROVIDE_SERVICE, array( |
@@ -131,16 +131,16 @@ discard block |
||
| 131 | 131 | return $service; |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | - protected function createService($key){
|
|
| 134 | + protected function createService($key) {
|
|
| 135 | 135 | $this->doFireEvent(self::EVENT_BEFORE_CREATE_SERVICE, array( |
| 136 | 136 | self::HEADER_KEY=>$key) |
| 137 | 137 | ); |
| 138 | 138 | $errorMessage = ''; |
| 139 | 139 | $config = $this->getServiceConfig($key); |
| 140 | 140 | |
| 141 | - if($config){
|
|
| 141 | + if ($config) {
|
|
| 142 | 142 | $node = $this->buildNode($config); |
| 143 | - if($node){
|
|
| 143 | + if ($node) {
|
|
| 144 | 144 | $this->setService( |
| 145 | 145 | $key, |
| 146 | 146 | $node |
@@ -151,11 +151,11 @@ discard block |
||
| 151 | 151 | )); |
| 152 | 152 | |
| 153 | 153 | return $node; |
| 154 | - }else{
|
|
| 154 | + }else {
|
|
| 155 | 155 | $errorMessage = 'COULD NOT BUILD NODE FOR KEY: '.$key; |
| 156 | 156 | } |
| 157 | 157 | |
| 158 | - }else{
|
|
| 158 | + }else {
|
|
| 159 | 159 | $errorMessage = 'NO CONFIG FOR KEY: '.$key; |
| 160 | 160 | } |
| 161 | 161 | $this->doFireEvent(self::EVENT_CREATE_SERVICE_ERROR, array( |
@@ -165,8 +165,8 @@ discard block |
||
| 165 | 165 | return NULL; |
| 166 | 166 | } |
| 167 | 167 | |
| 168 | - public function getServiceConfig($key){
|
|
| 169 | - if(!isset($this->ids[$key])){
|
|
| 168 | + public function getServiceConfig($key) {
|
|
| 169 | + if (!isset($this->ids[$key])) {
|
|
| 170 | 170 | return false; |
| 171 | 171 | } |
| 172 | 172 | return $this->config[$this->ids[$key]]; |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | * @param object $config configuration-node |
| 182 | 182 | * @return void |
| 183 | 183 | */ |
| 184 | - protected function buildNode($config){
|
|
| 184 | + protected function buildNode($config) {
|
|
| 185 | 185 | $nodeName = (string)$config['type']; |
| 186 | 186 | |
| 187 | 187 | $this->doFireEvent(self::EVENT_BEFORE_BUILD_NODE, array( |
@@ -189,20 +189,20 @@ discard block |
||
| 189 | 189 | self::HEADER_NODE_NAME=> $nodeName |
| 190 | 190 | )); |
| 191 | 191 | // call the builder method registered for the node. |
| 192 | - if(array_key_exists($nodeName, $this->nodeBuilders)){
|
|
| 192 | + if (array_key_exists($nodeName, $this->nodeBuilders)) {
|
|
| 193 | 193 | |
| 194 | 194 | $nodeInstance = call_user_func($this->nodeBuilders[$nodeName], $config); |
| 195 | - if(is_object($nodeInstance)){
|
|
| 195 | + if (is_object($nodeInstance)) {
|
|
| 196 | 196 | $this->doFireEvent(self::EVENT_BUILD_NODE_SUCCESS, array( |
| 197 | 197 | self::HEADER_NODE_CONFIG=>$config, |
| 198 | 198 | self::HEADER_NODE_NAME=> $nodeName, |
| 199 | 199 | self::HEADER_NODE => $nodeInstance |
| 200 | 200 | )); |
| 201 | 201 | return $nodeInstance; |
| 202 | - }else{
|
|
| 202 | + }else {
|
|
| 203 | 203 | $errorMessage = 'BUILDER RETURNED NO OBJECT FOR NODE-TYPE: '.$nodeName; |
| 204 | 204 | } |
| 205 | - }else{
|
|
| 205 | + }else {
|
|
| 206 | 206 | $errorMessage = 'NO BUILDER FOUND FOR NODE-TYPE: '.$nodeName; |
| 207 | 207 | } |
| 208 | 208 | |
@@ -213,27 +213,27 @@ discard block |
||
| 213 | 213 | )); |
| 214 | 214 | } |
| 215 | 215 | |
| 216 | - protected function getIdFromConfig($config){
|
|
| 216 | + protected function getIdFromConfig($config) {
|
|
| 217 | 217 | $id = ''; |
| 218 | - if(isset($config[$this->idAttribute])){
|
|
| 218 | + if (isset($config[$this->idAttribute])) {
|
|
| 219 | 219 | $id = trim((string)($config[$this->idAttribute])); |
| 220 | 220 | } |
| 221 | 221 | return $id; |
| 222 | 222 | } |
| 223 | 223 | |
| 224 | - protected function getCountConfig(){
|
|
| 224 | + protected function getCountConfig() {
|
|
| 225 | 225 | return count($this->config); |
| 226 | 226 | } |
| 227 | 227 | |
| 228 | - protected function doAddConfig($config){
|
|
| 228 | + protected function doAddConfig($config) {
|
|
| 229 | 229 | $countConfig = $this->getCountConfig(); |
| 230 | 230 | $this->config[$countConfig] = $config; |
| 231 | 231 | return $countConfig; |
| 232 | 232 | } |
| 233 | 233 | |
| 234 | - protected function doRegisterConfig($config){
|
|
| 235 | - $id = $this->getIdFromConfig($config); |
|
| 236 | - if($id != ''){
|
|
| 234 | + protected function doRegisterConfig($config) {
|
|
| 235 | + $id = $this->getIdFromConfig($config); |
|
| 236 | + if ($id != '') {
|
|
| 237 | 237 | $this->ids[$id] = $this->getCountConfig() - 1; |
| 238 | 238 | } |
| 239 | 239 | return $id; |
@@ -18,11 +18,11 @@ discard block |
||
| 18 | 18 | * @param Callable|PEIP\INF\Handler\Handler $listener listener to connect |
| 19 | 19 | * @return |
| 20 | 20 | */ |
| 21 | - public function connect($name, $listener){
|
|
| 21 | + public function connect($name, $listener) {
|
|
| 22 | 22 | $name = is_object($name) ? get_class($name) : (string)$name; |
| 23 | - if(Test::assertClassOrInterfaceExists($name)){
|
|
| 23 | + if (Test::assertClassOrInterfaceExists($name)) {
|
|
| 24 | 24 | parent::connect($name, $listener); |
| 25 | - }else{
|
|
| 25 | + }else {
|
|
| 26 | 26 | throw new \InvalidArgumentException($name." is not an Class nor Interface"); |
| 27 | 27 | } |
| 28 | 28 | } |
@@ -35,10 +35,10 @@ discard block |
||
| 35 | 35 | * @param mixed $subject the subject |
| 36 | 36 | * @return |
| 37 | 37 | */ |
| 38 | - public function notify($name, $subject){
|
|
| 38 | + public function notify($name, $subject) {
|
|
| 39 | 39 | $res = false; |
| 40 | - foreach(Reflection::getImplementedClassesAndInterfaces($name) as $cls){
|
|
| 41 | - if(parent::hasListeners($cls)){
|
|
| 40 | + foreach (Reflection::getImplementedClassesAndInterfaces($name) as $cls) {
|
|
| 41 | + if (parent::hasListeners($cls)) {
|
|
| 42 | 42 | self::doNotify($this->getListeners($cls), $subject); |
| 43 | 43 | $res = true; |
| 44 | 44 | } |
@@ -56,10 +56,10 @@ discard block |
||
| 56 | 56 | * @param mixed $subject the subject |
| 57 | 57 | * @return \PEIP\INF\Handler\Handler listener which returned a boolean true value |
| 58 | 58 | */ |
| 59 | - public function notifyUntil($name, $subject){
|
|
| 59 | + public function notifyUntil($name, $subject) {
|
|
| 60 | 60 | $res = NULL; |
| 61 | - foreach(Reflection::getImplementedClassesAndInterfaces($name) as $cls){
|
|
| 62 | - if(!$res && parent::hasListeners($cls)){
|
|
| 61 | + foreach (Reflection::getImplementedClassesAndInterfaces($name) as $cls) {
|
|
| 62 | + if (!$res && parent::hasListeners($cls)) {
|
|
| 63 | 63 | $res = self::doNotifyUntil($this->getListeners($cls), $subject); |
| 64 | 64 | } |
| 65 | 65 | } |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | * @param mixed $subject the subject |
| 76 | 76 | * @return |
| 77 | 77 | */ |
| 78 | - public function notifyOfInstance($subject){
|
|
| 78 | + public function notifyOfInstance($subject) {
|
|
| 79 | 79 | |
| 80 | 80 | return $this->notify(get_class($subject), $subject); |
| 81 | 81 | } |
@@ -86,9 +86,9 @@ discard block |
||
| 86 | 86 | * @param string $name name of the event |
| 87 | 87 | * @return boolean wether any listener is registered for event-name |
| 88 | 88 | */ |
| 89 | - public function hasListeners($name){
|
|
| 90 | - foreach(Reflection::getImplementedClassesAndInterfaces($name) as $cls){
|
|
| 91 | - if(parent::hasListeners($cls)){
|
|
| 89 | + public function hasListeners($name) {
|
|
| 90 | + foreach (Reflection::getImplementedClassesAndInterfaces($name) as $cls) {
|
|
| 91 | + if (parent::hasListeners($cls)) {
|
|
| 92 | 92 | return true; |
| 93 | 93 | } |
| 94 | 94 | } |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | * @param Callable|PEIP\INF\Handler\Handler $listener |
| 41 | 41 | * @return void |
| 42 | 42 | */ |
| 43 | - public function connect($listener){
|
|
| 43 | + public function connect($listener) {
|
|
| 44 | 44 | Test::ensureHandler($listener); |
| 45 | 45 | $this->listeners[] = $listener; |
| 46 | 46 | } |
@@ -52,10 +52,10 @@ discard block |
||
| 52 | 52 | * @param Callable|PEIP\INF\Handler\Handler $listener |
| 53 | 53 | * @return void |
| 54 | 54 | */ |
| 55 | - public function disconnect($listener){
|
|
| 55 | + public function disconnect($listener) {
|
|
| 56 | 56 | Test::ensureHandler($listener); |
| 57 | - foreach ($this->listeners as $i => $callable){
|
|
| 58 | - if ($listener === $callable){
|
|
| 57 | + foreach ($this->listeners as $i => $callable) {
|
|
| 58 | + if ($listener === $callable) {
|
|
| 59 | 59 | unset($this->listeners[$i]); |
| 60 | 60 | } |
| 61 | 61 | } |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | * @param Callable|PEIP\INF\Handler\Handler $listener |
| 69 | 69 | * @return void |
| 70 | 70 | */ |
| 71 | - public function disconnectAll(){
|
|
| 71 | + public function disconnectAll() {
|
|
| 72 | 72 | $this->listeners = array(); |
| 73 | 73 | } |
| 74 | 74 | |
@@ -78,8 +78,8 @@ discard block |
||
| 78 | 78 | * @access public |
| 79 | 79 | * @return boolean wether any listeners are registered |
| 80 | 80 | */ |
| 81 | - public function hasListeners(){
|
|
| 82 | - return (boolean) count($this->listeners); |
|
| 81 | + public function hasListeners() {
|
|
| 82 | + return (boolean)count($this->listeners); |
|
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | /** |
@@ -89,9 +89,9 @@ discard block |
||
| 89 | 89 | * @param mixed $subject the subject |
| 90 | 90 | * @return void |
| 91 | 91 | */ |
| 92 | - public function notify($subject){
|
|
| 92 | + public function notify($subject) {
|
|
| 93 | 93 | $res = NULL; |
| 94 | - if($this->hasListeners()){
|
|
| 94 | + if ($this->hasListeners()) {
|
|
| 95 | 95 | $res = self::doNotify($this->getListeners(), $subject); |
| 96 | 96 | } |
| 97 | 97 | return $res; |
@@ -104,8 +104,8 @@ discard block |
||
| 104 | 104 | * @param mixed $subject the subject |
| 105 | 105 | * @return \PEIP\INF\Handler\Handler the listener which returned a boolean true value |
| 106 | 106 | */ |
| 107 | - public function notifyUntil($subject){
|
|
| 108 | - if($this->hasListeners()){
|
|
| 107 | + public function notifyUntil($subject) {
|
|
| 108 | + if ($this->hasListeners()) {
|
|
| 109 | 109 | $res = self::doNotifyUntil($this->getListeners(), $subject); |
| 110 | 110 | } |
| 111 | 111 | return $res; |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | * @access public |
| 118 | 118 | * @return array the listeners |
| 119 | 119 | */ |
| 120 | - public function getListeners(){
|
|
| 120 | + public function getListeners() {
|
|
| 121 | 121 | return $this->listeners; |
| 122 | 122 | } |
| 123 | 123 | |
@@ -40,16 +40,16 @@ discard block |
||
| 40 | 40 | * @param \PEIP\INF\Event\Event $object an event object |
| 41 | 41 | * @return boolean |
| 42 | 42 | */ |
| 43 | - public function notify($name, $object){
|
|
| 44 | - if($object instanceof \PEIP\INF\Event\Event){
|
|
| 45 | - if(is_object($object->getContent())){
|
|
| 46 | - if($this->hasListeners($name, $object->getContent())){
|
|
| 43 | + public function notify($name, $object) {
|
|
| 44 | + if ($object instanceof \PEIP\INF\Event\Event) {
|
|
| 45 | + if (is_object($object->getContent())) {
|
|
| 46 | + if ($this->hasListeners($name, $object->getContent())) {
|
|
| 47 | 47 | return self::doNotify($this->getListeners($name, $object->getContent()), $object); |
| 48 | 48 | } |
| 49 | - }else{
|
|
| 49 | + }else {
|
|
| 50 | 50 | throw new \InvalidArgumentException('instance of \PEIP\INF\Event\Event must contain subject');
|
| 51 | 51 | } |
| 52 | - }else{
|
|
| 52 | + }else {
|
|
| 53 | 53 | throw new \InvalidArgumentException('object must be instance of \PEIP\INF\Event\Event');
|
| 54 | 54 | } |
| 55 | 55 | } |
@@ -66,8 +66,8 @@ discard block |
||
| 66 | 66 | * @return |
| 67 | 67 | * @see EventBuilder |
| 68 | 68 | */ |
| 69 | - public function buildAndNotify($name, $object, array $headers = array(), $eventClass = false, $type = false){
|
|
| 70 | - if(!$this->hasListeners($name, $object)){
|
|
| 69 | + public function buildAndNotify($name, $object, array $headers = array(), $eventClass = false, $type = false) {
|
|
| 70 | + if (!$this->hasListeners($name, $object)) {
|
|
| 71 | 71 | return false; |
| 72 | 72 | } |
| 73 | 73 | $event = EventBuilder::getInstance($eventClass)->build( |
@@ -43,13 +43,13 @@ discard block |
||
| 43 | 43 | * @param Callable|PEIP\INF\Handler\Handler $listener event-handler |
| 44 | 44 | * @return boolean |
| 45 | 45 | */ |
| 46 | - public function connect($name, $object, $listener){
|
|
| 46 | + public function connect($name, $object, $listener) {
|
|
| 47 | 47 | Test::ensureHandler($listener); |
| 48 | 48 | $listners = $this->doGetListeners(); |
| 49 | - if (!$this->listeners->contains($object)){
|
|
| 49 | + if (!$this->listeners->contains($object)) {
|
|
| 50 | 50 | $this->listeners->attach($object, new \ArrayObject); |
| 51 | 51 | } |
| 52 | - if (!array_key_exists($name, $listners[$object])){
|
|
| 52 | + if (!array_key_exists($name, $listners[$object])) {
|
|
| 53 | 53 | $this->listeners[$object][$name] = array(); |
| 54 | 54 | } |
| 55 | 55 | $hash = $this->getListenerHash($listener); |
@@ -67,14 +67,14 @@ discard block |
||
| 67 | 67 | * @param \PEIP\INF\Handler\Handler $listener event-handler |
| 68 | 68 | * @return boolean |
| 69 | 69 | */ |
| 70 | - public function disconnect($name, $object, $listener){
|
|
| 70 | + public function disconnect($name, $object, $listener) {
|
|
| 71 | 71 | $listners = $this->doGetListeners(); |
| 72 | - if (!$listners->contains($object) || !isset($listners[$object][$name])){
|
|
| 72 | + if (!$listners->contains($object) || !isset($listners[$object][$name])) {
|
|
| 73 | 73 | return false; |
| 74 | 74 | } |
| 75 | 75 | $eventListeners = $listners[$object][$name]; |
| 76 | 76 | $hash = $this->getListenerHash($listener); |
| 77 | - if(isset($eventListeners[$hash])){
|
|
| 77 | + if (isset($eventListeners[$hash])) {
|
|
| 78 | 78 | unset($eventListeners[$hash]); |
| 79 | 79 | |
| 80 | 80 | $listners[$object][$name] = $eventListeners; |
@@ -83,10 +83,10 @@ discard block |
||
| 83 | 83 | return false; |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | - public function disconnectAll($name, $object){
|
|
| 87 | - if(is_object($object)){
|
|
| 86 | + public function disconnectAll($name, $object) {
|
|
| 87 | + if (is_object($object)) {
|
|
| 88 | 88 | $listners = $this->doGetListeners(); |
| 89 | - if($listners && $this->hadListeners($name, $object)){
|
|
| 89 | + if ($listners && $this->hadListeners($name, $object)) {
|
|
| 90 | 90 | $listners[$object][$name] = array(); |
| 91 | 91 | } |
| 92 | 92 | } |
@@ -100,13 +100,13 @@ discard block |
||
| 100 | 100 | * @param object $object object to check for listeners |
| 101 | 101 | * @return boolean |
| 102 | 102 | */ |
| 103 | - public function hasListeners($name, $object){
|
|
| 103 | + public function hasListeners($name, $object) {
|
|
| 104 | 104 | $listners = $this->doGetListeners(); |
| 105 | - if (!$this->hadListeners($name, $object)){
|
|
| 105 | + if (!$this->hadListeners($name, $object)) {
|
|
| 106 | 106 | $res = false; |
| 107 | - }else{
|
|
| 107 | + }else {
|
|
| 108 | 108 | $listners = $this->doGetListeners(); |
| 109 | - $res = (boolean) count($listners[$object][$name]); |
|
| 109 | + $res = (boolean)count($listners[$object][$name]); |
|
| 110 | 110 | } |
| 111 | 111 | return $res; |
| 112 | 112 | } |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | * @param object $object object to check for listeners |
| 120 | 120 | * @return boolean |
| 121 | 121 | */ |
| 122 | - public function hadListeners($name, $object){
|
|
| 122 | + public function hadListeners($name, $object) {
|
|
| 123 | 123 | $listners = $this->doGetListeners(); |
| 124 | 124 | return ($listners->contains($object) && isset($listners[$object][$name])) ? true : false; |
| 125 | 125 | } |
@@ -131,9 +131,9 @@ discard block |
||
| 131 | 131 | * @param object $object object to get event-names for |
| 132 | 132 | * @return string[] array of event-names |
| 133 | 133 | */ |
| 134 | - public function getEventNames($object){
|
|
| 134 | + public function getEventNames($object) {
|
|
| 135 | 135 | $listeners = $this->doGetListeners(); |
| 136 | - if (!$listeners->contains($object)){
|
|
| 136 | + if (!$listeners->contains($object)) {
|
|
| 137 | 137 | return array(); |
| 138 | 138 | } |
| 139 | 139 | return array_keys($listeners[$object]->getArrayCopy()); |
@@ -147,8 +147,8 @@ discard block |
||
| 147 | 147 | * @param $object |
| 148 | 148 | * @return boolean |
| 149 | 149 | */ |
| 150 | - public function notify($name, $object){
|
|
| 151 | - if($this->hasListeners($name, $object)){
|
|
| 150 | + public function notify($name, $object) {
|
|
| 151 | + if ($this->hasListeners($name, $object)) {
|
|
| 152 | 152 | $listners = $this->doGetListeners(); |
| 153 | 153 | self::doNotify($listners[$object][$name], $object); |
| 154 | 154 | } |
@@ -164,8 +164,8 @@ discard block |
||
| 164 | 164 | * @param $subject |
| 165 | 165 | * @return mixed |
| 166 | 166 | */ |
| 167 | - public function notifyUntil($name, $subject){
|
|
| 168 | - if($this->hasListeners($name, $subject)){
|
|
| 167 | + public function notifyUntil($name, $subject) {
|
|
| 168 | + if ($this->hasListeners($name, $subject)) {
|
|
| 169 | 169 | $res = self::doNotifyUntil($this->getListeners($name, $subject), $subject); |
| 170 | 170 | } |
| 171 | 171 | return $res; |
@@ -179,8 +179,8 @@ discard block |
||
| 179 | 179 | * @param object $object object to check for listeners |
| 180 | 180 | * @return array array of listeners |
| 181 | 181 | */ |
| 182 | - public function getListeners($name, $object){
|
|
| 183 | - if (!$this->hadListeners($name, $object)){
|
|
| 182 | + public function getListeners($name, $object) {
|
|
| 183 | + if (!$this->hadListeners($name, $object)) {
|
|
| 184 | 184 | return array(); |
| 185 | 185 | } |
| 186 | 186 | $listeners = $this->listeners[$object]->getArrayCopy(); |
@@ -194,7 +194,7 @@ discard block |
||
| 194 | 194 | * @access protected |
| 195 | 195 | * @return ObjectStorage |
| 196 | 196 | */ |
| 197 | - protected function doGetListeners(){
|
|
| 197 | + protected function doGetListeners() {
|
|
| 198 | 198 | return isset($this->listeners) ? $this->listeners : $this->listeners = new ObjectStorage(); |
| 199 | 199 | } |
| 200 | 200 | |
@@ -207,11 +207,11 @@ discard block |
||
| 207 | 207 | * @param $object |
| 208 | 208 | * @return boolean |
| 209 | 209 | */ |
| 210 | - protected static function doNotify(array $listeners, $subject){
|
|
| 211 | - foreach($listeners as $listener){
|
|
| 212 | - if($listener instanceof \PEIP\INF\Handler\Handler){
|
|
| 210 | + protected static function doNotify(array $listeners, $subject) {
|
|
| 211 | + foreach ($listeners as $listener) {
|
|
| 212 | + if ($listener instanceof \PEIP\INF\Handler\Handler) {
|
|
| 213 | 213 | $listener->handle($subject); |
| 214 | - }elseif(is_callable($listener)){
|
|
| 214 | + }elseif (is_callable($listener)) {
|
|
| 215 | 215 | call_user_func($listener, $subject); |
| 216 | 216 | } |
| 217 | 217 | } |
@@ -226,12 +226,12 @@ discard block |
||
| 226 | 226 | * @param $object |
| 227 | 227 | * @return \PEIP\INF\Handler\Handler the listener which returned a boolean true value |
| 228 | 228 | */ |
| 229 | - protected static function doNotifyUntil(array $listeners, $subject){
|
|
| 229 | + protected static function doNotifyUntil(array $listeners, $subject) {
|
|
| 230 | 230 | $res = NULL; |
| 231 | - foreach ($listeners as $listener){
|
|
| 232 | - if($listener instanceof \PEIP\INF\Handler\Handler){
|
|
| 231 | + foreach ($listeners as $listener) {
|
|
| 232 | + if ($listener instanceof \PEIP\INF\Handler\Handler) {
|
|
| 233 | 233 | $res = $listener->handle($subject); |
| 234 | - if ($res){
|
|
| 234 | + if ($res) {
|
|
| 235 | 235 | return $listener; |
| 236 | 236 | } |
| 237 | 237 | } |
@@ -239,8 +239,8 @@ discard block |
||
| 239 | 239 | return $res; |
| 240 | 240 | } |
| 241 | 241 | |
| 242 | - protected function getListenerHash($listener){
|
|
| 243 | - if(!is_object($listener)){
|
|
| 242 | + protected function getListenerHash($listener) {
|
|
| 243 | + if (!is_object($listener)) {
|
|
| 244 | 244 | $o = new \stdClass(); |
| 245 | 245 | $o->listener = $listener; |
| 246 | 246 | $listener = $o; |