Commit 5e356acb by Carsten Brandt

exclude file support for apidocs

issue #1797
parent bbea1ab1
......@@ -62,7 +62,9 @@ class ApiController extends BaseController
}
// search for files to process
$files = $this->searchFiles($sourceDirs);
if (($files = $this->searchFiles($sourceDirs)) === false) {
return 1;
}
// load context from cache
$context = $this->loadContext($targetDir);
......@@ -71,7 +73,9 @@ class ApiController extends BaseController
if (!file_exists($file)) {
$this->stdout('At least one file has been removed. Rebuilding the context...');
$context = new Context();
$files = $this->searchFiles($sourceDirs);
if (($files = $this->searchFiles($sourceDirs)) === false) {
return 1;
}
break;
}
if (sha1_file($file) === $sha) {
......@@ -108,8 +112,11 @@ class ApiController extends BaseController
}
}
protected function findFiles($path, $except = ['vendor/', 'tests/'])
protected function findFiles($path, $except = [])
{
if (empty($except)) {
$except = ['vendor/', 'tests/'];
}
$path = FileHelper::normalizePath($path);
$options = [
'filter' => function ($path) {
......
......@@ -56,7 +56,9 @@ class GuideController extends BaseController
$this->updateContext($renderer->apiContext);
// search for files to process
$files = $this->searchFiles($sourceDirs);
if (($files = $this->searchFiles($sourceDirs)) === false) {
return 1;
}
$renderer->controller = $this;
$renderer->render($files, $targetDir);
......@@ -75,8 +77,11 @@ class GuideController extends BaseController
file_put_contents($targetDir . '/guide-references.txt', implode("\n", $references));
}
protected function findFiles($path, $except = ['README.md'])
protected function findFiles($path, $except = [])
{
if (empty($except)) {
$except = ['README.md'];
}
$path = FileHelper::normalizePath($path);
$options = [
'only' => ['*.md'],
......
......@@ -26,9 +26,9 @@ abstract class BaseController extends Controller
*/
public $template = 'bootstrap';
/**
* @var string|array files to exclude. NOT IMPLEMENTED YET
* @var string|array files to exclude.
*/
public $exclude; // TODO implement
public $exclude;
protected function normalizeTargetDir($target)
......@@ -53,8 +53,17 @@ abstract class BaseController extends Controller
{
$this->stdout('Searching files to process... ');
$files = [];
if (is_array($this->exclude)) {
$exclude = $this->exclude;
} elseif (is_string($this->exclude)) {
$exclude = explode(',', $this->exclude);
} else {
$exclude = [];
}
foreach($sourceDirs as $source) {
foreach($this->findFiles($source) as $fileName) {
foreach($this->findFiles($source, $exclude) as $fileName) {
$files[$fileName] = $fileName;
}
}
......@@ -62,12 +71,12 @@ abstract class BaseController extends Controller
if (empty($files)) {
$this->stderr('Error: No files found to process.' . PHP_EOL);
return 1;
return false;
}
return $files;
}
protected abstract function findFiles($dir);
protected abstract function findFiles($dir, $except = []);
protected function loadContext($location)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment