Completed
Push — master ( 84255c...a7d7e4 )
by Thomas
14:38
created

AbstractKernel::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
namespace keeko\core\kernel;
3
4
use keeko\core\events\KernelTargetEvent;
5
use keeko\core\package\AbstractApplication;
6
use keeko\core\service\ServiceContainer;
7
use Symfony\Component\EventDispatcher\EventDispatcher;
8
use Symfony\Component\HttpFoundation\Request;
9
use Symfony\Component\HttpFoundation\Response;
10
11
abstract class AbstractKernel {
12
	
13
	/** @var AbstractApplication */
14
	protected $app;
15
	
16
	/** @var ServiceContainer */
17
	protected $service;
18
	
19
	/** @var EventDispatcher */
20
	protected $dispatcher;
21
	
22
	public function __construct() {
23
		$this->service = new ServiceContainer($this);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
24
		$this->dispatcher = $this->service->getDispatcher();
25
	}
26
	
27
	/**
28
	 * Processes the main kernel action
29
	 *
30
	 * @return Response
31
	 */
32
	abstract public function main(array $options = []);
33
	
34
	/**
35
	 * Runs a kernel target
36
	 *
37
	 * @param RunnableInterface $target
38
	 * @param Request $request
39
	 * @return Response
40
	 */
41
	public function handle(KernelTargetInterface $target, Request $request) {
42
		$event = new KernelTargetEvent($target);
43
		
44
		$this->dispatcher->dispatch(KernelTargetEvent::BEFORE_RUN, $event);
45
		$response = $target->run($request);
46
		$this->dispatcher->dispatch(KernelTargetEvent::AFTER_RUN, $event);
47
	
48
		return $response;
49
	}
50
	
51
	/**
52
	 * Returns the service container
53
	 *
54
	 * @return ServiceContainer
55
	 */
56
	public function getServiceContainer() {
57
		return $this->service;
58
	}
59
	
60
	/**
61
	 * Returns the processed application
62
	 *
63
	 * @return AbstractApplication
64
	 */
65
	public function getApplication() {
66
		return $this->app;
67
	}
68
}