NelmioApiDocBundle/Describer/SwaggerPhpDescriber.php

38 lines
1.1 KiB
PHP
Raw Normal View History

2016-07-28 10:20:59 +02:00
<?php
/*
* This file is part of the ApiDocBundle package.
*
* (c) EXSyst
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace EXSyst\Bundle\ApiDocBundle\Describer;
2016-07-29 10:22:40 +02:00
class SwaggerPhpDescriber extends ExternalDocDescriber
2016-07-28 10:20:59 +02:00
{
public function __construct(string $projectPath, bool $overwrite = false)
{
2016-07-29 10:22:40 +02:00
parent::__construct(function () use ($projectPath) {
2016-08-01 19:58:57 +02:00
// Catch notices as the documentation can be completed by other describers
$prevHandler = set_error_handler(function ($type, $message, $file, $line, $context) use (&$prevHandler) {
if (E_USER_NOTICE === $type || E_USER_WARNING === $type) {
return;
}
2016-07-28 10:20:59 +02:00
2016-08-01 19:58:57 +02:00
return null !== $prevHandler && call_user_func($prevHandler, $type, $message, $file, $line, $context);
});
try {
$annotation = \Swagger\scan($projectPath);
return json_decode(json_encode($annotation));
} finally {
restore_error_handler();
}
2016-07-29 10:22:40 +02:00
}, $overwrite);
2016-07-28 10:20:59 +02:00
}
}