1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* AppserverIo\Messaging\IntegerMessage |
5
|
|
|
* |
6
|
|
|
* NOTICE OF LICENSE |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the Open Software License (OSL 3.0) |
9
|
|
|
* that is available through the world-wide-web at this URL: |
10
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
11
|
|
|
* |
12
|
|
|
* PHP version 5 |
13
|
|
|
* |
14
|
|
|
* @author Tim Wagner <[email protected]> |
15
|
|
|
* @copyright 2015 TechDivision GmbH <[email protected]> |
16
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
17
|
|
|
* @link https://github.com/appserver-io/messaging |
18
|
|
|
* @link http://www.appserver.io |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace AppserverIo\Messaging; |
22
|
|
|
|
23
|
|
|
use Rhumsaa\Uuid\Uuid; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* The implementation for sending a message containing data encapsulated in a Integer. |
27
|
|
|
* |
28
|
|
|
* @author Tim Wagner <[email protected]> |
29
|
|
|
* @copyright 2015 TechDivision GmbH <[email protected]> |
30
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
31
|
|
|
* @link https://github.com/appserver-io/messaging |
32
|
|
|
* @link http://www.appserver.io |
33
|
|
|
*/ |
34
|
|
View Code Duplication |
class IntegerMessage extends AbstractMessage |
|
|
|
|
35
|
|
|
{ |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* The message id as hash value. |
39
|
|
|
* |
40
|
|
|
* @var string |
41
|
|
|
*/ |
42
|
|
|
protected $messageId = null; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* The message itself. |
46
|
|
|
* |
47
|
|
|
* @var integer |
48
|
|
|
*/ |
49
|
|
|
protected $message = null; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Initializes the message with the Integer |
53
|
|
|
* to send to the queue. |
54
|
|
|
* |
55
|
|
|
* @param integer $message The integer with the data to send |
56
|
|
|
* |
57
|
|
|
* @throws \Exception Is thrown if the passed message is not a valid integer value |
58
|
|
|
*/ |
59
|
|
|
public function __construct($message) |
60
|
|
|
{ |
61
|
|
|
|
62
|
|
|
// call parent constructor |
63
|
|
|
parent::__construct(); |
64
|
|
|
|
65
|
|
|
// check if we've an integer passed |
66
|
|
|
if (is_integer($message) === false) { |
67
|
|
|
throw new \Exception(sprintf('Message \'%s\' is not a valid integer', $message)); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
// initialize the integer sent with the message |
71
|
|
|
$this->message = $message; |
72
|
|
|
// initialize the message id |
73
|
|
|
$this->messageId = Uuid::uuid4()->__toString(); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Returns the unique message-ID. |
78
|
|
|
* |
79
|
|
|
* @return string The unique message-ID |
80
|
|
|
*/ |
81
|
|
|
public function getMessageId() |
82
|
|
|
{ |
83
|
|
|
return $this->messageId; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* The message itself. |
88
|
|
|
* |
89
|
|
|
* @return integer The message itself |
90
|
|
|
*/ |
91
|
|
|
public function getMessage() |
92
|
|
|
{ |
93
|
|
|
return $this->message; |
|
|
|
|
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Returns the message as string. |
98
|
|
|
* |
99
|
|
|
* @return string The message as string |
100
|
|
|
*/ |
101
|
|
|
public function __toString() |
102
|
|
|
{ |
103
|
|
|
return "'" . $this->message . "'"; |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.