SingletonApiResource.php 746 B

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. namespace Pingpp;
  3. abstract class SingletonApiResource extends ApiResource
  4. {
  5. protected static function _singletonRetrieve($options = null)
  6. {
  7. $opts = Util\RequestOptions::parse($options);
  8. $instance = new static(null, $opts);
  9. $instance->refresh();
  10. return $instance;
  11. }
  12. /**
  13. * @param SingletonApiResource $class
  14. * @return string The endpoint associated with this singleton class.
  15. */
  16. public static function classUrl()
  17. {
  18. $base = static::className();
  19. return "/v1/${base}";
  20. }
  21. /**
  22. * @return string The endpoint associated with this singleton API resource.
  23. */
  24. public function instanceUrl()
  25. {
  26. return static::classUrl();
  27. }
  28. }