Generator
in package
Generate PHP client(s) from OpenAPI specification(s)
Table of Contents
Properties
- $componentMapperFactory : ComponentMapperFactory
- $endpointMapperFactory : EndpointMapperFactory
- $logger : LoggerInterface
Methods
- __construct() : mixed
- Meant for autowired dependency-injection
- generate() : void
- Generate PHP client(s) from OpenAPI specification(s)
- getDefaultLogger() : LoggerInterface
- Pre-configured console logger
- getBasePathFromSpec() : string
- Define base path to directory within which to generate the PHP client files.
- getNamespaceFromSpec() : string
- Define base namespace to directory within which to generate the PHP client objects.
- generateMapping() : void
- Generate a mapping from an OpenAPI spec to PHP client
- purge() : void
- Purge directory contents
Properties
$componentMapperFactory
private
ComponentMapperFactory
$componentMapperFactory
$endpointMapperFactory
private
EndpointMapperFactory
$endpointMapperFactory
$logger
private
LoggerInterface
$logger
Methods
__construct()
Meant for autowired dependency-injection
public
__construct(ComponentMapperFactory $componentMapperFactory, EndpointMapperFactory $endpointMapperFactory, LoggerInterface $logger) : mixed
Parameters
- $componentMapperFactory : ComponentMapperFactory
- $endpointMapperFactory : EndpointMapperFactory
- $logger : LoggerInterface
Tags
generate()
Generate PHP client(s) from OpenAPI specification(s)
public
generate(string $path, string $basePath, string $baseNamespace[, bool $purge = false ]) : void
Parameters
- $path : string
-
Path to an individual OpenAPI specification file or a directory containing OpenAPI specifications. Directories will be recursiely spidered to find all specification files.
- $basePath : string
-
Path to the directory in which to create the PHP client files
- $baseNamespace : string
-
Namespace within which to generate the PHP client objects
- $purge : bool = false
-
(Optional, default
false) Purge the$basePathdirectory of all contents before writing the generated files (if not purged, any conflicting files will be over-written)
getDefaultLogger()
Pre-configured console logger
public
static getDefaultLogger() : LoggerInterface
Return values
LoggerInterface —A color-coded console logger
getBasePathFromSpec()
Define base path to directory within which to generate the PHP client files.
protected
getBasePathFromSpec(string $specPath, OpenApi $spec, string $basePath) : string
Override to define a base path for client file creation based on a
combination of the specification itself, the path to the specification
and the originally passed $basePath argument.
For example: suppose you are generating clients on a nested directory of OpenAPI specifications and want the clients to mirror the directory structure of the nested specifications.
Defaults to the $basePath argument passed to generate()
Parameters
- $specPath : string
-
Path to an individual OpenAPI specification file
- $spec : OpenApi
-
OpenAPI specification
- $basePath : string
-
Path to the directory in which to create the PHP client files (
$basePathargument passed togenerate())
Tags
Return values
stringgetNamespaceFromSpec()
Define base namespace to directory within which to generate the PHP client objects.
protected
getNamespaceFromSpec(string $specPath, OpenApi $spec, string $baseNamespace) : string
Defaults to the $baseNamespace argument passed to generate()
Parameters
- $specPath : string
-
Path to an individual OpenAPI specification file
- $spec : OpenApi
-
OpenAPI specification
- $baseNamespace : string
-
Namespace within which to generate the PHP client objects (
$baseNamespaceargument passed togenerate())
Tags
Return values
stringgenerateMapping()
Generate a mapping from an OpenAPI spec to PHP client
private
generateMapping(OpenApi $spec, string $basePath, string $baseNamespace[, bool $purge = false ]) : void
Parameters
- $spec : OpenApi
-
OpenAPI specification
- $basePath : string
-
Path to the directory in which to create the PHP client files
- $baseNamespace : string
-
Namespace within which to generate the PHP client objects
- $purge : bool = false
-
(Optional, default
false) Purge the$basePathdirectory of all contents before writing the generated files (if not purged, any conflicting files will be over-written)
purge()
Purge directory contents
private
purge(string $path) : void
Parameters
- $path : string
-
Path to directory to purge