Retrieve.php 750 B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. namespace Stripe\ApiOperations;
  3. /**
  4. * Trait for retrievable resources. Adds a `retrieve()` static method to the
  5. * class.
  6. *
  7. * This trait should only be applied to classes that derive from StripeObject.
  8. */
  9. trait Retrieve
  10. {
  11. /**
  12. * @param array|string $id the ID of the API resource to retrieve,
  13. * or an options array containing an `id` key
  14. * @param null|array|string $opts
  15. *
  16. * @throws \Stripe\Exception\ApiErrorException if the request fails
  17. *
  18. * @return static
  19. */
  20. public static function retrieve($id, $opts = null)
  21. {
  22. $opts = \Stripe\Util\RequestOptions::parse($opts);
  23. $instance = new static($id, $opts);
  24. $instance->refresh();
  25. return $instance;
  26. }
  27. }