Scribe.php 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace Knuckles\Scribe;
  3. use Knuckles\Camel\Extraction\ExtractedEndpointData;
  4. use Knuckles\Scribe\Commands\GenerateDocumentation;
  5. use Knuckles\Scribe\Tools\Globals;
  6. use Symfony\Component\HttpFoundation\Request;
  7. class Scribe
  8. {
  9. public const VERSION = '4.29.0';
  10. /**
  11. * Specify a callback that will be executed just before a response call is made
  12. * (after configuring the environment and starting a transaction).
  13. *
  14. * @param callable(Request, ExtractedEndpointData): mixed $callable
  15. */
  16. public static function beforeResponseCall(callable $callable)
  17. {
  18. Globals::$__beforeResponseCall = $callable;
  19. }
  20. /**
  21. * Specify a callback that will be executed just before the generate command is executed
  22. *
  23. * @param callable(GenerateDocumentation): mixed $callable
  24. */
  25. public static function bootstrap(callable $callable)
  26. {
  27. Globals::$__bootstrap = $callable;
  28. }
  29. /**
  30. * Specify a callback that will be executed when Scribe is done generating your docs.
  31. * This callback will receive a map of all the output paths generated, that looks like this:
  32. * [
  33. * 'postman' => '/absolute/path/to/postman/collection',
  34. * 'openapi' => '/absolute/path/to/openapi/spec',
  35. * // If you're using `laravel` type, `html` will be null, and vice versa for `blade`.
  36. * 'html' => '/absolute/path/to/index.html/',
  37. * 'blade' => '/absolute/path/to/blade/view',
  38. * // These are paths to asset folders
  39. * 'assets' => [
  40. * 'js' => '/path/to/js/assets/folder',
  41. * 'css' => '/path/to/css/assets/folder',
  42. * 'images' => '/path/to/images/assets/folder',
  43. * ]
  44. * ]
  45. *
  46. * If you disabled `postman` or `openapi`, their values will be null.
  47. *
  48. * @param callable(array): mixed $callable
  49. */
  50. public static function afterGenerating(callable $callable)
  51. {
  52. Globals::$__afterGenerating = $callable;
  53. }
  54. /**
  55. * Specify a callback that will be used by all FormRequest strategies
  56. * to instantiate Form Requests. his callback takes the name of the form request class,
  57. * the current Laravel route being processed, and the controller method.
  58. *
  59. * @param ?callable(string,\Illuminate\Routing\Route,\ReflectionFunctionAbstract): mixed $callable
  60. */
  61. public static function instantiateFormRequestUsing(?callable $callable)
  62. {
  63. Globals::$__instantiateFormRequestUsing = $callable;
  64. }
  65. /**
  66. * Specify a callback that will be called when instantiating an `ExtractedEndpointData` object
  67. * in order to normalize the URL. The default normalization tries to convert URL parameters from
  68. * Laravel resource-style (`users/{user}/projects/{project}`)
  69. * to a general style (`users/{user_id}/projects/{id}`).
  70. * The callback will be passed the default Laravel URL, the route object, the controller method and class.
  71. *
  72. * @param ?callable(string,\Illuminate\Routing\Route,\ReflectionFunctionAbstract,?\ReflectionClass): string $callable
  73. */
  74. public static function normalizeEndpointUrlUsing(?callable $callable)
  75. {
  76. Globals::$__normalizeEndpointUrlUsing = $callable;
  77. }
  78. }