Carbon.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace Illuminate\Support;
  3. use Carbon\Carbon as BaseCarbon;
  4. use Carbon\CarbonImmutable as BaseCarbonImmutable;
  5. use Illuminate\Support\Traits\Conditionable;
  6. use Ramsey\Uuid\Uuid;
  7. use Symfony\Component\Uid\Ulid;
  8. class Carbon extends BaseCarbon
  9. {
  10. use Conditionable;
  11. /**
  12. * {@inheritdoc}
  13. */
  14. public static function setTestNow($testNow = null)
  15. {
  16. BaseCarbon::setTestNow($testNow);
  17. BaseCarbonImmutable::setTestNow($testNow);
  18. }
  19. /**
  20. * Create a Carbon instance from a given ordered UUID or ULID.
  21. *
  22. * @param \Ramsey\Uuid\Uuid|\Symfony\Component\Uid\Ulid|string $id
  23. * @return \Illuminate\Support\Carbon
  24. */
  25. public static function createFromId($id)
  26. {
  27. if (is_string($id)) {
  28. $id = Ulid::isValid($id) ? Ulid::fromString($id) : Uuid::fromString($id);
  29. }
  30. return static::createFromInterface($id->getDateTime());
  31. }
  32. /**
  33. * Dump the instance and end the script.
  34. *
  35. * @param mixed ...$args
  36. * @return never
  37. */
  38. public function dd(...$args)
  39. {
  40. dd($this, ...$args);
  41. }
  42. /**
  43. * Dump the instance.
  44. *
  45. * @return $this
  46. */
  47. public function dump()
  48. {
  49. dump($this);
  50. return $this;
  51. }
  52. }