コード例 #1
0
ファイル: Soauth.php プロジェクト: eggbe/soauth
 /**
  * @param string $name
  * @return AAdapter
  * @throws \Exception
  */
 protected final function getAdapter(string $name) : AAdapter
 {
     if (!array_key_exists($name = strtolower(trim($name)), $this->Adapters)) {
         /**
          * If any adapter currently is not cached we need to create it and add to the cache.
          * Of course it should be configured previously.
          */
         if (!array_key_exists($name, $this->Config)) {
             throw new \Exception('Undefined adapter "' . $name . '"!');
         }
         /**
          * All standard adapter are always defined in the \Eggbe\Soauth\ namespace.
          *
          * Alternatively you could use any custom adapter from different namespaces
          * by using the special attribute "class" at the adapter configuration.
          */
         if (!class_exists($class = Arr::get($this->Config, 'class', __NAMESPACE__ . '\\Adapter\\' . ucfirst($name)))) {
             throw new \Exception('Undefined adapter class "' . $class . '"!');
         }
         /**
          * All adapters should always extend the base
          * \Eggbe\Soauth\Abstracts\AAdapter class.
          */
         if (!is_subclass_of($class, AAdapter::class)) {
             throw new \Exception('Adapter class is not subclass of ' . AAdapter::class . '!');
         }
         $this->Adapters[$name] = new $class($this->Config[$name]);
     }
     return $this->Adapters[$name];
 }