Passed
Push — refactor/backendModule-ValueOb... ( ba8b37...91b878 )
by Tomas Norre
07:37
created

AbstractRequestForm::getLanguageService()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
nc 1
nop 0
dl 0
loc 3
c 0
b 0
f 0
cc 1
ccs 0
cts 3
cp 0
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AOE\Crawler\Backend\RequestForm;
6
7
/*
8
 * (c) 2020 AOE GmbH <[email protected]>
9
 *
10
 * This file is part of the TYPO3 Crawler Extension.
11
 *
12
 * It is free software; you can redistribute it and/or modify it under
13
 * the terms of the GNU General Public License, either version 2
14
 * of the License, or any later version.
15
 *
16
 * For the full copyright and license information, please read the
17
 * LICENSE.txt file that was distributed with this source code.
18
 *
19
 * The TYPO3 project - inspiring people to share!
20
 */
21
22
use AOE\Crawler\Controller\CrawlerController;
23
use AOE\Crawler\Utility\MessageUtility;
24
use AOE\Crawler\Utility\PhpBinaryUtility;
25
use TYPO3\CMS\Core\Localization\LanguageService;
26
use TYPO3\CMS\Core\Utility\CommandUtility;
27
use TYPO3\CMS\Core\Utility\GeneralUtility;
28
29
class AbstractRequestForm
30
{
31
    /**
32
     * @var CrawlerController
33
     */
34
    protected $crawlerController;
35
36
    /**
37
     * @var bool
38
     */
39
    protected $isErrorDetected = false;
40
41
    /**
42
     * @var array
43
     */
44
    protected $extensionSettings = [];
45
46
    protected function findCrawler(): CrawlerController
47
    {
48
        if (! $this->crawlerController instanceof CrawlerController) {
0 ignored issues
show
introduced by
$this->crawlerController is always a sub-type of AOE\Crawler\Controller\CrawlerController.
Loading history...
49
            $this->crawlerController = GeneralUtility::makeInstance(CrawlerController::class);
50
        }
51
        return $this->crawlerController;
52
    }
53
54
    protected function getLanguageService(): LanguageService
55
    {
56
        return $GLOBALS['LANG'];
57
    }
58
59
    /**
60
     * Verify that the crawler is executable.
61
     */
62
    protected function makeCrawlerProcessableChecks(array $extensionSettings): void
63
    {
64
        if (! $this->isPhpForkAvailable()) {
65
            $this->isErrorDetected = true;
66
            MessageUtility::addErrorMessage($this->getLanguageService()->sL('LLL:EXT:crawler/Resources/Private/Language/locallang.xlf:message.noPhpForkAvailable'));
67
        }
68
69
        $exitCode = 0;
70
        $out = [];
71
        CommandUtility::exec(
72
            PhpBinaryUtility::getPhpBinary() . ' -v',
73
            $out,
74
            $exitCode
75
        );
76
        if ($exitCode > 0) {
77
            $this->isErrorDetected = true;
78
            MessageUtility::addErrorMessage(sprintf($this->getLanguageService()->sL('LLL:EXT:crawler/Resources/Private/Language/locallang.xlf:message.phpBinaryNotFound'), htmlspecialchars($extensionSettings['phpPath'], ENT_QUOTES | ENT_HTML5)));
79
        }
80
    }
81
82
    /**
83
     * Indicate that the required PHP method "popen" is
84
     * available in the system.
85
     */
86
    private function isPhpForkAvailable(): bool
87
    {
88
        return function_exists('popen');
89
    }
90
}
91