SingletonRetrieve.php 742 B

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