mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-17 06:53:15 +00:00
Fix CS
This commit is contained in:
@@ -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