Generator
in package
OpenApi spec generator.
Scans PHP source code and generates OpenApi specifications from the found OpenApi annotations.
This is an object oriented alternative to using the now deprecated \OpenApi\scan()
function and
static class properties of the Analyzer
and Analysis
classes.
The aliases
property supersedes the Analyser::$defaultImports
; namespaces
maps to Analysis::$whitelist
.
Table of Contents
- UNDEFINED = '@OA\\Generator::UNDEFINED🙈'
- $aliases : array<string|int, mixed>
- $analyser : StaticAnalyser
- $logger : null|LoggerInterface
- $namespaces : array<string|int, mixed>
- $processors : null|array<string|int, callable>
- $configStack : mixed
- __construct() : mixed
- addProcessor() : Generator
- generate() : OpenApi
- Generate OpenAPI spec by scanning the given source files.
- getAliases() : array<string|int, mixed>
- getAnalyser() : StaticAnalyser
- getLogger() : LoggerInterface|null
- getNamespaces() : array<string|int, mixed>
- getProcessors() : array<string|int, callable>
- removeProcessor() : Generator
- scan() : OpenApi
- Static wrapper around `Generator::generate()`.
- setAliases() : Generator
- setAnalyser() : Generator
- setNamespaces() : Generator
- setProcessors() : Generator
- updateProcessor() : Generator
- Update/replace an existing processor with a new one.
- scanSources() : void
Constants
UNDEFINED
public
string
UNDEFINED
= '@OA\\Generator::UNDEFINED🙈'
Magic value to differentiate between null and undefined.
Properties
$aliases
protected
array<string|int, mixed>
$aliases
= null
Map of namespace aliases to be supported by doctrine.
$analyser
protected
StaticAnalyser
$analyser
The configured analyzer.
$logger
protected
null|LoggerInterface
$logger
= null
PSR logger.
$namespaces
protected
array<string|int, mixed>
$namespaces
= null
List of annotation namespaces to be autoloaded by doctrine.
$processors
protected
null|array<string|int, callable>
$processors
= null
List of configured processors.
$configStack
private
mixed
$configStack
Methods
__construct()
public
__construct([LoggerInterface|null $logger = null ]) : mixed
Parameters
- $logger : LoggerInterface|null = null
Return values
mixed —addProcessor()
public
addProcessor(callable $processor) : Generator
Parameters
- $processor : callable
Return values
Generator —generate()
Generate OpenAPI spec by scanning the given source files.
public
generate(iteratable<string|int, mixed> $sources[, null|Analysis $analysis = null ][, bool $validate = true ]) : OpenApi
Parameters
- $sources : iteratable<string|int, mixed>
-
PHP source files to scan. Supported sources:
- string - file / directory name
- \SplFileInfo
- \Symfony\Component\Finder\Finder
- $analysis : null|Analysis = null
-
custom analysis instance
- $validate : bool = true
-
flag to enable/disable validation of the returned spec
Return values
OpenApi —getAliases()
public
getAliases() : array<string|int, mixed>
Return values
array<string|int, mixed> —getAnalyser()
public
getAnalyser() : StaticAnalyser
Return values
StaticAnalyser —getLogger()
public
getLogger() : LoggerInterface|null
Return values
LoggerInterface|null —getNamespaces()
public
getNamespaces() : array<string|int, mixed>
Return values
array<string|int, mixed> —getProcessors()
public
getProcessors() : array<string|int, callable>
Return values
array<string|int, callable> —removeProcessor()
public
removeProcessor(callable $processor[, bool $silent = false ]) : Generator
Parameters
- $processor : callable
- $silent : bool = false
Return values
Generator —scan()
Static wrapper around `Generator::generate()`.
public
static scan(iteratable<string|int, mixed> $sources[, array<string|int, mixed> $options = [] ]) : OpenApi
Parameters
- $sources : iteratable<string|int, mixed>
-
PHP source files to scan. Supported sources:
- string
- \SplFileInfo
- \Symfony\Component\Finder\Finder
- $options : array<string|int, mixed> = []
-
aliases: null|array Defaults to
Analyser::$defaultImports
. namespaces: null|array Defaults toAnalyser::$whitelist
. analyser: null|StaticAnalyser Defaults to a newStaticAnalyser
. analysis: null|Analysis Defaults to a newAnalysis
. processors: null|array Defaults toAnalysis::processors()
. logger: null|\Psr\Log\LoggerInterface If not set logging will use \OpenApi\Logger as before. validate: bool Defaults totrue
.
Return values
OpenApi —setAliases()
public
setAliases(array<string|int, mixed>|null $aliases) : Generator
Parameters
- $aliases : array<string|int, mixed>|null
Return values
Generator —setAnalyser()
public
setAnalyser(StaticAnalyser|null $analyser) : Generator
Parameters
- $analyser : StaticAnalyser|null
Return values
Generator —setNamespaces()
public
setNamespaces(array<string|int, mixed>|null $namespaces) : Generator
Parameters
- $namespaces : array<string|int, mixed>|null
Return values
Generator —setProcessors()
public
setProcessors(null|array<string|int, callable> $processors) : Generator
Parameters
- $processors : null|array<string|int, callable>
Return values
Generator —updateProcessor()
Update/replace an existing processor with a new one.
public
updateProcessor(callable $processor[, null|callable $matcher = null ]) : Generator
Parameters
- $processor : callable
-
the new processor
- $matcher : null|callable = null
-
Optional matcher callable to identify the processor to replace. If none given, matching is based on the processors class.
Return values
Generator —scanSources()
protected
scanSources(iteratable<string|int, mixed> $sources, Analysis $analysis, Context $rootContext) : void