Skip to content

Commit

Permalink
Added dependency-injection to Swagger\scan()
Browse files Browse the repository at this point in the history
Allows a ReflectionAnalyser  #214
  • Loading branch information
bfanger committed Jul 4, 2015
1 parent 5a1fc15 commit 6893345
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion bin/swagger
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ set_exception_handler(function ($exception) {

$exclude = $options['exclude'] ? explode(',', $options['exclude']) : null;

$swagger = Swagger\scan($paths, $exclude);
$swagger = Swagger\scan($paths, ['exclude' => $exclude]);
$methods = ['get', 'put', 'post', 'delete', 'options', 'head', 'patch'];
$counter = 0;

Expand Down
17 changes: 12 additions & 5 deletions src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,27 @@
* Scan the filesystem for swagger annotations and build swagger-documentation.
*
* @param string|array|Finder $directory The directory(s) or filename(s)
* @param null|string|array $exclude The directory(s) or filename(s) to exclude (as absolute or relative paths)
* @param array $options
* exclude: string|array $exclude The directory(s) or filename(s) to exclude (as absolute or relative paths)
* analyser: defaults to StaticAnalyser
* analysis: defaults to a new Analysis
* processors: defaults to the registered processors in Analysis
* @return Swagger
*/
function scan($directory, $exclude = null)
function scan($directory, $options = array())
{
$analyser = new StaticAnalyser();
$analysis = new Analysis();
$analyser = @$options['analyser'] ?: new StaticAnalyser();
$analysis = @$options['analysis'] ?: new Analysis();
$processors = @$options['processors'] ?: Analysis::processors();
$exclude = @$options['exclude'] ?: null;

// Crawl directory and parse all files
$finder = Util::finder($directory, $exclude);
foreach ($finder as $file) {
$analysis->addAnalysis($analyser->fromFile($file->getPathname()));
}
// Post processing
$analysis->process();
$analysis->process($processors);
// Validation (Generate notices & warnings)
$analysis->validate();
return $analysis->swagger;
Expand Down
2 changes: 1 addition & 1 deletion tests/UtilTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class UtilTest extends SwaggerTestCase

function testExclude()
{
$swagger = \Swagger\scan(__DIR__ . '/Fixtures', ['Customer.php', 'UsingRefs.php', 'GrandParent.php']);
$swagger = \Swagger\scan(__DIR__ . '/Fixtures', ['exclude' => ['Customer.php', 'UsingRefs.php', 'GrandParent.php']]);
$this->assertSame('Fixture for ParserTest', $swagger->info->title, 'No errors about duplicate @SWG\Info() annotations');
}
}

0 comments on commit 6893345

Please sign in to comment.