1
1
<?php
2
2
namespace Eike \Yacy \Domain \Repository ;
3
3
4
+ use Eike \Yacy \Event \BeforeReturnResultsEvent ;
5
+ use Psr \EventDispatcher \EventDispatcherInterface ;
4
6
use TYPO3 \CMS \Extbase \SignalSlot \Exception \InvalidSlotException ;
5
7
use TYPO3 \CMS \Extbase \SignalSlot \Exception \InvalidSlotReturnException ;
6
8
use TYPO3 \CMS \Core \Log \LogManager ;
40
42
*/
41
43
class JsonSearchRepository extends AbstractSearchRepository
42
44
{
45
+ public function __construct (
46
+ private readonly EventDispatcherInterface $ eventDispatcher ,
47
+ ) {}
48
+
43
49
/**
44
50
* @param Demand $demand
45
51
* @param int $page
@@ -51,22 +57,20 @@ public function findDemanded(Demand $demand, $page = 1, $debug = 0)
51
57
{
52
58
53
59
try {
54
- $ json = json_decode (file_get_contents ($ demand ->getRequestUrl ()), true );
60
+ /** @var BeforeReturnResultsEvent $event */
61
+ $ event = $ this ->eventDispatcher ->dispatch (
62
+ new BeforeReturnResultsEvent (
63
+ $ demand ,
64
+ $ page ,
65
+ json_decode (file_get_contents ($ demand ->getRequestUrl ()), true )
66
+ ),
67
+ );
68
+ return $ event ->getJson ()['channels ' ][0 ];
55
69
}catch (\Exception $ exception ){
56
70
GeneralUtility::makeInstance (LogManager::class)->getLogger (__CLASS__ )->log (LogLevel::INFO , $ exception ->getMessage (), '' );
57
71
if ($ debug === '1 ' ){
58
72
throw $ exception ;
59
73
}
60
74
}
61
-
62
- /*todo this needs to be refactored to events
63
- * https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/10.4/Deprecation-90625-ExtbaseSignalSlotDispatcher.html
64
- $objectManager = GeneralUtility::makeInstance(ObjectManager::class);
65
-
66
- $signalSlotDispatcher = $objectManager->get(Dispatcher::class);
67
- $signalSlotDispatcher->dispatch(__CLASS__, 'beforeReturnResults', [$demand, $page, &$json]);
68
- */
69
- return $ json ['channels ' ][0 ];
70
-
71
75
}
72
76
}
0 commit comments