Use default strategies for each stage if not specified

This commit is contained in:
shalvah
2019-09-07 16:33:19 +01:00
parent 18938eb407
commit e94dc4ed92
2 changed files with 25 additions and 2 deletions

View File

@@ -8,7 +8,11 @@ Route processing is performed in four stages:
- queryParameters
- responses
For each stage, the Generator attempts one or more configured strategies to fetch data. The Generator will call of the strategies configured, progressively combining their results together before to produce the final output of that stage.
For each stage, the Generator attempts the specified strategies to fetch data. The Generator will call of the strategies configured, progressively combining their results together before to produce the final output of that stage.
There are a number of strategies inccluded with the package, so you don't have to set up anything to get it working.
> Note: The included ResponseCalls strategy is designed to stop if a response has already been gotten from any other strategy.
## Strategies
To create a strategy, create a class that extends `\Mpociot\ApiDoc\Strategies\Strategy`.

View File

@@ -120,7 +120,26 @@ class Generator
protected function iterateThroughStrategies(string $stage, array $context, array $arguments)
{
$strategies = $this->config->get("strategies.$stage", []);
$defaultStrategies = [
'metadata' => [
\Mpociot\ApiDoc\Strategies\Metadata\GetFromDocBlocks::class,
],
'bodyParameters' => [
\Mpociot\ApiDoc\Strategies\BodyParameters\GetFromBodyParamTag::class,
],
'queryParameters' => [
\Mpociot\ApiDoc\Strategies\QueryParameters\GetFromQueryParamTag::class,
],
'responses' => [
\Mpociot\ApiDoc\Strategies\Responses\UseResponseTag::class,
\Mpociot\ApiDoc\Strategies\Responses\UseResponseFileTag::class,
\Mpociot\ApiDoc\Strategies\Responses\UseTransformerTags::class,
\Mpociot\ApiDoc\Strategies\Responses\ResponseCalls::class,
]
];
// Use the default strategies for the stage, unless they were explicitly set
$strategies = $this->config->get("strategies.$stage", $defaultStrategies[$stage]);
$context[$stage] = $context[$stage] ?? [];
foreach ($strategies as $strategyClass) {
$strategy = new $strategyClass($stage, $this->config);