Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AbstractMessage.php
Go to the documentation of this file.
1 <?php
7 
14 abstract class AbstractMessage implements MessageInterface
15 {
19  protected $text;
20 
24  protected $identifier;
25 
29  protected $isSticky = false;
30 
34  protected $data;
35 
39  public function __construct(
40  $text = null
41  ) {
42  $this->text = $text;
43  }
44 
50  abstract public function getType();
51 
57  public function getText()
58  {
59  return (string)$this->text;
60  }
61 
68  public function setText($text)
69  {
70  $this->text = $text;
71  return $this;
72  }
73 
80  public function setIdentifier($identifier)
81  {
82  $this->identifier = $identifier;
83  return $this;
84  }
85 
91  public function getIdentifier()
92  {
93  return $this->identifier;
94  }
95 
102  public function setIsSticky($isSticky = true)
103  {
104  $this->isSticky = $isSticky;
105  return $this;
106  }
107 
114  public function getIsSticky()
115  {
116  return $this->isSticky;
117  }
118 
124  public function toString()
125  {
126  $out = $this->getType() . ': ' . $this->getIdentifier() . ': ' . $this->getText();
127  return $out;
128  }
129 
137  public function setData(array $data = [])
138  {
139  array_walk_recursive(
140  $data,
141  function ($element) {
142  if (is_object($element) && !$element instanceof \Serializable) {
143  throw new \InvalidArgumentException('Only serializable content is allowed.');
144  }
145  }
146  );
147 
148  $this->data = $data;
149  return $this;
150  }
151 
157  public function getData()
158  {
159  return (array)$this->data;
160  }
161 }
$element
Definition: element.phtml:12