DefaultProviders.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. namespace Illuminate\Support;
  3. class DefaultProviders
  4. {
  5. /**
  6. * The current providers.
  7. *
  8. * @var array
  9. */
  10. protected $providers;
  11. /**
  12. * Create a new default provider collection.
  13. *
  14. * @return void
  15. */
  16. public function __construct(?array $providers = null)
  17. {
  18. $this->providers = $providers ?: [
  19. \Illuminate\Auth\AuthServiceProvider::class,
  20. \Illuminate\Broadcasting\BroadcastServiceProvider::class,
  21. \Illuminate\Bus\BusServiceProvider::class,
  22. \Illuminate\Cache\CacheServiceProvider::class,
  23. \Illuminate\Foundation\Providers\ConsoleSupportServiceProvider::class,
  24. \Illuminate\Cookie\CookieServiceProvider::class,
  25. \Illuminate\Database\DatabaseServiceProvider::class,
  26. \Illuminate\Encryption\EncryptionServiceProvider::class,
  27. \Illuminate\Filesystem\FilesystemServiceProvider::class,
  28. \Illuminate\Foundation\Providers\FoundationServiceProvider::class,
  29. \Illuminate\Hashing\HashServiceProvider::class,
  30. \Illuminate\Mail\MailServiceProvider::class,
  31. \Illuminate\Notifications\NotificationServiceProvider::class,
  32. \Illuminate\Pagination\PaginationServiceProvider::class,
  33. \Illuminate\Auth\Passwords\PasswordResetServiceProvider::class,
  34. \Illuminate\Pipeline\PipelineServiceProvider::class,
  35. \Illuminate\Queue\QueueServiceProvider::class,
  36. \Illuminate\Redis\RedisServiceProvider::class,
  37. \Illuminate\Session\SessionServiceProvider::class,
  38. \Illuminate\Translation\TranslationServiceProvider::class,
  39. \Illuminate\Validation\ValidationServiceProvider::class,
  40. \Illuminate\View\ViewServiceProvider::class,
  41. ];
  42. }
  43. /**
  44. * Merge the given providers into the provider collection.
  45. *
  46. * @param array $providers
  47. * @return static
  48. */
  49. public function merge(array $providers)
  50. {
  51. $this->providers = array_merge($this->providers, $providers);
  52. return new static($this->providers);
  53. }
  54. /**
  55. * Replace the given providers with other providers.
  56. *
  57. * @param array $items
  58. * @return static
  59. */
  60. public function replace(array $replacements)
  61. {
  62. $current = collect($this->providers);
  63. foreach ($replacements as $from => $to) {
  64. $key = $current->search($from);
  65. $current = is_int($key) ? $current->replace([$key => $to]) : $current;
  66. }
  67. return new static($current->values()->toArray());
  68. }
  69. /**
  70. * Disable the given providers.
  71. *
  72. * @param array $providers
  73. * @return static
  74. */
  75. public function except(array $providers)
  76. {
  77. return new static(collect($this->providers)
  78. ->reject(fn ($p) => in_array($p, $providers))
  79. ->values()
  80. ->toArray());
  81. }
  82. /**
  83. * Convert the provider collection to an array.
  84. *
  85. * @return array
  86. */
  87. public function toArray()
  88. {
  89. return $this->providers;
  90. }
  91. }