Completed
Push — develop ( 71fd61...bbac44 )
by Jaap
06:03 queued 02:27
created

src/phpDocumentor/Plugin/Core/ServiceProvider.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * phpDocumentor
4
 *
5
 * PHP Version 5.3
6
 *
7
 * @copyright 2010-2014 Mike van Riel / Naenius (http://www.naenius.com)
8
 * @license   http://www.opensource.org/licenses/mit-license.php MIT
9
 * @link      http://phpdoc.org
10
 */
11
12
namespace phpDocumentor\Plugin\Core;
13
14
use Cilex\Application;
15
use Pimple\Container;
16
use Pimple\ServiceProviderInterface;
17
use phpDocumentor\Translator\Translator;
18
use phpDocumentor\Plugin\Core\Transformer\Writer;
19
use phpDocumentor\Transformer\Writer\Collection;
20
21
/**
22
 * Register all services and subservices necessary to get phpDocumentor up and running.
23
 *
24
 * This provider exposes no services of its own but populates the Writer Collection with the basic writers for
25
 * phpDocumentor and, for backwards compatibility, registers the service providers for Graphs, Twig and PDF to
26
 * the container.
27
 */
28
final class ServiceProvider implements ServiceProviderInterface
0 ignored issues
show
The class ServiceProvider has a coupling between objects value of 13. Consider to reduce the number of dependencies under 13.
Loading history...
29
{
30
    /**
31
     * Registers services on the given app.
32
     *
33
     * @param Container $app An Application instance.
34
     *
35
     * @return void
36
     */
37 1
    public function register(Container $app)
38
    {
39 1
        $this->registerTranslationMessages($app);
40 1
        $this->registerWriters($app);
41 1
        $this->registerDependenciesOnXsltExtension($app);
42
43 1
        $app->register(new \phpDocumentor\Plugin\Graphs\ServiceProvider());
44 1
        $app->register(new \phpDocumentor\Plugin\Twig\ServiceProvider());
45 1
    }
46
47
    /**
48
     * Creates all writers for this plugin and adds them to the WriterCollection object.
49
     *
50
     * This action will enable transformations in templates to make use of these writers.
51
     *
52
     * @param Application $app
53
     *
54
     * @return void
55
     */
56 1
    private function registerWriters(Application $app)
57
    {
58 1
        $writerCollection = $this->getWriterCollection($app);
59
60 1
        $writerCollection['FileIo'] = new Writer\FileIo();
61 1
        $writerCollection['checkstyle'] = new Writer\Checkstyle();
62 1
        $writerCollection['sourcecode'] = new Writer\Sourcecode();
63 1
        $writerCollection['statistics'] = new Writer\Statistics();
64 1
        $writerCollection['xml'] = new Writer\Xml($app['transformer.routing.standard']);
65 1
        $writerCollection['xsl'] = new Writer\Xsl($app['monolog']);
66
67 1
        $writerCollection['checkstyle']->setTranslator($this->getTranslator($app));
68 1
        $writerCollection['xml']->setTranslator($this->getTranslator($app));
69 1
    }
70
71
    /**
72
     * Registers the Messages folder in this plugin as a source of translations.
73
     *
74
     * @param Application $app
75
     *
76
     * @return void
77
     */
78 1
    private function registerTranslationMessages(Application $app)
79
    {
80 1
        $this->getTranslator($app)->addTranslationFolder(__DIR__ . DIRECTORY_SEPARATOR . 'Messages');
81 1
    }
82
83
    /**
84
     * Registers the Routing Queue and Descriptor Builder objects on the XSLT Extension class.
85
     *
86
     * In every template we use PHP helpers in order to be able to have routing that is universal between templates and
87
     * convert Markdown text into HTML (for example). The only way for XSL to do this is by having global functions or
88
     * static methods in a class because you cannot inject an object into an XSL processor.
89
     *
90
     * With this method we make sure that all dependencies used by the static methods are injected as static properties.
91
     *
92
     * @param Application $app
93
     *
94
     * @return void
95
     */
96 1
    private function registerDependenciesOnXsltExtension(Application $app)
97
    {
98 1
        Xslt\Extension::$routers = $app['transformer.routing.queue'];
99 1
        Xslt\Extension::$descriptorBuilder = $app['descriptor.builder'];
100 1
    }
101
102
    /**
103
     * Returns the Translator service from the Service Locator.
104
     *
105
     * @param Application $app
106
     *
107
     * @return Translator
108
     */
109 1
    private function getTranslator(Application $app)
110
    {
111 1
        return $app['translator'];
112
    }
113
114
    /**
115
     * Returns the WriterCollection service from the Service Locator.
116
     *
117
     * @param Application $app
118
     *
119
     * @return Collection
120
     */
121 1
    private function getWriterCollection(Application $app)
122
    {
123 1
        return $app['transformer.writer.collection'];
124
    }
125
}
126