-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathSerializerTrait.php
More file actions
113 lines (102 loc) · 3.24 KB
/
SerializerTrait.php
File metadata and controls
113 lines (102 loc) · 3.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
/**
* TechDivision\Import\Adapter\SerializerTrait
*
* PHP version 7
*
* @author Tim Wagner <t.wagner@techdivision.com>
* @copyright 2016 TechDivision GmbH <info@techdivision.com>
* @license https://opensource.org/licenses/MIT
* @link https://github.com/techdivision/import
* @link http://www.techdivision.com
*/
namespace TechDivision\Import\Adapter;
use TechDivision\Import\Serializer\SerializerInterface;
/**
* The trait implementation that provides serializer functionality.
*
* @author Tim Wagner <t.wagner@techdivision.com>
* @copyright 2016 TechDivision GmbH <info@techdivision.com>
* @license https://opensource.org/licenses/MIT
* @link https://github.com/techdivision/import
* @link http://www.techdivision.com
*/
trait SerializerTrait
{
/**
* The serializer instance to use.
*
* @var \TechDivision\Import\Serializer\SerializerInterface
*/
protected $serializer;
/**
* Sets the serializer instance.
*
* @param \TechDivision\Import\Serializer\SerializerInterface $serializer The serializer instance
*
* @return void
*/
public function setSerializer(SerializerInterface $serializer)
{
$this->serializer = $serializer;
}
/**
* Returns the serializer instance.
*
* @return \TechDivision\Import\Serializer\SerializerInterface The serializer instance
*/
public function getSerializer()
{
return $this->serializer;
}
/**
* Extracts the elements of the passed value by exploding them
* with the also passed delimiter.
*
* @param string|null $value The value to extract
* @param string|null $delimiter The delimiter used to extract the elements
*
* @return array|null The exploded values
*/
public function explode($value = null, $delimiter = null)
{
return $this->getSerializer()->explode($value, $delimiter);
}
/**
* Compacts the elements of the passed value by imploding them
* with the also passed delimiter.
*
* @param array|null $value The values to compact
* @param string|null $delimiter The delimiter used to implode the values
*
* @return string|null The compatected value
*/
public function implode(?array $value = null, $delimiter = null)
{
return $this->getSerializer()->implode($value, $delimiter);
}
/**
* Serializes the elements of the passed array.
*
* @param array|null $unserialized The serialized data
* @param string|null $delimiter The delimiter used to serialize the values
*
* @return string The serialized array
*/
public function serialize(?array $unserialized = null, $delimiter = null)
{
return $this->getSerializer()->serialize($unserialized, $delimiter);
}
/**
* Unserializes the elements of the passed string.
*
* @param string|null $serialized The value to unserialize
* @param string|null $delimiter The delimiter used to unserialize the elements
*
* @return array The unserialized values
*/
public function unserialize($serialized = null, $delimiter = null)
{
return $this->getSerializer()->unserialize($serialized, $delimiter);
}
}