Bitrix-D7  20.5.0
main/lib/response.php
См. документацию.
1 <?php
2 namespace Bitrix\Main;
3 
4 abstract class Response
5 {
6  /** @var string */
7  protected $content;
8 
9  public function __construct()
10  {
11  }
12 
13  public function clear()
14  {
15  }
16 
17  public function flush($text = '')
18  {
19  $this->writeBody($text);
20  }
21 
22  /**
23  * Sets content.
24  * Valid types are strings, numbers, null, and objects that implement a __toString() method.
25  *
26  * @param mixed $content Content that can be cast to string.
27  *
28  * @return $this
29  * @throws ArgumentTypeException
30  */
31  public function setContent($content)
32  {
33  if (!$this->checkContent($content))
34  {
35  throw new ArgumentTypeException('content', 'string');
36  }
37 
38  $this->content = (string)$content;
39 
40  return $this;
41  }
42 
43  /**
44  * Appends content.
45  * Valid types are strings, numbers, null, and objects that implement a __toString() method.
46  *
47  * @param mixed $content Content that can be cast to string.
48  *
49  * @return $this
50  * @throws ArgumentTypeException
51  */
52  public function appendContent($content)
53  {
54  if (!$this->checkContent($content))
55  {
56  throw new ArgumentTypeException('content', 'string');
57  }
58 
59  $this->content .= (string)$content;
60 
61  return $this;
62  }
63 
64  protected function checkContent($content)
65  {
66  return (
67  $content === null ||
68  is_string($content) ||
69  is_numeric($content) ||
70  is_callable(array($content, '__toString'))
71  );
72  }
73 
74  /**
75  * Returns content of response.
76  *
77  * @return string
78  */
79  public function getContent()
80  {
81  return $this->content;
82  }
83 
84  /**
85  * Sends content to the output.
86  *
87  * @return void
88  */
89  public function send()
90  {
91  $this->flush($this->content);
92  }
93 
94  protected function writeBody($text)
95  {
96  echo $text;
97  }
98 }
Exception is thrown when the type of an argument is not accepted by function.
appendContent($content)
Appends content.
setContent($content)
Sets content.
send()
Sends content to the output.
getContent()
Returns content of response.