StorageMessage::setIdentifier()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
crap 1
1
<?php
2
3
/*
4
 * Copyright (c) 2011-2015, Celestino Diaz <[email protected]>
5
 *
6
 * Permission is hereby granted, free of charge, to any person obtaining a copy
7
 * of this software and associated documentation files (the "Software"), to deal
8
 * in the Software without restriction, including without limitation the rights
9
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
 * copies of the Software, and to permit persons to whom the Software is
11
 * furnished to do so, subject to the following conditions:
12
 *
13
 * The above copyright notice and this permission notice shall be included in
14
 * all copies or substantial portions of the Software.
15
 *
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
 * THE SOFTWARE.
23
 */
24
25
namespace Brickoo\Component\Storage\Messaging\Message;
26
27
use Brickoo\Component\Messaging\GenericMessage;
28
use Brickoo\Component\Common\Assert;
29
30
/**
31
 * StorageMessage
32
 *
33
 * Implements a cache message definition.
34
 * @author Celestino Diaz <[email protected]>
35
 */
36
class StorageMessage extends GenericMessage {
37
38
    /**
39
     * Storage message identifier parameter.
40
     * @var string
41
     */
42
    const PARAM_IDENTIFIER = "id";
43
44
    /**
45
     * Storage message content parameter
46
     * @var string
47
     */
48
    const PARAM_CONTENT = "content";
49
50
    /**
51
     * Storage message callback parameter.
52
     * @var string
53
     */
54
    const PARAM_CALLBACK = "callback";
55
56
    /**
57
     * Storage message callback arguments parameter.
58
     * @var string
59
     */
60
    const PARAM_CALLBACK_ARGS = "callbackArguments";
61
62
    /**
63
     * Storage message content lifetime parameter.
64
     * @var string
65
     */
66
    const PARAM_LIFETIME = "lifetime";
67
68
    /**
69
     * Set the cache message identifier.
70
     * @param string $identifier
71
     * @throws \InvalidArgumentException
72
     * @return \Brickoo\Component\Storage\Messaging\Message\StorageMessage
73
     */
74 1
    public function setIdentifier($identifier) {
75 1
        Assert::isString($identifier);
76 1
        $this->setParam(self::PARAM_IDENTIFIER, $identifier);
77 1
        return $this;
78
    }
79
80
    /**
81
     * Return the cache identifier.
82
     * @return string the cache identifier
83
     */
84 1
    public function getIdentifier() {
85 1
        return $this->getParam(self::PARAM_IDENTIFIER);
86
    }
87
88
    /**
89
     * Set the cache message content to cache.
90
     * @param mixed $content
91
     * @return \Brickoo\Component\Storage\Messaging\Message\StorageMessage
92
     */
93 1
    public function setContent($content) {
94 1
        $this->setParam(self::PARAM_CONTENT, $content);
95 1
        return $this;
96
    }
97
98
    /**
99
     * Return the content to cache.
100
     * @return mixed the content to cache
101
     */
102 1
    public function getContent() {
103 1
        return $this->getParam(self::PARAM_CONTENT);
104
    }
105
106
    /**
107
     * Set the retrieve fresh copy callback.
108
     * @param callable $callback
109
     * @return \Brickoo\Component\Storage\Messaging\Message\StorageMessage
110
     */
111 1
    public function setCallback(callable $callback) {
112 1
        $this->setParam(self::PARAM_CALLBACK, $callback);
113 1
        return $this;
114
    }
115
116
    /**
117
     * Return the callback for fresh content pull.
118
     * @return callable
119
     */
120 1
    public function getCallback() {
121 1
        return $this->getParam(self::PARAM_CALLBACK);
122
    }
123
124
    /**
125
     * Set the callback arguments.
126
     * @param array $arguments
127
     * @return \Brickoo\Component\Storage\Messaging\Message\StorageMessage
128
     */
129 1
    public function setCallbackArguments(array $arguments) {
130 1
        $this->setParam(self::PARAM_CALLBACK_ARGS, $arguments);
131 1
        return $this;
132
    }
133
134
    /**
135
     * Returns the callback arguments needed to be passed.
136
     * @return array the callback arguments
137
     */
138 1
    public function getCallbackArguments() {
139 1
        return $this->getParam(self::PARAM_CALLBACK_ARGS);
140
    }
141
142
    /**
143
     * Set the cache content lifetime.
144
     * @param integer $lifetime
145
     * @throws \InvalidArgumentException
146
     * @return \Brickoo\Component\Storage\Messaging\Message\StorageMessage
147
     */
148 1
    public function setLifetime($lifetime) {
149 1
        Assert::isInteger($lifetime);
150 1
        $this->setParam(self::PARAM_LIFETIME, $lifetime);
151 1
        return $this;
152
    }
153
154
    /**
155
     * Returns the maximum cache lifetime for fresh content pulls.
156
     * @return integer the cache lifetime
157
     */
158 1
    public function getLifetime() {
159 1
        return $this->getParam(self::PARAM_LIFETIME);
160
    }
161
162
}
163