Passed
Push — master ( 791909...fe60d3 )
by Timo
52s
created

Dispatcher   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 13.64%

Importance

Changes 0
Metric Value
wmc 5
c 0
b 0
f 0
lcom 1
cbo 4
dl 0
loc 54
ccs 3
cts 22
cp 0.1364
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A dispatch() 0 12 2
A shutdown() 0 9 2
A __construct() 0 4 1
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 2 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 ApacheSolrForTypo3\Solr\IndexQueue\FrontendHelper\Manager;
28
use ApacheSolrForTypo3\Solr\IndexQueue\PageIndexerRequest;
29
use ApacheSolrForTypo3\Solr\IndexQueue\PageIndexerResponse;
30
use TYPO3\CMS\Core\Utility\GeneralUtility;
31
32
/**
33
 * Dispatches the actions requested to the matching frontend helpers.
34
 *
35
 * @author Ingo Renner <[email protected]>
36
 */
37
class Dispatcher
38
{
39
40
    /**
41
     * Frontend helper manager.
42
     *
43
     * @var Manager
44
     */
45
    protected $frontendHelperManager;
46
47
    /**
48
     * Constructor
49
     *
50
     */
51 1
    public function __construct()
52
    {
53 1
        $this->frontendHelperManager = GeneralUtility::makeInstance(Manager::class);
54 1
    }
55
56
    /**
57
     * Takes the request's actions and hands them of to the according frontend
58
     * helpers.
59
     *
60
     * @param PageIndexerRequest $request The request to dispatch
61
     * @param PageIndexerResponse $response The request's response
62
     */
63
    public function dispatch(
64
        PageIndexerRequest $request,
65
        PageIndexerResponse $response
66
    ) {
67
        $actions = $request->getActions();
68
69
        foreach ($actions as $action) {
70
            $frontendHelper = $this->frontendHelperManager->resolveAction($action);
71
            $frontendHelper->activate();
72
            $frontendHelper->processRequest($request, $response);
73
        }
74
    }
75
76
    /**
77
     * Sends a shutdown signal to all activated frontend helpers.
78
     *
79
     * @return void
80
     */
81
    public function shutdown()
82
    {
83
        $frontendHelpers = $this->frontendHelperManager->getActivatedFrontendHelpers();
84
85
        foreach ($frontendHelpers as $frontendHelper) {
86
            /** @var FrontendHelper $frontendHelper */
87
            $frontendHelper->deactivate();
88
        }
89
    }
90
}
91