SingletonApiResource.php 917 B

1234567891011121314151617181920212223242526272829303132333435363738
  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. $base = \str_replace('.', '/', static::OBJECT_NAME);
  23. return "/v1/{$base}";
  24. }
  25. /**
  26. * @return string the endpoint associated with this singleton API resource
  27. */
  28. public function instanceUrl()
  29. {
  30. return static::classUrl();
  31. }
  32. }