Completed
Push — master ( b5ceee...f69b09 )
by Marco
05:46
created

RouterCache::dump()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 1
nop 2
crap 2
1
<?php namespace Comodojo\Dispatcher\Cache;
2
3
/**
4
 * Router cache handler
5
 *
6
 * The dispatcher router uses the cache layer to store a "compiled" version of
7
 * the routing table, to speedup the parsing of configuration files at startup.
8
 *
9
 * @package     Comodojo Dispatcher
10
 * @author      Marco Giovinazzi <[email protected]>
11
 * @author      Marco Castiello <[email protected]>
12
 * @license     MIT
13
 *
14
 * LICENSE:
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
class RouterCache extends AbstractCache {
26
27
    /**
28
     * @const string CACHE_NAMESPACE
29
     *  Namespace for routing table cache
30
     */
31
    const CACHE_NAMESPACE = "DISPATCHERINTERNALS";
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal DISPATCHERINTERNALS does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
32
33
    /**
34
     * @const string CACHE_NAME
35
     *  Name for routing table cache
36
     */
37
    const CACHE_NAME = "dispatcher-routes";
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal dispatcher-routes does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
38
39
    /**
40
     * Read the routing table from cache (if any)
41
     *
42
     * @return array
43
     */
44 1
    public function read() {
45
46 1
        return $this->getCache()
47 1
            ->setNamespace(self::CACHE_NAMESPACE)
48 1
            ->get(self::CACHE_NAME);
49
50
    }
51
52
    /**
53
     * Store the routing table in cache
54
     *
55
     * @return array $data
56
     * @return int $ttl
57
     * @return bool
58
     */
59 1
    public function dump($data, $ttl=null) {
60
61 1
        return $this->getCache()
62 1
            ->setNamespace(self::CACHE_NAMESPACE)
63 1
            ->set(self::CACHE_NAME, $data, $ttl === null ? self::DEFAULTTTL : intval($ttl));
64
65
    }
66
67
}
68