Verzeichnisstruktur phpBB-3.1.0


Veröffentlicht
27.10.2014

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

      (Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

ServiceFactory.php

Zuletzt modifiziert: 09.10.2024, 12:57 - Dateigröße: 2.72 KiB


 01  <?php
 02  /**
 03   * OAuth service factory.
 04   *
 05   * PHP version 5.4
 06   *
 07   * @category   OAuth
 08   * @author     David Desberg <david@daviddesberg.com>
 09   * @copyright  Copyright (c) 2013 The authors
 10   * @license    http://www.opensource.org/licenses/mit-license.html  MIT License
 11   */
 12  namespace OAuth;
 13  use OAuth\Common\Service\ServiceInterface;
 14  use OAuth\Common\Http\Client\ClientInterface;
 15   
 16  class ServiceFactory
 17  {
 18      /** @var Common\Http\Client\ClientInterface */
 19      private $httpClient;
 20   
 21      /**
 22       * @param Common\Http\Client\ClientInterface $httpClient
 23       * @return ServiceFactory
 24       */
 25      public function setHttpClient(ClientInterface $httpClient)
 26      {
 27          $this->httpClient = $httpClient;
 28          return $this;
 29      }
 30   
 31      /**
 32       * @param $serviceName string name of service to create
 33       * @param Common\Consumer\Credentials $credentials
 34       * @param Common\Storage\TokenStorageInterface $storage
 35       * @param array|null $scopes If creating an oauth2 service, array of scopes
 36       * @return ServiceInterface
 37       * @throws Common\Exception\Exception
 38       */
 39      public function createService($serviceName, Common\Consumer\Credentials $credentials, Common\Storage\TokenStorageInterface $storage, $scopes = array())
 40      {
 41          if( !$this->httpClient ) {
 42              // for backwards compatibility.
 43              $this->httpClient = new \OAuth\Common\Http\Client\StreamClient();
 44          }
 45   
 46          $serviceName = ucfirst($serviceName);
 47          $v2ClassName = "\\OAuth\\OAuth2\\Service\\$serviceName";
 48          $v1ClassName = "\\OAuth\\OAuth1\\Service\\$serviceName";
 49   
 50          // if an oauth2 version exists, prefer it
 51          if( class_exists($v2ClassName) ) {
 52              // resolve scopes
 53              $resolvedScopes = array();
 54              $reflClass = new \ReflectionClass($v2ClassName);
 55              $constants = $reflClass->getConstants();
 56   
 57              foreach($scopes as $scope)
 58              {
 59                  $key = strtoupper('SCOPE_' . $scope);
 60                  // try to find a class constant with this name
 61                  if( array_key_exists( $key, $constants ) ) {
 62                      $resolvedScopes[] = $constants[$key];
 63                  } else {
 64                      $resolvedScopes[] = $scope;
 65                  }
 66              }
 67   
 68              return new $v2ClassName($credentials, $this->httpClient, $storage, $resolvedScopes);
 69          }
 70   
 71          if( class_exists($v1ClassName) ) {
 72              if(!empty($scopes)) {
 73                  throw new Common\Exception\Exception('Scopes passed to ServiceFactory::createService but an OAuth1 service was requested.');
 74              }
 75              $signature = new OAuth1\Signature\Signature($credentials);
 76              return new $v1ClassName($credentials, $this->httpClient, $storage, $signature);
 77          }
 78   
 79          return null;
 80      }
 81  }
 82