Completed
Push — 8.x ( 824af6 )
by Tim
09:11
created

SerializerTrait::getSerializer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 0
cts 4
cp 0
rs 10
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
/**
4
 * TechDivision\Import\Adapter\SerializerTrait
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 2016 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/techdivision/import
18
 * @link      http://www.techdivision.com
19
 */
20
21
namespace TechDivision\Import\Adapter;
22
23
use TechDivision\Import\Serializers\SerializerInterface;
24
25
/**
26
 * The trait implementation that provides serializer functionality.
27
 *
28
 * @author    Tim Wagner <[email protected]>
29
 * @copyright 2016 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/techdivision/import
32
 * @link      http://www.techdivision.com
33
 */
34
trait SerializerTrait
35
{
36
37
    /**
38
     * The serializer instance to use.
39
     *
40
     * @var \TechDivision\Import\Serializers\SerializerInterface
41
     */
42
    protected $serializer;
43
44
    /**
45
     * Sets the serializer instance.
46
     *
47
     * @param \TechDivision\Import\Serializers\SerializerInterface $serializer The serializer instance
48
     *
49
     * @return void
50
     */
51
    public function setSerializer(SerializerInterface $serializer)
52
    {
53
        $this->serializer = $serializer;
54
    }
55
56
    /**
57
     * Returns the serializer instance.
58
     *
59
     * @return \TechDivision\Import\Serializers\SerializerInterface The serializer instance
60
     */
61
    public function getSerializer()
62
    {
63
        return $this->serializer;
64
    }
65
66
    /**
67
     * Extracts the elements of the passed value by exploding them
68
     * with the also passed delimiter.
69
     *
70
     * @param string|null $value     The value to extract
71
     * @param string|null $delimiter The delimiter used to extrace the elements
72
     *
73
     * @return array|null The exploded values
74
     */
75
    public function explode($value = null, $delimiter = null)
76
    {
77
        return $this->getSerializer()->explode($value, $delimiter);
78
    }
79
80
    /**
81
     * Compacts the elements of the passed value by imploding them
82
     * with the also passed delimiter.
83
     *
84
     * @param array|null  $value     The values to compact
85
     * @param string|null $delimiter The delimiter use to implode the values
86
     *
87
     * @return string|null The compatected value
88
     */
89
    public function implode(array $value = null, $delimiter = null)
90
    {
91
        return $this->getSerializer()->implode($value, $delimiter);
92
    }
93
94
    /**
95
     * Serializes the elements of the passed array.
96
     *
97
     * @param array|null $unserialized The serialized data
98
     *
99
     * @return string The serialized array
100
     */
101
    public function serialize(array $unserialized = null)
102
    {
103
        return $this->getSerializer()->serialize($unserialized);
104
    }
105
106
    /**
107
     * Unserializes the elements of the passed string.
108
     *
109
     * @param string|null $serialized The value to unserialize
110
     *
111
     * @return array The unserialized values
112
     */
113
    public function unserialize($serialized = null)
114
    {
115
        return $this->getSerializer()->unserialize($serialized);
116
    }
117
}
118