Completed
Push — master ( 16bb48...aeb0d0 )
by Franck
12:02
created

Msgpack::serialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
/**
4
 *
5
 * This file is part of the Apix Project.
6
 *
7
 * (c) Franck Cassedanne <franck at ouarz.net>
8
 *
9
 * @license     http://opensource.org/licenses/BSD-3-Clause  New BSD License
10
 *
11
 */
12
13
namespace Apix\Cache\Serializer;
14
15
/**
16
 * Serializes data using the Msgpack extension.
17
 * @see https://github.com/msgpack/msgpack-php
18
 *
19
 * @author Franck Cassedanne <franck at ouarz.net>
20
 */
21
class Msgpack implements Adapter
22
{
23
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function serialize($data)
28
    {
29
        return \msgpack_pack($data);
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35
    public function unserialize($str)
36
    {
37
        return \msgpack_unpack($str);
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function isSerialized($str)
44
    {
45
        if (!is_string($str)) {
46
            return false;
47
        }
48
49
        return (boolean) !is_integer( @\msgpack_unpack($str) );
50
    }
51
52
}
53