forked from phpDocumentor/phpDocumentor
/
ServiceProvider.php
42 lines (36 loc) · 1.33 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
<?php
namespace phpDocumentor\Plugin;
use Cilex\Application;
use Cilex\ServiceProviderInterface;
use phpDocumentor\Configuration as ApplicationConfiguration;
class ServiceProvider implements ServiceProviderInterface
{
public function register(Application $app)
{
/** @var ApplicationConfiguration $config */
$config = $app['config'];
$plugins = $config->getPlugins();
if (! $plugins) {
$app->register(new Core\ServiceProvider());
$app->register(new Scrybe\ServiceProvider());
return;
}
array_walk(
$plugins,
function ($plugin) use ($app) {
/** @var Plugin $plugin */
$provider = (strpos($plugin->getClassName(), '\\') === false)
? sprintf('phpDocumentor\\Plugin\\%s\\ServiceProvider', $plugin->getClassName())
: $plugin->getClassName();
if (!class_exists($provider)) {
throw new \RuntimeException('Loading Service Provider for ' . $provider . ' failed.');
}
try {
$app->register(new $provider($plugin));
} catch (\InvalidArgumentException $e) {
throw new \RuntimeException($e->getMessage());
}
}
);
}
}