Completed
Push — master ( 77abb4...5b1cd3 )
by Chris
02:37
created

HttpService::register()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 10
rs 9.4285
cc 1
eloc 6
nc 1
nop 1
1
<?php
2
namespace Darya\Foundation\Providers;
3
4
use Darya\Http\Request;
5
use Darya\Http\Response;
6
use Darya\Http\Session;
7
use Darya\Service\Contracts\Container;
8
use Darya\Service\Contracts\Provider;
9
10
/**
11
 * A service provider that provides HTTP request and response objects.
12
 * 
13
 * Also provides the default PHP session.
14
 * 
15
 * @author Chris Andrew <[email protected]>
16
 */
17
class HttpService implements Provider
18
{
19
	/**
20
	 * Register a global HTTP request, response and session with the container.
21
	 * 
22
	 * @param Container $container
23
	 */
24
	public function register(Container $container)
25
	{
26
		$container->register(array(
27
			'Darya\Http\Request' => function ($container) {
28
				return Request::createFromGlobals($container->resolve('Darya\Http\Session'));
29
			},
30
			'Darya\Http\Response' => new Response,
31
			'Darya\Http\Session' => new Session\Php
32
		));
33
	}
34
}
35