[ Index ]

PHP Cross Reference of phpBB-3.2.11-deutsch

title

Body

[close]

/vendor/guzzlehttp/guzzle/src/ -> BatchResults.php (source)

   1  <?php
   2  namespace GuzzleHttp;
   3  
   4  /**
   5   * Represents the result of a batch operation. This result container is
   6   * iterable, countable, and you can can get a result by value using the
   7   * getResult function.
   8   *
   9   * Successful results are anything other than exceptions. Failure results are
  10   * exceptions.
  11   *
  12   * @package GuzzleHttp
  13   */
  14  class BatchResults implements \Countable, \IteratorAggregate, \ArrayAccess
  15  {
  16      private $hash;
  17  
  18      /**
  19       * @param \SplObjectStorage $hash Hash of key objects to result values.
  20       */
  21      public function __construct(\SplObjectStorage $hash)
  22      {
  23          $this->hash = $hash;
  24      }
  25  
  26      /**
  27       * Get the keys that are available on the batch result.
  28       *
  29       * @return array
  30       */
  31      public function getKeys()
  32      {
  33          return iterator_to_array($this->hash);
  34      }
  35  
  36      /**
  37       * Gets a result from the container for the given object. When getting
  38       * results for a batch of requests, provide the request object.
  39       *
  40       * @param object $forObject Object to retrieve the result for.
  41       *
  42       * @return mixed|null
  43       */
  44      public function getResult($forObject)
  45      {
  46          return isset($this->hash[$forObject]) ? $this->hash[$forObject] : null;
  47      }
  48  
  49      /**
  50       * Get an array of successful results.
  51       *
  52       * @return array
  53       */
  54      public function getSuccessful()
  55      {
  56          $results = [];
  57          foreach ($this->hash as $key) {
  58              if (!($this->hash[$key] instanceof \Exception)) {
  59                  $results[] = $this->hash[$key];
  60              }
  61          }
  62  
  63          return $results;
  64      }
  65  
  66      /**
  67       * Get an array of failed results.
  68       *
  69       * @return array
  70       */
  71      public function getFailures()
  72      {
  73          $results = [];
  74          foreach ($this->hash as $key) {
  75              if ($this->hash[$key] instanceof \Exception) {
  76                  $results[] = $this->hash[$key];
  77              }
  78          }
  79  
  80          return $results;
  81      }
  82  
  83      /**
  84       * Allows iteration over all batch result values.
  85       *
  86       * @return \ArrayIterator
  87       */
  88      public function getIterator()
  89      {
  90          $results = [];
  91          foreach ($this->hash as $key) {
  92              $results[] = $this->hash[$key];
  93          }
  94  
  95          return new \ArrayIterator($results);
  96      }
  97  
  98      /**
  99       * Counts the number of elements in the batch result.
 100       *
 101       * @return int
 102       */
 103      public function count()
 104      {
 105          return count($this->hash);
 106      }
 107  
 108      /**
 109       * Checks if the batch contains a specific numerical array index.
 110       *
 111       * @param int $key Index to access
 112       *
 113       * @return bool
 114       */
 115      public function offsetExists($key)
 116      {
 117          return $key < count($this->hash);
 118      }
 119  
 120      /**
 121       * Allows access of the batch using a numerical array index.
 122       *
 123       * @param int $key Index to access.
 124       *
 125       * @return mixed|null
 126       */
 127      public function offsetGet($key)
 128      {
 129          $i = -1;
 130          foreach ($this->hash as $obj) {
 131              if ($key === ++$i) {
 132                  return $this->hash[$obj];
 133              }
 134          }
 135  
 136          return null;
 137      }
 138  
 139      public function offsetUnset($key)
 140      {
 141          throw new \RuntimeException('Not implemented');
 142      }
 143  
 144      public function offsetSet($key, $value)
 145      {
 146          throw new \RuntimeException('Not implemented');
 147      }
 148  }


Generated: Wed Nov 11 20:33:01 2020 Cross-referenced by PHPXref 0.7.1