Code

< 40 %
40-60 %
> 60 %
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: lucifer
5
 * Date: 13.2.2017 г.
6
 * Time: 17:18
7
 */
8
9
namespace anavaro\pmsearch;
10
11
12
class helper
13
{
14
	public function __construct(\phpbb\extension\manager $ext_manager, \phpbb\auth\auth $auth, \phpbb\config\config $config,
15
		\phpbb\db\driver\driver_interface $db, \phpbb\user $user, \phpbb\language\language $language, \phpbb\event\dispatcher $dispatcher,
16
		$phpbb_root_path, $phpEx)
17
	{
18
		$this->ext_manager = $ext_manager;
19
		$this->auth = $auth;
20
		$this->config = $config;
21
		$this->db = $db;
22
		$this->user = $user;
23
		$this->lang = $language;
24
		$this->dispatcher = $dispatcher;
25
		$this->root_path = $phpbb_root_path;
26
		$this->php_ext = $phpEx;
27
	}
28
29
	public function get_search_types()
30
	{
31
		$finder = $this->ext_manager->get_finder();
32
33
		return $finder
34
			->extension_suffix('_backend1')
35
			->extension_directory('')
36
			->core_path('ext/anavaro/pmsearch/search/')
37
			->get_classes();
38
	}
39
40
	public function init_search($type, &$search, &$error)
41
	{
42
		if (!class_exists($type) || !method_exists($type, 'keyword_search'))
43
		{
44
			$error = $this->lang->lang('NO_SUCH_SEARCH_MODULE');
45
			return $error;
46
		}
47
48
		$error = false;
49
		$search = new $type($error, $this->root_path, $this->php_ext, $this->auth, $this->config, $this->db, $this->user, $this->dispatcher);
50
51
		return $error;
52
	}
53
}