Completed
Push — master ( e502a6...b659c5 )
by Michael
08:23
created

Wiring::wireConfig()   B

Complexity

Conditions 6
Paths 24

Size

Total Lines 35
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 42

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 35
ccs 0
cts 22
cp 0
rs 8.439
cc 6
eloc 22
nc 24
nop 0
crap 42
1
<?php
2
declare(strict_types = 1);
3
/**
4
 * Contains Wiring class.
5
 *
6
 * PHP version 7.0+
7
 *
8
 * LICENSE:
9
 * This file is part of Yet Another Php Eve Api Library also know as Yapeal
10
 * which can be used to access the Eve Online API data and place it into a
11
 * database.
12
 * Copyright (C) 2014-2016 Michael Cummings
13
 *
14
 * This program is free software: you can redistribute it and/or modify it
15
 * under the terms of the GNU Lesser General Public License as published by the
16
 * Free Software Foundation, either version 3 of the License, or (at your
17
 * option) any later version.
18
 *
19
 * This program is distributed in the hope that it will be useful, but WITHOUT
20
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
22
 * for more details.
23
 *
24
 * You should have received a copy of the GNU Lesser General Public License
25
 * along with this program. If not, see
26
 * <http://spdx.org/licenses/LGPL-3.0.html>.
27
 *
28
 * You should be able to find a copy of this license in the COPYING-LESSER.md
29
 * file. A copy of the GNU GPL should also be available in the COPYING.md file.
30
 *
31
 * @copyright 2014-2016 Michael Cummings
32
 * @license   http://www.gnu.org/copyleft/lesser.html GNU LGPL
33
 * @author    Michael Cummings <[email protected]>
34
 */
35
namespace Yapeal\Configuration;
36
37
use Yapeal\Container\ContainerInterface;
38
use Yapeal\Container\DicAwareInterface;
39
use Yapeal\Container\DicAwareTrait;
40
41
/**
42
 * Class Wiring
43
 */
44
class Wiring implements DicAwareInterface
45
{
46
    use ConfigFileProcessingTrait;
47
    use DicAwareTrait;
48
    /**
49
     * @param ContainerInterface $dic
50
     */
51 1
    public function __construct(ContainerInterface $dic)
52
    {
53 1
        $this->setDic($dic);
54
    }
55
    /**
56
     * This is used to configure/wire all the pieces of Yapeal-ng together.
57
     *
58
     * It is not required to use this method or even this class but the rest of Yapeal-ng relies heavily on the
59
     * container $dic having been setup in a way that mimics it closely. With all the other ways this method and other
60
     * parts of Yapeal-ng provides to override or change things it is __very strongly__ suggested that application
61
     * developers use it.
62
     *
63
     * _NOTE:_
64
     *
65
     *     The Yapeal.Wiring.Handlers.config setting has extra special handling because everything else is very heavily
66
     *     dependant on the initial paths it determines which are used to find everything else. An application developer
67
     *     considering override this setting should shoot yourself in the foot first to help dull the pain you will be
68
     *     causing yourself by overriding it. For the masochists that go ahead, enjoy it, but I don't want any pictures
69
     *     or descriptive e-mail sent to me about your experience please.
70
     *
71
     * @return self Fluent interface.
72
     * @throws \LogicException
73
     */
74
    public function wireAll(): self
75
    {
76
        $dic = $this->getDic();
77
        $base = 'Yapeal.Wiring.Classes.';
78
        $dic[$base . 'config'] = $dic[$base . 'config'] ?? '\Yapeal\Configuration\ConfigWiring';
79
        $names = ['Config', 'Event', 'Log', 'Sql', 'Xml', 'Xsd', 'Xsl', 'FileSystem', 'Network', 'EveApi'];
80
        /**
81
         * @var WiringInterface $class
82
         */
83
        foreach ($names as $name) {
84
            $setting = $base . strtolower($name);
85
            if (!empty($dic[$setting])
86
                && is_subclass_of($dic[$setting], '\Yapeal\Configuration\WiringInterface', true)
87
            ) {
88
                $class = new $dic[$setting];
89
                $class->wire($dic);
90
                continue;
91
            }
92
            $methodName = 'wire' . $name;
93
            if (method_exists($this, $methodName)) {
94
                $this->$methodName();
95
            } else {
96
                $mess = 'Could NOT find class or method for ' . $name;
97
                throw new \LogicException($mess);
98
            }
99
        }
100
        return $this;
101
    }
102
}
103