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/ajaxjson.php
<?php

namespace Bitrix\Main\Engine\Response;


use Bitrix\Main\Error;
use Bitrix\Main\ErrorCollection;
use Bitrix\Main\Errorable;

class AjaxJson extends Json implements Errorable
{
	const STATUS_SUCCESS = 'success';
	const STATUS_DENIED  = 'denied';
	const STATUS_ERROR   = 'error';
	/**
	 * @var string
	 */
	private $status;
	/**
	 * @var ErrorCollection
	 */
	private $errorCollection;

	public function __construct($data = null, $status = self::STATUS_SUCCESS, ErrorCollection $errorCollection = null)
	{
		$this->status = $status?: self::STATUS_SUCCESS;
		$this->errorCollection = $errorCollection?: new ErrorCollection;

		parent::__construct($data);
	}

	final public static function createSuccess($data = null)
	{
		return new self($data, self::STATUS_SUCCESS, null);
	}

	final public static function createError(ErrorCollection $errorCollection = null, $data = null)
	{
		return new self($data, self::STATUS_ERROR, $errorCollection);
	}

	final public static function createDenied(ErrorCollection $errorCollection = null, $data = null)
	{
		return new self($data, self::STATUS_DENIED, $errorCollection);
	}

	final public function setData($data)
	{
		/**
		 * @see \Bitrix\Main\Type\Contract\Arrayable
		 * @see \Bitrix\Main\Type\Contract\Jsonable
		 * todo: we have to add in Json::encode work with Arrayable, Jsonable, to convert this data properly.
		 */
		return parent::setData(
			array(
				'status' => $this->status,
				'data' => $data,
				'errors' => $this->getErrorsToResponse(),
			)
		);
	}

	final protected function getErrorsToResponse()
	{
		$errors = array();
		foreach ($this->errorCollection as $error)
		{
			/** @var Error $error */
			$errors[] = $error;
		}

		return $errors;
	}

	/**
	 * Getting array of errors.
	 * @return Error[]
	 */
	final public function getErrors()
	{
		return $this->errorCollection->toArray();
	}

	/**
	 * Getting once error with the necessary code.
	 * @param string $code Code of error.
	 * @return Error
	 */
	final public function getErrorByCode($code)
	{
		return $this->errorCollection->getErrorByCode($code);
	}
}

Youez - 2016 - github.com/yon3zu
LinuXploit