-
-
Notifications
You must be signed in to change notification settings - Fork 634
/
ServiceProvider.php
67 lines (62 loc) · 2.5 KB
/
ServiceProvider.php
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
<?php
/**
* phpDocumentor
*
* PHP Version 5.3
*
* @copyright 2010-2018 Mike van Riel / Naenius (http://www.naenius.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
namespace phpDocumentor\Configuration;
use Cilex\Application;
use Doctrine\Common\Annotations\AnnotationRegistry;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
use Doctrine\Common\Annotations\AnnotationReader;
use Symfony\Component\Console\Application as ConsoleApplication;
use Symfony\Component\Console\Input\InputOption;
/**
* Provides a series of services in order to handle the configuration for phpDocumentor.
*
* This class is responsible for registering a 'Merger' service that is used to combine several configuration
* definitions into one and will add a new option `config` to all commands of phpDocumentor.
*
* Exposed services:
*
* - 'config', the configuration service containing all options and parameters for phpDocumentor.
* - 'config.merger', a service used to combine the configuration template with the user configuration file (phpdoc.xml
* of phpdoc.dist.xml).
*
* The following variables are exposed:
*
* - 'config.path.template', the location of the configuration template with defaults.
* - 'config.path.user', the location of the user configuration file that will be merged with the template.
* - 'config.class', the class name of the root configuration object.
*/
class ServiceProvider implements ServiceProviderInterface
{
/**
* 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.
*
* @param Container $app An Application instance
*/
public function register(Container $app)
{
$app['config.path.template'] = __DIR__ . '/Resources/phpdoc.tpl.xml';
$app['config.path.user'] = getcwd()
. ((file_exists(getcwd() . '/phpdoc.xml')) ? '/phpdoc.xml' : '/phpdoc.dist.xml');
$app['config.class'] = 'phpDocumentor\Configuration';
$app['config'] = function ($app) {
$loader = new Loader($app['serializer'], new Merger(new AnnotationReader()));
return $loader->load($app['config.path.template'], $app['config.path.user'], $app['config.class']);
};
}
}