Handler::createQueue()
last analyzed

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 1
c 0
b 0
f 0
nc 1
1
<?php
2
3
/*
4
 * This file is part of the Phive Queue package.
5
 *
6
 * (c) Eugene Leonovich <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Phive\Queue\Tests\Handler;
13
14
use Phive\Queue\Queue;
15
16
abstract class Handler implements \Serializable
17
{
18
    /**
19
     * @var array
20
     */
21
    private $options;
22
23
    public function __construct($options = null)
24
    {
25
        $this->options = (array) $options;
26
        $this->configure();
27
    }
28
29
    /**
30
     * @return array
31
     */
32
    public function getOptions()
33
    {
34
        return $this->options;
35
    }
36
37
    /**
38
     * @param string $name
39
     *
40
     * @return mixed
41
     *
42
     * @throws \InvalidArgumentException
43
     */
44
    public function getOption($name)
45
    {
46
        if (array_key_exists($name, $this->options)) {
47
            return $this->options[$name];
48
        }
49
50
        throw new \InvalidArgumentException(sprintf('Option "%s" is not found.', $name));
51
    }
52
53
    public function serialize()
54
    {
55
        return serialize($this->options);
56
    }
57
58
    public function unserialize($data)
59
    {
60
        $this->options = unserialize($data);
61
        $this->configure();
62
    }
63
64
    public function getQueueName(Queue $queue)
65
    {
66
        return get_class($queue);
67
    }
68
69
    public function reset()
70
    {
71
    }
72
73
    public function clear()
74
    {
75
    }
76
77
    protected function configure()
78
    {
79
    }
80
81
    /**
82
     * @return Queue
83
     */
84
    abstract public function createQueue();
85
}
86