Selaa lähdekoodia

Use default strategies for each stage if not specified

shalvah 5 vuotta sitten
vanhempi
commit
e94dc4ed92
2 muutettua tiedostoa jossa 25 lisäystä ja 2 poistoa
  1. 5 1
      docs/plugins.md
  2. 20 1
      src/Tools/Generator.php

+ 5 - 1
docs/plugins.md

@@ -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`.

+ 20 - 1
src/Tools/Generator.php

@@ -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);