SingletonApiResource.php 959 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. namespace Stripe;
  3. /**
  4. * Class SingletonApiResource.
  5. */
  6. abstract class SingletonApiResource extends ApiResource
  7. {
  8. protected static function _singletonRetrieve($options = null)
  9. {
  10. $opts = Util\RequestOptions::parse($options);
  11. $instance = new static(null, $opts);
  12. $instance->refresh();
  13. return $instance;
  14. }
  15. /**
  16. * @return string the endpoint associated with this singleton class
  17. */
  18. public static function classUrl()
  19. {
  20. // Replace dots with slashes for namespaced resources, e.g. if the object's name is
  21. // "foo.bar", then its URL will be "/v1/foo/bar".
  22. /** @phpstan-ignore-next-line */
  23. $base = \str_replace('.', '/', static::OBJECT_NAME);
  24. return "/v1/{$base}";
  25. }
  26. /**
  27. * @return string the endpoint associated with this singleton API resource
  28. */
  29. public function instanceUrl()
  30. {
  31. return static::classUrl();
  32. }
  33. }