action_handler::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 4
dl 0
loc 6
ccs 5
cts 5
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 *
4
 * @package sitemaker
5
 * @copyright (c) 2013 Daniel A. (blitze)
6
 * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
7
 *
8
 */
9
10
namespace blitze\sitemaker\services\menus;
11
12
class action_handler
13
{
14
	/** @var \phpbb\cache\driver\driver_interface */
15
	protected $cache;
16
17
	/** @var \phpbb\request\request_interface */
18
	protected $request;
19
20
	/** @var \phpbb\language\language */
21
	protected $translator;
22
23
	/** @var \blitze\sitemaker\model\mapper_factory */
24
	protected $mapper_factory;
25
26
	/**
27
	 * Constructor
28
	 *
29
	 * @param \phpbb\cache\driver\driver_interface			$cache					Cache object
30
	 * @param \phpbb\request\request_interface				$request				Request object
31
	 * @param \phpbb\language\language						$translator				Language object
32
	 * @param \blitze\sitemaker\model\mapper_factory		$mapper_factory			Mapper factory object
33
	 */
34 12
	public function __construct(\phpbb\cache\driver\driver_interface $cache, \phpbb\request\request_interface $request, \phpbb\language\language $translator, \blitze\sitemaker\model\mapper_factory $mapper_factory)
35
	{
36 12
		$this->cache = $cache;
37 12
		$this->request = $request;
38 12
		$this->translator = $translator;
39 12
		$this->mapper_factory = $mapper_factory;
40 12
	}
41
42
	/**
43
	 * @param string $action
44
	 * @return \blitze\sitemaker\services\menus\action\action_interface
45
	 * @throws \blitze\sitemaker\exception\unexpected_value
46
	 */
47 11
	public function create($action)
48
	{
49 11
		$action_class = 'blitze\\sitemaker\\services\\menus\\action\\' . $action;
50
51 11
		if (!class_exists($action_class))
52 11
		{
53 1
			throw new \blitze\sitemaker\exception\unexpected_value(array($action, 'INVALID_ACTION'));
54
		}
55
56 10
		return new $action_class($this->request, $this->translator, $this->mapper_factory);
57
	}
58
59
	/**
60
	 * Clear cache after every action
61
	 */
62 1
	public function clear_cache()
63
	{
64 1
		$this->cache->destroy('sitemaker_menus');
65 1
	}
66
}
67