All.php 1019 B

12345678910111213141516171819202122232425262728293031323334
  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 array|null $params
  12. * @param array|string|null $opts
  13. *
  14. * @return \Stripe\Collection of ApiResources
  15. */
  16. public static function all($params = null, $opts = null)
  17. {
  18. self::_validateParams($params);
  19. $url = static::classUrl();
  20. list($response, $opts) = static::_staticRequest('get', $url, $params, $opts);
  21. $obj = \Stripe\Util\Util::convertToStripeObject($response->json, $opts);
  22. if (!is_a($obj, 'Stripe\\Collection')) {
  23. $class = get_class($obj);
  24. $message = "Expected type \"Stripe\\Collection\", got \"$class\" instead";
  25. throw new \Stripe\Error\Api($message);
  26. }
  27. $obj->setLastResponse($response);
  28. $obj->setRequestParams($params);
  29. return $obj;
  30. }
  31. }