|
1
|
|
|
<?php |
|
2
|
|
|
namespace ApacheSolrForTypo3\Solr\IndexQueue\FrontendHelper; |
|
3
|
|
|
|
|
4
|
|
|
/*************************************************************** |
|
5
|
|
|
* Copyright notice |
|
6
|
|
|
* |
|
7
|
|
|
* (c) 2010-2015 Ingo Renner <[email protected]> |
|
8
|
|
|
* All rights reserved |
|
9
|
|
|
* |
|
10
|
|
|
* This script is part of the TYPO3 project. The TYPO3 project is |
|
11
|
|
|
* free software; you can redistribute it and/or modify |
|
12
|
|
|
* it under the terms of the GNU General Public License as published by |
|
13
|
|
|
* the Free Software Foundation; either version 3 of the License, or |
|
14
|
|
|
* (at your option) any later version. |
|
15
|
|
|
* |
|
16
|
|
|
* The GNU General Public License can be found at |
|
17
|
|
|
* http://www.gnu.org/copyleft/gpl.html. |
|
18
|
|
|
* |
|
19
|
|
|
* This script is distributed in the hope that it will be useful, |
|
20
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
21
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
22
|
|
|
* GNU General Public License for more details. |
|
23
|
|
|
* |
|
24
|
|
|
* This copyright notice MUST APPEAR in all copies of the script! |
|
25
|
|
|
***************************************************************/ |
|
26
|
|
|
|
|
27
|
|
|
use RuntimeException; |
|
28
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Index Queue Page Indexer frontend helper manager. |
|
32
|
|
|
* |
|
33
|
|
|
* Manages frontend helpers and creates instances. |
|
34
|
|
|
* |
|
35
|
|
|
* @author Ingo Renner <[email protected]> |
|
36
|
|
|
*/ |
|
37
|
|
|
class Manager |
|
38
|
|
|
{ |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Frontend helper descriptions. |
|
42
|
|
|
* |
|
43
|
|
|
* @var array |
|
44
|
|
|
*/ |
|
45
|
|
|
protected static $frontendHelperRegistry = []; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Instances of activated frontend helpers. |
|
49
|
|
|
* |
|
50
|
|
|
* @var array |
|
51
|
|
|
*/ |
|
52
|
|
|
protected $activatedFrontendHelpers = []; |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Registers a frontend helper class for a certain action. |
|
56
|
|
|
* |
|
57
|
|
|
* @param string $action Action to register. |
|
58
|
|
|
* @param string $class Class to register for an action. |
|
59
|
|
|
*/ |
|
60
|
|
|
public static function registerFrontendHelper($action, $class) |
|
61
|
|
|
{ |
|
62
|
|
|
self::$frontendHelperRegistry[$action] = $class; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Tries to find a frontend helper for a given action. If found, creates an |
|
67
|
|
|
* instance of the helper. |
|
68
|
|
|
* |
|
69
|
|
|
* @param string $action The action to get a frontend helper for. |
|
70
|
|
|
* @return FrontendHelper Index Queue page indexer frontend helper |
|
71
|
|
|
* @throws RuntimeException if the class registered for an action is not an implementation of ApacheSolrForTypo3\Solr\IndexQueue\FrontendHelper\FrontendHelper |
|
72
|
|
|
*/ |
|
73
|
|
|
public function resolveAction($action) |
|
74
|
|
|
{ |
|
75
|
|
|
if (!array_key_exists($action, self::$frontendHelperRegistry)) { |
|
76
|
|
|
return null; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
$frontendHelper = GeneralUtility::makeInstance(self::$frontendHelperRegistry[$action]); |
|
80
|
|
|
if (!$frontendHelper instanceof FrontendHelper) { |
|
81
|
|
|
$message = self::$frontendHelperRegistry[$action] . ' is not an implementation of ApacheSolrForTypo3\Solr\IndexQueue\FrontendHelper\FrontendHelper'; |
|
82
|
|
|
throw new RuntimeException($message, 1292497896); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
$this->activatedFrontendHelpers[$action] = $frontendHelper; |
|
86
|
|
|
return $frontendHelper; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* Gets an array with references to activated frontend helpers. |
|
91
|
|
|
* |
|
92
|
|
|
* @return array Array of references to activated frontend helpers. |
|
93
|
|
|
*/ |
|
94
|
|
|
public function getActivatedFrontendHelpers() |
|
95
|
|
|
{ |
|
96
|
|
|
return $this->activatedFrontendHelpers; |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|