public function run(DataSourceInterface $dataSource, SourceSet $sourceSet, IoInterface $io = null)
{
if (null === $io) {
$io = new NullIo();
}
$found = false;
$startTime = microtime(true);
$dataSource->refresh($sourceSet);
$this->eventDispatcher->dispatch(self::EVENT_BEFORE_RUN, new SourceSetEvent($sourceSet));
if ($updatedSources = array_filter($sourceSet->updatedSources(), function ($source) {
return !$source->isGenerated();
})) {
if (!$found) {
$io->write('Detected new or updated files');
$found = true;
}
$total = count($updatedSources);
$io->write('Generating: ', false);
$io->write('', false);
$counter = 0;
$timer = microtime(true);
foreach ($updatedSources as $source) {
$this->generatorManager->generate($source, $sourceSet);
$io->overwrite(sprintf('%3d%%', 100 * (++$counter / $total)), false);
}
$io->write(sprintf(' (%d sources / %4.2f seconds)', $total, microtime(true) - $timer));
}
foreach ($sourceSet->updatedSources() as $source) {
$permalink = $this->permalinkFactory->create($source);
$source->setPermalink($permalink);
$source->data()->set('url', $permalink->relativeUrlPath());
}
if ($updatedSources = $sourceSet->updatedSources()) {
if (!$found) {
$io->write('Detected new or updated files');
$found = true;
}
$total = count($updatedSources);
$io->write('Converting: ', false);
$io->write('', false);
$counter = 0;
$timer = microtime(true);
foreach ($updatedSources as $source) {
$this->converterManager->convertSource($source);
if ($source->canBeFormatted()) {
$source->data()->set('blocks', $this->formatterManager->formatSourceBlocks($source));
}
$io->overwrite(sprintf('%3d%%', 100 * (++$counter / $total)), false);
}
$io->write(sprintf(' (%d sources / %4.2f seconds)', $total, microtime(true) - $timer));
}
if ($updatedSources = $sourceSet->updatedSources()) {
if (!$found) {
$io->write('Detected new or updated files');
$found = true;
}
$total = count($updatedSources);
$io->write('Formatting: ', false);
$io->write('', false);
$counter = 0;
$timer = microtime(true);
foreach ($updatedSources as $source) {
if ($source->canBeFormatted()) {
$source->setFormattedContent($this->formatterManager->formatSourcePage($source));
} else {
$source->setFormattedContent($source->content());
}
$io->overwrite(sprintf('%3d%%', 100 * (++$counter / $total)), false);
}
$this->eventDispatcher->dispatch(self::EVENT_AFTER_FORMAT, new SourceSetEvent($sourceSet));
$io->write(sprintf(' (%d sources / %4.2f seconds)', $total, microtime(true) - $timer));
}
foreach ($sourceSet->updatedSources() as $source) {
if ($source->isGenerator() || $source->shouldBeSkipped()) {
continue;
}
$this->writer->write(new SourceOutput($source));
if ($io->isVerbose()) {
$io->write(' + ' . $source->sourceId());
}
}
$this->eventDispatcher->dispatch(self::EVENT_AFTER_RUN, new SourceSetEvent($sourceSet));
if ($found) {
$io->write(sprintf('Processing completed in %4.2f seconds', microtime(true) - $startTime));
}
}