All.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. namespace Stripe\ApiOperations;
  3. /**
  4. * Trait for listable resources. Adds a `all()` static method to the class.
  5. *
  6. * This trait should only be applied to classes that derive from StripeObject.
  7. */
  8. trait All
  9. {
  10. /**
  11. * @param null|array $params
  12. * @param null|array|string $opts
  13. *
  14. * @throws \Stripe\Exception\ApiErrorException if the request fails
  15. *
  16. * @return \Stripe\Collection of ApiResources
  17. */
  18. public static function all($params = null, $opts = null)
  19. {
  20. self::_validateParams($params);
  21. $url = static::classUrl();
  22. list($response, $opts) = static::_staticRequest('get', $url, $params, $opts);
  23. $obj = \Stripe\Util\Util::convertToStripeObject($response->json, $opts);
  24. if (!($obj instanceof \Stripe\Collection)) {
  25. throw new \Stripe\Exception\UnexpectedValueException(
  26. 'Expected type ' . \Stripe\Collection::class . ', got "' . \get_class($obj) . '" instead.'
  27. );
  28. }
  29. $obj->setLastResponse($response);
  30. $obj->setFilters($params);
  31. return $obj;
  32. }
  33. }