Browse Source

Rename beforeGenerating hook to beforeGenerateCommandStarts

Peter Ragheb 2 years ago
parent
commit
c8ef074673
3 changed files with 15 additions and 9 deletions
  1. 10 5
      src/Commands/GenerateDocumentation.php
  2. 4 3
      src/Scribe.php
  3. 1 1
      src/Tools/Globals.php

+ 10 - 5
src/Commands/GenerateDocumentation.php

@@ -40,8 +40,6 @@ class GenerateDocumentation extends Command
 
     public function handle(RouteMatcherInterface $routeMatcher, GroupedEndpointsFactory $groupedEndpointsFactory): void
     {
-        $this->runBeforeGeneratingHook();
-
         $this->bootstrap();
 
         if (!empty($this->docConfig->get("default_group"))) {
@@ -88,11 +86,16 @@ class GenerateDocumentation extends Command
         return $this->docConfig;
     }
 
-    protected function runBeforeGeneratingHook()
+    public function setDocConfig(DocumentationConfig $config)
     {
-        if (is_callable(Globals::$__beforeGenerating)) {
+        $this->docConfig = $config;
+    }
+
+    protected function runBeforeGenerateCommandStartsHook()
+    {
+        if (is_callable(Globals::$__beforeGenerateCommandStarts)) {
             c::info("Running `beforeGenerating()` hook...");
-            call_user_func_array(Globals::$__beforeGenerating, []);
+            call_user_func_array(Globals::$__beforeGenerateCommandStarts, [$this]);
         }
     }
 
@@ -120,6 +123,8 @@ class GenerateDocumentation extends Command
         if ($this->forcing && !$this->shouldExtract) {
             throw new \InvalidArgumentException("Can't use --force and --no-extraction together.");
         }
+
+        $this->runBeforeGenerateCommandStartsHook();
     }
 
     protected function mergeUserDefinedEndpoints(array $groupedEndpoints, array $userDefinedEndpoints): array

+ 4 - 3
src/Scribe.php

@@ -3,6 +3,7 @@
 namespace Knuckles\Scribe;
 
 use Knuckles\Camel\Extraction\ExtractedEndpointData;
+use Knuckles\Scribe\Commands\GenerateDocumentation;
 use Knuckles\Scribe\Tools\Globals;
 use Symfony\Component\HttpFoundation\Request;
 
@@ -24,11 +25,11 @@ class Scribe
     /**
      * Specify a callback that will be executed just before the generate command is executed
      *
-     * @param callable(): mixed $callable
+     * @param callable(GenerateDocumentation): mixed $callable
      */
-    public static function beforeGenerating(callable $callable)
+    public static function beforeGenerateCommandStarts(callable $callable)
     {
-        Globals::$__beforeGenerating = $callable;
+        Globals::$__beforeGenerateCommandStarts = $callable;
     }
 
     /**

+ 1 - 1
src/Tools/Globals.php

@@ -12,7 +12,7 @@ class Globals
 
     public static $__beforeResponseCall;
 
-    public static $__beforeGenerating;
+    public static $__beforeGenerateCommandStarts;
 
     public static $__afterGenerating;