<?php
namespace phpDocumentor\Parser;
use Cilex\Application;
use Cilex\ServiceProviderInterface;
use phpDocumentor\Fileset\Collection;
use phpDocumentor\Parser\Command\Project\ParseCommand;
use phpDocumentor\Plugin\Core\Descriptor\Validator\ValidatorAbstract;
use phpDocumentor\Reflection\Event\PostDocBlockExtractionEvent;
use phpDocumentor\Translator\Translator;
class ServiceProvider implements ServiceProviderInterface
{
public function register(Application $app)
{
if (!isset($app['descriptor.builder'])) {
throw new Exception\MissingDependencyException(
'The builder object that is used to construct the ProjectDescriptor is missing'
);
}
$app['parser'] = $app->share(
function ($app) {
$parser = new Parser();
$parser->setStopwatch($app['kernel.stopwatch']);
$parser->setLogger($app['monolog']);
return $parser;
}
);
$app['markdown'] = $app->share(
function () {
return \Parsedown::instance();
}
);
$translator = $app['translator'];
$translator->addTranslationFolder(__DIR__ . DIRECTORY_SEPARATOR . 'Messages');
$app['parser.files'] = new Collection();
$app->command(new ParseCommand($app['descriptor.builder'], $app['parser'], $translator, $app['parser.files']));
}
public function validateDocBlocks($data)
{
$element = $data->getSubject();
$docblock = $data->getDocblock();
$type = substr(
get_class($element),
strrpos(get_class($element), '\\') + 1,
-9 );
if ($docblock && $docblock->hasTag('ignore')) {
return;
}
$validatorOptions = $this->loadConfiguration();
foreach (array('Deprecated', 'Required', $type) as $validator) {
$class = 'phpDocumentor\Plugin\Core\Parser\DocBlock\Validator\\' . $validator . 'Validator';
if (class_exists($class)) {
$val = new $class($element->getName(), $docblock, $element);
$val->setOptions($validatorOptions);
$val->isValid($element);
}
}
}
protected function loadConfiguration()
{
$validatorOptions = array();
return $validatorOptions;
}
protected function loadConfigurationByElement($configOptions, $configType)
{
$validatorOptions = array();
if (isset($configOptions[$configType]->tag)) {
foreach ($configOptions[$configType]->tag as $tag) {
$tagName = (string) $tag['name'];
if (isset($tag->element)) {
foreach ($tag->element as $type) {
$typeName = (string) $type;
$validatorOptions[$typeName][] = $tagName;
}
} else {
$validatorOptions['__ALL__'][] = $tagName;
}
}
}
return $validatorOptions;
}
}