Completed
Push — master ( 590121...93c00c )
by Maxence
03:52 queued 02:35
created

ExtensionService::indexComparing()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

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