Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
390 lines (342 loc) · 11.7 KB

File metadata and controls

390 lines (342 loc) · 11.7 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
<?php
/**
* phpDocumentor
*
* PHP Version 5.3
*
* @copyright 2010-2013 Mike van Riel / Naenius (http://www.naenius.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
namespace phpDocumentor;
use Cilex\Application as Cilex;
use Cilex\Provider\MonologServiceProvider;
use Cilex\Provider\ValidatorServiceProvider;
use Doctrine\Common\Annotations\AnnotationRegistry;
use JMS\Serializer\SerializerBuilder;
use Monolog\ErrorHandler;
use Monolog\Handler\NullHandler;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
use phpDocumentor\Command\Helper\LoggerHelper;
use phpDocumentor\Console\Input\ArgvInput;
use phpDocumentor\Transformer\Writer\Exception\RequirementMissing;
use Symfony\Component\Console\Application as ConsoleApplication;
use Symfony\Component\Console\Helper\ProgressHelper;
use Symfony\Component\Console\Shell;
use Symfony\Component\Stopwatch\Stopwatch;
use Zend\Config\Factory;
/**
* Finds and activates the autoloader.
*/
require_once findAutoloader();
/**
* Application class for phpDocumentor.
*
* Can be used as bootstrap when the run method is not invoked.
*/
class Application extends Cilex
{
/** @var string $VERSION represents the version of phpDocumentor as stored in /VERSION */
public static $VERSION;
/**
* Initializes all components used by phpDocumentor.
*/
public function __construct()
{
ini_set('memory_limit', -1);
self::$VERSION = file_get_contents(__DIR__ . '/../../VERSION');
parent::__construct('phpDocumentor', self::$VERSION);
$this['kernel.timer.start'] = time();
$this['kernel.stopwatch'] = function () {
return new Stopwatch();
};
$this->setTimezone();
$this->addAutoloader();
$this->addConfiguration();
$this->addLogging();
$this->addEventDispatcher();
$this->addTranslator();
/** @var ConsoleApplication $console */
$console = $this['console'];
$console->getHelperSet()->set(new LoggerHelper());
$this->addSerializer();
$this->register(new ValidatorServiceProvider());
$this->register(new Descriptor\ServiceProvider());
$this->register(new Parser\ServiceProvider());
$this->register(new Transformer\ServiceProvider());
// TODO: make plugin service provider calls registrable from config
$this->register(new Plugin\Core\ServiceProvider());
$this->verifyWriterRequirementsAndExitIfBroken();
$this->addCommandsForProjectNamespace();
}
/**
* If the timezone is not set anywhere, set it to UTC.
*
* This is done to prevent any warnings being outputted in relation to using
* date/time functions. What is checked is php.ini, and if the PHP version
* is prior to 5.4, the TZ environment variable.
*
* @return void
*/
public function setTimezone()
{
if (false === ini_get('date.timezone') || (version_compare(phpversion(), '5.4.0', '<')
&& false === getenv('TZ'))
) {
date_default_timezone_set('UTC');
}
}
/**
* Instantiates the autoloader and adds it to phpDocumentor's container.
*
* @return void
*/
protected function addAutoloader()
{
$this['autoloader'] = include findAutoloader();
}
/**
* Adds a logging provider to the container of phpDocumentor.
*
* @return void
*/
protected function addLogging()
{
$this->register(
new MonologServiceProvider(),
array(
'monolog.name' => 'phpDocumentor',
'monolog.logfile' => sys_get_temp_dir() . '/phpdoc.log',
'monolog.debugfile' => sys_get_temp_dir() . '/phpdoc.debug.log',
'monolog.level' => Logger::INFO,
)
);
$app = $this;
$this['monolog.configure'] = $this->protect(
function ($log) use ($app) {
$level = (string)$app['config']->logging->level;
// null means the default is used
$logPath = isset($app['config']->logging->paths->default)
? (string) $app['config']->logging->paths->default
: null;
// null means the default is used
$debugPath = isset($app['config']->logging->paths->errors)
? (string) $app['config']->logging->paths->errors
: null;
$app->configureLogger($log, $level, $logPath, $debugPath);
}
);
ErrorHandler::register($this['monolog']);
}
/**
* Removes all logging handlers and replaces them with handlers that can write to the given logPath and level.
*
* @param Logger $logger The logger instance that needs to be configured.
* @param integer $level The minimum level that will be written to the normal logfile; matches one of the
* constants in {@see \Monolog\Logger}.
* @param string $logPath The full path where the normal log file needs to be written.
*
* @return void
*/
public function configureLogger($logger, $level, $logPath = null)
{
/** @var Logger $monolog */
$monolog = $logger;
switch($level) {
case 'emergency':
case 'emerg':
$level = Logger::EMERGENCY;
break;
case 'alert':
$level = Logger::ALERT;
break;
case 'critical':
case 'crit':
$level = Logger::CRITICAL;
break;
case 'error':
case 'err':
$level = Logger::ERROR;
break;
case 'warning':
case 'warn':
$level = Logger::WARNING;
break;
case 'notice':
$level = Logger::NOTICE;
break;
case 'info':
$level = Logger::INFO;
break;
case 'debug':
$level = Logger::DEBUG;
break;
}
$this['monolog.level'] = $level;
if ($logPath) {
$logPath = str_replace(
array('{APP_ROOT}', '{DATE}'),
array(realpath(__DIR__.'/../..'), $this['kernel.timer.start']),
$logPath
);
$this['monolog.logfile'] = $logPath;
}
// remove all handlers from the stack
try {
while ($monolog->popHandler()) {
}
} catch (\LogicException $e) {
// popHandler throws an exception when you try to pop the empty stack; to us this is not an
// error but an indication that the handler stack is empty.
}
if ($level === 'quiet') {
$monolog->pushHandler(new NullHandler());
return;
}
// set our new handlers
if ($logPath) {
$monolog->pushHandler(new StreamHandler($logPath, $level));
} else {
$monolog->pushHandler(new StreamHandler('php://stdout', $level));
}
}
/**
* Adds the Configuration object to the DIC.
*
* phpDocumentor first loads the template config file (/data/phpdoc.tpl.xml)
* and then the phpdoc.dist.xml, or the phpdoc.xml if it exists but not both,
* from the current working directory.
*
* The user config file (either phpdoc.dist.xml or phpdoc.xml) is merged
* with the template file.
*
* @return void
*/
protected function addConfiguration()
{
$this['config'] = $this->share(
function () {
$user_config_file = (file_exists(getcwd() . DIRECTORY_SEPARATOR . 'phpdoc.xml'))
? getcwd() . DIRECTORY_SEPARATOR . 'phpdoc.xml'
: getcwd() . DIRECTORY_SEPARATOR . 'phpdoc.dist.xml';
$config_files = array(__DIR__ . '/../../data/phpdoc.tpl.xml');
if (is_readable($user_config_file)) {
$config_files[] = $user_config_file;
}
return Factory::fromFiles($config_files, true);
}
);
}
/**
* Adds the event dispatcher to phpDocumentor's container.
*
* @return void
*/
protected function addEventDispatcher()
{
$this['event_dispatcher'] = $this->share(
function () {
return Event\Dispatcher::getInstance();
}
);
}
/**
* Adds the message translator to phpDocumentor's container.
*
* @return void
*/
protected function addTranslator()
{
$config = $this['config']->toArray();
$this['translator.locale'] = isset($config['translator']['locale']) ? $config['translator']['locale'] : 'en';
$this['translator'] = $this->share(
function ($app) {
$translator = new Translator();
$translator->setLocale($app['translator.locale']);
return $translator;
}
);
}
/**
* Adds the command to phpDocumentor that belong to the Project namespace.
*
* @return void
*/
protected function addCommandsForProjectNamespace()
{
$this->command(new Command\Project\RunCommand());
}
/**
* Adds the serializer to the container
*
* @return void
*/
protected function addSerializer()
{
$this['serializer'] = $this->share(
function () {
$serializerPath = __DIR__ . '/../../vendor/jms/serializer/src';
if (!file_exists($serializerPath)) {
$serializerPath = __DIR__ . '/../../../../jms/serializer/src';
}
AnnotationRegistry::registerAutoloadNamespace(
'JMS\Serializer\Annotation',
$serializerPath
);
return SerializerBuilder::create()->build();
}
);
}
/**
* Run the application and if no command is provided, use project:run.
*
* @param bool $interactive Whether to run in interactive mode.
*
* @return void
*/
public function run($interactive = false)
{
/** @var ConsoleApplication $app */
$app = $this['console'];
$app->setAutoExit(false);
if ($interactive) {
$app = new Shell($app);
}
$output = new Console\Output\Output();
$output->setLogger($this['monolog']);
$app->run(new ArgvInput(), $output);
}
protected function verifyWriterRequirementsAndExitIfBroken()
{
try {
$this['transformer.writer.collection']->checkRequirements();
} catch (RequirementMissing $e) {
$this['monolog']->emerg(
'phpDocumentor detected that a requirement is missing in your system setup: ' . $e->getMessage()
);
exit(1);
}
}
}
/**
* Tries to find the autoloader relative to this file and return its path.
*
* @throws \RuntimeException if the autoloader could not be found.
*
* @return string the path of the autoloader.
*/
function findAutoloader()
{
$autoloader_base_path = '/../../vendor/autoload.php';
// if the file does not exist from a base path it is included as vendor
$autoloader_location = file_exists(__DIR__ . $autoloader_base_path)
? __DIR__ . $autoloader_base_path
: __DIR__ . '/../../..' . $autoloader_base_path;
if (!file_exists($autoloader_location)) {
throw new \RuntimeException(
'Unable to find autoloader at ' . $autoloader_location
);
}
return $autoloader_location;
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.