/** * Creates a new CommandTransferException from a MultiTransferException * * @param MultiTransferException $e Exception to base a new exception on * * @return self */ public static function fromMultiTransferException(MultiTransferException $e) { $ce = new self($e->getMessage(), $e->getCode(), $e->getPrevious()); $ce->setSuccessfulRequests($e->getSuccessfulRequests()); $alreadyAddedExceptions = array(); foreach ($e->getFailedRequests() as $request) { if ($re = $e->getExceptionForFailedRequest($request)) { $alreadyAddedExceptions[] = $re; $ce->addFailedRequestWithException($request, $re); } else { $ce->addFailedRequest($request); } } // Add any exceptions that did not map to a request if (count($alreadyAddedExceptions) < count($e)) { foreach ($e as $ex) { if (!in_array($ex, $alreadyAddedExceptions)) { $ce->add($ex); } } } return $ce; }
/** * Build and throw a MultiTransferException * * @param array $exceptions Exceptions encountered * @param array $successful Successful requests * @throws MultiTransferException */ protected function throwMultiException(array $exceptions, array $successful) { $multiException = new MultiTransferException('Errors during multi transfer'); while ($e = array_shift($exceptions)) { $multiException->addFailedRequestWithException($e['request'], $e['exception']); } // Add successful requests foreach ($successful as $request) { if (!$multiException->containsRequest($request)) { $multiException->addSuccessfulRequest($request); } } throw $multiException; }