|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Contains class CacheWiring. |
|
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 CacheWiring. |
|
40
|
|
|
*/ |
|
41
|
|
|
class CacheWiring 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 ('none' !== $dic['Yapeal.Cache.fileSystemMode']) { |
|
52
|
|
|
if (empty($dic['Yapeal.FileSystem.CachePreserver'])) { |
|
53
|
|
|
$dic['Yapeal.FileSystem.CachePreserver'] = function () use ($dic) { |
|
54
|
|
|
return new $dic['Yapeal.Cache.Handlers.preserve']($dic['Yapeal.Cache.dir']); |
|
55
|
|
|
}; |
|
56
|
|
|
} |
|
57
|
|
|
if (empty($dic['Yapeal.FileSystem.CacheRetriever'])) { |
|
58
|
|
|
$dic['Yapeal.FileSystem.CacheRetriever'] = function () use ($dic) { |
|
59
|
|
|
return new $dic['Yapeal.Cache.Handlers.retrieve']($dic['Yapeal.Cache.dir']); |
|
60
|
|
|
}; |
|
61
|
|
|
} |
|
62
|
|
|
if (!isset($dic['Yapeal.Event.Mediator'])) { |
|
63
|
|
|
$mess = 'Tried to call Mediator before it has been added'; |
|
64
|
|
|
throw new \LogicException($mess); |
|
65
|
|
|
} |
|
66
|
|
|
/** |
|
67
|
|
|
* @var \Yapeal\Event\MediatorInterface $mediator |
|
68
|
|
|
*/ |
|
69
|
|
|
$mediator = $dic['Yapeal.Event.Mediator']; |
|
70
|
|
|
$mediator->addServiceSubscriberByEventList( |
|
71
|
|
|
'Yapeal.FileSystem.CachePreserver', |
|
72
|
|
|
['Yapeal.EveApi.cache' => ['preserveEveApi', 'last']] |
|
73
|
|
|
); |
|
74
|
|
|
$mediator->addServiceSubscriberByEventList( |
|
75
|
|
|
'Yapeal.FileSystem.CacheRetriever', |
|
76
|
|
|
['Yapeal.EveApi.retrieve' => ['retrieveEveApi', 'last']] |
|
77
|
|
|
); |
|
78
|
|
|
} |
|
79
|
|
|
return $this; |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|