mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-09 19:13:26 +00:00
Fix CS
This commit is contained in:
@@ -21,278 +21,270 @@
|
||||
*/
|
||||
class API_OAuth2_Account
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var appbox
|
||||
*/
|
||||
protected $appbox;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var appbox
|
||||
*/
|
||||
protected $appbox;
|
||||
/**
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $id;
|
||||
/**
|
||||
*
|
||||
* @var User_Adapter
|
||||
*/
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var User_Adapter
|
||||
*/
|
||||
protected $user;
|
||||
/**
|
||||
*
|
||||
* @var API_OAuth2_Application
|
||||
*/
|
||||
protected $application;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var API_OAuth2_Application
|
||||
*/
|
||||
protected $application;
|
||||
/**
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $application_id;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $application_id;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $api_version;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $api_version;
|
||||
/**
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $revoked;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $revoked;
|
||||
/**
|
||||
*
|
||||
* @var DateTime
|
||||
*/
|
||||
protected $created_on;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var DateTime
|
||||
*/
|
||||
protected $created_on;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $token;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $token;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param appbox $appbox
|
||||
* @param int $account_id
|
||||
* @return API_OAuth2_Account
|
||||
*/
|
||||
public function __construct(appbox &$appbox, $account_id)
|
||||
{
|
||||
$this->appbox = $appbox;
|
||||
$this->id = (int) $account_id;
|
||||
$sql = 'SELECT api_account_id, usr_id, api_version, revoked
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param appbox $appbox
|
||||
* @param int $account_id
|
||||
* @return API_OAuth2_Account
|
||||
*/
|
||||
public function __construct(appbox &$appbox, $account_id)
|
||||
{
|
||||
$this->appbox = $appbox;
|
||||
$this->id = (int) $account_id;
|
||||
$sql = 'SELECT api_account_id, usr_id, api_version, revoked
|
||||
, application_id, created
|
||||
FROM api_accounts
|
||||
WHERE api_account_id = :api_account_id';
|
||||
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute(array(':api_account_id' => $this->id));
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute(array(':api_account_id' => $this->id));
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$this->application_id = (int) $row['application_id'];
|
||||
$this->user = User_Adapter::getInstance($row['usr_id'], $this->appbox);
|
||||
$this->application_id = (int) $row['application_id'];
|
||||
$this->user = User_Adapter::getInstance($row['usr_id'], $this->appbox);
|
||||
|
||||
$this->api_version = $row['api_version'];
|
||||
$this->revoked = !!$row['revoked'];
|
||||
$this->created_on = new DateTime($row['created']);
|
||||
$this->api_version = $row['api_version'];
|
||||
$this->revoked = ! ! $row['revoked'];
|
||||
$this->created_on = new DateTime($row['created']);
|
||||
|
||||
return $this;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function get_id()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function get_id()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return User_Adapter
|
||||
*/
|
||||
public function get_user()
|
||||
{
|
||||
return $this->user;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @return User_Adapter
|
||||
*/
|
||||
public function get_user()
|
||||
{
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_api_version()
|
||||
{
|
||||
return $this->api_version;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_api_version()
|
||||
{
|
||||
return $this->api_version;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function is_revoked()
|
||||
{
|
||||
return $this->revoked;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function is_revoked()
|
||||
{
|
||||
return $this->revoked;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param boolean $boolean
|
||||
* @return API_OAuth2_Account
|
||||
*/
|
||||
public function set_revoked($boolean)
|
||||
{
|
||||
$this->revoked = !!$boolean;
|
||||
/**
|
||||
*
|
||||
* @param boolean $boolean
|
||||
* @return API_OAuth2_Account
|
||||
*/
|
||||
public function set_revoked($boolean)
|
||||
{
|
||||
$this->revoked = ! ! $boolean;
|
||||
|
||||
$sql = 'UPDATE api_accounts SET revoked = :revoked
|
||||
$sql = 'UPDATE api_accounts SET revoked = :revoked
|
||||
WHERE api_account_id = :account_id';
|
||||
|
||||
$params = array(
|
||||
':revoked' => ($boolean ? '1' : '0')
|
||||
, 'account_id' => $this->id
|
||||
);
|
||||
$params = array(
|
||||
':revoked' => ($boolean ? '1' : '0')
|
||||
, 'account_id' => $this->id
|
||||
);
|
||||
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return DateTime
|
||||
*/
|
||||
public function get_created_on()
|
||||
{
|
||||
return $this->created_on;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return API_OAuth2_Token
|
||||
*/
|
||||
public function get_token()
|
||||
{
|
||||
if (!$this->token)
|
||||
{
|
||||
try
|
||||
{
|
||||
$this->token = new API_OAuth2_Token($this->appbox, $this);
|
||||
}
|
||||
catch (Exception_NotFound $e)
|
||||
{
|
||||
$this->token = API_OAuth2_Token::create($this->appbox, $this);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
return $this->token;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return API_OAuth2_Application
|
||||
*/
|
||||
public function get_application()
|
||||
{
|
||||
if (!$this->application)
|
||||
$this->application = new API_OAuth2_Application($this->appbox, $this->application_id);
|
||||
|
||||
return $this->application;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
$this->get_token()->delete();
|
||||
|
||||
foreach(API_OAuth2_AuthCode::load_codes_by_account($this->appbox, $this) as $code)
|
||||
/**
|
||||
*
|
||||
* @return DateTime
|
||||
*/
|
||||
public function get_created_on()
|
||||
{
|
||||
$code->delete();
|
||||
}
|
||||
foreach(API_OAuth2_RefreshToken::load_by_account($this->appbox, $this) as $token)
|
||||
{
|
||||
$token->delete();
|
||||
return $this->created_on;
|
||||
}
|
||||
|
||||
$sql = 'DELETE FROM api_accounts WHERE api_account_id = :account_id';
|
||||
/**
|
||||
*
|
||||
* @return API_OAuth2_Token
|
||||
*/
|
||||
public function get_token()
|
||||
{
|
||||
if ( ! $this->token) {
|
||||
try {
|
||||
$this->token = new API_OAuth2_Token($this->appbox, $this);
|
||||
} catch (Exception_NotFound $e) {
|
||||
$this->token = API_OAuth2_Token::create($this->appbox, $this);
|
||||
}
|
||||
}
|
||||
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute(array('account_id' => $this->id));
|
||||
$stmt->closeCursor();
|
||||
return $this->token;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @return API_OAuth2_Application
|
||||
*/
|
||||
public function get_application()
|
||||
{
|
||||
if ( ! $this->application)
|
||||
$this->application = new API_OAuth2_Application($this->appbox, $this->application_id);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param appbox $appbox
|
||||
* @param User_Adapter $user
|
||||
* @param API_OAuth2_Application $application
|
||||
* @return API_OAuth2_Account
|
||||
*/
|
||||
public static function create(appbox &$appbox, User_Adapter $user, API_OAuth2_Application $application)
|
||||
{
|
||||
$sql = 'INSERT INTO api_accounts
|
||||
return $this->application;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
$this->get_token()->delete();
|
||||
|
||||
foreach (API_OAuth2_AuthCode::load_codes_by_account($this->appbox, $this) as $code) {
|
||||
$code->delete();
|
||||
}
|
||||
foreach (API_OAuth2_RefreshToken::load_by_account($this->appbox, $this) as $token) {
|
||||
$token->delete();
|
||||
}
|
||||
|
||||
$sql = 'DELETE FROM api_accounts WHERE api_account_id = :account_id';
|
||||
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute(array('account_id' => $this->id));
|
||||
$stmt->closeCursor();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param appbox $appbox
|
||||
* @param User_Adapter $user
|
||||
* @param API_OAuth2_Application $application
|
||||
* @return API_OAuth2_Account
|
||||
*/
|
||||
public static function create(appbox &$appbox, User_Adapter $user, API_OAuth2_Application $application)
|
||||
{
|
||||
$sql = 'INSERT INTO api_accounts
|
||||
(api_account_id, usr_id, revoked, api_version, application_id, created)
|
||||
VALUES (null, :usr_id, :revoked, :api_version, :application_id, :created)';
|
||||
|
||||
$datetime = new Datetime();
|
||||
$params = array(
|
||||
':usr_id' => $user->get_id()
|
||||
, ':application_id' => $application->get_id()
|
||||
, ':api_version' => API_OAuth2_Adapter::API_VERSION
|
||||
, ':revoked' => 0
|
||||
, ':created' => $datetime->format("Y-m-d H:i:s")
|
||||
);
|
||||
$datetime = new Datetime();
|
||||
$params = array(
|
||||
':usr_id' => $user->get_id()
|
||||
, ':application_id' => $application->get_id()
|
||||
, ':api_version' => API_OAuth2_Adapter::API_VERSION
|
||||
, ':revoked' => 0
|
||||
, ':created' => $datetime->format("Y-m-d H:i:s")
|
||||
);
|
||||
|
||||
$stmt = $appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
$stmt = $appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$account_id = $appbox->get_connection()->lastInsertId();
|
||||
$account_id = $appbox->get_connection()->lastInsertId();
|
||||
|
||||
return new self($appbox, $account_id);
|
||||
}
|
||||
return new self($appbox, $account_id);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param appbox $appbox
|
||||
* @param API_OAuth2_Application $application
|
||||
* @param User_Adapter $user
|
||||
* @return API_OAuth2_Account
|
||||
*/
|
||||
public static function load_with_user(appbox &$appbox, API_OAuth2_Application $application, User_Adapter $user)
|
||||
{
|
||||
$sql = 'SELECT api_account_id FROM api_accounts
|
||||
/**
|
||||
*
|
||||
* @param appbox $appbox
|
||||
* @param API_OAuth2_Application $application
|
||||
* @param User_Adapter $user
|
||||
* @return API_OAuth2_Account
|
||||
*/
|
||||
public static function load_with_user(appbox &$appbox, API_OAuth2_Application $application, User_Adapter $user)
|
||||
{
|
||||
$sql = 'SELECT api_account_id FROM api_accounts
|
||||
WHERE usr_id = :usr_id AND application_id = :application_id';
|
||||
|
||||
$params = array(
|
||||
":usr_id" => $user->get_id(),
|
||||
":application_id" => $application->get_id()
|
||||
);
|
||||
$params = array(
|
||||
":usr_id" => $user->get_id(),
|
||||
":application_id" => $application->get_id()
|
||||
);
|
||||
|
||||
|
||||
$stmt = $appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
$stmt = $appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
if (!$row)
|
||||
throw new Exception_NotFound();
|
||||
|
||||
return new self($appbox, $row['api_account_id']);
|
||||
}
|
||||
if ( ! $row)
|
||||
throw new Exception_NotFound();
|
||||
|
||||
return new self($appbox, $row['api_account_id']);
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -21,170 +21,167 @@
|
||||
*/
|
||||
class API_OAuth2_AuthCode
|
||||
{
|
||||
protected $appbox;
|
||||
protected $code;
|
||||
protected $account;
|
||||
protected $account_id;
|
||||
protected $redirect_uri;
|
||||
protected $expires;
|
||||
protected $scope;
|
||||
|
||||
protected $appbox;
|
||||
protected $code;
|
||||
protected $account;
|
||||
protected $account_id;
|
||||
protected $redirect_uri;
|
||||
protected $expires;
|
||||
protected $scope;
|
||||
|
||||
public function __construct(appbox &$appbox, $code)
|
||||
{
|
||||
$this->appbox = $appbox;
|
||||
$this->code = $code;
|
||||
$sql = 'SELECT code, api_account_id, redirect_uri, UNIX_TIMESTAMP(expires) AS expires, scope
|
||||
public function __construct(appbox &$appbox, $code)
|
||||
{
|
||||
$this->appbox = $appbox;
|
||||
$this->code = $code;
|
||||
$sql = 'SELECT code, api_account_id, redirect_uri, UNIX_TIMESTAMP(expires) AS expires, scope
|
||||
FROM api_oauth_codes WHERE code = :code';
|
||||
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute(array(':code' => $this->code));
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute(array(':code' => $this->code));
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
if (!$row)
|
||||
throw new Exception_NotFound();
|
||||
if ( ! $row)
|
||||
throw new Exception_NotFound();
|
||||
|
||||
$this->account_id = (int) $row['api_account_id'];
|
||||
$this->redirect_uri = $row['redirect_uri'];
|
||||
$this->expires = $row['expires'];
|
||||
$this->scope = $row['scope'];
|
||||
$this->account_id = (int) $row['api_account_id'];
|
||||
$this->redirect_uri = $row['redirect_uri'];
|
||||
$this->expires = $row['expires'];
|
||||
$this->scope = $row['scope'];
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function get_code()
|
||||
{
|
||||
return $this->code;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return API_OAuth2_Account
|
||||
*/
|
||||
public function get_account()
|
||||
{
|
||||
if (!$this->account)
|
||||
$this->account = new API_OAuth2_Account($this->appbox, $this->account_id);
|
||||
|
||||
return $this->account;
|
||||
}
|
||||
|
||||
public function get_redirect_uri()
|
||||
{
|
||||
return $this->redirect_uri;
|
||||
}
|
||||
|
||||
public function set_redirect_uri($redirect_uri)
|
||||
{
|
||||
$sql = 'UPDATE api_oauth_codes SET redirect_uri = :redirect_uri
|
||||
WHERE code = :code';
|
||||
|
||||
$params = array(':redirect_uri' => $redirect_uri, ':code' => $this->code);
|
||||
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$this->redirect_uri = $redirect_uri;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function get_expires()
|
||||
{
|
||||
return $this->expires;
|
||||
}
|
||||
|
||||
public function get_scope()
|
||||
{
|
||||
return $this->scope;
|
||||
}
|
||||
|
||||
public function set_scope($scope)
|
||||
{
|
||||
$sql = 'UPDATE api_oauth_codes SET scope = :scope
|
||||
WHERE code = :code';
|
||||
|
||||
$params = array(':scope' => $scope, ':code' => $this->code);
|
||||
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$this->scope = $scope;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function delete()
|
||||
{
|
||||
$sql = 'DELETE FROM api_oauth_codes WHERE code = :code';
|
||||
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute(array(':code' => $this->code));
|
||||
$stmt->closeCursor();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param appbox $appbox
|
||||
* @param API_OAuth2_Account $account
|
||||
* @return array
|
||||
*/
|
||||
public static function load_codes_by_account(appbox &$appbox, API_OAuth2_Account $account)
|
||||
{
|
||||
$sql = 'SELECT code FROM api_oauth_codes
|
||||
WHERE api_account_id = :account_id';
|
||||
|
||||
$stmt = $appbox->get_connection()->prepare($sql);
|
||||
|
||||
$params = array(":account_id" => $account->get_id());
|
||||
$stmt->execute($params);
|
||||
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$codes = array();
|
||||
|
||||
foreach ($rs as $row)
|
||||
{
|
||||
$codes[] = new API_OAuth2_AuthCode($appbox, $row['code']);
|
||||
return $this;
|
||||
}
|
||||
|
||||
return $codes;
|
||||
}
|
||||
public function get_code()
|
||||
{
|
||||
return $this->code;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param appbox $appbox
|
||||
* @param API_OAuth2_Account $account
|
||||
* @param type $code
|
||||
* @param int $expires
|
||||
* @return API_OAuth2_AuthCode
|
||||
*/
|
||||
public static function create(appbox &$appbox, API_OAuth2_Account $account, $code, $expires)
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @return API_OAuth2_Account
|
||||
*/
|
||||
public function get_account()
|
||||
{
|
||||
if ( ! $this->account)
|
||||
$this->account = new API_OAuth2_Account($this->appbox, $this->account_id);
|
||||
|
||||
$sql = 'INSERT INTO api_oauth_codes (code, api_account_id, expires)
|
||||
return $this->account;
|
||||
}
|
||||
|
||||
public function get_redirect_uri()
|
||||
{
|
||||
return $this->redirect_uri;
|
||||
}
|
||||
|
||||
public function set_redirect_uri($redirect_uri)
|
||||
{
|
||||
$sql = 'UPDATE api_oauth_codes SET redirect_uri = :redirect_uri
|
||||
WHERE code = :code';
|
||||
|
||||
$params = array(':redirect_uri' => $redirect_uri, ':code' => $this->code);
|
||||
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$this->redirect_uri = $redirect_uri;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function get_expires()
|
||||
{
|
||||
return $this->expires;
|
||||
}
|
||||
|
||||
public function get_scope()
|
||||
{
|
||||
return $this->scope;
|
||||
}
|
||||
|
||||
public function set_scope($scope)
|
||||
{
|
||||
$sql = 'UPDATE api_oauth_codes SET scope = :scope
|
||||
WHERE code = :code';
|
||||
|
||||
$params = array(':scope' => $scope, ':code' => $this->code);
|
||||
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$this->scope = $scope;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function delete()
|
||||
{
|
||||
$sql = 'DELETE FROM api_oauth_codes WHERE code = :code';
|
||||
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute(array(':code' => $this->code));
|
||||
$stmt->closeCursor();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param appbox $appbox
|
||||
* @param API_OAuth2_Account $account
|
||||
* @return array
|
||||
*/
|
||||
public static function load_codes_by_account(appbox &$appbox, API_OAuth2_Account $account)
|
||||
{
|
||||
$sql = 'SELECT code FROM api_oauth_codes
|
||||
WHERE api_account_id = :account_id';
|
||||
|
||||
$stmt = $appbox->get_connection()->prepare($sql);
|
||||
|
||||
$params = array(":account_id" => $account->get_id());
|
||||
$stmt->execute($params);
|
||||
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$codes = array();
|
||||
|
||||
foreach ($rs as $row) {
|
||||
$codes[] = new API_OAuth2_AuthCode($appbox, $row['code']);
|
||||
}
|
||||
|
||||
return $codes;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param appbox $appbox
|
||||
* @param API_OAuth2_Account $account
|
||||
* @param type $code
|
||||
* @param int $expires
|
||||
* @return API_OAuth2_AuthCode
|
||||
*/
|
||||
public static function create(appbox &$appbox, API_OAuth2_Account $account, $code, $expires)
|
||||
{
|
||||
|
||||
$sql = 'INSERT INTO api_oauth_codes (code, api_account_id, expires)
|
||||
VALUES (:code, :account_id, FROM_UNIXTIME(:expires))';
|
||||
|
||||
$stmt = $appbox->get_connection()->prepare($sql);
|
||||
$stmt = $appbox->get_connection()->prepare($sql);
|
||||
|
||||
$params = array(
|
||||
":code" => $code,
|
||||
":account_id" => $account->get_id(),
|
||||
":expires" => $expires
|
||||
);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
|
||||
return new self($appbox, $code);
|
||||
}
|
||||
$params = array(
|
||||
":code" => $code,
|
||||
":account_id" => $account->get_id(),
|
||||
":expires" => $expires
|
||||
);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
|
||||
return new self($appbox, $code);
|
||||
}
|
||||
}
|
||||
|
@@ -22,160 +22,158 @@
|
||||
*/
|
||||
class API_OAuth2_Exception_Exception extends Exception implements API_OAuth2_Exception_Interface
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $http_code;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $http_code;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error_description;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error_description;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error_uri;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error_uri;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $scope;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $scope;
|
||||
/**
|
||||
*
|
||||
* @param int $http_code
|
||||
* @param string $error
|
||||
* @param string $error_description
|
||||
* @param string $scope
|
||||
* @param string $error_uri
|
||||
* @return API_OAuth2_Exception_Exception
|
||||
*/
|
||||
public function __construct($http_code, $error, $error_description = null, $scope = null, $error_uri = null)
|
||||
{
|
||||
$this->error = $error;
|
||||
$this->error_description = $error_description;
|
||||
$this->scope = $scope;
|
||||
$this->error_uri = $error_uri;
|
||||
parent::__construct();
|
||||
|
||||
/**
|
||||
*
|
||||
* @param int $http_code
|
||||
* @param string $error
|
||||
* @param string $error_description
|
||||
* @param string $scope
|
||||
* @param string $error_uri
|
||||
* @return API_OAuth2_Exception_Exception
|
||||
*/
|
||||
public function __construct($http_code, $error, $error_description = null, $scope = null, $error_uri = null)
|
||||
{
|
||||
$this->error = $error;
|
||||
$this->error_description = $error_description;
|
||||
$this->scope = $scope;
|
||||
$this->error_uri = $error_uri;
|
||||
parent::__construct();
|
||||
return $this;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getHttp_code()
|
||||
{
|
||||
return $this->http_code;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getHttp_code()
|
||||
{
|
||||
return $this->http_code;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param int $http_code
|
||||
* @return API_OAuth2_Exception_Exception
|
||||
*/
|
||||
public function setHttp_code($http_code)
|
||||
{
|
||||
$this->http_code = $http_code;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param int $http_code
|
||||
* @return API_OAuth2_Exception_Exception
|
||||
*/
|
||||
public function setHttp_code($http_code)
|
||||
{
|
||||
$this->http_code = $http_code;
|
||||
return $this;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getError()
|
||||
{
|
||||
return $this->error;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getError()
|
||||
{
|
||||
return $this->error;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param string $scope
|
||||
* @return API_OAuth2_Exception_Exception
|
||||
*/
|
||||
public function setError($error)
|
||||
{
|
||||
$this->error = $error;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $scope
|
||||
* @return API_OAuth2_Exception_Exception
|
||||
*/
|
||||
public function setError($error)
|
||||
{
|
||||
$this->error = $error;
|
||||
return $this;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getError_description()
|
||||
{
|
||||
return $this->error_description;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getError_description()
|
||||
{
|
||||
return $this->error_description;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param string $scope
|
||||
* @return API_OAuth2_Exception_Exception
|
||||
*/
|
||||
public function setError_description($error_description)
|
||||
{
|
||||
$this->error_description = $error_description;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $scope
|
||||
* @return API_OAuth2_Exception_Exception
|
||||
*/
|
||||
public function setError_description($error_description)
|
||||
{
|
||||
$this->error_description = $error_description;
|
||||
return $this;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getError_uri()
|
||||
{
|
||||
return $this->error_uri;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getError_uri()
|
||||
{
|
||||
return $this->error_uri;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param string $scope
|
||||
* @return API_OAuth2_Exception_Exception
|
||||
*/
|
||||
public function setError_uri($error_uri)
|
||||
{
|
||||
$this->error_uri = $error_uri;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $scope
|
||||
* @return API_OAuth2_Exception_Exception
|
||||
*/
|
||||
public function setError_uri($error_uri)
|
||||
{
|
||||
$this->error_uri = $error_uri;
|
||||
return $this;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getScope()
|
||||
{
|
||||
return $this->scope;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getScope()
|
||||
{
|
||||
return $this->scope;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $scope
|
||||
* @return API_OAuth2_Exception_Exception
|
||||
*/
|
||||
public function setScope($scope)
|
||||
{
|
||||
$this->scope = $scope;
|
||||
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param string $scope
|
||||
* @return API_OAuth2_Exception_Exception
|
||||
*/
|
||||
public function setScope($scope)
|
||||
{
|
||||
$this->scope = $scope;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
@@ -23,11 +23,11 @@
|
||||
interface API_OAuth2_Exception_Interface
|
||||
{
|
||||
|
||||
public function getError();
|
||||
public function getError();
|
||||
|
||||
public function getHttp_code();
|
||||
public function getHttp_code();
|
||||
|
||||
public function getError_description();
|
||||
public function getError_description();
|
||||
|
||||
public function getError_uri();
|
||||
public function getError_uri();
|
||||
}
|
||||
|
@@ -22,81 +22,81 @@
|
||||
*/
|
||||
class API_OAuth2_Exception_Redirect extends API_OAuth2_Exception_Exception
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $http_code = 302;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $http_code = 302;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $state;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $redirect_uri;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $state;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $redirect_uri
|
||||
* @param string $error
|
||||
* @param string $error_description
|
||||
* @param string $state
|
||||
* @param string $error_uri
|
||||
* @return API_OAuth2_Exception_Redirect
|
||||
*/
|
||||
public function __construct($redirect_uri, $error, $error_description = null, $state = null, $error_uri = null)
|
||||
{
|
||||
$this->redirect_uri = $redirect_uri;
|
||||
$this->state = $state;
|
||||
parent::__construct($this->http_code, $error, $error_description, $error_uri);
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $redirect_uri;
|
||||
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param string $redirect_uri
|
||||
* @param string $error
|
||||
* @param string $error_description
|
||||
* @param string $state
|
||||
* @param string $error_uri
|
||||
* @return API_OAuth2_Exception_Redirect
|
||||
*/
|
||||
public function __construct($redirect_uri, $error, $error_description = null, $state = null, $error_uri = null)
|
||||
{
|
||||
$this->redirect_uri = $redirect_uri;
|
||||
$this->state = $state;
|
||||
parent::__construct($this->http_code, $error, $error_description, $error_uri);
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getState()
|
||||
{
|
||||
return $this->state;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $redirect_uri
|
||||
* @return API_OAuth2_Exception_Redirect
|
||||
*/
|
||||
public function setState($state)
|
||||
{
|
||||
$this->state = $state;
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getState()
|
||||
{
|
||||
return $this->state;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param string $redirect_uri
|
||||
* @return API_OAuth2_Exception_Redirect
|
||||
*/
|
||||
public function setState($state)
|
||||
{
|
||||
$this->state = $state;
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRedirect_uri()
|
||||
{
|
||||
return $this->redirect_uri;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $redirect_uri
|
||||
* @return API_OAuth2_Exception_Redirect
|
||||
*/
|
||||
public function setRedirect_uri($redirect_uri)
|
||||
{
|
||||
$this->redirect_uri = $redirect_uri;
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRedirect_uri()
|
||||
{
|
||||
return $this->redirect_uri;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param string $redirect_uri
|
||||
* @return API_OAuth2_Exception_Redirect
|
||||
*/
|
||||
public function setRedirect_uri($redirect_uri)
|
||||
{
|
||||
$this->redirect_uri = $redirect_uri;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
@@ -22,31 +22,29 @@
|
||||
*/
|
||||
class API_OAuth2_Exception_Redirect_AccessDenied extends API_OAuth2_Exception_Redirect
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error = 'access_denied';
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error = 'access_denied';
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error_description = " The resource owner or authorization server denied the request.";
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error_description = " The resource owner or authorization server denied the request.";
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $redirect_uri
|
||||
* @param string $state
|
||||
* @param string $error_uri
|
||||
* @return API_OAuth2_Exception_Redirect_AccessDenied
|
||||
*/
|
||||
public function __construct($redirect_uri, $state = null, $error_uri = null)
|
||||
{
|
||||
parent::__construct($redirect_uri, $this->error, $this->error_description, $state, $error_uri);
|
||||
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param string $redirect_uri
|
||||
* @param string $state
|
||||
* @param string $error_uri
|
||||
* @return API_OAuth2_Exception_Redirect_AccessDenied
|
||||
*/
|
||||
public function __construct($redirect_uri, $state = null, $error_uri = null)
|
||||
{
|
||||
parent::__construct($redirect_uri, $this->error, $this->error_description, $state, $error_uri);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
@@ -22,31 +22,29 @@
|
||||
*/
|
||||
class API_OAuth2_Exception_Redirect_InvalidClient extends API_OAuth2_Exception_Redirect
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error = 'invalid_Client';
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error = 'invalid_Client';
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error_description = "The Client id is not valid.";
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error_description = "The Client id is not valid.";
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $redirect_uri
|
||||
* @param string $state
|
||||
* @param string $error_uri
|
||||
* @return API_OAuth2_Exception_Redirect_InvalidClient
|
||||
*/
|
||||
public function __construct($redirect_uri, $state = null, $error_uri = null)
|
||||
{
|
||||
parent::__construct($redirect_uri, $this->error, $this->error_description, $state, $error_uri);
|
||||
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param string $redirect_uri
|
||||
* @param string $state
|
||||
* @param string $error_uri
|
||||
* @return API_OAuth2_Exception_Redirect_InvalidClient
|
||||
*/
|
||||
public function __construct($redirect_uri, $state = null, $error_uri = null)
|
||||
{
|
||||
parent::__construct($redirect_uri, $this->error, $this->error_description, $state, $error_uri);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
@@ -22,31 +22,29 @@
|
||||
*/
|
||||
class API_OAuth2_Exception_Redirect_InvalidRequest extends API_OAuth2_Exception_Redirect
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error = 'invalid_request';
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error = 'invalid_request';
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error_description = "The request is missing a required parameter, includes an unsupported parameter or parameter value, repeats the same parameter, uses more than one method for including an access token, or is otherwise malformed.";
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error_description = "The request is missing a required parameter, includes an unsupported parameter or parameter value, repeats the same parameter, uses more than one method for including an access token, or is otherwise malformed.";
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $redirect_uri
|
||||
* @param string $state
|
||||
* @param string $error_uri
|
||||
* @return API_OAuth2_Exception_Redirect_InvalidRequest
|
||||
*/
|
||||
public function __construct($redirect_uri, $state = null, $error_uri = null)
|
||||
{
|
||||
parent::__construct($redirect_uri, $this->error, $this->error_description, $state, $error_uri);
|
||||
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param string $redirect_uri
|
||||
* @param string $state
|
||||
* @param string $error_uri
|
||||
* @return API_OAuth2_Exception_Redirect_InvalidRequest
|
||||
*/
|
||||
public function __construct($redirect_uri, $state = null, $error_uri = null)
|
||||
{
|
||||
parent::__construct($redirect_uri, $this->error, $this->error_description, $state, $error_uri);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
@@ -22,60 +22,58 @@
|
||||
*/
|
||||
class API_OAuth2_Exception_Redirect_InvalidScope extends API_OAuth2_Exception_Redirect
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error = 'invalid_scope';
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error = 'invalid_scope';
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error_description = "The requested scope is invalid, unknown, or malformed.";
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error_description = "The requested scope is invalid, unknown, or malformed.";
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $scope;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $scope;
|
||||
/**
|
||||
*
|
||||
* @param string $redirect_uri
|
||||
* @param string $scope
|
||||
* @param string $state
|
||||
* @param string $error_uri
|
||||
* @return API_OAuth2_Exception_Redirect_InvalidScope
|
||||
*/
|
||||
public function __construct($redirect_uri, $scope, $state = null, $error_uri = null)
|
||||
{
|
||||
$this->scope = $scope;
|
||||
parent::__construct($redirect_uri, $this->error, $this->error_description, $state, $error_uri);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $redirect_uri
|
||||
* @param string $scope
|
||||
* @param string $state
|
||||
* @param string $error_uri
|
||||
* @return API_OAuth2_Exception_Redirect_InvalidScope
|
||||
*/
|
||||
public function __construct($redirect_uri, $scope, $state = null, $error_uri = null)
|
||||
{
|
||||
$this->scope = $scope;
|
||||
parent::__construct($redirect_uri, $this->error, $this->error_description, $state, $error_uri);
|
||||
return $this;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public function getScope()
|
||||
{
|
||||
return $this->scope;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public function getScope()
|
||||
{
|
||||
return $this->scope;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $scope
|
||||
* @return API_OAuth2_Exception_Redirect_InvalidScope
|
||||
*/
|
||||
public function setScope($scope)
|
||||
{
|
||||
$this->scope = $scope;
|
||||
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param string $scope
|
||||
* @return API_OAuth2_Exception_Redirect_InvalidScope
|
||||
*/
|
||||
public function setScope($scope)
|
||||
{
|
||||
$this->scope = $scope;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
@@ -22,29 +22,29 @@
|
||||
*/
|
||||
class API_OAuth2_Exception_Redirect_ServerError extends API_OAuth2_Exception_Redirect
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error = 'server_error';
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error = 'server_error';
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error_description = "The authorization server encountered an unexpected condition which prevented it from fulfilling the request.";
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error_description = "The authorization server encountered an unexpected condition which prevented it from fulfilling the request.";
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $redirect_uri
|
||||
* @param string $state
|
||||
* @param string $error_uri
|
||||
* @return API_OAuth2_Exception_Redirect_ServerError
|
||||
*/
|
||||
public function __construct($redirect_uri, $state = null, $error_uri = null)
|
||||
{
|
||||
parent::__construct($redirect_uri, $this->error, $this->error_description, $state, $error_uri);
|
||||
/**
|
||||
*
|
||||
* @param string $redirect_uri
|
||||
* @param string $state
|
||||
* @param string $error_uri
|
||||
* @return API_OAuth2_Exception_Redirect_ServerError
|
||||
*/
|
||||
public function __construct($redirect_uri, $state = null, $error_uri = null)
|
||||
{
|
||||
parent::__construct($redirect_uri, $this->error, $this->error_description, $state, $error_uri);
|
||||
|
||||
return $this;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
@@ -22,31 +22,29 @@
|
||||
*/
|
||||
class API_OAuth2_Exception_Redirect_Unauthorized extends API_OAuth2_Exception_Redirect
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error = 'temporarily_unavailable';
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error = 'temporarily_unavailable';
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error_description = "The authorization server is currently unable to handle the request due to a temporary overloading or maintenance of the server.";
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error_description = "The authorization server is currently unable to handle the request due to a temporary overloading or maintenance of the server.";
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $redirect_uri
|
||||
* @param string $state
|
||||
* @param string $error_uri
|
||||
* @return API_OAuth2_Exception_Redirect_Unauthorized
|
||||
*/
|
||||
public function __construct($redirect_uri, $state = null, $error_uri = null)
|
||||
{
|
||||
parent::__construct($redirect_uri, $this->error, $this->error_description, $state, $error_uri);
|
||||
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param string $redirect_uri
|
||||
* @param string $state
|
||||
* @param string $error_uri
|
||||
* @return API_OAuth2_Exception_Redirect_Unauthorized
|
||||
*/
|
||||
public function __construct($redirect_uri, $state = null, $error_uri = null)
|
||||
{
|
||||
parent::__construct($redirect_uri, $this->error, $this->error_description, $state, $error_uri);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
@@ -22,31 +22,29 @@
|
||||
*/
|
||||
class API_OAuth2_Exception_Redirect_UnauthorizedClient extends API_OAuth2_Exception_Redirect
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error = 'unauthorized_client';
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error = 'unauthorized_client';
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error_description = "The client is not authorized to request an authorization code using this method.";
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error_description = "The client is not authorized to request an authorization code using this method.";
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $redirect_uri
|
||||
* @param string $state
|
||||
* @param string $error_uri
|
||||
* @return API_OAuth2_Exception_Redirect_UnauthorizedClient
|
||||
*/
|
||||
public function __construct($redirect_uri, $state = null, $error_uri = null)
|
||||
{
|
||||
parent::__construct($redirect_uri, $this->error, $this->error_description, $state, $error_uri);
|
||||
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param string $redirect_uri
|
||||
* @param string $state
|
||||
* @param string $error_uri
|
||||
* @return API_OAuth2_Exception_Redirect_UnauthorizedClient
|
||||
*/
|
||||
public function __construct($redirect_uri, $state = null, $error_uri = null)
|
||||
{
|
||||
parent::__construct($redirect_uri, $this->error, $this->error_description, $state, $error_uri);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
@@ -22,60 +22,58 @@
|
||||
*/
|
||||
class API_OAuth2_Exception_Redirect_UnsupportedResponseType extends API_OAuth2_Exception_Redirect
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error = 'unsupported_response_type';
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error = 'unsupported_response_type';
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error_description = "The authorization server does not support obtaining an authorization code using this method.";
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error_description = "The authorization server does not support obtaining an authorization code using this method.";
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $method;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $method;
|
||||
/**
|
||||
*
|
||||
* @param string $redirect_uri
|
||||
* @param string $method
|
||||
* @param string $state
|
||||
* @param string $error_uri
|
||||
* @return API_OAuth2_Exception_Redirect_UnsupportedResponseType
|
||||
*/
|
||||
public function __construct($redirect_uri, $method, $state = null, $error_uri = null)
|
||||
{
|
||||
$this->method = $method;
|
||||
parent::__construct($redirect_uri, $this->error, $this->error_description, $state, $error_uri);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $redirect_uri
|
||||
* @param string $method
|
||||
* @param string $state
|
||||
* @param string $error_uri
|
||||
* @return API_OAuth2_Exception_Redirect_UnsupportedResponseType
|
||||
*/
|
||||
public function __construct($redirect_uri, $method, $state = null, $error_uri = null)
|
||||
{
|
||||
$this->method = $method;
|
||||
parent::__construct($redirect_uri, $this->error, $this->error_description, $state, $error_uri);
|
||||
return $this;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public function getMethod()
|
||||
{
|
||||
return $this->method;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public function getMethod()
|
||||
{
|
||||
return $this->method;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $method
|
||||
* @return API_OAuth2_Exception_Redirect_UnsupportedResponseType
|
||||
*/
|
||||
public function setMethod($method)
|
||||
{
|
||||
$this->method = $method;
|
||||
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param string $method
|
||||
* @return API_OAuth2_Exception_Redirect_UnsupportedResponseType
|
||||
*/
|
||||
public function setMethod($method)
|
||||
{
|
||||
$this->method = $method;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
@@ -22,58 +22,56 @@
|
||||
*/
|
||||
class API_OAuth2_Exception_WWWAuthenticate extends API_OAuth2_Exception_Exception
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $realm;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $realm;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $scope;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $scope;
|
||||
/**
|
||||
*
|
||||
* @param int $http_code
|
||||
* @param string $realm
|
||||
* @param string $error
|
||||
* @param string $error_description
|
||||
* @param string $error_uri
|
||||
* @param string $scope
|
||||
* @return API_OAuth2_Exception_WWWAuthenticate
|
||||
*/
|
||||
public function __construct($http_code, $realm, $error, $error_description = null, $error_uri = null, $scope = null)
|
||||
{
|
||||
$this->realm = $realm;
|
||||
$this->scope = $scope;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param int $http_code
|
||||
* @param string $realm
|
||||
* @param string $error
|
||||
* @param string $error_description
|
||||
* @param string $error_uri
|
||||
* @param string $scope
|
||||
* @return API_OAuth2_Exception_WWWAuthenticate
|
||||
*/
|
||||
public function __construct($http_code, $realm, $error, $error_description = null, $error_uri = null, $scope = null)
|
||||
{
|
||||
$this->realm = $realm;
|
||||
$this->scope = $scope;
|
||||
parent::__construct($http_code, $error, $error_description, $error_uri);
|
||||
|
||||
parent::__construct($http_code, $error, $error_description, $error_uri);
|
||||
return $this;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRealm()
|
||||
{
|
||||
return $this->realm;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRealm()
|
||||
{
|
||||
return $this->realm;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $realm
|
||||
* @return API_OAuth2_Exception_WWWAuthenticate
|
||||
*/
|
||||
public function setRealm($realm)
|
||||
{
|
||||
$this->realm = $realm;
|
||||
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param string $realm
|
||||
* @return API_OAuth2_Exception_WWWAuthenticate
|
||||
*/
|
||||
public function setRealm($realm)
|
||||
{
|
||||
$this->realm = $realm;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
@@ -22,31 +22,29 @@
|
||||
*/
|
||||
class API_OAuth2_Exception_WWWAuthenticate_ExpiredToken extends API_OAuth2_Exception_WWWAuthenticate_Type_Unauthorized
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error = 'expired_token';
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error = 'expired_token';
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error_description = "The access token provided has expired.";
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error_description = "The access token provided has expired.";
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $realm
|
||||
* @param string $scope
|
||||
* @param string $error_uri
|
||||
* @return API_OAuth2_Exception_WWWAuthenticate_ExpiredToken
|
||||
*/
|
||||
public function __construct($realm, $scope = null, $error_uri = null)
|
||||
{
|
||||
parent::__construct($realm, $this->error, $this->error_description, $error_uri, $scope);
|
||||
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param string $realm
|
||||
* @param string $scope
|
||||
* @param string $error_uri
|
||||
* @return API_OAuth2_Exception_WWWAuthenticate_ExpiredToken
|
||||
*/
|
||||
public function __construct($realm, $scope = null, $error_uri = null)
|
||||
{
|
||||
parent::__construct($realm, $this->error, $this->error_description, $error_uri, $scope);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
@@ -22,31 +22,29 @@
|
||||
*/
|
||||
class API_OAuth2_Exception_WWWAuthenticate_InsufficientScope extends API_OAuth2_Exception_WWWAuthenticate_Type_Forbidden
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error = 'insufficient_scope';
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error = 'insufficient_scope';
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error_description = "The request requires higher privileges than provided by the access token.";
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error_description = "The request requires higher privileges than provided by the access token.";
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $realm
|
||||
* @param string $scope
|
||||
* @param string $error_uri
|
||||
* @return API_OAuth2_Exception_WWWAuthenticate_InsufficientScope
|
||||
*/
|
||||
public function __construct($realm, $scope = null, $error_uri = null)
|
||||
{
|
||||
parent::__construct($realm, $this->error, $this->error_description, $error_uri, $scope);
|
||||
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param string $realm
|
||||
* @param string $scope
|
||||
* @param string $error_uri
|
||||
* @return API_OAuth2_Exception_WWWAuthenticate_InsufficientScope
|
||||
*/
|
||||
public function __construct($realm, $scope = null, $error_uri = null)
|
||||
{
|
||||
parent::__construct($realm, $this->error, $this->error_description, $error_uri, $scope);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
@@ -22,31 +22,29 @@
|
||||
*/
|
||||
class API_OAuth2_Exception_WWWAuthenticate_InvalidClient extends API_OAuth2_Exception_WWWAuthenticate_Type_BadRequest
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error = 'invalid_request';
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error = 'invalid_request';
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error_description = "The request is missing a required parameter, includes an unsupported parameter or parameter value, repeats the same parameter, uses more than one method for including an access token, or is otherwise malformed.";
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error_description = "The request is missing a required parameter, includes an unsupported parameter or parameter value, repeats the same parameter, uses more than one method for including an access token, or is otherwise malformed.";
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $realm
|
||||
* @param string $scope
|
||||
* @param string $error_uri
|
||||
* @return API_OAuth2_Exception_WWWAuthenticate_InvalidClient
|
||||
*/
|
||||
public function __construct($realm, $scope = null, $error_uri = null)
|
||||
{
|
||||
parent::__construct($realm, $this->error, $this->error_description, $error_uri, $scope);
|
||||
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param string $realm
|
||||
* @param string $scope
|
||||
* @param string $error_uri
|
||||
* @return API_OAuth2_Exception_WWWAuthenticate_InvalidClient
|
||||
*/
|
||||
public function __construct($realm, $scope = null, $error_uri = null)
|
||||
{
|
||||
parent::__construct($realm, $this->error, $this->error_description, $error_uri, $scope);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
@@ -22,31 +22,29 @@
|
||||
*/
|
||||
class API_OAuth2_Exception_WWWAuthenticate_InvalidRequest extends API_OAuth2_Exception_WWWAuthenticate_Type_BadRequest
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error = 'invalid_request';
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error = 'invalid_request';
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error_description = "The request is missing a required parameter, includes an unsupported parameter or parameter value, repeats the same parameter, uses more than one method for including an access token, or is otherwise malformed.";
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error_description = "The request is missing a required parameter, includes an unsupported parameter or parameter value, repeats the same parameter, uses more than one method for including an access token, or is otherwise malformed.";
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $realm
|
||||
* @param string $scope
|
||||
* @param string $error_uri
|
||||
* @return API_OAuth2_Exception_WWWAuthenticate_InvalidRequest
|
||||
*/
|
||||
public function __construct($realm, $scope = null, $error_uri = null)
|
||||
{
|
||||
parent::__construct($realm, $this->error, $this->error_description, $error_uri, $scope);
|
||||
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param string $realm
|
||||
* @param string $scope
|
||||
* @param string $error_uri
|
||||
* @return API_OAuth2_Exception_WWWAuthenticate_InvalidRequest
|
||||
*/
|
||||
public function __construct($realm, $scope = null, $error_uri = null)
|
||||
{
|
||||
parent::__construct($realm, $this->error, $this->error_description, $error_uri, $scope);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
@@ -22,31 +22,29 @@
|
||||
*/
|
||||
class API_OAuth2_Exception_WWWAuthenticate_InvalidToken extends API_OAuth2_Exception_WWWAuthenticate_Type_Unauthorized
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error = 'invalid_token';
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error = 'invalid_token';
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error_description = "The access token provided is invalid.";
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error_description = "The access token provided is invalid.";
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $realm
|
||||
* @param string $scope
|
||||
* @param string $error_uri
|
||||
* @return API_OAuth2_Exception_WWWAuthenticate_InvalidToken
|
||||
*/
|
||||
public function __construct($realm, $scope = null, $error_uri = null)
|
||||
{
|
||||
parent::__construct($realm, $this->error, $this->error_description, $error_uri, $scope);
|
||||
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param string $realm
|
||||
* @param string $scope
|
||||
* @param string $error_uri
|
||||
* @return API_OAuth2_Exception_WWWAuthenticate_InvalidToken
|
||||
*/
|
||||
public function __construct($realm, $scope = null, $error_uri = null)
|
||||
{
|
||||
parent::__construct($realm, $this->error, $this->error_description, $error_uri, $scope);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
@@ -22,27 +22,25 @@
|
||||
*/
|
||||
class API_OAuth2_Exception_WWWAuthenticate_Type_BadRequest extends API_OAuth2_Exception_WWWAuthenticate
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $http_code = 400;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $http_code = 400;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $realm
|
||||
* @param string $error
|
||||
* @param string $error_description
|
||||
* @param string $error_uri
|
||||
* @param string $scope
|
||||
* @return API_OAuth2_Exception_WWWAuthenticate_Type_BadRequest
|
||||
*/
|
||||
public function __construct($realm, $error, $error_description = null, $error_uri = null, $scope = null)
|
||||
{
|
||||
parent::__construct($this->http_code, $realm, $error, $error_description = null, $error_uri, $scope);
|
||||
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param string $realm
|
||||
* @param string $error
|
||||
* @param string $error_description
|
||||
* @param string $error_uri
|
||||
* @param string $scope
|
||||
* @return API_OAuth2_Exception_WWWAuthenticate_Type_BadRequest
|
||||
*/
|
||||
public function __construct($realm, $error, $error_description = null, $error_uri = null, $scope = null)
|
||||
{
|
||||
parent::__construct($this->http_code, $realm, $error, $error_description = null, $error_uri, $scope);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
@@ -23,21 +23,20 @@
|
||||
class API_OAuth2_Exception_WWWAuthenticate_Type_Forbidden extends API_OAuth2_Exception_WWWAuthenticate
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $realm
|
||||
* @param string $error
|
||||
* @param string $error_description
|
||||
* @param string $error_uri
|
||||
* @param string $scope
|
||||
* @return API_OAuth2_Exception_WWWAuthenticate_Type_Forbidden
|
||||
*/
|
||||
public function __construct($realm, $error, $error_description = null, $error_uri = null, $scope = null)
|
||||
{
|
||||
parent::__construct($realm, $error, $error_description = null, $error_uri, $scope);
|
||||
$this->setHttp_code(403);
|
||||
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param string $realm
|
||||
* @param string $error
|
||||
* @param string $error_description
|
||||
* @param string $error_uri
|
||||
* @param string $scope
|
||||
* @return API_OAuth2_Exception_WWWAuthenticate_Type_Forbidden
|
||||
*/
|
||||
public function __construct($realm, $error, $error_description = null, $error_uri = null, $scope = null)
|
||||
{
|
||||
parent::__construct($realm, $error, $error_description = null, $error_uri, $scope);
|
||||
$this->setHttp_code(403);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
@@ -22,27 +22,25 @@
|
||||
*/
|
||||
class API_OAuth2_Exception_WWWAuthenticate_Type_Unauthorized extends API_OAuth2_Exception_WWWAuthenticate
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $http_code = 401;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $http_code = 401;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $realm
|
||||
* @param string $error
|
||||
* @param string $error_description
|
||||
* @param string $error_uri
|
||||
* @param string $scope
|
||||
* @return API_OAuth2_Exception_WWWAuthenticate_Type_Unauthorized
|
||||
*/
|
||||
public function __construct($realm, $error, $error_description = null, $error_uri = null, $scope = null)
|
||||
{
|
||||
parent::__construct($this->http_code, $realm, $error, $error_description = null, $error_uri, $scope);
|
||||
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param string $realm
|
||||
* @param string $error
|
||||
* @param string $error_description
|
||||
* @param string $error_uri
|
||||
* @param string $scope
|
||||
* @return API_OAuth2_Exception_WWWAuthenticate_Type_Unauthorized
|
||||
*/
|
||||
public function __construct($realm, $error, $error_description = null, $error_uri = null, $scope = null)
|
||||
{
|
||||
parent::__construct($this->http_code, $realm, $error, $error_description = null, $error_uri, $scope);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
@@ -26,134 +26,132 @@ use Symfony\Component\Validator\Constraints;
|
||||
|
||||
class API_OAuth2_Form_DevAppDesktop
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $name;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $description;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $website;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $callback;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $type;
|
||||
public $scheme_website;
|
||||
public $urlwebsite;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param Request $request
|
||||
* @return API_OAuth2_Form_DevApp
|
||||
*/
|
||||
public function __construct(Request $request)
|
||||
{
|
||||
$this->name = $request->get('name', '');
|
||||
$this->description = $request->get('description', '');
|
||||
$this->scheme_website = $request->get('scheme-website', 'http://');
|
||||
$this->website = $request->get('website', '');
|
||||
$this->callback = API_OAuth2_Application::NATIVE_APP_REDIRECT_URI;
|
||||
$this->type = API_OAuth2_Application::DESKTOP_TYPE;
|
||||
|
||||
$this->urlwebsite = $this->scheme_website . $this->website;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDescription()
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getWebsite()
|
||||
{
|
||||
return $this->website;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCallback()
|
||||
{
|
||||
return $this->callback;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
public function getSchemeWebsite()
|
||||
{
|
||||
return $this->scheme_website;
|
||||
}
|
||||
|
||||
public function getUrlwebsite()
|
||||
{
|
||||
return $this->urlwebsite;
|
||||
}
|
||||
|
||||
public function getSchemeCallback()
|
||||
{
|
||||
return '';
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $name;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param ClassMetadata $metadata
|
||||
* @return API_OAuth2_Form_DevApp
|
||||
*/
|
||||
static public function loadValidatorMetadata(ClassMetadata $metadata)
|
||||
{
|
||||
$blank = array('message' => _('Cette valeur ne peut être vide'));
|
||||
$url = array('message' => _('Url non valide'));
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $description;
|
||||
|
||||
$metadata->addPropertyConstraint('name', new Constraints\NotBlank($blank));
|
||||
$metadata->addPropertyConstraint('description', new Constraints\NotBlank($blank));
|
||||
$metadata->addPropertyConstraint('urlwebsite', new Constraints\NotBlank($blank));
|
||||
$metadata->addPropertyConstraint('urlwebsite', new Constraints\Url($url));
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $website;
|
||||
|
||||
return;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $callback;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $type;
|
||||
public $scheme_website;
|
||||
public $urlwebsite;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param Request $request
|
||||
* @return API_OAuth2_Form_DevApp
|
||||
*/
|
||||
public function __construct(Request $request)
|
||||
{
|
||||
$this->name = $request->get('name', '');
|
||||
$this->description = $request->get('description', '');
|
||||
$this->scheme_website = $request->get('scheme-website', 'http://');
|
||||
$this->website = $request->get('website', '');
|
||||
$this->callback = API_OAuth2_Application::NATIVE_APP_REDIRECT_URI;
|
||||
$this->type = API_OAuth2_Application::DESKTOP_TYPE;
|
||||
|
||||
$this->urlwebsite = $this->scheme_website . $this->website;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDescription()
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getWebsite()
|
||||
{
|
||||
return $this->website;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCallback()
|
||||
{
|
||||
return $this->callback;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
public function getSchemeWebsite()
|
||||
{
|
||||
return $this->scheme_website;
|
||||
}
|
||||
|
||||
public function getUrlwebsite()
|
||||
{
|
||||
return $this->urlwebsite;
|
||||
}
|
||||
|
||||
public function getSchemeCallback()
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param ClassMetadata $metadata
|
||||
* @return API_OAuth2_Form_DevApp
|
||||
*/
|
||||
static public function loadValidatorMetadata(ClassMetadata $metadata)
|
||||
{
|
||||
$blank = array('message' => _('Cette valeur ne peut être vide'));
|
||||
$url = array('message' => _('Url non valide'));
|
||||
|
||||
$metadata->addPropertyConstraint('name', new Constraints\NotBlank($blank));
|
||||
$metadata->addPropertyConstraint('description', new Constraints\NotBlank($blank));
|
||||
$metadata->addPropertyConstraint('urlwebsite', new Constraints\NotBlank($blank));
|
||||
$metadata->addPropertyConstraint('urlwebsite', new Constraints\Url($url));
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@@ -26,141 +26,137 @@ use Symfony\Component\Validator\Constraints;
|
||||
|
||||
class API_OAuth2_Form_DevAppInternet
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $name;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $description;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $website;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $callback;
|
||||
|
||||
public $scheme_website;
|
||||
public $scheme_callback;
|
||||
|
||||
public $urlwebsite;
|
||||
public $urlcallback;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param Request $request
|
||||
* @return API_OAuth2_Form_DevApp
|
||||
*/
|
||||
public function __construct(Request $request)
|
||||
{
|
||||
$this->name = $request->get('name', '');
|
||||
$this->description = $request->get('description', '');
|
||||
$this->website = $request->get('website', '');
|
||||
$this->callback = $request->get('callback', '');
|
||||
$this->scheme_website = $request->get('scheme-website', 'http://');
|
||||
$this->scheme_callback = $request->get('scheme-callback', 'http://');
|
||||
$this->type = API_OAuth2_Application::WEB_TYPE;
|
||||
|
||||
$this->urlwebsite = $this->scheme_website.$this->website;
|
||||
$this->urlcallback = $this->scheme_callback.$this->callback;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDescription()
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getWebsite()
|
||||
{
|
||||
return $this->website;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCallback()
|
||||
{
|
||||
return $this->callback;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
public function getSchemeWebsite()
|
||||
{
|
||||
return $this->scheme_website;
|
||||
}
|
||||
|
||||
public function getSchemeCallback()
|
||||
{
|
||||
return $this->scheme_callback;
|
||||
}
|
||||
|
||||
public function getUrlwebsite()
|
||||
{
|
||||
return $this->urlwebsite;
|
||||
}
|
||||
|
||||
public function getUrlcallback()
|
||||
{
|
||||
return $this->urlcallback;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $name;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param ClassMetadata $metadata
|
||||
* @return API_OAuth2_Form_DevApp
|
||||
*/
|
||||
static public function loadValidatorMetadata(ClassMetadata $metadata)
|
||||
{
|
||||
$blank = array('message' => _('Cette valeur ne peut être vide'));
|
||||
$url = array('message' => _('Url non valide'));
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $description;
|
||||
|
||||
$metadata->addPropertyConstraint('name', new Constraints\NotBlank($blank));
|
||||
$metadata->addPropertyConstraint('description', new Constraints\NotBlank($blank));
|
||||
$metadata->addPropertyConstraint('urlwebsite', new Constraints\NotBlank($blank));
|
||||
$metadata->addPropertyConstraint('urlwebsite', new Constraints\Url($url));
|
||||
$metadata->addPropertyConstraint('urlcallback', new Constraints\NotBlank($blank));
|
||||
$metadata->addPropertyConstraint('urlcallback', new Constraints\Url($url));
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $website;
|
||||
|
||||
return;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $callback;
|
||||
public $scheme_website;
|
||||
public $scheme_callback;
|
||||
public $urlwebsite;
|
||||
public $urlcallback;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param Request $request
|
||||
* @return API_OAuth2_Form_DevApp
|
||||
*/
|
||||
public function __construct(Request $request)
|
||||
{
|
||||
$this->name = $request->get('name', '');
|
||||
$this->description = $request->get('description', '');
|
||||
$this->website = $request->get('website', '');
|
||||
$this->callback = $request->get('callback', '');
|
||||
$this->scheme_website = $request->get('scheme-website', 'http://');
|
||||
$this->scheme_callback = $request->get('scheme-callback', 'http://');
|
||||
$this->type = API_OAuth2_Application::WEB_TYPE;
|
||||
|
||||
$this->urlwebsite = $this->scheme_website . $this->website;
|
||||
$this->urlcallback = $this->scheme_callback . $this->callback;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDescription()
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getWebsite()
|
||||
{
|
||||
return $this->website;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCallback()
|
||||
{
|
||||
return $this->callback;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
public function getSchemeWebsite()
|
||||
{
|
||||
return $this->scheme_website;
|
||||
}
|
||||
|
||||
public function getSchemeCallback()
|
||||
{
|
||||
return $this->scheme_callback;
|
||||
}
|
||||
|
||||
public function getUrlwebsite()
|
||||
{
|
||||
return $this->urlwebsite;
|
||||
}
|
||||
|
||||
public function getUrlcallback()
|
||||
{
|
||||
return $this->urlcallback;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param ClassMetadata $metadata
|
||||
* @return API_OAuth2_Form_DevApp
|
||||
*/
|
||||
static public function loadValidatorMetadata(ClassMetadata $metadata)
|
||||
{
|
||||
$blank = array('message' => _('Cette valeur ne peut être vide'));
|
||||
$url = array('message' => _('Url non valide'));
|
||||
|
||||
$metadata->addPropertyConstraint('name', new Constraints\NotBlank($blank));
|
||||
$metadata->addPropertyConstraint('description', new Constraints\NotBlank($blank));
|
||||
$metadata->addPropertyConstraint('urlwebsite', new Constraints\NotBlank($blank));
|
||||
$metadata->addPropertyConstraint('urlwebsite', new Constraints\Url($url));
|
||||
$metadata->addPropertyConstraint('urlcallback', new Constraints\NotBlank($blank));
|
||||
$metadata->addPropertyConstraint('urlcallback', new Constraints\Url($url));
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@@ -21,129 +21,126 @@
|
||||
*/
|
||||
class API_OAuth2_RefreshToken
|
||||
{
|
||||
protected $appbox;
|
||||
protected $token;
|
||||
protected $account_id;
|
||||
protected $account;
|
||||
protected $expires;
|
||||
protected $scope;
|
||||
|
||||
protected $appbox;
|
||||
protected $token;
|
||||
protected $account_id;
|
||||
protected $account;
|
||||
protected $expires;
|
||||
protected $scope;
|
||||
public function __construct(appbox &$appbox, $token)
|
||||
{
|
||||
$this->appbox = $appbox;
|
||||
$this->token = $token;
|
||||
|
||||
public function __construct(appbox &$appbox, $token)
|
||||
{
|
||||
$this->appbox = $appbox;
|
||||
$this->token = $token;
|
||||
|
||||
$sql = 'SELECT api_account_id, UNIX_TIMESTAMP(expires) AS expires, scope
|
||||
$sql = 'SELECT api_account_id, UNIX_TIMESTAMP(expires) AS expires, scope
|
||||
FROM api_oauth_refresh_tokens WHERE refresh_token = :token';
|
||||
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute(array(':token' => $this->token));
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute(array(':token' => $this->token));
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$this->account_id = (int) $row['api_account_id'];
|
||||
$this->expires = $row['expires'];
|
||||
$this->scope = $row['scope'];
|
||||
$this->account_id = (int) $row['api_account_id'];
|
||||
$this->expires = $row['expires'];
|
||||
$this->scope = $row['scope'];
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function get_value()
|
||||
{
|
||||
return $this->token;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return API_OAuth2_Account
|
||||
*/
|
||||
public function get_account()
|
||||
{
|
||||
if (!$this->account)
|
||||
$this->account = new API_OAuth2_Account($this->appbox, $this->account_id);
|
||||
|
||||
return $this->account;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function get_expires()
|
||||
{
|
||||
return $this->expires;
|
||||
}
|
||||
|
||||
public function get_scope()
|
||||
{
|
||||
return $this->scope;
|
||||
}
|
||||
|
||||
public function delete()
|
||||
{
|
||||
$sql = 'DELETE FROM api_oauth_refresh_tokens
|
||||
WHERE refresh_token = :refresh_token';
|
||||
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute(array(":refresh_token" => $this->token));
|
||||
$stmt->closeCursor();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param appbox $appbox
|
||||
* @param API_OAuth2_Account $account
|
||||
* @return array
|
||||
*/
|
||||
public static function load_by_account(appbox &$appbox, API_OAuth2_Account $account)
|
||||
{
|
||||
$sql = 'SELECT refresh_token FROM api_oauth_refresh_tokens
|
||||
WHERE api_account_id = :account_id';
|
||||
|
||||
$stmt = $appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute(array(':account_id' => $account->get_id()));
|
||||
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$tokens = array();
|
||||
|
||||
foreach ($rs as $row)
|
||||
{
|
||||
$tokens[] = new API_OAuth2_RefreshToken($appbox, $row['refresh_token']);
|
||||
return $this;
|
||||
}
|
||||
|
||||
return $tokens;
|
||||
}
|
||||
public function get_value()
|
||||
{
|
||||
return $this->token;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param appbox $appbox
|
||||
* @param API_OAuth2_Account $account
|
||||
* @param int $expires
|
||||
* @param type $refresh_token
|
||||
* @param type $scope
|
||||
* @return API_OAuth2_RefreshToken
|
||||
*/
|
||||
public static function create(appbox &$appbox, API_OAuth2_Account $account, $expires, $refresh_token, $scope)
|
||||
{
|
||||
$sql = 'INSERT INTO api_oauth_refresh_tokens
|
||||
/**
|
||||
*
|
||||
* @return API_OAuth2_Account
|
||||
*/
|
||||
public function get_account()
|
||||
{
|
||||
if ( ! $this->account)
|
||||
$this->account = new API_OAuth2_Account($this->appbox, $this->account_id);
|
||||
|
||||
return $this->account;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function get_expires()
|
||||
{
|
||||
return $this->expires;
|
||||
}
|
||||
|
||||
public function get_scope()
|
||||
{
|
||||
return $this->scope;
|
||||
}
|
||||
|
||||
public function delete()
|
||||
{
|
||||
$sql = 'DELETE FROM api_oauth_refresh_tokens
|
||||
WHERE refresh_token = :refresh_token';
|
||||
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute(array(":refresh_token" => $this->token));
|
||||
$stmt->closeCursor();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param appbox $appbox
|
||||
* @param API_OAuth2_Account $account
|
||||
* @return array
|
||||
*/
|
||||
public static function load_by_account(appbox &$appbox, API_OAuth2_Account $account)
|
||||
{
|
||||
$sql = 'SELECT refresh_token FROM api_oauth_refresh_tokens
|
||||
WHERE api_account_id = :account_id';
|
||||
|
||||
$stmt = $appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute(array(':account_id' => $account->get_id()));
|
||||
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$tokens = array();
|
||||
|
||||
foreach ($rs as $row) {
|
||||
$tokens[] = new API_OAuth2_RefreshToken($appbox, $row['refresh_token']);
|
||||
}
|
||||
|
||||
return $tokens;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param appbox $appbox
|
||||
* @param API_OAuth2_Account $account
|
||||
* @param int $expires
|
||||
* @param type $refresh_token
|
||||
* @param type $scope
|
||||
* @return API_OAuth2_RefreshToken
|
||||
*/
|
||||
public static function create(appbox &$appbox, API_OAuth2_Account $account, $expires, $refresh_token, $scope)
|
||||
{
|
||||
$sql = 'INSERT INTO api_oauth_refresh_tokens
|
||||
(refresh_token, api_account_id, expires, scope)
|
||||
VALUES (:refresh_token, :account_id, :expires, :scope)';
|
||||
|
||||
$stmt = $appbox->get_connection()->prepare($sql);
|
||||
$params = array(
|
||||
":refresh_token" => $refresh_token,
|
||||
":account_id" => $account->get_id(),
|
||||
":expires" => $expires,
|
||||
":scope" => $scope
|
||||
);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
|
||||
return new self($appbox, $refresh_token);
|
||||
}
|
||||
$stmt = $appbox->get_connection()->prepare($sql);
|
||||
$params = array(
|
||||
":refresh_token" => $refresh_token,
|
||||
":account_id" => $account->get_id(),
|
||||
":expires" => $expires,
|
||||
":scope" => $scope
|
||||
);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
|
||||
return new self($appbox, $refresh_token);
|
||||
}
|
||||
}
|
||||
|
@@ -21,311 +21,309 @@
|
||||
*/
|
||||
class API_OAuth2_Token
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var appbox
|
||||
*/
|
||||
protected $appbox;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var appbox
|
||||
*/
|
||||
protected $appbox;
|
||||
/**
|
||||
*
|
||||
* @var API_OAuth2_Account
|
||||
*/
|
||||
protected $account;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var API_OAuth2_Account
|
||||
*/
|
||||
protected $account;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $token;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $token;
|
||||
/**
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $session_id;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $session_id;
|
||||
/**
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $expires;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $expires;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $scope;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $scope;
|
||||
/**
|
||||
*
|
||||
* @param appbox $appbox
|
||||
* @param API_OAuth2_Account $account
|
||||
* @return API_OAuth2_Token
|
||||
*/
|
||||
public function __construct(appbox &$appbox, API_OAuth2_Account &$account)
|
||||
{
|
||||
$this->appbox = $appbox;
|
||||
$this->account = $account;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param appbox $appbox
|
||||
* @param API_OAuth2_Account $account
|
||||
* @return API_OAuth2_Token
|
||||
*/
|
||||
public function __construct(appbox &$appbox, API_OAuth2_Account &$account)
|
||||
{
|
||||
$this->appbox = $appbox;
|
||||
$this->account = $account;
|
||||
|
||||
$sql = 'SELECT oauth_token, session_id, UNIX_TIMESTAMP(expires) as expires, scope
|
||||
$sql = 'SELECT oauth_token, session_id, UNIX_TIMESTAMP(expires) as expires, scope
|
||||
FROM api_oauth_tokens
|
||||
WHERE api_account_id = :account_id';
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute(array(':account_id' => $this->account->get_id()));
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute(array(':account_id' => $this->account->get_id()));
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if (!$row)
|
||||
throw new Exception_NotFound();
|
||||
if ( ! $row)
|
||||
throw new Exception_NotFound();
|
||||
|
||||
$stmt->closeCursor();
|
||||
$stmt->closeCursor();
|
||||
|
||||
$this->token = $row['oauth_token'];
|
||||
$this->session_id = is_null($row['session_id']) ? null : (int) $row['session_id'];
|
||||
$this->expires = $row['expires'];
|
||||
$this->scope = $row['scope'];
|
||||
$this->token = $row['oauth_token'];
|
||||
$this->session_id = is_null($row['session_id']) ? null : (int) $row['session_id'];
|
||||
$this->expires = $row['expires'];
|
||||
$this->scope = $row['scope'];
|
||||
|
||||
return $this;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_value()
|
||||
{
|
||||
return $this->token;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_value()
|
||||
{
|
||||
return $this->token;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $oauth_token
|
||||
* @return API_OAuth2_Token
|
||||
*/
|
||||
public function set_value($oauth_token)
|
||||
{
|
||||
$sql = 'UPDATE api_oauth_tokens SET oauth_token = :oauth_token
|
||||
/**
|
||||
*
|
||||
* @param string $oauth_token
|
||||
* @return API_OAuth2_Token
|
||||
*/
|
||||
public function set_value($oauth_token)
|
||||
{
|
||||
$sql = 'UPDATE api_oauth_tokens SET oauth_token = :oauth_token
|
||||
WHERE oauth_token = :current_token';
|
||||
|
||||
$params = array(
|
||||
':oauth_token' => $oauth_token
|
||||
, ':current_token' => $this->token
|
||||
);
|
||||
$params = array(
|
||||
':oauth_token' => $oauth_token
|
||||
, ':current_token' => $this->token
|
||||
);
|
||||
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$this->token = $oauth_token;
|
||||
$this->token = $oauth_token;
|
||||
|
||||
return $this;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function get_session_id()
|
||||
{
|
||||
return $this->session_id;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function get_session_id()
|
||||
{
|
||||
return $this->session_id;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param int $session_id
|
||||
* @return API_OAuth2_Token
|
||||
*/
|
||||
public function set_session_id($session_id)
|
||||
{
|
||||
$sql = 'UPDATE api_oauth_tokens SET session_id = :session_id
|
||||
/**
|
||||
*
|
||||
* @param int $session_id
|
||||
* @return API_OAuth2_Token
|
||||
*/
|
||||
public function set_session_id($session_id)
|
||||
{
|
||||
$sql = 'UPDATE api_oauth_tokens SET session_id = :session_id
|
||||
WHERE oauth_token = :current_token';
|
||||
|
||||
$params = array(
|
||||
':session_id' => $session_id
|
||||
, ':current_token' => $this->token
|
||||
);
|
||||
$params = array(
|
||||
':session_id' => $session_id
|
||||
, ':current_token' => $this->token
|
||||
);
|
||||
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$this->session_id = (int) $session_id;
|
||||
$this->session_id = (int) $session_id;
|
||||
|
||||
return $this;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function get_expires()
|
||||
{
|
||||
return $this->expires;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function get_expires()
|
||||
{
|
||||
return $this->expires;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param int $expires
|
||||
* @return API_OAuth2_Token
|
||||
*/
|
||||
public function set_expires($expires)
|
||||
{
|
||||
$sql = 'UPDATE api_oauth_tokens SET expires = FROM_UNIXTIME(:expires)
|
||||
/**
|
||||
*
|
||||
* @param int $expires
|
||||
* @return API_OAuth2_Token
|
||||
*/
|
||||
public function set_expires($expires)
|
||||
{
|
||||
$sql = 'UPDATE api_oauth_tokens SET expires = FROM_UNIXTIME(:expires)
|
||||
WHERE oauth_token = :oauth_token';
|
||||
|
||||
$params = array(
|
||||
':expires' => $expires
|
||||
, ':oauth_token' => $this->get_value()
|
||||
);
|
||||
$params = array(
|
||||
':expires' => $expires
|
||||
, ':oauth_token' => $this->get_value()
|
||||
);
|
||||
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$this->expires = $expires;
|
||||
$this->expires = $expires;
|
||||
|
||||
return $this;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_scope()
|
||||
{
|
||||
return $this->scope;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_scope()
|
||||
{
|
||||
return $this->scope;
|
||||
}
|
||||
|
||||
public function set_scope($scope)
|
||||
{
|
||||
$sql = 'UPDATE api_oauth_tokens SET scope = :scope
|
||||
public function set_scope($scope)
|
||||
{
|
||||
$sql = 'UPDATE api_oauth_tokens SET scope = :scope
|
||||
WHERE oauth_token = :oauth_token';
|
||||
|
||||
$params = array(
|
||||
':scope' => $scope
|
||||
, ':oauth_token' => $this->get_value()
|
||||
);
|
||||
$params = array(
|
||||
':scope' => $scope
|
||||
, ':oauth_token' => $this->get_value()
|
||||
);
|
||||
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$this->scope = $scope;
|
||||
$this->scope = $scope;
|
||||
|
||||
return $this;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return API_OAuth2_Account
|
||||
*/
|
||||
public function get_account()
|
||||
{
|
||||
return $this->account;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @return API_OAuth2_Account
|
||||
*/
|
||||
public function get_account()
|
||||
{
|
||||
return $this->account;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return API_OAuth2_Token
|
||||
*/
|
||||
public function renew()
|
||||
{
|
||||
$sql = 'UPDATE api_oauth_tokens SET oauth_token = :new_token
|
||||
/**
|
||||
*
|
||||
* @return API_OAuth2_Token
|
||||
*/
|
||||
public function renew()
|
||||
{
|
||||
$sql = 'UPDATE api_oauth_tokens SET oauth_token = :new_token
|
||||
WHERE oauth_token = :old_token';
|
||||
|
||||
$new_token = self::generate_token();
|
||||
$new_token = self::generate_token();
|
||||
|
||||
$params = array(
|
||||
':new_token' => $new_token
|
||||
, ':old_token' => $this->get_value()
|
||||
);
|
||||
$params = array(
|
||||
':new_token' => $new_token
|
||||
, ':old_token' => $this->get_value()
|
||||
);
|
||||
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$this->token = $new_token;
|
||||
$this->token = $new_token;
|
||||
|
||||
return $this;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
$sql = 'DELETE FROM api_oauth_tokens WHERE oauth_token = :oauth_token';
|
||||
/**
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
$sql = 'DELETE FROM api_oauth_tokens WHERE oauth_token = :oauth_token';
|
||||
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute(array(':oauth_token' => $this->get_value()));
|
||||
$stmt->closeCursor();
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute(array(':oauth_token' => $this->get_value()));
|
||||
$stmt->closeCursor();
|
||||
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param appbox $appbox
|
||||
* @param type $oauth_token
|
||||
* @return API_OAuth2_Token
|
||||
*/
|
||||
public static function load_by_oauth_token(appbox &$appbox, $oauth_token)
|
||||
{
|
||||
$sql = 'SELECT a.api_account_id
|
||||
/**
|
||||
*
|
||||
* @param appbox $appbox
|
||||
* @param type $oauth_token
|
||||
* @return API_OAuth2_Token
|
||||
*/
|
||||
public static function load_by_oauth_token(appbox &$appbox, $oauth_token)
|
||||
{
|
||||
$sql = 'SELECT a.api_account_id
|
||||
FROM api_oauth_tokens a, api_accounts b
|
||||
WHERE a.oauth_token = :oauth_token
|
||||
AND a.api_account_id = b.api_account_id';
|
||||
|
||||
$stmt = $appbox->get_connection()->prepare($sql);
|
||||
$params = array(":oauth_token" => $oauth_token);
|
||||
$stmt->execute($params);
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
$stmt = $appbox->get_connection()->prepare($sql);
|
||||
$params = array(":oauth_token" => $oauth_token);
|
||||
$stmt->execute($params);
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
if (!$row)
|
||||
throw new Exception_NotFound();
|
||||
if ( ! $row)
|
||||
throw new Exception_NotFound();
|
||||
|
||||
$account = new API_OAuth2_Account($appbox, $row['api_account_id']);
|
||||
$account = new API_OAuth2_Account($appbox, $row['api_account_id']);
|
||||
|
||||
return new self($appbox, $account);
|
||||
}
|
||||
return new self($appbox, $account);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param appbox $appbox
|
||||
* @param API_OAuth2_Account $account
|
||||
* @param string $scope
|
||||
* @return API_OAuth2_Token
|
||||
*/
|
||||
public static function create(appbox &$appbox, API_OAuth2_Account &$account, $scope = null)
|
||||
{
|
||||
$sql = 'INSERT INTO api_oauth_tokens
|
||||
/**
|
||||
*
|
||||
* @param appbox $appbox
|
||||
* @param API_OAuth2_Account $account
|
||||
* @param string $scope
|
||||
* @return API_OAuth2_Token
|
||||
*/
|
||||
public static function create(appbox &$appbox, API_OAuth2_Account &$account, $scope = null)
|
||||
{
|
||||
$sql = 'INSERT INTO api_oauth_tokens
|
||||
(oauth_token, session_id, api_account_id, expires, scope)
|
||||
VALUES (:token, null, :account_id, :expire, :scope)';
|
||||
|
||||
$params = array(
|
||||
':token' => self::generate_token()
|
||||
, ':account_id' => $account->get_id()
|
||||
, ':expire' => time() + 3600
|
||||
, ':scope' => $scope
|
||||
);
|
||||
$params = array(
|
||||
':token' => self::generate_token()
|
||||
, ':account_id' => $account->get_id()
|
||||
, ':expire' => time() + 3600
|
||||
, ':scope' => $scope
|
||||
);
|
||||
|
||||
$stmt = $appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
$stmt = $appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
|
||||
return new API_OAuth2_Token($appbox, $account);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function generate_token()
|
||||
{
|
||||
return md5(base64_encode(pack('N6', mt_rand(), mt_rand(), mt_rand(), mt_rand(), mt_rand(), uniqid())));
|
||||
}
|
||||
return new API_OAuth2_Token($appbox, $account);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function generate_token()
|
||||
{
|
||||
return md5(base64_encode(pack('N6', mt_rand(), mt_rand(), mt_rand(), mt_rand(), mt_rand(), uniqid())));
|
||||
}
|
||||
}
|
||||
|
@@ -17,300 +17,301 @@
|
||||
*/
|
||||
interface API_V1_Interface
|
||||
{
|
||||
public function get_version();
|
||||
|
||||
/**
|
||||
* Route : /databoxes/list/FORMAT/
|
||||
*
|
||||
* Method : GET
|
||||
*
|
||||
* Parameters :
|
||||
*
|
||||
*/
|
||||
public function get_databoxes(\Symfony\Component\HttpFoundation\Request $request);
|
||||
public function get_version();
|
||||
|
||||
/**
|
||||
* Route /databoxes/DATABOX_ID/collections/FORMAT/
|
||||
*
|
||||
* Method : GET
|
||||
*
|
||||
* Parameters ;
|
||||
* DATABOX_ID : required INT
|
||||
*/
|
||||
public function get_databox_collections(\Symfony\Component\HttpFoundation\Request $request, $databox_id);
|
||||
/**
|
||||
* Route : /databoxes/list/FORMAT/
|
||||
*
|
||||
* Method : GET
|
||||
*
|
||||
* Parameters :
|
||||
*
|
||||
*/
|
||||
public function get_databoxes(\Symfony\Component\HttpFoundation\Request $request);
|
||||
|
||||
/**
|
||||
* Route /databoxes/DATABOX_ID/status/FORMAT/
|
||||
*
|
||||
* Method : GET
|
||||
*
|
||||
* Parameters ;
|
||||
* DATABOX_ID : required INT
|
||||
*/
|
||||
public function get_databox_status(\Symfony\Component\HttpFoundation\Request $request, $databox_id);
|
||||
/**
|
||||
* Route /databoxes/DATABOX_ID/collections/FORMAT/
|
||||
*
|
||||
* Method : GET
|
||||
*
|
||||
* Parameters ;
|
||||
* DATABOX_ID : required INT
|
||||
*/
|
||||
public function get_databox_collections(\Symfony\Component\HttpFoundation\Request $request, $databox_id);
|
||||
|
||||
/**
|
||||
* Route /databoxes/DATABOX_ID/metadatas/FORMAT/
|
||||
*
|
||||
* Method : GET
|
||||
*
|
||||
* Parameters ;
|
||||
* DATABOX_ID : required INT
|
||||
*/
|
||||
public function get_databox_metadatas(\Symfony\Component\HttpFoundation\Request $request, $databox_id);
|
||||
/**
|
||||
* Route /databoxes/DATABOX_ID/status/FORMAT/
|
||||
*
|
||||
* Method : GET
|
||||
*
|
||||
* Parameters ;
|
||||
* DATABOX_ID : required INT
|
||||
*/
|
||||
public function get_databox_status(\Symfony\Component\HttpFoundation\Request $request, $databox_id);
|
||||
|
||||
/**
|
||||
* Route /databoxes/DATABOX_ID/termsOfUse/FORMAT/
|
||||
*
|
||||
* Method : GET
|
||||
*
|
||||
* Parameters ;
|
||||
* DATABOX_ID : required INT
|
||||
*/
|
||||
public function get_databox_terms(\Symfony\Component\HttpFoundation\Request $request, $databox_id);
|
||||
/**
|
||||
* Route /databoxes/DATABOX_ID/metadatas/FORMAT/
|
||||
*
|
||||
* Method : GET
|
||||
*
|
||||
* Parameters ;
|
||||
* DATABOX_ID : required INT
|
||||
*/
|
||||
public function get_databox_metadatas(\Symfony\Component\HttpFoundation\Request $request, $databox_id);
|
||||
|
||||
/**
|
||||
* Route : /records/search/FORMAT/
|
||||
*
|
||||
* Method : GET or POST
|
||||
*
|
||||
* Parameters :
|
||||
* bases[] : array
|
||||
* status[] : array
|
||||
* fields[] : array
|
||||
* record_type : boolean
|
||||
* media_type : string
|
||||
*
|
||||
* Response :
|
||||
* Array of record objects
|
||||
*
|
||||
*/
|
||||
public function search_records(\Symfony\Component\HttpFoundation\Request $request);
|
||||
/**
|
||||
* Route /databoxes/DATABOX_ID/termsOfUse/FORMAT/
|
||||
*
|
||||
* Method : GET
|
||||
*
|
||||
* Parameters ;
|
||||
* DATABOX_ID : required INT
|
||||
*/
|
||||
public function get_databox_terms(\Symfony\Component\HttpFoundation\Request $request, $databox_id);
|
||||
|
||||
/**
|
||||
* Route : /records/DATABOX_ID/RECORD_ID/related/FORMAT/
|
||||
*
|
||||
* Method : GET
|
||||
*
|
||||
* Parameters :
|
||||
* DATABOX_ID : required INT
|
||||
* RECORD_ID : required INT
|
||||
*
|
||||
*/
|
||||
public function get_record_related(\Symfony\Component\HttpFoundation\Request $request, $databox_id, $record_id);
|
||||
/**
|
||||
* Route : /records/search/FORMAT/
|
||||
*
|
||||
* Method : GET or POST
|
||||
*
|
||||
* Parameters :
|
||||
* bases[] : array
|
||||
* status[] : array
|
||||
* fields[] : array
|
||||
* record_type : boolean
|
||||
* media_type : string
|
||||
*
|
||||
* Response :
|
||||
* Array of record objects
|
||||
*
|
||||
*/
|
||||
public function search_records(\Symfony\Component\HttpFoundation\Request $request);
|
||||
|
||||
/**
|
||||
* Route : /records/DATABOX_ID/RECORD_ID/metadatas/FORMAT/
|
||||
*
|
||||
* Method : GET
|
||||
*
|
||||
* Parameters :
|
||||
* DATABOX_ID : required INT
|
||||
* RECORD_ID : required INT
|
||||
*
|
||||
*/
|
||||
public function get_record_metadatas(\Symfony\Component\HttpFoundation\Request $request, $databox_id, $record_id);
|
||||
/**
|
||||
* Route : /records/DATABOX_ID/RECORD_ID/related/FORMAT/
|
||||
*
|
||||
* Method : GET
|
||||
*
|
||||
* Parameters :
|
||||
* DATABOX_ID : required INT
|
||||
* RECORD_ID : required INT
|
||||
*
|
||||
*/
|
||||
public function get_record_related(\Symfony\Component\HttpFoundation\Request $request, $databox_id, $record_id);
|
||||
|
||||
/**
|
||||
* Route : /records/DATABOX_ID/RECORD_ID/status/FORMAT/
|
||||
*
|
||||
* Method : GET
|
||||
*
|
||||
* Parameters :
|
||||
* DATABOX_ID : required INT
|
||||
* RECORD_ID : required INT
|
||||
*
|
||||
*/
|
||||
public function get_record_status(\Symfony\Component\HttpFoundation\Request $request, $databox_id, $record_id);
|
||||
/**
|
||||
* Route : /records/DATABOX_ID/RECORD_ID/metadatas/FORMAT/
|
||||
*
|
||||
* Method : GET
|
||||
*
|
||||
* Parameters :
|
||||
* DATABOX_ID : required INT
|
||||
* RECORD_ID : required INT
|
||||
*
|
||||
*/
|
||||
public function get_record_metadatas(\Symfony\Component\HttpFoundation\Request $request, $databox_id, $record_id);
|
||||
|
||||
/**
|
||||
* Route : /records/DATABOX_ID/RECORD_ID/embed/FORMAT/
|
||||
*
|
||||
* Method : GET
|
||||
*
|
||||
* Parameters :
|
||||
* DATABOX_ID : required INT
|
||||
* RECORD_ID : required INT
|
||||
*
|
||||
*/
|
||||
public function get_record_embed(\Symfony\Component\HttpFoundation\Request $request, $databox_id, $record_id);
|
||||
/**
|
||||
* Route : /records/DATABOX_ID/RECORD_ID/status/FORMAT/
|
||||
*
|
||||
* Method : GET
|
||||
*
|
||||
* Parameters :
|
||||
* DATABOX_ID : required INT
|
||||
* RECORD_ID : required INT
|
||||
*
|
||||
*/
|
||||
public function get_record_status(\Symfony\Component\HttpFoundation\Request $request, $databox_id, $record_id);
|
||||
|
||||
/**
|
||||
* Route : /records/DATABOX_ID/RECORD_ID/setmetadatas/FORMAT/
|
||||
*
|
||||
* Method : POST
|
||||
*
|
||||
* Parameters :
|
||||
* DATABOX_ID : required INT
|
||||
* RECORD_ID : required INT
|
||||
*
|
||||
*/
|
||||
public function set_record_metadatas(\Symfony\Component\HttpFoundation\Request $request, $databox_id, $record_id);
|
||||
/**
|
||||
* Route : /records/DATABOX_ID/RECORD_ID/embed/FORMAT/
|
||||
*
|
||||
* Method : GET
|
||||
*
|
||||
* Parameters :
|
||||
* DATABOX_ID : required INT
|
||||
* RECORD_ID : required INT
|
||||
*
|
||||
*/
|
||||
public function get_record_embed(\Symfony\Component\HttpFoundation\Request $request, $databox_id, $record_id);
|
||||
|
||||
/**
|
||||
* Route : /records/DATABOX_ID/RECORD_ID/setstatus/FORMAT/
|
||||
*
|
||||
* Method : POST
|
||||
*
|
||||
* Parameters :
|
||||
* DATABOX_ID : required INT
|
||||
* RECORD_ID : required INT
|
||||
*
|
||||
*/
|
||||
public function set_record_status(\Symfony\Component\HttpFoundation\Request $request, $databox_id, $record_id);
|
||||
/**
|
||||
* Route : /records/DATABOX_ID/RECORD_ID/setmetadatas/FORMAT/
|
||||
*
|
||||
* Method : POST
|
||||
*
|
||||
* Parameters :
|
||||
* DATABOX_ID : required INT
|
||||
* RECORD_ID : required INT
|
||||
*
|
||||
*/
|
||||
public function set_record_metadatas(\Symfony\Component\HttpFoundation\Request $request, $databox_id, $record_id);
|
||||
|
||||
/**
|
||||
* Route : /records/DATABOX_ID/RECORD_ID/setcollection/FORMAT/
|
||||
*
|
||||
* Method : POST
|
||||
*
|
||||
* Parameters :
|
||||
* DATABOX_ID : required INT
|
||||
* RECORD_ID : required INT
|
||||
*
|
||||
*/
|
||||
public function set_record_collection(\Symfony\Component\HttpFoundation\Request $request, $databox_id, $record_id);
|
||||
/**
|
||||
* Route : /records/DATABOX_ID/RECORD_ID/setstatus/FORMAT/
|
||||
*
|
||||
* Method : POST
|
||||
*
|
||||
* Parameters :
|
||||
* DATABOX_ID : required INT
|
||||
* RECORD_ID : required INT
|
||||
*
|
||||
*/
|
||||
public function set_record_status(\Symfony\Component\HttpFoundation\Request $request, $databox_id, $record_id);
|
||||
|
||||
/**
|
||||
* Route : /records/DATABOX_ID/RECORD_ID/addtobasket/FORMAT/
|
||||
*
|
||||
* Method : POST
|
||||
*
|
||||
* Parameters :
|
||||
* DATABOX_ID : required INT
|
||||
* RECORD_ID : required INT
|
||||
*
|
||||
*/
|
||||
public function add_record_tobasket(\Symfony\Component\HttpFoundation\Request $request, $databox_id, $record_id);
|
||||
/**
|
||||
* Route : /records/DATABOX_ID/RECORD_ID/setcollection/FORMAT/
|
||||
*
|
||||
* Method : POST
|
||||
*
|
||||
* Parameters :
|
||||
* DATABOX_ID : required INT
|
||||
* RECORD_ID : required INT
|
||||
*
|
||||
*/
|
||||
public function set_record_collection(\Symfony\Component\HttpFoundation\Request $request, $databox_id, $record_id);
|
||||
|
||||
/**
|
||||
* Route : /baskets/list/FORMAT/
|
||||
*
|
||||
* Method : POST
|
||||
*
|
||||
* Parameters :
|
||||
*
|
||||
*/
|
||||
public function search_baskets(\Symfony\Component\HttpFoundation\Request $request);
|
||||
/**
|
||||
* Route : /records/DATABOX_ID/RECORD_ID/addtobasket/FORMAT/
|
||||
*
|
||||
* Method : POST
|
||||
*
|
||||
* Parameters :
|
||||
* DATABOX_ID : required INT
|
||||
* RECORD_ID : required INT
|
||||
*
|
||||
*/
|
||||
public function add_record_tobasket(\Symfony\Component\HttpFoundation\Request $request, $databox_id, $record_id);
|
||||
|
||||
/**
|
||||
* Route : /baskets/add/FORMAT/
|
||||
*
|
||||
* Method : POST
|
||||
*
|
||||
* Parameters :
|
||||
*
|
||||
*/
|
||||
public function create_basket(\Symfony\Component\HttpFoundation\Request $request);
|
||||
/**
|
||||
* Route : /baskets/list/FORMAT/
|
||||
*
|
||||
* Method : POST
|
||||
*
|
||||
* Parameters :
|
||||
*
|
||||
*/
|
||||
public function search_baskets(\Symfony\Component\HttpFoundation\Request $request);
|
||||
|
||||
/**
|
||||
* Route : /baskets/BASKET_ID/delete/FORMAT/
|
||||
*
|
||||
* Method : POST
|
||||
*
|
||||
* Parameters :
|
||||
* BASKET_ID : required INT
|
||||
*
|
||||
*/
|
||||
public function delete_basket(\Symfony\Component\HttpFoundation\Request $request, $basket_id);
|
||||
/**
|
||||
* Route : /baskets/add/FORMAT/
|
||||
*
|
||||
* Method : POST
|
||||
*
|
||||
* Parameters :
|
||||
*
|
||||
*/
|
||||
public function create_basket(\Symfony\Component\HttpFoundation\Request $request);
|
||||
|
||||
/**
|
||||
* Route : /baskets/BASKET_ID/content/FORMAT/
|
||||
*
|
||||
* Method : POST
|
||||
*
|
||||
* Parameters :
|
||||
* BASKET_ID : required INT
|
||||
*
|
||||
*/
|
||||
public function get_basket(\Symfony\Component\HttpFoundation\Request $request, $basket_id);
|
||||
/**
|
||||
* Route : /baskets/BASKET_ID/delete/FORMAT/
|
||||
*
|
||||
* Method : POST
|
||||
*
|
||||
* Parameters :
|
||||
* BASKET_ID : required INT
|
||||
*
|
||||
*/
|
||||
public function delete_basket(\Symfony\Component\HttpFoundation\Request $request, $basket_id);
|
||||
|
||||
/**
|
||||
* Route : /baskets/BASKET_ID/title/FORMAT/
|
||||
*
|
||||
* Method : GET
|
||||
*
|
||||
* Parameters :
|
||||
* BASKET_ID : required INT
|
||||
*
|
||||
*/
|
||||
public function set_basket_title(\Symfony\Component\HttpFoundation\Request $request, $basket_id);
|
||||
/**
|
||||
* Route : /baskets/BASKET_ID/content/FORMAT/
|
||||
*
|
||||
* Method : POST
|
||||
*
|
||||
* Parameters :
|
||||
* BASKET_ID : required INT
|
||||
*
|
||||
*/
|
||||
public function get_basket(\Symfony\Component\HttpFoundation\Request $request, $basket_id);
|
||||
|
||||
/**
|
||||
* Route : /baskets/BASKET_ID/description/FORMAT/
|
||||
*
|
||||
* Method : POST
|
||||
*
|
||||
* Parameters :
|
||||
* BASKET_ID : required INT
|
||||
*
|
||||
*/
|
||||
public function set_basket_description(\Symfony\Component\HttpFoundation\Request $request, $basket_id);
|
||||
/**
|
||||
* Route : /baskets/BASKET_ID/title/FORMAT/
|
||||
*
|
||||
* Method : GET
|
||||
*
|
||||
* Parameters :
|
||||
* BASKET_ID : required INT
|
||||
*
|
||||
*/
|
||||
public function set_basket_title(\Symfony\Component\HttpFoundation\Request $request, $basket_id);
|
||||
|
||||
/**
|
||||
* Route : /publications/list/FORMAT/
|
||||
*
|
||||
* Method : POST
|
||||
*
|
||||
* Parameters :
|
||||
*
|
||||
*/
|
||||
public function search_publications(\Symfony\Component\HttpFoundation\Request $request, User_Adapter &$user);
|
||||
/**
|
||||
* Route : /baskets/BASKET_ID/description/FORMAT/
|
||||
*
|
||||
* Method : POST
|
||||
*
|
||||
* Parameters :
|
||||
* BASKET_ID : required INT
|
||||
*
|
||||
*/
|
||||
public function set_basket_description(\Symfony\Component\HttpFoundation\Request $request, $basket_id);
|
||||
|
||||
/**
|
||||
* Route : /publications/PUBLICATION_ID/remove/FORMAT/
|
||||
*
|
||||
* Method : GET
|
||||
*
|
||||
* Parameters :
|
||||
* PUBLICATION_ID : required INT
|
||||
*
|
||||
*/
|
||||
public function remove_publications(\Symfony\Component\HttpFoundation\Request $request, $publication_id);
|
||||
/**
|
||||
* Route : /publications/list/FORMAT/
|
||||
*
|
||||
* Method : POST
|
||||
*
|
||||
* Parameters :
|
||||
*
|
||||
*/
|
||||
public function search_publications(\Symfony\Component\HttpFoundation\Request $request, User_Adapter &$user);
|
||||
|
||||
/**
|
||||
* Route : /publications/PUBLICATION_ID/content/FORMAT/
|
||||
*
|
||||
* Method : GET
|
||||
*
|
||||
* Parameters :
|
||||
* PUBLICATION_ID : required INT
|
||||
*
|
||||
*/
|
||||
public function get_publication(\Symfony\Component\HttpFoundation\Request $request, $publication_id, User_Adapter &$user);
|
||||
/**
|
||||
* Route : /publications/PUBLICATION_ID/remove/FORMAT/
|
||||
*
|
||||
* Method : GET
|
||||
*
|
||||
* Parameters :
|
||||
* PUBLICATION_ID : required INT
|
||||
*
|
||||
*/
|
||||
public function remove_publications(\Symfony\Component\HttpFoundation\Request $request, $publication_id);
|
||||
|
||||
/**
|
||||
* Route : /users/search/FORMAT/
|
||||
*
|
||||
* Method : POST-GET
|
||||
*
|
||||
* Parameters :
|
||||
*
|
||||
*/
|
||||
public function search_users(\Symfony\Component\HttpFoundation\Request $request);
|
||||
/**
|
||||
* Route : /publications/PUBLICATION_ID/content/FORMAT/
|
||||
*
|
||||
* Method : GET
|
||||
*
|
||||
* Parameters :
|
||||
* PUBLICATION_ID : required INT
|
||||
*
|
||||
*/
|
||||
public function get_publication(\Symfony\Component\HttpFoundation\Request $request, $publication_id, User_Adapter &$user);
|
||||
|
||||
/**
|
||||
* Route : /users/USER_ID/access/FORMAT/
|
||||
*
|
||||
* Method : GET
|
||||
*
|
||||
* Parameters :
|
||||
* USER_ID : required INT
|
||||
*
|
||||
*/
|
||||
public function get_user_acces(\Symfony\Component\HttpFoundation\Request $request, $usr_id);
|
||||
/**
|
||||
* Route : /users/search/FORMAT/
|
||||
*
|
||||
* Method : POST-GET
|
||||
*
|
||||
* Parameters :
|
||||
*
|
||||
*/
|
||||
public function search_users(\Symfony\Component\HttpFoundation\Request $request);
|
||||
|
||||
/**
|
||||
* Route : /users/add/FORMAT/
|
||||
*
|
||||
* Method : POST
|
||||
*
|
||||
* Parameters :
|
||||
*
|
||||
*/
|
||||
public function add_user(\Symfony\Component\HttpFoundation\Request $request);
|
||||
/**
|
||||
* Route : /users/USER_ID/access/FORMAT/
|
||||
*
|
||||
* Method : GET
|
||||
*
|
||||
* Parameters :
|
||||
* USER_ID : required INT
|
||||
*
|
||||
*/
|
||||
public function get_user_acces(\Symfony\Component\HttpFoundation\Request $request, $usr_id);
|
||||
|
||||
public function get_error_message(\Symfony\Component\HttpFoundation\Request $request, $error);
|
||||
/**
|
||||
* Route : /users/add/FORMAT/
|
||||
*
|
||||
* Method : POST
|
||||
*
|
||||
* Parameters :
|
||||
*
|
||||
*/
|
||||
public function add_user(\Symfony\Component\HttpFoundation\Request $request);
|
||||
|
||||
public function get_error_code(\Symfony\Component\HttpFoundation\Request $request, $code);
|
||||
public function get_error_message(\Symfony\Component\HttpFoundation\Request $request, $error);
|
||||
|
||||
public function get_error_code(\Symfony\Component\HttpFoundation\Request $request, $code);
|
||||
}
|
||||
|
@@ -10,89 +10,89 @@ use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class API_V1_Log
|
||||
{
|
||||
const DATABOXES_RESSOURCE = 'databoxes';
|
||||
const RECORDS_RESSOURCE = 'record';
|
||||
const BASKETS_RESSOURCE = 'baskets';
|
||||
const FEEDS_RESSOURCE = 'feeds';
|
||||
|
||||
const DATABOXES_RESSOURCE = 'databoxes';
|
||||
const RECORDS_RESSOURCE = 'record';
|
||||
const BASKETS_RESSOURCE = 'baskets';
|
||||
const FEEDS_RESSOURCE = 'feeds';
|
||||
/**
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $id;
|
||||
/**
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $account_id;
|
||||
/**
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $account_id;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var DateTime
|
||||
*/
|
||||
protected $date;
|
||||
/**
|
||||
*
|
||||
* @var DateTime
|
||||
*/
|
||||
protected $date;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $status_code;
|
||||
/**
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $status_code;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $format;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $format;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $ressource;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $ressource;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $general;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $general;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $aspect;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $aspect;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $action;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $action;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var API_OAuth2_Account
|
||||
*/
|
||||
protected $account;
|
||||
/**
|
||||
*
|
||||
* @var API_OAuth2_Account
|
||||
*/
|
||||
protected $account;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var appbox
|
||||
*/
|
||||
protected $appbox;
|
||||
/**
|
||||
*
|
||||
* @var appbox
|
||||
*/
|
||||
protected $appbox;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param appbox $appbox
|
||||
* @param Request $request
|
||||
* @param API_OAuth2_Account $account
|
||||
*/
|
||||
public function __construct(appbox &$appbox, $log_id)
|
||||
{
|
||||
$this->appbox = $appbox;
|
||||
$this->id = (int) $log_id;
|
||||
/**
|
||||
*
|
||||
* @param appbox $appbox
|
||||
* @param Request $request
|
||||
* @param API_OAuth2_Account $account
|
||||
*/
|
||||
public function __construct(appbox &$appbox, $log_id)
|
||||
{
|
||||
$this->appbox = $appbox;
|
||||
$this->id = (int) $log_id;
|
||||
|
||||
$sql = '
|
||||
$sql = '
|
||||
SELECT
|
||||
api_log_id,
|
||||
api_account_id,
|
||||
@@ -109,239 +109,238 @@ class API_V1_Log
|
||||
WHERE
|
||||
api_log_id = :log_id';
|
||||
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute(array(':log_id' => $this->id));
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute(array(':log_id' => $this->id));
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$this->account_id = $row['api_account_id'];
|
||||
$this->account = new API_OAuth2_Account($this->appbox, (int) $row['api_account_id']);
|
||||
$this->aspect = $row['api_log_aspect'];
|
||||
$this->date = new DateTime($row['api_log_date']);
|
||||
$this->format = $row['api_log_format'];
|
||||
$this->general = $row['api_log_general'];
|
||||
$this->ressource = $row['api_log_ressource'];
|
||||
$this->status_code = (int) $row['api_log_status_code'];
|
||||
$this->account_id = $row['api_account_id'];
|
||||
$this->account = new API_OAuth2_Account($this->appbox, (int) $row['api_account_id']);
|
||||
$this->aspect = $row['api_log_aspect'];
|
||||
$this->date = new DateTime($row['api_log_date']);
|
||||
$this->format = $row['api_log_format'];
|
||||
$this->general = $row['api_log_general'];
|
||||
$this->ressource = $row['api_log_ressource'];
|
||||
$this->status_code = (int) $row['api_log_status_code'];
|
||||
|
||||
return $this;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function get_account_id()
|
||||
{
|
||||
return $this->account_id;
|
||||
}
|
||||
public function get_account_id()
|
||||
{
|
||||
return $this->account_id;
|
||||
}
|
||||
|
||||
public function set_account_id($account_id)
|
||||
{
|
||||
$this->account_id = $account_id;
|
||||
public function set_account_id($account_id)
|
||||
{
|
||||
$this->account_id = $account_id;
|
||||
|
||||
$sql = 'UPDATE api_log
|
||||
$sql = 'UPDATE api_log
|
||||
SET api_account_id = :account_id
|
||||
WHERE api_log_id = :log_id';
|
||||
|
||||
$params = array(
|
||||
':api_account_id' => $this->account_id
|
||||
, ':log_id' => $this->id
|
||||
);
|
||||
$params = array(
|
||||
':api_account_id' => $this->account_id
|
||||
, ':log_id' => $this->id
|
||||
);
|
||||
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
|
||||
return $this;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function get_date()
|
||||
{
|
||||
return $this->date;
|
||||
}
|
||||
public function get_date()
|
||||
{
|
||||
return $this->date;
|
||||
}
|
||||
|
||||
public function set_date(DateTime $date)
|
||||
{
|
||||
$this->date = $date;
|
||||
public function set_date(DateTime $date)
|
||||
{
|
||||
$this->date = $date;
|
||||
|
||||
$sql = 'UPDATE api_log
|
||||
$sql = 'UPDATE api_log
|
||||
SET api_log_date = :date
|
||||
WHERE api_log_id = :log_id';
|
||||
|
||||
$params = array(
|
||||
':date' => $this->date->format("Y-m-d H:i:s")
|
||||
, ':log_id' => $this->id
|
||||
);
|
||||
$params = array(
|
||||
':date' => $this->date->format("Y-m-d H:i:s")
|
||||
, ':log_id' => $this->id
|
||||
);
|
||||
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
|
||||
return $this;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function get_status_code()
|
||||
{
|
||||
return $this->status_code;
|
||||
}
|
||||
public function get_status_code()
|
||||
{
|
||||
return $this->status_code;
|
||||
}
|
||||
|
||||
public function set_status_code($status_code)
|
||||
{
|
||||
$this->status_code = (int) $status_code;
|
||||
public function set_status_code($status_code)
|
||||
{
|
||||
$this->status_code = (int) $status_code;
|
||||
|
||||
$sql = 'UPDATE api_log
|
||||
$sql = 'UPDATE api_log
|
||||
SET api_log_status_code = :code
|
||||
WHERE api_log_id = :log_id';
|
||||
|
||||
$params = array(
|
||||
':code' => $this->status_code
|
||||
, ':log_id' => $this->id
|
||||
);
|
||||
$params = array(
|
||||
':code' => $this->status_code
|
||||
, ':log_id' => $this->id
|
||||
);
|
||||
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
|
||||
return $this;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function get_format()
|
||||
{
|
||||
return $this->format;
|
||||
}
|
||||
public function get_format()
|
||||
{
|
||||
return $this->format;
|
||||
}
|
||||
|
||||
public function set_format($format)
|
||||
{
|
||||
public function set_format($format)
|
||||
{
|
||||
|
||||
if (!in_array($format, array('json', 'jsonp', 'yaml', 'unknow')))
|
||||
throw new Exception_InvalidArgument();
|
||||
if ( ! in_array($format, array('json', 'jsonp', 'yaml', 'unknow')))
|
||||
throw new Exception_InvalidArgument();
|
||||
|
||||
$this->format = $format;
|
||||
$this->format = $format;
|
||||
|
||||
$sql = 'UPDATE api_log
|
||||
$sql = 'UPDATE api_log
|
||||
SET api_log_format = :format
|
||||
WHERE api_log_id = :log_id';
|
||||
|
||||
$params = array(
|
||||
':format' => $this->format
|
||||
, ':log_id' => $this->id
|
||||
);
|
||||
$params = array(
|
||||
':format' => $this->format
|
||||
, ':log_id' => $this->id
|
||||
);
|
||||
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
|
||||
return $this;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function get_ressource()
|
||||
{
|
||||
return $this->ressource;
|
||||
}
|
||||
public function get_ressource()
|
||||
{
|
||||
return $this->ressource;
|
||||
}
|
||||
|
||||
public function set_ressource($ressource)
|
||||
{
|
||||
if (!in_array($format, array(self::DATABOXES_RESSOURCE,self::BASKETS_RESSOURCE, self::FEEDS_RESSOURCE, self::RECORDS_RESSOURCE)))
|
||||
throw new Exception_InvalidArgument();
|
||||
public function set_ressource($ressource)
|
||||
{
|
||||
if ( ! in_array($format, array(self::DATABOXES_RESSOURCE, self::BASKETS_RESSOURCE, self::FEEDS_RESSOURCE, self::RECORDS_RESSOURCE)))
|
||||
throw new Exception_InvalidArgument();
|
||||
|
||||
$this->ressource = $ressource;
|
||||
$this->ressource = $ressource;
|
||||
|
||||
$sql = 'UPDATE api_log
|
||||
$sql = 'UPDATE api_log
|
||||
SET api_log_ressource = :ressource
|
||||
WHERE api_log_id = :log_id';
|
||||
|
||||
$params = array(
|
||||
':ressource' => $this->ressource
|
||||
, ':log_id' => $this->id
|
||||
);
|
||||
$params = array(
|
||||
':ressource' => $this->ressource
|
||||
, ':log_id' => $this->id
|
||||
);
|
||||
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
|
||||
return $this;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function get_general()
|
||||
{
|
||||
return $this->general;
|
||||
}
|
||||
public function get_general()
|
||||
{
|
||||
return $this->general;
|
||||
}
|
||||
|
||||
public function set_general($general)
|
||||
{
|
||||
$this->general = $general;
|
||||
public function set_general($general)
|
||||
{
|
||||
$this->general = $general;
|
||||
|
||||
$sql = 'UPDATE api_log
|
||||
$sql = 'UPDATE api_log
|
||||
SET api_log_general = :general
|
||||
WHERE api_log_id = :log_id';
|
||||
|
||||
$params = array(
|
||||
':general' => $this->general
|
||||
, ':log_id' => $this->id
|
||||
);
|
||||
$params = array(
|
||||
':general' => $this->general
|
||||
, ':log_id' => $this->id
|
||||
);
|
||||
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
|
||||
return $this;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function get_aspect()
|
||||
{
|
||||
return $this->aspect;
|
||||
}
|
||||
public function get_aspect()
|
||||
{
|
||||
return $this->aspect;
|
||||
}
|
||||
|
||||
public function set_aspect($aspect)
|
||||
{
|
||||
$this->aspect = $aspect;
|
||||
public function set_aspect($aspect)
|
||||
{
|
||||
$this->aspect = $aspect;
|
||||
|
||||
$sql = 'UPDATE api_log
|
||||
$sql = 'UPDATE api_log
|
||||
SET api_log_aspect = :aspect
|
||||
WHERE api_log_id = :log_id';
|
||||
|
||||
$params = array(
|
||||
':aspect' => $this->aspect
|
||||
, ':log_id' => $this->id
|
||||
);
|
||||
$params = array(
|
||||
':aspect' => $this->aspect
|
||||
, ':log_id' => $this->id
|
||||
);
|
||||
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
|
||||
return $this;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function get_action()
|
||||
{
|
||||
return $this->action;
|
||||
}
|
||||
public function get_action()
|
||||
{
|
||||
return $this->action;
|
||||
}
|
||||
|
||||
public function set_action($action)
|
||||
{
|
||||
$this->action = $action;
|
||||
public function set_action($action)
|
||||
{
|
||||
$this->action = $action;
|
||||
|
||||
$sql = 'UPDATE api_log
|
||||
$sql = 'UPDATE api_log
|
||||
SET api_log_action = :action
|
||||
WHERE api_log_id = :log_id';
|
||||
|
||||
$params = array(
|
||||
':action' => $this->action
|
||||
, ':log_id' => $this->id
|
||||
);
|
||||
$params = array(
|
||||
':action' => $this->action
|
||||
, ':log_id' => $this->id
|
||||
);
|
||||
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
|
||||
return $this;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function get_account()
|
||||
{
|
||||
return $this->account;
|
||||
}
|
||||
public function get_account()
|
||||
{
|
||||
return $this->account;
|
||||
}
|
||||
|
||||
|
||||
public static function create(appbox &$appbox, API_OAuth2_Account $account, $route, $status_code, $format, $ressource, $general = null, $aspect = null, $action = null)
|
||||
{
|
||||
$sql = '
|
||||
public static function create(appbox &$appbox, API_OAuth2_Account $account, $route, $status_code, $format, $ressource, $general = null, $aspect = null, $action = null)
|
||||
{
|
||||
$sql = '
|
||||
INSERT INTO
|
||||
api_logs (
|
||||
api_log_id,
|
||||
@@ -368,23 +367,23 @@ class API_V1_Log
|
||||
:action
|
||||
)';
|
||||
|
||||
$params = array(
|
||||
':account_id' => $account->get_id(),
|
||||
':route' => $route,
|
||||
':status_code' => $status_code,
|
||||
':format' => $format,
|
||||
':ressource' => $ressource,
|
||||
':general' => $general,
|
||||
':aspect' => $aspect,
|
||||
':action' => $action
|
||||
);
|
||||
$params = array(
|
||||
':account_id' => $account->get_id(),
|
||||
':route' => $route,
|
||||
':status_code' => $status_code,
|
||||
':format' => $format,
|
||||
':ressource' => $ressource,
|
||||
':general' => $general,
|
||||
':aspect' => $aspect,
|
||||
':action' => $action
|
||||
);
|
||||
|
||||
$stmt = $appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
$stmt = $appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$log_id = $appbox->get_connection()->lastInsertId();
|
||||
$log_id = $appbox->get_connection()->lastInsertId();
|
||||
|
||||
return new self($appbox, $log_id);
|
||||
}
|
||||
return new self($appbox, $log_id);
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -17,17 +17,15 @@
|
||||
*/
|
||||
abstract class API_V1_exception_abstract extends Exception
|
||||
{
|
||||
protected static $details;
|
||||
|
||||
protected static $details;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
public static function get_details()
|
||||
{
|
||||
return static::$details;
|
||||
}
|
||||
public function __construct()
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
public static function get_details()
|
||||
{
|
||||
return static::$details;
|
||||
}
|
||||
}
|
||||
|
@@ -17,7 +17,6 @@
|
||||
*/
|
||||
class API_V1_exception_badrequest extends API_V1_exception_abstract
|
||||
{
|
||||
|
||||
protected static $details = 'Parameter is invalid or missing';
|
||||
protected static $details = 'Parameter is invalid or missing';
|
||||
|
||||
}
|
||||
|
@@ -17,7 +17,6 @@
|
||||
*/
|
||||
class API_V1_exception_forbidden extends API_V1_exception_abstract
|
||||
{
|
||||
|
||||
protected static $details = 'Access to the requested ressource is forbidden';
|
||||
protected static $details = 'Access to the requested ressource is forbidden';
|
||||
|
||||
}
|
||||
|
@@ -17,7 +17,6 @@
|
||||
*/
|
||||
class API_V1_exception_internalservererror extends API_V1_exception_abstract
|
||||
{
|
||||
|
||||
protected static $details = 'Internal Server Error';
|
||||
protected static $details = 'Internal Server Error';
|
||||
|
||||
}
|
||||
|
@@ -17,7 +17,6 @@
|
||||
*/
|
||||
class API_V1_exception_methodnotallowed extends API_V1_exception_abstract
|
||||
{
|
||||
|
||||
protected static $details = 'Attempting to use POST with a GET-only endpoint, or vice-versa';
|
||||
protected static $details = 'Attempting to use POST with a GET-only endpoint, or vice-versa';
|
||||
|
||||
}
|
||||
|
@@ -17,7 +17,6 @@
|
||||
*/
|
||||
class API_V1_exception_notfound extends API_V1_exception_abstract
|
||||
{
|
||||
|
||||
protected static $details = 'Requested ressource is not found';
|
||||
protected static $details = 'Requested ressource is not found';
|
||||
|
||||
}
|
||||
|
@@ -17,7 +17,6 @@
|
||||
*/
|
||||
class API_V1_exception_unauthorized extends API_V1_exception_abstract
|
||||
{
|
||||
|
||||
protected static $details = 'The OAuth token was provided but was invalid.';
|
||||
protected static $details = 'The OAuth token was provided but was invalid.';
|
||||
|
||||
}
|
||||
|
@@ -21,356 +21,341 @@ use \Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
class API_V1_result
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $api_version;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $api_version;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $response_time;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $response_time;
|
||||
/**
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $http_code = 200;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $http_code = 200;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error_message;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error_message;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error_details;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error_details;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $request;
|
||||
/**
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
protected $response;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
protected $response;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $response_type;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $response_type;
|
||||
/**
|
||||
* Constant for responsetype json
|
||||
*/
|
||||
const FORMAT_JSON = 'json';
|
||||
/**
|
||||
* Constant for responsetype yaml
|
||||
*/
|
||||
const FORMAT_YAML = 'yaml';
|
||||
/**
|
||||
* Constant for responsetype jsonp
|
||||
*/
|
||||
const FORMAT_JSONP = 'jsonp';
|
||||
const ERROR_BAD_REQUEST = 'Bad Request';
|
||||
const ERROR_UNAUTHORIZED = 'Unauthorized';
|
||||
const ERROR_FORBIDDEN = 'Forbidden';
|
||||
const ERROR_NOTFOUND = 'Not Found';
|
||||
const ERROR_METHODNOTALLOWED = 'Method Not Allowed';
|
||||
const ERROR_INTERNALSERVERERROR = 'Internal Server Error';
|
||||
|
||||
/**
|
||||
* Constant for responsetype json
|
||||
*/
|
||||
|
||||
const FORMAT_JSON = 'json';
|
||||
/**
|
||||
* Constant for responsetype yaml
|
||||
*/
|
||||
const FORMAT_YAML = 'yaml';
|
||||
/**
|
||||
* Constant for responsetype jsonp
|
||||
*/
|
||||
const FORMAT_JSONP = 'jsonp';
|
||||
const ERROR_BAD_REQUEST = 'Bad Request';
|
||||
const ERROR_UNAUTHORIZED = 'Unauthorized';
|
||||
const ERROR_FORBIDDEN = 'Forbidden';
|
||||
const ERROR_NOTFOUND = 'Not Found';
|
||||
const ERROR_METHODNOTALLOWED = 'Method Not Allowed';
|
||||
const ERROR_INTERNALSERVERERROR = 'Internal Server Error';
|
||||
|
||||
/**
|
||||
* API v1 Result constructor
|
||||
*
|
||||
* @param Request $request
|
||||
* @param API_V1_adapter $api
|
||||
* @param string $response_type One of the API_V1_result 'FORMAT_*' constants
|
||||
* @return API_V1_result
|
||||
*/
|
||||
public function __construct(Request $request, API_V1_adapter $api)
|
||||
{
|
||||
$date = new DateTime();
|
||||
|
||||
$this->request = $request;
|
||||
$this->api_version = $api->get_version();
|
||||
$this->response_time = $date->format(DATE_ATOM);
|
||||
$this->response = new stdClass();
|
||||
|
||||
$this->parse_response_type();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function parse_response_type()
|
||||
{
|
||||
if (trim($this->request->get('callback')) !== '')
|
||||
|
||||
return $this->response_type = self::FORMAT_JSONP;
|
||||
|
||||
$accept = $this->request->getAcceptableContentTypes();
|
||||
$response_types = array();
|
||||
|
||||
foreach ($accept as $key => $app_type)
|
||||
/**
|
||||
* API v1 Result constructor
|
||||
*
|
||||
* @param Request $request
|
||||
* @param API_V1_adapter $api
|
||||
* @param string $response_type One of the API_V1_result 'FORMAT_*' constants
|
||||
* @return API_V1_result
|
||||
*/
|
||||
public function __construct(Request $request, API_V1_adapter $api)
|
||||
{
|
||||
$response_types[strtolower($app_type)] = true;
|
||||
$date = new DateTime();
|
||||
|
||||
$this->request = $request;
|
||||
$this->api_version = $api->get_version();
|
||||
$this->response_time = $date->format(DATE_ATOM);
|
||||
$this->response = new stdClass();
|
||||
|
||||
$this->parse_response_type();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
if (array_key_exists('application/json', $response_types))
|
||||
protected function parse_response_type()
|
||||
{
|
||||
return $this->response_type = self::FORMAT_JSON;
|
||||
}
|
||||
if (array_key_exists('application/yaml', $response_types))
|
||||
{
|
||||
return $this->response_type = self::FORMAT_YAML;
|
||||
}
|
||||
if (array_key_exists('text/yaml', $response_types))
|
||||
{
|
||||
return $this->response_type = self::FORMAT_YAML;
|
||||
if (trim($this->request->get('callback')) !== '')
|
||||
return $this->response_type = self::FORMAT_JSONP;
|
||||
|
||||
$accept = $this->request->getAcceptableContentTypes();
|
||||
$response_types = array();
|
||||
|
||||
foreach ($accept as $key => $app_type) {
|
||||
$response_types[strtolower($app_type)] = true;
|
||||
}
|
||||
|
||||
if (array_key_exists('application/json', $response_types)) {
|
||||
return $this->response_type = self::FORMAT_JSON;
|
||||
}
|
||||
if (array_key_exists('application/yaml', $response_types)) {
|
||||
return $this->response_type = self::FORMAT_YAML;
|
||||
}
|
||||
if (array_key_exists('text/yaml', $response_types)) {
|
||||
return $this->response_type = self::FORMAT_YAML;
|
||||
}
|
||||
|
||||
return $this->response_type = self::FORMAT_JSON;
|
||||
}
|
||||
|
||||
return $this->response_type = self::FORMAT_JSON;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set datas to the response
|
||||
* If no datas provided (aka empty array), a stdClass if set,
|
||||
* so the serialized datas will be objects
|
||||
*
|
||||
* @param array $datas
|
||||
* @return API_V1_result
|
||||
*/
|
||||
public function set_datas(array $datas)
|
||||
{
|
||||
if (count($datas) === 0)
|
||||
$datas = new stdClass ();
|
||||
$this->response = $datas;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the data and return serialized string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function format()
|
||||
{
|
||||
$request_uri = sprintf('%s %s'
|
||||
, $this->request->getMethod()
|
||||
, $this->request->getBasePath()
|
||||
. $this->request->getPathInfo()
|
||||
);
|
||||
|
||||
$ret = array(
|
||||
'meta' => array(
|
||||
'api_version' => $this->api_version
|
||||
, 'request' => $request_uri
|
||||
, 'response_time' => $this->response_time
|
||||
, 'http_code' => $this->http_code
|
||||
, 'error_message' => $this->error_message
|
||||
, 'error_details' => $this->error_details
|
||||
, 'charset' => 'UTF-8'
|
||||
)
|
||||
, 'response' => $this->response
|
||||
);
|
||||
|
||||
$return_value = false;
|
||||
|
||||
switch ($this->response_type)
|
||||
/**
|
||||
* Set datas to the response
|
||||
* If no datas provided (aka empty array), a stdClass if set,
|
||||
* so the serialized datas will be objects
|
||||
*
|
||||
* @param array $datas
|
||||
* @return API_V1_result
|
||||
*/
|
||||
public function set_datas(array $datas)
|
||||
{
|
||||
case self::FORMAT_JSON:
|
||||
default:
|
||||
$return_value = p4string::jsonencode($ret);
|
||||
break;
|
||||
case self::FORMAT_YAML:
|
||||
if ($ret['response'] instanceof stdClass)
|
||||
$ret['response'] = array();
|
||||
if (count($datas) === 0)
|
||||
$datas = new stdClass ();
|
||||
$this->response = $datas;
|
||||
|
||||
$dumper = new Symfony\Component\Yaml\Dumper();
|
||||
$return_value = $dumper->dump($ret, 8);
|
||||
break;
|
||||
case self::FORMAT_JSONP:
|
||||
$callback = trim($this->request->get('callback'));
|
||||
$return_value = $callback . '(' . p4string::jsonencode($ret) . ')';
|
||||
break;
|
||||
return $this;
|
||||
}
|
||||
|
||||
return $return_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return serailized datas content type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_content_type()
|
||||
{
|
||||
switch ($this->response_type)
|
||||
/**
|
||||
* Format the data and return serialized string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function format()
|
||||
{
|
||||
$request_uri = sprintf('%s %s'
|
||||
, $this->request->getMethod()
|
||||
, $this->request->getBasePath()
|
||||
. $this->request->getPathInfo()
|
||||
);
|
||||
|
||||
case self::FORMAT_JSON:
|
||||
default:
|
||||
$return_value = 'application/json';
|
||||
break;
|
||||
case self::FORMAT_YAML:
|
||||
$return_value = 'application/yaml';
|
||||
break;
|
||||
case self::FORMAT_JSONP:
|
||||
$return_value = 'text/javascript';
|
||||
break;
|
||||
$ret = array(
|
||||
'meta' => array(
|
||||
'api_version' => $this->api_version
|
||||
, 'request' => $request_uri
|
||||
, 'response_time' => $this->response_time
|
||||
, 'http_code' => $this->http_code
|
||||
, 'error_message' => $this->error_message
|
||||
, 'error_details' => $this->error_details
|
||||
, 'charset' => 'UTF-8'
|
||||
)
|
||||
, 'response' => $this->response
|
||||
);
|
||||
|
||||
$return_value = false;
|
||||
|
||||
switch ($this->response_type) {
|
||||
case self::FORMAT_JSON:
|
||||
default:
|
||||
$return_value = p4string::jsonencode($ret);
|
||||
break;
|
||||
case self::FORMAT_YAML:
|
||||
if ($ret['response'] instanceof stdClass)
|
||||
$ret['response'] = array();
|
||||
|
||||
$dumper = new Symfony\Component\Yaml\Dumper();
|
||||
$return_value = $dumper->dump($ret, 8);
|
||||
break;
|
||||
case self::FORMAT_JSONP:
|
||||
$callback = trim($this->request->get('callback'));
|
||||
$return_value = $callback . '(' . p4string::jsonencode($ret) . ')';
|
||||
break;
|
||||
}
|
||||
|
||||
return $return_value;
|
||||
}
|
||||
|
||||
return $return_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the API_V1_result http_code, error_message and error_details
|
||||
* with the appropriate datas
|
||||
*
|
||||
* @param string $const
|
||||
* @return API_V1_result
|
||||
*/
|
||||
public function set_error_message($const)
|
||||
{
|
||||
switch ($const)
|
||||
/**
|
||||
* Return serailized datas content type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_content_type()
|
||||
{
|
||||
case self::ERROR_BAD_REQUEST:
|
||||
$this->http_code = 400;
|
||||
$this->error_message = $const;
|
||||
$this->error_details = API_V1_exception_badrequest::get_details();
|
||||
break;
|
||||
case self::ERROR_UNAUTHORIZED:
|
||||
$this->http_code = 401;
|
||||
$this->error_message = $const;
|
||||
$this->error_details = API_V1_exception_unauthorized::get_details();
|
||||
break;
|
||||
case self::ERROR_FORBIDDEN:
|
||||
$this->http_code = 403;
|
||||
$this->error_message = $const;
|
||||
$this->error_details = API_V1_exception_forbidden::get_details();
|
||||
break;
|
||||
case self::ERROR_NOTFOUND:
|
||||
$this->http_code = 404;
|
||||
$this->error_message = $const;
|
||||
$this->error_details = API_V1_exception_notfound::get_details();
|
||||
break;
|
||||
case self::ERROR_METHODNOTALLOWED:
|
||||
$this->http_code = 405;
|
||||
$this->error_message = $const;
|
||||
$this->error_details = API_V1_exception_methodnotallowed::get_details();
|
||||
break;
|
||||
case self::ERROR_INTERNALSERVERERROR:
|
||||
$this->http_code = 500;
|
||||
$this->error_message = $const;
|
||||
$this->error_details = API_V1_exception_internalservererror::get_details();
|
||||
break;
|
||||
case OAUTH2_ERROR_INVALID_REQUEST:
|
||||
$this->error_message = $const;
|
||||
break;
|
||||
switch ($this->response_type) {
|
||||
|
||||
case self::FORMAT_JSON:
|
||||
default:
|
||||
$return_value = 'application/json';
|
||||
break;
|
||||
case self::FORMAT_YAML:
|
||||
$return_value = 'application/yaml';
|
||||
break;
|
||||
case self::FORMAT_JSONP:
|
||||
$return_value = 'text/javascript';
|
||||
break;
|
||||
}
|
||||
|
||||
return $return_value;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the API_V1_result http_code, error_message and error_details
|
||||
* with the appropriate datas
|
||||
*
|
||||
* @param string $const
|
||||
* @return API_V1_result
|
||||
*/
|
||||
public function set_error_code($code)
|
||||
{
|
||||
switch ($code = (int) $code)
|
||||
/**
|
||||
* Set the API_V1_result http_code, error_message and error_details
|
||||
* with the appropriate datas
|
||||
*
|
||||
* @param string $const
|
||||
* @return API_V1_result
|
||||
*/
|
||||
public function set_error_message($const)
|
||||
{
|
||||
case 400:
|
||||
$this->http_code = $code;
|
||||
$this->error_message = self::ERROR_BAD_REQUEST;
|
||||
$this->error_details = API_V1_exception_badrequest::get_details();
|
||||
break;
|
||||
case 401:
|
||||
$this->http_code = $code;
|
||||
$this->error_message = self::ERROR_UNAUTHORIZED;
|
||||
$this->error_details = API_V1_exception_unauthorized::get_details();
|
||||
break;
|
||||
case 403:
|
||||
$this->http_code = $code;
|
||||
$this->error_message = self::ERROR_FORBIDDEN;
|
||||
$this->error_details = API_V1_exception_forbidden::get_details();
|
||||
break;
|
||||
case 404:
|
||||
$this->http_code = $code;
|
||||
$this->error_message = self::ERROR_NOTFOUND;
|
||||
$this->error_details = API_V1_exception_notfound::get_details();
|
||||
break;
|
||||
case 405:
|
||||
$this->http_code = $code;
|
||||
$this->error_message = self::ERROR_METHODNOTALLOWED;
|
||||
$this->error_details = API_V1_exception_methodnotallowed::get_details();
|
||||
break;
|
||||
case 500:
|
||||
$this->http_code = $code;
|
||||
$this->error_message = self::ERROR_INTERNALSERVERERROR;
|
||||
$this->error_details = API_V1_exception_internalservererror::get_details();
|
||||
break;
|
||||
switch ($const) {
|
||||
case self::ERROR_BAD_REQUEST:
|
||||
$this->http_code = 400;
|
||||
$this->error_message = $const;
|
||||
$this->error_details = API_V1_exception_badrequest::get_details();
|
||||
break;
|
||||
case self::ERROR_UNAUTHORIZED:
|
||||
$this->http_code = 401;
|
||||
$this->error_message = $const;
|
||||
$this->error_details = API_V1_exception_unauthorized::get_details();
|
||||
break;
|
||||
case self::ERROR_FORBIDDEN:
|
||||
$this->http_code = 403;
|
||||
$this->error_message = $const;
|
||||
$this->error_details = API_V1_exception_forbidden::get_details();
|
||||
break;
|
||||
case self::ERROR_NOTFOUND:
|
||||
$this->http_code = 404;
|
||||
$this->error_message = $const;
|
||||
$this->error_details = API_V1_exception_notfound::get_details();
|
||||
break;
|
||||
case self::ERROR_METHODNOTALLOWED:
|
||||
$this->http_code = 405;
|
||||
$this->error_message = $const;
|
||||
$this->error_details = API_V1_exception_methodnotallowed::get_details();
|
||||
break;
|
||||
case self::ERROR_INTERNALSERVERERROR:
|
||||
$this->http_code = 500;
|
||||
$this->error_message = $const;
|
||||
$this->error_details = API_V1_exception_internalservererror::get_details();
|
||||
break;
|
||||
case OAUTH2_ERROR_INVALID_REQUEST:
|
||||
$this->error_message = $const;
|
||||
break;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the correct http code depending on the errors
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function get_http_code()
|
||||
{
|
||||
if ($this->response_type == self::FORMAT_JSONP && $this->http_code != 500)
|
||||
/**
|
||||
* Set the API_V1_result http_code, error_message and error_details
|
||||
* with the appropriate datas
|
||||
*
|
||||
* @param string $const
|
||||
* @return API_V1_result
|
||||
*/
|
||||
public function set_error_code($code)
|
||||
{
|
||||
return 200;
|
||||
switch ($code = (int) $code) {
|
||||
case 400:
|
||||
$this->http_code = $code;
|
||||
$this->error_message = self::ERROR_BAD_REQUEST;
|
||||
$this->error_details = API_V1_exception_badrequest::get_details();
|
||||
break;
|
||||
case 401:
|
||||
$this->http_code = $code;
|
||||
$this->error_message = self::ERROR_UNAUTHORIZED;
|
||||
$this->error_details = API_V1_exception_unauthorized::get_details();
|
||||
break;
|
||||
case 403:
|
||||
$this->http_code = $code;
|
||||
$this->error_message = self::ERROR_FORBIDDEN;
|
||||
$this->error_details = API_V1_exception_forbidden::get_details();
|
||||
break;
|
||||
case 404:
|
||||
$this->http_code = $code;
|
||||
$this->error_message = self::ERROR_NOTFOUND;
|
||||
$this->error_details = API_V1_exception_notfound::get_details();
|
||||
break;
|
||||
case 405:
|
||||
$this->http_code = $code;
|
||||
$this->error_message = self::ERROR_METHODNOTALLOWED;
|
||||
$this->error_details = API_V1_exception_methodnotallowed::get_details();
|
||||
break;
|
||||
case 500:
|
||||
$this->http_code = $code;
|
||||
$this->error_message = self::ERROR_INTERNALSERVERERROR;
|
||||
$this->error_details = API_V1_exception_internalservererror::get_details();
|
||||
break;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
else
|
||||
|
||||
/**
|
||||
* Returns the correct http code depending on the errors
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function get_http_code()
|
||||
{
|
||||
return $this->http_code;
|
||||
if ($this->response_type == self::FORMAT_JSONP && $this->http_code != 500) {
|
||||
return 200;
|
||||
} else {
|
||||
return $this->http_code;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param int $code
|
||||
*/
|
||||
public function set_http_code($code)
|
||||
{
|
||||
$this->http_code = (int) $code;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param int $code
|
||||
*/
|
||||
public function set_http_code($code)
|
||||
{
|
||||
$this->http_code = (int) $code;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a Symfony Response
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function get_response()
|
||||
{
|
||||
$response = new Symfony\Component\HttpFoundation\Response(
|
||||
$this->format()
|
||||
, $this->get_http_code()
|
||||
, array('Content-Type' => $this->get_content_type())
|
||||
);
|
||||
/**
|
||||
* Return a Symfony Response
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function get_response()
|
||||
{
|
||||
$response = new Symfony\Component\HttpFoundation\Response(
|
||||
$this->format()
|
||||
, $this->get_http_code()
|
||||
, array('Content-Type' => $this->get_content_type())
|
||||
);
|
||||
|
||||
$response->setCharset('UTF-8');
|
||||
|
||||
return $response;
|
||||
}
|
||||
$response->setCharset('UTF-8');
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user