vendor/ruflin/elastica/src/Exception/Bulk/ResponseException.php line 12

Open in your IDE?
  1. <?php
  2. namespace Elastica\Exception\Bulk;
  3. use Elastica\Bulk\ResponseSet;
  4. use Elastica\Exception\Bulk\Response\ActionException;
  5. use Elastica\Exception\BulkException;
  6. /**
  7.  * Bulk Response exception.
  8.  */
  9. class ResponseException extends BulkException
  10. {
  11.     /**
  12.      * @var ResponseSet ResponseSet object
  13.      */
  14.     protected $_responseSet;
  15.     /**
  16.      * @var ActionException[]
  17.      */
  18.     protected $_actionExceptions = [];
  19.     /**
  20.      * Construct Exception.
  21.      */
  22.     public function __construct(ResponseSet $responseSet)
  23.     {
  24.         $this->_init($responseSet);
  25.         $message 'Error in one or more bulk request actions:'.\PHP_EOL.\PHP_EOL;
  26.         $message .= $this->getActionExceptionsAsString();
  27.         parent::__construct($message);
  28.     }
  29.     /**
  30.      * Returns bulk response set object.
  31.      */
  32.     public function getResponseSet(): ResponseSet
  33.     {
  34.         return $this->_responseSet;
  35.     }
  36.     /**
  37.      * Returns array of failed actions.
  38.      *
  39.      * @return string[] Array of failed actions
  40.      */
  41.     public function getFailures(): array
  42.     {
  43.         $errors = [];
  44.         foreach ($this->getActionExceptions() as $actionException) {
  45.             $errors[] = $actionException->getMessage();
  46.         }
  47.         return $errors;
  48.     }
  49.     /**
  50.      * @return ActionException[]
  51.      */
  52.     public function getActionExceptions(): array
  53.     {
  54.         return $this->_actionExceptions;
  55.     }
  56.     public function getActionExceptionsAsString(): string
  57.     {
  58.         $message '';
  59.         foreach ($this->getActionExceptions() as $actionException) {
  60.             $message .= $actionException->getMessage().\PHP_EOL;
  61.         }
  62.         return $message;
  63.     }
  64.     protected function _init(ResponseSet $responseSet): void
  65.     {
  66.         $this->_responseSet $responseSet;
  67.         foreach ($responseSet->getBulkResponses() as $bulkResponse) {
  68.             if ($bulkResponse->hasError()) {
  69.                 $this->_actionExceptions[] = new ActionException($bulkResponse);
  70.             }
  71.         }
  72.     }
  73. }