Completed
Push — master ( a0e683...2cd560 )
by Maxence
02:06
created

ExtensionService::dispatch()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
/**
3
 * Files_FullTextSearch - Index the content of your files
4
 *
5
 * This file is licensed under the Affero General Public License version 3 or
6
 * later. See the COPYING file.
7
 *
8
 * @author Maxence Lange <[email protected]>
9
 * @copyright 2018
10
 * @license GNU AGPL version 3 or any later version
11
 *
12
 * This program is free software: you can redistribute it and/or modify
13
 * it under the terms of the GNU Affero General Public License as
14
 * published by the Free Software Foundation, either version 3 of the
15
 * License, or (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU Affero General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU Affero General Public License
23
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
24
 *
25
 */
26
27
28
namespace OCA\Files_FullTextSearch\Service;
29
30
31
use OCA\Files_FullTextSearch\Model\FilesDocument;
32
use OCA\FullTextSearch\Model\SearchRequest;
33
use OCP\Files\Node;
34
use Symfony\Component\EventDispatcher\EventDispatcher;
35
use Symfony\Component\EventDispatcher\GenericEvent;
36
37
class ExtensionService {
38
39
	/** @var EventDispatcher */
40
	private $eventDispatcher;
41
42
	/** @var ConfigService */
43
	private $configService;
44
45
	/** @var MiscService */
46
	private $miscService;
47
48
49
	/**
50
	 * ExtensionService constructor.
51
	 *
52
	 * @param EventDispatcher $eventDispatcher
53
	 * @param ConfigService $configService
54
	 * @param MiscService $miscService
55
	 */
56
	public function __construct(
57
		EventDispatcher $eventDispatcher, ConfigService $configService, MiscService $miscService
58
	) {
59
		$this->eventDispatcher = $eventDispatcher;
60
		$this->configService = $configService;
61
		$this->miscService = $miscService;
62
	}
63
64
65
	/**
66
	 * @param FilesDocument $document
67
	 * @param Node $file
68
	 */
69
	public function fileIndexing(FilesDocument &$document, Node $file) {
70
		$this->dispatch(
71
			'\OCA\Files_FullTextSearch::onFileIndexing',
72
			['file' => $file, 'document' => &$document]
73
		);
74
	}
75
76
77
	/**
78
	 * @param SearchRequest $request
79
	 */
80
	public function searchRequest(SearchRequest &$request) {
81
		$this->dispatch(
82
			'\OCA\Files_FullTextSearch::onSearchRequest',
83
			['request' => &$request]
84
		);
85
	}
86
87
88
	/**
89
	 * @param string $context
90
	 * @param array $arguments
91
	 */
92
	private function dispatch($context, $arguments) {
93
		$this->eventDispatcher->dispatch($context, new GenericEvent(null, $arguments));
94
	}
95
96
}