Completed
Push — master ( 205443...4952c2 )
by Emlyn
07:58
created

ApplicationServicesProvider   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 91.3%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 7
c 1
b 0
f 1
lcom 1
cbo 4
dl 0
loc 71
ccs 21
cts 23
cp 0.913
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 16 1
A constructComponentManager() 0 4 1
A constructRequest() 0 8 2
A constructResponse() 0 8 2
A isCli() 0 4 1
1
<?php
2
/**
3
 * @package    Fuel\Foundation
4
 * @version    2.0
5
 * @author     Fuel Development Team
6
 * @license    MIT License
7
 * @copyright  2010 - 2016 Fuel Development Team
8
 * @link       http://fuelphp.com
9
 */
10
11
declare(strict_types=1);
12
13
namespace Fuel\Foundation;
14
15
use Fuel\Foundation\Request\Http;
16
use Fuel\Foundation\Request\RequestInterface;
17
use Fuel\Foundation\Response\ResponseInterface;
18
use League\Container\ServiceProvider\AbstractServiceProvider;
19
20
class ApplicationServicesProvider extends AbstractServiceProvider
21
{
22
23
	protected $provides = [
24
		'fuel.application.event',
25
26
		'fuel.application.request',
27
		'Fuel\Foundation\Request\Cli',
28
		'Fuel\Foundation\Request\Http',
29
30
		'fuel.application.response',
31
		'Fuel\Foundation\Response\Cli',
32
		'Fuel\Foundation\Response\Http',
33
34
		'fuel.application.component_manager',
35
	];
36
37
	/**
38
	 * {@inheritdoc}
39
	 */
40 7
	public function register()
41
	{
42 7
		$this->getContainer()->add('fuel.application.event', 'League\Event\Emitter', true);
43
44 7
		$this->getContainer()->add('Fuel\Foundation\Request\Cli', 'Fuel\Foundation\Request\Cli', false);
45 7
		$this->getContainer()->add('Fuel\Foundation\Request\Http', Http::forge(), false);
46 7
		$this->getContainer()->add('fuel.application.request', $this->constructRequest(), true);
47
48 7
		$this->getContainer()->add('Fuel\Foundation\Response\Cli', 'Fuel\Foundation\Response\Cli', false);
49 7
		$this->getContainer()->add('Fuel\Foundation\Response\Http', 'Fuel\Foundation\Response\Http', false);
50 7
		$this->getContainer()->add('fuel.application.response', $this->constructResponse(), true);
51
52 7
		$this->getContainer()->add('fuel.application.component_manager', $this->constructComponentManager(), true);
53
54 7
		$this->getContainer()->add('fuel.application.router', 'Fuel\Routing\Router', true);
55 7
	}
56
57 7
	protected function constructComponentManager()
58
	{
59 7
		return new ComponentManager($this->getContainer()->get('fuel.config'));
60
	}
61
62
	/**
63
	 * @return RequestInterface
64
	 */
65 7
	protected function constructRequest() : RequestInterface
66
	{
67 7
		if ($this->isCli()) {
68 7
			return $this->getContainer()->get('Fuel\Foundation\Request\Cli');
69
		}
70
71
		return $this->getContainer()->get('Fuel\Foundation\Request\Http');
72
	}
73
74
	/**
75
	 * @return ResponseInterface
76
	 */
77 7
	protected function constructResponse() : ResponseInterface
78
	{
79 7
		if ($this->isCli()) {
80 7
			return $this->getContainer()->get('Fuel\Foundation\Response\Cli');
81
		}
82
83
		return $this->getContainer()->get('Fuel\Foundation\Response\Http');
84
	}
85
86 7
	public function isCli()
87
	{
88 7
		return php_sapi_name() === 'cli';
89
	}
90
}
91