Completed
Push — master ( bf07e5...f61ec4 )
by Beniamin
02:20
created

InternalContainer::initialized()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
3
/**
4
 * This file is part of Phuria SQL Builder package.
5
 *
6
 * Copyright (c) 2016 Beniamin Jonatan Šimko
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 Phuria\SQLBuilder\DependencyInjection;
13
14
use Phuria\SQLBuilder\Parameter\ParameterManager;
15
use Phuria\SQLBuilder\QueryCompiler\QueryCompiler;
16
use Phuria\SQLBuilder\TableFactory\TableFactory;
17
use Phuria\SQLBuilder\TableRegistry;
18
use Symfony\Component\DependencyInjection\ContainerInterface;
19
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
20
21
/**
22
 * @author Beniamin Jonatan Šimko <[email protected]>
23
 */
24
class InternalContainer implements ContainerInterface
25
{
26
    /**
27
     * @var array
28
     */
29
    private $services = [];
30
31
    /**
32
     * @var array
33
     */
34
    private $parameters = [];
35
36 6
    public function __construct()
37
    {
38 6
        $this->parameters['phuria.sql_builder.parameter_manager.class'] = ParameterManager::class;
39
40 6
        $this->services['phuria.sql_builder.table_registry'] = new TableRegistry();
41 6
        $this->services['phuria.sql_builder.table_factory'] = new TableFactory();
42 6
        $this->services['phuria.sql_builder.query_compiler'] = new QueryCompiler();
43 6
    }
44
45
    /**
46
     * @inheritdoc
47
     */
48
    public function set($id, $service)
49
    {
50
        $this->services[$id] = $service;
51
52
        return $this;
53
    }
54
55
    /**
56
     * @inheritdoc
57
     */
58 34
    public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE)
59
    {
60 34
        if ($this->has($id)) {
61 34
            return $this->services[$id];
62
        }
63
64
        if (self::EXCEPTION_ON_INVALID_REFERENCE === $invalidBehavior) {
65
            throw new ServiceNotFoundException($id);
66
        }
67
68
        return null;
69
    }
70
71
    /**
72
     * @inheritdoc
73
     */
74 34
    public function has($id)
75
    {
76 34
        return array_key_exists($id, $this->services);
77
    }
78
79
    /**
80
     * @inheritdoc
81
     */
82
    public function initialized($id)
83
    {
84
        return true;
85
    }
86
87
    /**
88
     * @inheritdoc
89
     */
90 34
    public function getParameter($name)
91
    {
92 34
        return $this->parameters[$name];
93
    }
94
95
    /**
96
     * @inheritdoc
97
     */
98
    public function hasParameter($name)
99
    {
100
        return array_key_exists($name, $this->parameters);
101
    }
102
103
    /**
104
     * @inheritdoc
105
     */
106
    public function setParameter($name, $value)
107
    {
108
        $this->parameters[$name] = $value;
109
110
        return $this;
111
    }
112
}