ScribeServiceProvider.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace Knuckles\Scribe;
  3. use Illuminate\Support\ServiceProvider;
  4. use Knuckles\Scribe\Commands\GenerateDocumentation;
  5. use Knuckles\Scribe\Commands\MakeStrategy;
  6. use Knuckles\Scribe\Matching\RouteMatcher;
  7. use Knuckles\Scribe\Matching\RouteMatcherInterface;
  8. class ScribeServiceProvider extends ServiceProvider
  9. {
  10. /**
  11. * Bootstrap the application events.
  12. *
  13. * @return void
  14. */
  15. public function boot()
  16. {
  17. $this->loadViewsFrom(__DIR__ . '/../resources/views/', 'scribe');
  18. $this->publishes([
  19. __DIR__ . '/../resources/views' => $this->app->basePath('resources/views/vendor/scribe'),
  20. ], 'scribe-views');
  21. $this->publishes([
  22. __DIR__ . '/../config/scribe.php' => $this->app->configPath('scribe.php'),
  23. ], 'scribe-config');
  24. $this->mergeConfigFrom(__DIR__ . '/../config/scribe.php', 'scribe');
  25. $this->bootRoutes();
  26. if ($this->app->runningInConsole()) {
  27. $this->commands([
  28. GenerateDocumentation::class,
  29. MakeStrategy::class,
  30. ]);
  31. }
  32. // Bind the route matcher implementation
  33. $this->app->bind(RouteMatcherInterface::class, config('scribe.routeMatcher', RouteMatcher::class));
  34. if (!class_exists('Str')) {
  35. // Lumen may not have the aliases set up, and we don't want to have to use the FQN in our blade files.
  36. class_alias(\Illuminate\Support\Str::class, 'Str');
  37. }
  38. }
  39. /**
  40. * Add docs routes for users that want their docs to pass through their Laravel app.
  41. */
  42. protected function bootRoutes()
  43. {
  44. if (
  45. config('scribe.type', 'static') === 'laravel' &&
  46. config('scribe.laravel.add_routes', false)
  47. ) {
  48. $this->loadRoutesFrom(
  49. __DIR__ . '/../routes/laravel.php'
  50. );
  51. }
  52. }
  53. }