Commit 5e356acb by Carsten Brandt

exclude file support for apidocs

issue #1797
parent bbea1ab1
...@@ -62,7 +62,9 @@ class ApiController extends BaseController ...@@ -62,7 +62,9 @@ class ApiController extends BaseController
} }
// search for files to process // search for files to process
$files = $this->searchFiles($sourceDirs); if (($files = $this->searchFiles($sourceDirs)) === false) {
return 1;
}
// load context from cache // load context from cache
$context = $this->loadContext($targetDir); $context = $this->loadContext($targetDir);
...@@ -71,7 +73,9 @@ class ApiController extends BaseController ...@@ -71,7 +73,9 @@ class ApiController extends BaseController
if (!file_exists($file)) { if (!file_exists($file)) {
$this->stdout('At least one file has been removed. Rebuilding the context...'); $this->stdout('At least one file has been removed. Rebuilding the context...');
$context = new Context(); $context = new Context();
$files = $this->searchFiles($sourceDirs); if (($files = $this->searchFiles($sourceDirs)) === false) {
return 1;
}
break; break;
} }
if (sha1_file($file) === $sha) { if (sha1_file($file) === $sha) {
...@@ -108,8 +112,11 @@ class ApiController extends BaseController ...@@ -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); $path = FileHelper::normalizePath($path);
$options = [ $options = [
'filter' => function ($path) { 'filter' => function ($path) {
......
...@@ -56,7 +56,9 @@ class GuideController extends BaseController ...@@ -56,7 +56,9 @@ class GuideController extends BaseController
$this->updateContext($renderer->apiContext); $this->updateContext($renderer->apiContext);
// search for files to process // search for files to process
$files = $this->searchFiles($sourceDirs); if (($files = $this->searchFiles($sourceDirs)) === false) {
return 1;
}
$renderer->controller = $this; $renderer->controller = $this;
$renderer->render($files, $targetDir); $renderer->render($files, $targetDir);
...@@ -75,8 +77,11 @@ class GuideController extends BaseController ...@@ -75,8 +77,11 @@ class GuideController extends BaseController
file_put_contents($targetDir . '/guide-references.txt', implode("\n", $references)); 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); $path = FileHelper::normalizePath($path);
$options = [ $options = [
'only' => ['*.md'], 'only' => ['*.md'],
......
...@@ -26,9 +26,9 @@ abstract class BaseController extends Controller ...@@ -26,9 +26,9 @@ abstract class BaseController extends Controller
*/ */
public $template = 'bootstrap'; 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) protected function normalizeTargetDir($target)
...@@ -53,8 +53,17 @@ abstract class BaseController extends Controller ...@@ -53,8 +53,17 @@ abstract class BaseController extends Controller
{ {
$this->stdout('Searching files to process... '); $this->stdout('Searching files to process... ');
$files = []; $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($sourceDirs as $source) {
foreach($this->findFiles($source) as $fileName) { foreach($this->findFiles($source, $exclude) as $fileName) {
$files[$fileName] = $fileName; $files[$fileName] = $fileName;
} }
} }
...@@ -62,12 +71,12 @@ abstract class BaseController extends Controller ...@@ -62,12 +71,12 @@ abstract class BaseController extends Controller
if (empty($files)) { if (empty($files)) {
$this->stderr('Error: No files found to process.' . PHP_EOL); $this->stderr('Error: No files found to process.' . PHP_EOL);
return 1; return false;
} }
return $files; return $files;
} }
protected abstract function findFiles($dir); protected abstract function findFiles($dir, $except = []);
protected function loadContext($location) 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