Completed
Push — master ( 0cb618...205443 )
by Steve
11:02
created

ApplicationServicesProvider::isCli()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 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 6
	public function register()
41
	{
42 6
		$this->getContainer()->add('fuel.application.event', 'League\Event\Emitter', true);
43
44 6
		$this->getContainer()->add('Fuel\Foundation\Request\Cli', 'Fuel\Foundation\Request\Cli', false);
45 6
		$this->getContainer()->add('Fuel\Foundation\Request\Http', Http::forge(), false);
46 6
		$this->getContainer()->add('fuel.application.request', $this->constructRequest(), true);
47
48 6
		$this->getContainer()->add('Fuel\Foundation\Response\Cli', 'Fuel\Foundation\Response\Cli', false);
49 6
		$this->getContainer()->add('Fuel\Foundation\Response\Http', 'Fuel\Foundation\Response\Http', false);
50 6
		$this->getContainer()->add('fuel.application.response', $this->constructResponse(), true);
51
52 6
		$this->getContainer()->add('fuel.application.component_manager', $this->constructComponentManager(), true);
53 6
	}
54
55 6
	protected function constructComponentManager()
56
	{
57 6
		return new ComponentManager($this->getContainer()->get('fuel.config'));
58
	}
59
60
	/**
61
	 * @return RequestInterface
62
	 */
63 6
	protected function constructRequest() : RequestInterface
64
	{
65 6
		if ($this->isCli()) {
66 6
			return $this->getContainer()->get('Fuel\Foundation\Request\Cli');
67
		}
68
69
		return $this->getContainer()->get('Fuel\Foundation\Request\Http');
70
	}
71
72
	/**
73
	 * @return ResponseInterface
74
	 */
75 6
	protected function constructResponse() : ResponseInterface
76
	{
77 6
		if ($this->isCli()) {
78 6
			return $this->getContainer()->get('Fuel\Foundation\Response\Cli');
79
		}
80
81
		return $this->getContainer()->get('Fuel\Foundation\Response\Http');
82
	}
83
84 6
	public function isCli()
85
	{
86 6
		return php_sapi_name() === 'cli';
87
	}
88
}
89