Completed
Push — master ( 7b9c22...3563e8 )
by Nikola
03:28
created

Manager::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
ccs 0
cts 3
cp 0
rs 9.4286
cc 1
eloc 4
nc 1
nop 3
crap 2
1
<?php
2
/*
3
 * This file is part of the Backup package, an RunOpenCode project.
4
 *
5
 * (c) 2015 RunOpenCode
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * This project is fork of "kbond/php-backup", for full credits info, please
11
 * view CREDITS file that was distributed with this source code.
12
 */
13
namespace RunOpenCode\Backup;
14
15
use Psr\Log\LoggerInterface;
16
use RunOpenCode\Backup\Contract\ManagerInterface;
17
use RunOpenCode\Backup\Contract\ProfileInterface;
18
use RunOpenCode\Backup\Event\EventDispatcherAwareTrait;
19
use RunOpenCode\Backup\Log\LoggerAwareTrait;
20
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
21
22
/**
23
 * Class Manager
24
 *
25
 * Backup manager.
26
 *
27
 * @package RunOpenCode\Backup
28
 */
29
final class Manager implements ManagerInterface
30
{
31
    use LoggerAwareTrait;
32
    use EventDispatcherAwareTrait;
33
34
    /**
35
     * @var ProfileInterface[]
36
     */
37
    private $profiles;
38
39
    /**
40
     * @var EventDispatcherInterface
41
     */
42
    private $eventDispatcher;
43
44
    /**
45
     * @var LoggerInterface
46
     */
47
    private $logger;
48
49
    public function __construct(EventDispatcherInterface $eventDispatcher = null, LoggerInterface $logger = null, $profiles = array())
50
    {
51
        $this->profiles = $profiles;
52
        $this->eventDispatcher = $eventDispatcher;
53
        $this->logger = $logger;
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59
    public function add(ProfileInterface $profile)
60
    {
61
        $this->profiles[$profile->getName()] = $profile;
62
        return $this;
63
    }
64
65
    /**
66
     * {@inheritdoc}
67
     */
68
    public function has($name)
69
    {
70
        return (isset($this->profiles[$name]));
71
    }
72
73
    /**
74
     * {@inheritdoc}
75
     */
76
    public function get($name)
77
    {
78
        return $this->profiles[$name];
79
    }
80
81
    /**
82
     * {@inheritdoc}
83
     */
84
    public function execute($name)
85
    {
86
        if (!$this->has($name)) {
87
            throw new \RuntimeException(sprintf('Unknown profile: "%s".', $name));
88
        }
89
90
        $this->get($name)->getWorkflow()->execute($this->get($name));
91
92
        return $this;
93
    }
94
95
    /**
96
     * {@inheritdoc}
97
     */
98
    public function getIterator()
99
    {
100
        return new \ArrayIterator($this->profiles);
101
    }
102
}
103