Completed
Pull Request — master (#76)
by Luke
02:26
created

IsSerializable::toArray()

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
nc 1
dl 0
loc 1
c 0
b 0
f 0
ccs 0
cts 0
cp 0
1
<?php
2
/**
3
 * Nozavroni/Collections
4
 * Just another collections library for PHP5.6+.
5
 * @version   {version}
6
 * @copyright Copyright (c) 2016 Luke Visinoni <[email protected]>
7
 * @author    Luke Visinoni <[email protected]>
8
 * @license   https://github.com/deni-zen/csvelte/blob/master/LICENSE The MIT License (MIT)
9
 */
10
namespace Noz\Traits;
11
12
/**
13
 * Interface IsSerializable.
14
 *
15
 * Ensures a class can be converted to an array using toArray()
16
 *
17
 * @package Noz\Contracts
18
 */
19
trait IsSerializable
20
{
21
    /**
22
     * Serialize collection data and return it.
23
     *
24
     * @return string
25
     */
26
    public function serialize()
27
    {
28
        return serialize($this->toArray());
29
    }
30
31
    /**
32
     * Unserialize serialized data.
33
     *
34
     * @param string $serialized The serialized data
35
     */
36
    abstract public function unserialize($serialized);
37
38
    /**
39
     * @return array
40
     */
41
    abstract public function toArray();
42
}
43