mirror of
https://github.com/ambieco/scribe.git
synced 2026-04-24 07:54:57 +08:00
Use default strategies for each stage if not specified
This commit is contained in:
@@ -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`.
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user