|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the TYPO3 CMS project. |
|
5
|
|
|
* |
|
6
|
|
|
* It is free software; you can redistribute it and/or modify it under |
|
7
|
|
|
* the terms of the GNU General Public License, either version 2 |
|
8
|
|
|
* of the License, or any later version. |
|
9
|
|
|
* |
|
10
|
|
|
* For the full copyright and license information, please read the |
|
11
|
|
|
* LICENSE.txt file that was distributed with this source code. |
|
12
|
|
|
* |
|
13
|
|
|
* The TYPO3 project - inspiring people to share! |
|
14
|
|
|
*/ |
|
15
|
|
|
|
|
16
|
|
|
namespace ApacheSolrForTypo3\Solr\IndexQueue\FrontendHelper; |
|
17
|
|
|
|
|
18
|
|
|
use RuntimeException; |
|
19
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Index Queue Page Indexer frontend helper manager. |
|
23
|
|
|
* |
|
24
|
|
|
* Manages frontend helpers and creates instances. |
|
25
|
|
|
* |
|
26
|
|
|
* @author Ingo Renner <[email protected]> |
|
27
|
|
|
*/ |
|
28
|
|
|
class Manager |
|
29
|
|
|
{ |
|
30
|
|
|
/** |
|
31
|
|
|
* Frontend helper descriptions. |
|
32
|
|
|
* |
|
33
|
|
|
* @var array |
|
34
|
|
|
*/ |
|
35
|
|
|
protected static $frontendHelperRegistry = []; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Instances of activated frontend helpers. |
|
39
|
|
|
* |
|
40
|
|
|
* @var array |
|
41
|
|
|
*/ |
|
42
|
|
|
protected $activatedFrontendHelpers = []; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Registers a frontend helper class for a certain action. |
|
46
|
|
|
* |
|
47
|
|
|
* @param string $action Action to register. |
|
48
|
|
|
* @param string $class Class to register for an action. |
|
49
|
|
|
*/ |
|
50
|
296 |
|
public static function registerFrontendHelper($action, $class) |
|
51
|
|
|
{ |
|
52
|
296 |
|
self::$frontendHelperRegistry[$action] = $class; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Tries to find a frontend helper for a given action. If found, creates an |
|
57
|
|
|
* instance of the helper. |
|
58
|
|
|
* |
|
59
|
|
|
* @param string $action The action to get a frontend helper for. |
|
60
|
|
|
* @return FrontendHelper Index Queue page indexer frontend helper |
|
61
|
|
|
* @throws RuntimeException if the class registered for an action is not an implementation of ApacheSolrForTypo3\Solr\IndexQueue\FrontendHelper\FrontendHelper |
|
62
|
|
|
*/ |
|
63
|
2 |
|
public function resolveAction($action) |
|
64
|
|
|
{ |
|
65
|
2 |
|
if (!array_key_exists($action, self::$frontendHelperRegistry)) { |
|
66
|
1 |
|
return null; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
1 |
|
$frontendHelper = GeneralUtility::makeInstance(self::$frontendHelperRegistry[$action]); |
|
70
|
1 |
|
if (!$frontendHelper instanceof FrontendHelper) { |
|
71
|
1 |
|
$message = self::$frontendHelperRegistry[$action] . ' is not an implementation of ApacheSolrForTypo3\Solr\IndexQueue\FrontendHelper\FrontendHelper'; |
|
72
|
1 |
|
throw new RuntimeException($message, 1292497896); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
$this->activatedFrontendHelpers[$action] = $frontendHelper; |
|
76
|
|
|
return $frontendHelper; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Gets an array with references to activated frontend helpers. |
|
81
|
|
|
* |
|
82
|
|
|
* @return array Array of references to activated frontend helpers. |
|
83
|
|
|
*/ |
|
84
|
|
|
public function getActivatedFrontendHelpers() |
|
85
|
|
|
{ |
|
86
|
|
|
return $this->activatedFrontendHelpers; |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|