You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
1.8 KiB

  1. <?php namespace Sensory5\Shortcode\Classes;
  2. class ProcessedShortcode implements ShortcodeInterface
  3. {
  4. private $attributes;
  5. private $content;
  6. private $name;
  7. private function __construct()
  8. {
  9. }
  10. /**
  11. * Create from shortcode data
  12. */
  13. public static function create($attributes, $content, $tagName)
  14. {
  15. $self = new self();
  16. $self->attributes = $attributes;
  17. $self->content = $content;
  18. $self->name = $tagName;
  19. return $self;
  20. }
  21. /**
  22. * Returns new instance of given shortcode with changed content
  23. *
  24. * @param string $content
  25. *
  26. * @return self
  27. */
  28. public function withContent($content)
  29. {
  30. $self = clone $this;
  31. return $self->content = $content;
  32. }
  33. /**
  34. * Returns shortcode name
  35. *
  36. * @return string
  37. */
  38. public function getName()
  39. {
  40. return $this->name;
  41. }
  42. /**
  43. * Returns associative array(name => value) of shortcode parameters
  44. *
  45. * @return array
  46. */
  47. public function getParameters()
  48. {
  49. return $this->attributes;
  50. }
  51. /**
  52. * Returns parameter value using its name, will return null for parameter
  53. * without value
  54. *
  55. * @param string $name Parameter name
  56. * @param null $default Value returned if there is no parameter with given name
  57. *
  58. * @return mixed
  59. */
  60. public function getParameter($name, $default = null)
  61. {
  62. return array_get($this->attributes, $name, $default);
  63. }
  64. /**
  65. * Returns shortcode content (data between opening and closing tag). Null
  66. * means that shortcode had no content (was self closing), do not confuse
  67. * that with empty string (hint: use strict comparison operator ===).
  68. *
  69. * @return string|null
  70. */
  71. public function getContent()
  72. {
  73. return $this->content;
  74. }
  75. }