Passed
Push — release-3.0.0 ( e8971e...d75c10 )
by Daniel
04:23
created

factory::get()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 1
nc 2
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 *
4
 * @package sitemaker
5
 * @copyright (c) 2019 Daniel A. (blitze)
6
 * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
7
 *
8
 */
9
10
namespace blitze\content\services\comments;
11
12
class factory
13
{
14
	/** @var array */
15
	private $comment_types;
16
17
	/**
18
	 * Constructor
19
	 *
20
	 * @param \phpbb\di\service_collection		$types		Service Collection
21
	 */
22
	public function __construct(\phpbb\di\service_collection $types)
23
	{
24
		$this->register_comment_types($types);
25
	}
26
27
	/**
28
	 * Register available content views
29
	 * @param \phpbb\di\service_collection $views
30
	 */
31
	protected function register_comment_types(\phpbb\di\service_collection $types)
32
	{
33
		$this->comment_types = array();
34
		foreach ($types as $service => $driver)
35
		{
36
			$this->comment_types[$service] = $driver;
37
		}
38
	}
39
40
	/**
41
	 * Get comment type
42
	 *
43
	 * @param string $service_name
44
	 * @return null|\blitze\content\services\comments\comments_interface
45
	 */
46
	public function get($service_name)
47
	{
48
		return isset($this->comment_types[$service_name]) ? $this->comment_types[$service_name] : null;
49
	}
50
51
	/**
52
	 * Get available comment types
53
	 * @return array
54
	 */
55
	public function get_all_types()
56
	{
57
		$types = array();
58
		foreach ($this->comment_types as $service => $driver)
59
		{
60
			$types[$service] = $driver->get_langname();
61
		}
62
63
		return $types;
64
	}
65
}
66