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/forum/lib/internals/error/

Upload File :
current_dir [ Writeable] document_root [ Writeable]

 

Command :


[ Back ]     

Current File : /home/bitrix/ext_www/rospirotorg.ru/bitrix/modules/forum/lib/internals/error/errorcollection.php
<?php

namespace Bitrix\Forum\Internals\Error;

use Bitrix\Main\ArgumentTypeException;
use Bitrix\Main\Entity\Result;
use Bitrix\Main\Type\Dictionary;

final class ErrorCollection extends Dictionary
{
	/**
	 * Constructor ErrorCollection.
	 * @param array $values Errors which need to add in collection.
	 * @throws ArgumentTypeException
	 */
	public function __construct(array $values = null)
	{
		if($values)
		{
			foreach($values as $value)
			{
				$this->checkType($value);
			}
		}
		unset($value);

		parent::__construct($values);
	}

	/**
	 * Adds array of errors to collection.
	 * @param Error[] $errors Array of errors.
	 * @return void
	 */
	public function add(array $errors)
	{
		foreach ($errors as $error)
		{
			$this[] = $error;
		}
		unset($error);
	}

	/**
	 * Adds one error to collection.
	 * @param Error $error Error object.
	 * @return void
	 */
	public function addOne(Error $error)
	{
		$this[] = $error;
	}

	/**
	 * Adds errors from Main\Entity\Result.
	 * @param Result $result Result after action in Entity.
	 * @return void
	 */
	public function addFromResult(Result $result)
	{
		$errors = array();
		foreach ($result->getErrorMessages() as $message)
		{
			$errors[] = new Error($message);
		}
		unset($message);

		$this->add($errors);
	}

	/**
	 * Returns true if collection has errors.
	 * @return bool
	 */
	public function hasErrors()
	{
		return (bool)count($this);
	}

	/**
	 * Getting array of errors with the necessary code.
	 * @param string $code Code of error.
	 * @return Error[]
	 */
	public function getErrorsByCode($code)
	{
		$needle = array();
		foreach($this->values as $error)
		{
			/** @var Error $error */
			if($error->getCode() == $code)
			{
				$needle[] = $error;
			}
		}
		unset($error);

		return $needle;
	}

	/**
	 * Getting once error with the necessary code.
	 * @param string $code Code of error.
	 * @return Error[]
	 */
	public function getErrorByCode($code)
	{
		foreach($this->values as $error)
		{
			/** @var Error $error */
			if($error->getCode() == $code)
			{
				return $error;
			}
		}
		unset($error);

		return null;
	}

	/**
	 * Offset to set error.
	 * @param Error $offset Offset.
	 * @param string|int $value Error.
	 * @throws ArgumentTypeException
	 * @return void
	 */
	public function offsetSet($offset, $value)
	{
		$this->checkType($value);
		parent::offsetSet($offset, $value);
	}

	/**
	 * @param $value
	 * @throws ArgumentTypeException
	 */
	private function checkType($value)
	{
		if(!$value instanceof Error)
		{
			throw new ArgumentTypeException('Could not push in ErrorCollection non Error.');
		}
	}
}

Youez - 2016 - github.com/yon3zu
LinuXploit