functions.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <?php
  2. namespace Illuminate\Support;
  3. use Carbon\CarbonInterface;
  4. use Carbon\CarbonInterval;
  5. use Illuminate\Support\Defer\DeferredCallback;
  6. use Illuminate\Support\Defer\DeferredCallbackCollection;
  7. use Illuminate\Support\Facades\Date;
  8. use Symfony\Component\Process\PhpExecutableFinder;
  9. if (! function_exists('Illuminate\Support\defer')) {
  10. /**
  11. * Defer execution of the given callback.
  12. *
  13. * @param callable|null $callback
  14. * @param string|null $name
  15. * @param bool $always
  16. * @return ($callback is null ? \Illuminate\Support\Defer\DeferredCallbackCollection : \Illuminate\Support\Defer\DeferredCallback)
  17. */
  18. function defer(?callable $callback = null, ?string $name = null, bool $always = false): DeferredCallback|DeferredCallbackCollection
  19. {
  20. if ($callback === null) {
  21. return app(DeferredCallbackCollection::class);
  22. }
  23. return tap(
  24. new DeferredCallback($callback, $name, $always),
  25. fn ($deferred) => app(DeferredCallbackCollection::class)[] = $deferred
  26. );
  27. }
  28. }
  29. if (! function_exists('Illuminate\Support\php_binary')) {
  30. /**
  31. * Determine the PHP Binary.
  32. */
  33. function php_binary(): string
  34. {
  35. return (new PhpExecutableFinder)->find(false) ?: 'php';
  36. }
  37. }
  38. if (! function_exists('Illuminate\Support\artisan_binary')) {
  39. /**
  40. * Determine the proper Artisan executable.
  41. */
  42. function artisan_binary(): string
  43. {
  44. return defined('ARTISAN_BINARY') ? ARTISAN_BINARY : 'artisan';
  45. }
  46. }
  47. // Time functions...
  48. if (! function_exists('Illuminate\Support\now')) {
  49. /**
  50. * Create a new Carbon instance for the current time.
  51. *
  52. * @param \DateTimeZone|\UnitEnum|string|null $tz
  53. * @return \Illuminate\Support\Carbon
  54. */
  55. function now($tz = null): CarbonInterface
  56. {
  57. return Date::now(enum_value($tz));
  58. }
  59. }
  60. if (! function_exists('Illuminate\Support\microseconds')) {
  61. /**
  62. * Get the current date / time plus the given number of microseconds.
  63. */
  64. function microseconds(int|float $microseconds): CarbonInterval
  65. {
  66. return CarbonInterval::microseconds($microseconds);
  67. }
  68. }
  69. if (! function_exists('Illuminate\Support\milliseconds')) {
  70. /**
  71. * Get the current date / time plus the given number of milliseconds.
  72. */
  73. function milliseconds(int|float $milliseconds): CarbonInterval
  74. {
  75. return CarbonInterval::milliseconds($milliseconds);
  76. }
  77. }
  78. if (! function_exists('Illuminate\Support\seconds')) {
  79. /**
  80. * Get the current date / time plus the given number of seconds.
  81. */
  82. function seconds(int|float $seconds): CarbonInterval
  83. {
  84. return CarbonInterval::seconds($seconds);
  85. }
  86. }
  87. if (! function_exists('Illuminate\Support\minutes')) {
  88. /**
  89. * Get the current date / time plus the given number of minutes.
  90. */
  91. function minutes(int|float $minutes): CarbonInterval
  92. {
  93. return CarbonInterval::minutes($minutes);
  94. }
  95. }
  96. if (! function_exists('Illuminate\Support\hours')) {
  97. /**
  98. * Get the current date / time plus the given number of hours.
  99. */
  100. function hours(int|float $hours): CarbonInterval
  101. {
  102. return CarbonInterval::hours($hours);
  103. }
  104. }
  105. if (! function_exists('Illuminate\Support\days')) {
  106. /**
  107. * Get the current date / time plus the given number of days.
  108. */
  109. function days(int|float $days): CarbonInterval
  110. {
  111. return CarbonInterval::days($days);
  112. }
  113. }
  114. if (! function_exists('Illuminate\Support\weeks')) {
  115. /**
  116. * Get the current date / time plus the given number of weeks.
  117. */
  118. function weeks(int $weeks): CarbonInterval
  119. {
  120. return CarbonInterval::weeks($weeks);
  121. }
  122. }
  123. if (! function_exists('Illuminate\Support\months')) {
  124. /**
  125. * Get the current date / time plus the given number of months.
  126. */
  127. function months(int $months): CarbonInterval
  128. {
  129. return CarbonInterval::months($months);
  130. }
  131. }
  132. if (! function_exists('Illuminate\Support\years')) {
  133. /**
  134. * Get the current date / time plus the given number of years.
  135. */
  136. function years(int $years): CarbonInterval
  137. {
  138. return CarbonInterval::years($years);
  139. }
  140. }