summaryrefslogtreecommitdiff
path: root/vendor/OAuth/Common/Service/AbstractService.php
diff options
context:
space:
mode:
authorFrédéric Guillot <fguillot@users.noreply.github.com>2014-05-03 22:24:03 -0400
committerFrédéric Guillot <fguillot@users.noreply.github.com>2014-05-03 22:24:03 -0400
commit560a12f0bd6347a335f8ed5201d6d9562d03d4bc (patch)
tree00510d25c1cf5e747573543fa88d44ef003b1c9a /vendor/OAuth/Common/Service/AbstractService.php
parent9531e439cd99fb7dbcfb039f422f1d1ba414ec30 (diff)
Add Google authentication
Diffstat (limited to 'vendor/OAuth/Common/Service/AbstractService.php')
-rwxr-xr-xvendor/OAuth/Common/Service/AbstractService.php100
1 files changed, 100 insertions, 0 deletions
diff --git a/vendor/OAuth/Common/Service/AbstractService.php b/vendor/OAuth/Common/Service/AbstractService.php
new file mode 100755
index 00000000..0bf572b4
--- /dev/null
+++ b/vendor/OAuth/Common/Service/AbstractService.php
@@ -0,0 +1,100 @@
+<?php
+
+namespace OAuth\Common\Service;
+
+use OAuth\Common\Consumer\CredentialsInterface;
+use OAuth\Common\Http\Client\ClientInterface;
+use OAuth\Common\Http\Uri\Uri;
+use OAuth\Common\Http\Uri\UriInterface;
+use OAuth\Common\Exception\Exception;
+use OAuth\Common\Storage\TokenStorageInterface;
+
+/**
+ * Abstract OAuth service, version-agnostic
+ */
+abstract class AbstractService implements ServiceInterface
+{
+ /** @var Credentials */
+ protected $credentials;
+
+ /** @var ClientInterface */
+ protected $httpClient;
+
+ /** @var TokenStorageInterface */
+ protected $storage;
+
+ /**
+ * @param CredentialsInterface $credentials
+ * @param ClientInterface $httpClient
+ * @param TokenStorageInterface $storage
+ */
+ public function __construct(
+ CredentialsInterface $credentials,
+ ClientInterface $httpClient,
+ TokenStorageInterface $storage
+ ) {
+ $this->credentials = $credentials;
+ $this->httpClient = $httpClient;
+ $this->storage = $storage;
+ }
+
+ /**
+ * @param UriInterface|string $path
+ * @param UriInterface $baseApiUri
+ *
+ * @return UriInterface
+ *
+ * @throws Exception
+ */
+ protected function determineRequestUriFromPath($path, UriInterface $baseApiUri = null)
+ {
+ if ($path instanceof UriInterface) {
+ $uri = $path;
+ } elseif (stripos($path, 'http://') === 0 || stripos($path, 'https://') === 0) {
+ $uri = new Uri($path);
+ } else {
+ if (null === $baseApiUri) {
+ throw new Exception(
+ 'An absolute URI must be passed to ServiceInterface::request as no baseApiUri is set.'
+ );
+ }
+
+ $uri = clone $baseApiUri;
+ if (false !== strpos($path, '?')) {
+ $parts = explode('?', $path, 2);
+ $path = $parts[0];
+ $query = $parts[1];
+ $uri->setQuery($query);
+ }
+
+ if ($path[0] === '/') {
+ $path = substr($path, 1);
+ }
+
+ $uri->setPath($uri->getPath() . $path);
+ }
+
+ return $uri;
+ }
+
+ /**
+ * Accessor to the storage adapter to be able to retrieve tokens
+ *
+ * @return TokenStorageInterface
+ */
+ public function getStorage()
+ {
+ return $this->storage;
+ }
+
+ /**
+ * @return string
+ */
+ public function service()
+ {
+ // get class name without backslashes
+ $classname = get_class($this);
+
+ return preg_replace('/^.*\\\\/', '', $classname);
+ }
+}