1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* This file is part of phpDocumentor. |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
* |
10
|
|
|
* @author Mike van Riel <[email protected]> |
11
|
|
|
* @copyright 2010-2018 Mike van Riel / Naenius (http://www.naenius.com) |
12
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT |
13
|
|
|
* @link http://phpdoc.org |
14
|
|
|
*/ |
15
|
|
|
|
16
|
|
|
namespace phpDocumentor; |
17
|
|
|
|
18
|
|
|
use phpDocumentor\Event\Dispatcher; |
19
|
|
|
use phpDocumentor\Parser\Event\PreFileEvent; |
20
|
|
|
use Psr\Log\LoggerInterface; |
21
|
|
|
use Psr\Log\LogLevel; |
22
|
|
|
use RuntimeException; |
23
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Application class for phpDocumentor. |
27
|
|
|
* |
28
|
|
|
* Can be used as bootstrap when the run method is not invoked. |
29
|
|
|
* |
30
|
|
|
* @codeCoverageIgnore too many side-effects and system calls to properly test |
31
|
|
|
*/ |
32
|
|
|
class Application |
33
|
|
|
{ |
34
|
|
|
public static function VERSION(): string |
35
|
|
|
{ |
36
|
|
|
return trim(file_get_contents(__DIR__ . '/../../VERSION')); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public static function templateDirectory(): string |
40
|
|
|
{ |
41
|
|
|
$templateDir = __DIR__ . '/../../data/templates'; |
42
|
|
|
|
43
|
|
|
// when installed using composer the templates are in a different folder |
44
|
|
|
$composerTemplatePath = __DIR__ . '/../../../templates'; |
45
|
|
|
if (file_exists($composerTemplatePath)) { |
46
|
|
|
$templateDir = $composerTemplatePath; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
return $templateDir; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Initializes all components used by phpDocumentor. |
54
|
|
|
*/ |
55
|
|
|
public function __construct(LoggerInterface $logger) |
56
|
|
|
{ |
57
|
|
|
$this->defineIniSettings(); |
58
|
|
|
|
59
|
|
|
Dispatcher::getInstance()->addListener( |
60
|
|
|
'parser.file.pre', |
61
|
|
|
function (PreFileEvent $event) use ($logger) { |
62
|
|
|
$logger->log(LogLevel::NOTICE, 'Parsing ' . $event->getFile()); |
63
|
|
|
} |
64
|
|
|
); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Adjust php.ini settings. |
69
|
|
|
* |
70
|
|
|
* @throws RuntimeException |
71
|
|
|
*/ |
72
|
|
|
protected function defineIniSettings(): void |
73
|
|
|
{ |
74
|
|
|
$this->setTimezone(); |
75
|
|
|
ini_set('memory_limit', '-1'); |
76
|
|
|
|
77
|
|
|
if (extension_loaded('Zend OPcache') && ini_get('opcache.enable') && ini_get('opcache.enable_cli')) { |
78
|
|
|
if (ini_get('opcache.save_comments')) { |
79
|
|
|
ini_set('opcache.load_comments', '1'); |
80
|
|
|
} else { |
81
|
|
|
ini_set('opcache.enable', '0'); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
if (extension_loaded('Zend Optimizer+') && ini_get('zend_optimizerplus.save_comments') === 0) { |
|
|
|
|
86
|
|
|
throw new RuntimeException('Please enable zend_optimizerplus.save_comments in php.ini.'); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* If the timezone is not set anywhere, set it to UTC. |
92
|
|
|
* |
93
|
|
|
* This is done to prevent any warnings being outputted in relation to using |
94
|
|
|
* date/time functions. |
95
|
|
|
* |
96
|
|
|
* @link http://php.net/manual/en/function.date-default-timezone-get.php for more information how PHP determines the |
97
|
|
|
* default timezone. |
98
|
|
|
*/ |
99
|
|
|
protected function setTimezone(): void |
100
|
|
|
{ |
101
|
|
|
if (false === ini_get('date.timezone')) { |
102
|
|
|
date_default_timezone_set('UTC'); |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|