Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
contentjson.php
1<?php
9
12
13Loc::loadMessages(__FILE__);
14
19class ContentJson extends Content
20{
21 protected $parameters = array();
22
23 public function set(array $parameters)
24 {
25 $this->parameters = $parameters;
26 }
27
28 public function add($name, $value)
29 {
30 $this->parameters[$name] = $value;
31 }
32
33 public function toText()
34 {
35 $default = array(
36 'error' => !$this->errors->isEmpty(),
37 'text' => implode('<br>', $this->getErrorMessages()),
38 );
39 $errorCodes = [];
40 foreach ($this->getErrorCollection() as $error)
41 {
43 if ($error->getCode())
44 $errorCodes[] = $error->getCode();
45 }
46 if ($errorCodes)
47 {
48 $default['code'] = $errorCodes[0];
49 }
50 return Json::encode($this->parameters + $default);
51 }
52
53 public function onFlush()
54 {
55 $this->response->addHeader('Content-Type', 'application/json; charset=UTF-8');
56 }
57}
static loadMessages($file)
Definition loc.php:64