V 3.5 RC 1

This commit is contained in:
Romain Neutron
2011-12-05 00:23:28 +01:00
parent 6f1ee368aa
commit 4c5b7eb658
5563 changed files with 466984 additions and 985416 deletions

View File

@@ -0,0 +1,21 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
*
* @package APIv1
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
abstract class API_V1_Abstract implements API_V1_Interface
{
}

View File

@@ -0,0 +1,316 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
*
* @package APIv1
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
interface API_V1_Interface
{
public function get_version();
/**
* Route : /databoxes/list/FORMAT/
*
* Method : GET
*
* Parameters :
*
*/
public function get_databoxes(\Symfony\Component\HttpFoundation\Request $request);
/**
* 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/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/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/termsOfUse/FORMAT/
*
* Method : GET
*
* Parameters ;
* DATABOX_ID : required INT
*/
public function get_databox_terms(\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 : /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/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/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/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/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/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/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/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/list/FORMAT/
*
* Method : POST
*
* Parameters :
*
*/
public function search_baskets(\Symfony\Component\HttpFoundation\Request $request);
/**
* Route : /baskets/add/FORMAT/
*
* Method : POST
*
* Parameters :
*
*/
public function create_basket(\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/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/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/description/FORMAT/
*
* Method : POST
*
* Parameters :
* BASKET_ID : required INT
*
*/
public function set_basket_description(\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 : /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/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/search/FORMAT/
*
* Method : POST-GET
*
* Parameters :
*
*/
public function search_users(\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);
/**
* Route : /users/add/FORMAT/
*
* Method : POST
*
* Parameters :
*
*/
public function add_user(\Symfony\Component\HttpFoundation\Request $request);
public function get_error_message(\Symfony\Component\HttpFoundation\Request $request, $error);
public function get_error_code(\Symfony\Component\HttpFoundation\Request $request, $code);
}

View File

@@ -0,0 +1,390 @@
<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
use Symfony\Component\HttpFoundation\Request;
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';
/**
*
* @var int
*/
protected $id;
/**
*
* @var int
*/
protected $account_id;
/**
*
* @var DateTime
*/
protected $date;
/**
*
* @var int
*/
protected $status_code;
/**
*
* @var string
*/
protected $format;
/**
*
* @var string
*/
protected $ressource;
/**
*
* @var string
*/
protected $general;
/**
*
* @var string
*/
protected $aspect;
/**
*
* @var string
*/
protected $action;
/**
*
* @var API_OAuth2_Account
*/
protected $account;
/**
*
* @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;
$sql = '
SELECT
api_log_id,
api_account_id,
api_log_route,
api_log_date,
api_log_status_code,
api_log_format,
api_log_ressource,
api_log_general,
api_log_aspect,
api_log_action
FROM
api_logs
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();
$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;
}
public function get_account_id()
{
return $this->account_id;
}
public function set_account_id($account_id)
{
$this->account_id = $account_id;
$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
);
$stmt = $this->appbox->get_connection()->prepare($sql);
$stmt->execute($params);
$stmt->closeCursor();
return $this;
}
public function get_date()
{
return $this->date;
}
public function set_date(DateTime $date)
{
$this->date = $date;
$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
);
$stmt = $this->appbox->get_connection()->prepare($sql);
$stmt->execute($params);
$stmt->closeCursor();
return $this;
}
public function get_status_code()
{
return $this->status_code;
}
public function set_status_code($status_code)
{
$this->status_code = (int) $status_code;
$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
);
$stmt = $this->appbox->get_connection()->prepare($sql);
$stmt->execute($params);
$stmt->closeCursor();
return $this;
}
public function get_format()
{
return $this->format;
}
public function set_format($format)
{
if (!in_array($format, array('json', 'jsonp', 'yaml', 'unknow')))
throw new Exception_InvalidArgument();
$this->format = $format;
$sql = 'UPDATE api_log
SET api_log_format = :format
WHERE api_log_id = :log_id';
$params = array(
':format' => $this->format
, ':log_id' => $this->id
);
$stmt = $this->appbox->get_connection()->prepare($sql);
$stmt->execute($params);
$stmt->closeCursor();
return $this;
}
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();
$this->ressource = $ressource;
$sql = 'UPDATE api_log
SET api_log_ressource = :ressource
WHERE api_log_id = :log_id';
$params = array(
':ressource' => $this->ressource
, ':log_id' => $this->id
);
$stmt = $this->appbox->get_connection()->prepare($sql);
$stmt->execute($params);
$stmt->closeCursor();
return $this;
}
public function get_general()
{
return $this->general;
}
public function set_general($general)
{
$this->general = $general;
$sql = 'UPDATE api_log
SET api_log_general = :general
WHERE api_log_id = :log_id';
$params = array(
':general' => $this->general
, ':log_id' => $this->id
);
$stmt = $this->appbox->get_connection()->prepare($sql);
$stmt->execute($params);
$stmt->closeCursor();
return $this;
}
public function get_aspect()
{
return $this->aspect;
}
public function set_aspect($aspect)
{
$this->aspect = $aspect;
$sql = 'UPDATE api_log
SET api_log_aspect = :aspect
WHERE api_log_id = :log_id';
$params = array(
':aspect' => $this->aspect
, ':log_id' => $this->id
);
$stmt = $this->appbox->get_connection()->prepare($sql);
$stmt->execute($params);
$stmt->closeCursor();
return $this;
}
public function get_action()
{
return $this->action;
}
public function set_action($action)
{
$this->action = $action;
$sql = 'UPDATE api_log
SET api_log_action = :action
WHERE api_log_id = :log_id';
$params = array(
':action' => $this->action
, ':log_id' => $this->id
);
$stmt = $this->appbox->get_connection()->prepare($sql);
$stmt->execute($params);
$stmt->closeCursor();
return $this;
}
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 = '
INSERT INTO
api_logs (
api_log_id,
api_account_id,
api_log_route,
api_log_date,
api_log_status_code,
api_log_format,
api_log_ressource,
api_log_general,
api_log_aspect,
api_log_action
)
VALUES (
null,
:account_id,
:route,
NOW(),
:status_code,
:format,
:ressource,
:general,
:aspect,
: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();
$log_id = $appbox->get_connection()->lastInsertId();
return new self($appbox, $log_id);
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,33 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
*
* @package APIv1
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
abstract class API_V1_exception_abstract extends Exception
{
protected static $details;
public function __construct()
{
return $this;
}
public static function get_details()
{
return static::$details;
}
}

View File

@@ -0,0 +1,23 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
*
* @package APIv1
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class API_V1_exception_badrequest extends API_V1_exception_abstract
{
protected static $details = 'Parameter is invalid or missing';
}

View File

@@ -0,0 +1,23 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
*
* @package APIv1
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class API_V1_exception_forbidden extends API_V1_exception_abstract
{
protected static $details = 'Access to the requested ressource is forbidden';
}

View File

@@ -0,0 +1,23 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
*
* @package APIv1
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class API_V1_exception_internalservererror extends API_V1_exception_abstract
{
protected static $details = 'Internal Server Error';
}

View File

@@ -0,0 +1,23 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
*
* @package APIv1
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
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';
}

View File

@@ -0,0 +1,23 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
*
* @package APIv1
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class API_V1_exception_notfound extends API_V1_exception_abstract
{
protected static $details = 'Requested ressource is not found';
}

View File

@@ -0,0 +1,23 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
*
* @package APIv1
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class API_V1_exception_unauthorized extends API_V1_exception_abstract
{
protected static $details = 'The OAuth token was provided but was invalid.';
}

View File

@@ -0,0 +1,348 @@
<?php
require_once dirname(__FILE__) . "/../../../../lib/vendor/oauth2/lib/OAuth2.inc";
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
*
*
*
* @package APIv1
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
use \Symfony\Component\HttpFoundation\Request;
class API_V1_result
{
/**
*
* @var string
*/
protected $api_version;
/**
*
* @var string
*/
protected $response_time;
/**
*
* @var int
*/
protected $http_code = 200;
/**
*
* @var string
*/
protected $error_message;
/**
*
* @var string
*/
protected $error_details;
/**
*
* @var string
*/
protected $request;
/**
*
* @var mixed
*/
protected $response;
/**
*
* @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';
/**
* 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)
{
$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;
}
/**
* 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)
{
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 serailized datas content type
*
* @return string
*/
public function get_content_type()
{
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;
}
/**
* 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)
{
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;
}
/**
* 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)
{
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;
}
/**
* 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)
return 200;
else
return $this->http_code;
}
/**
*
* @param int $code
*/
public function set_http_code($code)
{
$this->http_code = (int)$code;
}
}