public function getMiddleware(Slim $app) { if (!$this->auth) { $auth = $app->config('api.classes.auth.adapter'); if (!$auth || !class_exists($auth)) { throw new \InvalidArgumentException('Config value api.classes.auth.adapter="' . $auth . '" which does not exist'); } $storage = $app->config('api.classes.auth.storage'); if (!$storage || !class_exists($storage)) { throw new \InvalidArgumentException('Config value api.classes.auth.storage="' . $storage . '" which does not exist'); } $storage = new $storage($app->settings()); if (!$storage instanceof StorageInterface) { throw new \InvalidArgumentException('Class ' . get_class($storage) . ' must implement StorageInterface'); } $auth = $this->auth = new $auth($storage, $app); if (!$auth instanceof AuthInterface) { throw new \InvalidArgumentException('Class ' . get_class($auth) . ' must implement AuthInterface'); } } return array($this->auth, 'authenticate'); // this notation is lighter in the engine than a closure }