|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace PEIP\ABS\Service; |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the PEIP package. |
|
7
|
|
|
* (c) 2009-2011 Timo Michna <timomichna/yahoo.de> |
|
8
|
|
|
* |
|
9
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
10
|
|
|
* file that was distributed with this source code. |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
/* |
|
14
|
|
|
* PEIP\ABS\Service\ServiceActivator |
|
15
|
|
|
* Abstract base class for all service activators |
|
16
|
|
|
* |
|
17
|
|
|
* @author Timo Michna <timomichna/yahoo.de> |
|
18
|
|
|
* @package PEIP |
|
19
|
|
|
* @subpackage service |
|
20
|
|
|
* @extends \PEIP\Pipe\Pipe |
|
21
|
|
|
* @implements \PEIP\INF\Event\Connectable, \PEIP\INF\Channel\SubscribableChannel, \PEIP\INF\Channel\Channel, \PEIP\INF\Handler\Handler, \PEIP\INF\Message\MessageBuilder |
|
22
|
|
|
*/ |
|
23
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
abstract class ServiceActivator extends \PEIP\Pipe\Pipe |
|
26
|
|
|
{ |
|
27
|
|
|
protected $serviceCallable; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Handles the reply logic. |
|
31
|
|
|
* Delegates calling of service to method 'callService'. |
|
32
|
|
|
* Replies on message�s reply-channel or registered output-channel if set. |
|
33
|
|
|
* |
|
34
|
|
|
* @param \PEIP\INF\Message\Message $message message to handle/reply for |
|
35
|
|
|
* |
|
36
|
|
|
* @return |
|
37
|
|
|
*/ |
|
38
|
|
|
public function doReply(\PEIP\INF\Message\Message $message) |
|
39
|
|
|
{ |
|
40
|
|
|
$res = $this->callService($message); |
|
41
|
|
|
$out = (bool) $message->hasHeader('REPLY_CHANNEL') |
|
42
|
|
|
? $message->getHeader('REPLY_CHANNEL') |
|
43
|
|
|
: $this->outputChannel; |
|
44
|
|
|
if ($out) { |
|
45
|
|
|
$this->replyMessage($res, $res); |
|
|
|
|
|
|
46
|
|
|
} |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Calls a method on a service (registered as a callable) with |
|
51
|
|
|
* content/payload of given message as argument. |
|
52
|
|
|
* |
|
53
|
|
|
* @param \PEIP\INF\Message\Message $message message to call the service with it�s content/payload |
|
54
|
|
|
* |
|
55
|
|
|
* @return mixed result of calling the registered service callable with message content/payload |
|
56
|
|
|
*/ |
|
57
|
|
View Code Duplication |
protected function callService(\PEIP\INF\Message\Message $message) |
|
|
|
|
|
|
58
|
|
|
{ |
|
59
|
|
|
$res = null; |
|
60
|
|
|
if (is_callable($this->serviceCallable)) { |
|
61
|
|
|
$res = call_user_func($this->serviceCallable, $message->getContent()); |
|
62
|
|
|
} else { |
|
63
|
|
|
if (is_object($this->serviceCallable) && method_exists($this->serviceCallable, 'handle')) { |
|
64
|
|
|
$res = $this->serviceCallable->handle($message->getContent()); |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
return $res; |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignorePhpDoc annotation to the duplicate definition and it will be ignored.