You are here

private function StreamHandler::createResource in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/guzzlehttp/guzzle/src/Handler/StreamHandler.php \GuzzleHttp\Handler\StreamHandler::createResource()

Create a resource and check to ensure it was created successfully

Parameters

callable $callback Callable that returns stream resource:

Return value

resource

Throws

\RuntimeException on error

1 call to StreamHandler::createResource()
StreamHandler::createStream in vendor/guzzlehttp/guzzle/src/Handler/StreamHandler.php

File

vendor/guzzlehttp/guzzle/src/Handler/StreamHandler.php, line 200

Class

StreamHandler
HTTP handler that uses PHP's HTTP stream wrapper.

Namespace

GuzzleHttp\Handler

Code

private function createResource(callable $callback) {
  $errors = null;
  set_error_handler(function ($_, $msg, $file, $line) use (&$errors) {
    $errors[] = [
      'message' => $msg,
      'file' => $file,
      'line' => $line,
    ];
    return true;
  });
  $resource = $callback();
  restore_error_handler();
  if (!$resource) {
    $message = 'Error creating resource: ';
    foreach ($errors as $err) {
      foreach ($err as $key => $value) {
        $message .= "[{$key}] {$value}" . PHP_EOL;
      }
    }
    throw new \RuntimeException(trim($message));
  }
  return $resource;
}