Completed
Push — master ( 81de03...f81b3d )
by Michael
02:52
created

FileSystemWiring   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 1
dl 0
loc 40
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B wire() 0 31 4
1
<?php
2
/**
3
 * Contains class FileSystemWiring.
4
 *
5
 * PHP version 5.5
6
 *
7
 * LICENSE:
8
 * This file is part of Yet Another Php Eve Api Library also know as Yapeal
9
 * which can be used to access the Eve Online API data and place it into a
10
 * database.
11
 * Copyright (C) 2016 Michael Cummings
12
 *
13
 * This program is free software: you can redistribute it and/or modify it
14
 * under the terms of the GNU Lesser General Public License as published by the
15
 * Free Software Foundation, either version 3 of the License, or (at your
16
 * option) any later version.
17
 *
18
 * This program is distributed in the hope that it will be useful, but WITHOUT
19
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
21
 * for more details.
22
 *
23
 * You should have received a copy of the GNU Lesser General Public License
24
 * along with this program. If not, see
25
 * <http://www.gnu.org/licenses/>.
26
 *
27
 * You should be able to find a copy of this license in the LICENSE.md file. A
28
 * copy of the GNU GPL should also be available in the GNU-GPL.md file.
29
 *
30
 * @copyright 2016 Michael Cummings
31
 * @license   LGPL-3.0+
32
 * @author    Michael Cummings <[email protected]>
33
 */
34
namespace Yapeal\Configuration;
35
36
use Yapeal\Container\ContainerInterface;
37
38
/**
39
 * Class FileSystemWiring.
40
 */
41
class FileSystemWiring implements WiringInterface
42
{
43
    /**
44
     * @param ContainerInterface $dic
45
     *
46
     * @return self Fluent interface.
47
     * @throws \LogicException
48
     */
49
    public function wire(ContainerInterface $dic)
50
    {
51
        if (empty($dic['Yapeal.FileSystem.CachePreserver'])) {
52
            $dic['Yapeal.FileSystem.CachePreserver'] = function () use ($dic) {
53
                return new $dic['Yapeal.FileSystem.Handlers.preserve']($dic['Yapeal.FileSystem.Cache.dir'],
54
                    $dic['Yapeal.FileSystem.Cache.preserve']);
55
            };
56
        }
57
        if (empty($dic['Yapeal.FileSystem.CacheRetriever'])) {
58
            $dic['Yapeal.FileSystem.CacheRetriever'] = function () use ($dic) {
59
                return new $dic['Yapeal.FileSystem.Handlers.retrieve']($dic['Yapeal.FileSystem.Cache.dir'],
60
                    $dic['Yapeal.FileSystem.Cache.retrieve']);
61
            };
62
        }
63
        if (empty($dic['Yapeal.Event.Mediator'])) {
64
            $mess = 'Tried to call Mediator before it has been added';
65
            throw new \LogicException($mess);
66
        }
67
        /**
68
         * @var \Yapeal\Event\MediatorInterface $mediator
69
         */
70
        $mediator = $dic['Yapeal.Event.Mediator'];
71
        $mediator->addServiceSubscriberByEventList('Yapeal.FileSystem.CachePreserver',
72
            [
73
                'Yapeal.EveApi.preserve' => ['preserveEveApi', 'last'],
74
                'Yapeal.Xml.Error.preserve' => ['preserveEveApi', 'last']
75
            ]);
76
        $mediator->addServiceSubscriberByEventList('Yapeal.FileSystem.CacheRetriever',
77
            ['Yapeal.EveApi.retrieve' => ['retrieveEveApi', 'last']]);
78
        return $this;
79
    }
80
}
81