Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
yandexjson.php
1<?php
2namespace Bitrix\Seo\Engine;
3
5
6class YandexJson extends Json
7{
8 public static function encode($data, $options = null)
9 {
10 // php 5.4.0+
11 if(defined('JSON_UNESCAPED_UNICODE'))
12 {
13 return parent::encode($data, JSON_UNESCAPED_UNICODE);
14 }
15 else
16 {
17 return static::_encode(static::convertData($data));
18 }
19 }
20
21 protected static function _encode($data)
22 {
23 $str = '';
24 if(is_array($data))
25 {
26 $assoc = array_diff_key($data,array_keys(array_keys($data)));
27
28 $str .= $assoc ? '{' : '[';
29
30 $first = true;
31 foreach($data as $key => $value)
32 {
33 $str .= $first ? '' : ',';
34 $str .= $assoc ? static::_quote($key).':' : '';
35 $str .= static::_encode($value);
36 $first = false;
37 }
38
39 $str .= $assoc ? '}' : ']';
40 }
41 elseif(is_int($data))
42 {
43 $str = $data;
44 }
45 elseif($data === null)
46 {
47 $str = "null";
48 }
49 else
50 {
51 $str = static::_quote($data);
52 }
53
54 return $str;
55 }
56
57 protected static function _quote($s)
58 {
59 return '"'.str_replace(array('\\', '"'), array('\\\\', '\"'), $s).'"';
60 }
61}
static encode($data, $options=null)
Definition yandexjson.php:8