SingletonApiResource.php 937 B

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