DefaultProviders.php 3.1 KB

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