HtmlString.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace Illuminate\Support;
  3. use Illuminate\Contracts\Support\Htmlable;
  4. use Stringable;
  5. class HtmlString implements Htmlable, Stringable
  6. {
  7. /**
  8. * The HTML string.
  9. *
  10. * @var string
  11. */
  12. protected $html;
  13. /**
  14. * Create a new HTML string instance.
  15. *
  16. * @param string $html
  17. */
  18. public function __construct($html = '')
  19. {
  20. $this->html = $html;
  21. }
  22. /**
  23. * Get the HTML string.
  24. *
  25. * @return string
  26. */
  27. public function toHtml()
  28. {
  29. return $this->html;
  30. }
  31. /**
  32. * Determine if the given HTML string is empty.
  33. *
  34. * @return bool
  35. */
  36. public function isEmpty()
  37. {
  38. return ($this->html ?? '') === '';
  39. }
  40. /**
  41. * Determine if the given HTML string is not empty.
  42. *
  43. * @return bool
  44. */
  45. public function isNotEmpty()
  46. {
  47. return ! $this->isEmpty();
  48. }
  49. /**
  50. * Get the HTML string.
  51. *
  52. * @return string
  53. */
  54. public function __toString()
  55. {
  56. return $this->toHtml() ?? '';
  57. }
  58. }