Completed
Push — master ( d1d579...590121 )
by Maxence
02:10 queued 50s
created

ExtensionService::fileIndexing()   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 2
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\ISearchRequest;
36
use OCP\Files\Node;
37
use OCP\FullTextSearch\Model\ISearchResult;
38
use Symfony\Component\EventDispatcher\EventDispatcher;
39
use Symfony\Component\EventDispatcher\GenericEvent;
40
41
42
/**
43
 * Class ExtensionService
44
 *
45
 * @package OCA\Files_FullTextSearch\Service
46
 */
47
class ExtensionService {
48
49
50
	/** @var EventDispatcher */
51
	private $eventDispatcher;
52
53
	/** @var ConfigService */
54
	private $configService;
55
56
	/** @var MiscService */
57
	private $miscService;
58
59
60
	/**
61
	 * ExtensionService constructor.
62
	 *
63
	 * @param EventDispatcher $eventDispatcher
64
	 * @param ConfigService $configService
65
	 * @param MiscService $miscService
66
	 */
67
	public function __construct(
68
		EventDispatcher $eventDispatcher, ConfigService $configService, MiscService $miscService
69
	) {
70
		$this->eventDispatcher = $eventDispatcher;
71
		$this->configService = $configService;
72
		$this->miscService = $miscService;
73
	}
74
75
76
	/**
77
	 * @param FilesDocument $document
78
	 * @param Node $file
79
	 */
80
	public function fileIndexing(FilesDocument &$document, Node $file) {
81
		$this->dispatch(
82
			'\OCA\Files_FullTextSearch::onFileIndexing',
83
			['file' => $file, 'document' => &$document]
84
		);
85
	}
86
87
88
	/**
89
	 * @param ISearchRequest $request
90
	 */
91
	public function searchRequest(ISearchRequest &$request) {
92
		$this->dispatch(
93
			'\OCA\Files_FullTextSearch::onSearchRequest',
94
			['request' => &$request]
95
		);
96
	}
97
98
99
	/**
100
	 * @param ISearchResult $result
101
	 */
102
	public function searchResult(ISearchResult &$result) {
103
		$this->dispatch(
104
			'\OCA\Files_FullTextSearch::onSearchResult',
105
			['result' => &$result]
106
		);
107
	}
108
109
110
	/**
111
	 * @param string $context
112
	 * @param array $arguments
113
	 */
114
	private function dispatch(string $context, array $arguments) {
115
		$this->eventDispatcher->dispatch($context, new GenericEvent(null, $arguments));
116
	}
117
118
}
119
120