OAuthCommonServiceAbstractService

Abstract OAuth service, version-agnostic.

Defined (1)

The class is defined in the following location(s).

/lib/PHPoAuthLib/src/OAuth/Common/Service/AbstractService.php  
  1. abstract class AbstractService implements ServiceInterface 
  2. /** @var Credentials */ 
  3. protected $credentials; 
  4.  
  5. /** @var ClientInterface */ 
  6. protected $httpClient; 
  7.  
  8. /** @var TokenStorageInterface */ 
  9. protected $storage; 
  10.  
  11. /** 
  12. * @param CredentialsInterface $credentials 
  13. * @param ClientInterface $httpClient 
  14. * @param TokenStorageInterface $storage 
  15. */ 
  16. public function __construct( 
  17. CredentialsInterface $credentials,  
  18. ClientInterface $httpClient,  
  19. TokenStorageInterface $storage 
  20. ) { 
  21. $this->credentials = $credentials; 
  22. $this->httpClient = $httpClient; 
  23. $this->storage = $storage; 
  24.  
  25. /** 
  26. * @param UriInterface|string $path 
  27. * @param UriInterface $baseApiUri 
  28. * @return UriInterface 
  29. * @throws Exception 
  30. */ 
  31. protected function determineRequestUriFromPath($path, UriInterface $baseApiUri = null) 
  32. if ($path instanceof UriInterface) { 
  33. $uri = $path; 
  34. } elseif (stripos($path, 'http://') === 0 || stripos($path, 'https://') === 0) { 
  35. $uri = new Uri($path); 
  36. } else { 
  37. if (null === $baseApiUri) { 
  38. throw new Exception( 
  39. 'An absolute URI must be passed to ServiceInterface::request as no baseApiUri is set.' 
  40. ); 
  41.  
  42. $uri = clone $baseApiUri; 
  43. if (false !== strpos($path, '?')) { 
  44. $parts = explode('?', $path, 2); 
  45. $path = $parts[0]; 
  46. $query = $parts[1]; 
  47. $uri->setQuery($query); 
  48.  
  49. if ($path[0] === '/') { 
  50. $path = substr($path, 1); 
  51.  
  52. $uri->setPath($uri->getPath() . $path); 
  53.  
  54. return $uri; 
  55.  
  56. /** 
  57. * Accessor to the storage adapter to be able to retrieve tokens 
  58. * @return TokenStorageInterface 
  59. */ 
  60. public function getStorage() 
  61. return $this->storage; 
  62.  
  63. /** 
  64. * @return string 
  65. */ 
  66. public function service() 
  67. // get class name without backslashes 
  68. $classname = get_class($this); 
  69.  
  70. return preg_replace('/^.*\\\\/', '', $classname);