setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); if (isset($options["databaseAdapter"]) && $options["databaseAdapter"] instanceof PDO) { $this->db=$options["databaseAdapter"]; } else { throw new \Exception("Missing required parameter databaseAdapter", self::ERR_INVALID_ARGUMENT); } // Which login is allowed? $this->allowedAuth=array(); if (isset($options["loginAdapterList"]) && is_array($options["loginAdapterList"]) ) { foreach($options["loginAdapterList"] as $lal) { $this->allowedAuth[] = (string)$lal; } } // To which logger(s) shall we log to? if (isset($options["loggerAdapter"])) { if (!is_array($options["loggerAdapter"])) $options["loggerAdapter"]=array($options["loggerAdapter"]); foreach($options["loggerAdapter"] as $la) { if ($la instanceof Psr\Log\LoggerInterface) $this->loggerList[]=$la; } } } // __construct /** * Authenticate into an AlternC server * @param $auth hash with * method: string describing the authentication name (in Alternc_Api_Auth_xxx) * options: array list of parameters for the corresponding auth. * if 'uid' is set in the option hash, the account MUST be an administrator one * and as a result, the returned Api_Token will be set to this UID and not the admin one. * @return Alternc_Api_Token an API Token */ function auth($auth) { if (!isset($auth["method"]) || !is_string($auth["method"])) { throw new \Exception("Missing required parameter method", self::ERR_INVALID_ARGUMENT); } if (!isset($auth["options"]) || !is_array($auth["options"])) { throw new \Exception("Missing required parameter options", self::ERR_INVALID_ARGUMENT); } if (count($this->allowedAuth) && !in_array($auth["method"],$this->allowedAuth)) { throw new \Exception("Method not allowed", self::ERR_METHOD_DENIED); } $adapterName = "Alternc_Api_Auth_".ucfirst(strtolower($auth["method"])); $authAdapter = new $adapterName($this); return $authAdapter->auth($auth["options"]); // table des tokens : token, expire, json_encode('uid','is_admin') // return new Alternc_Api_Token(); } /** * Manage an API Call * @param Alternc_Api_Request $request The API call * @return Alternc_Api_Response an API response */ function call($request) { return new Alternc_Api_Response(); } /** * Getter for the databaseAdapter * (used by authAdapter) */ function getDb() { return $this->db; } } // class Alternc_Api_Service