PHP 클래스 REST_Controller

A fully RESTful server implementation for CodeIgniter using one library, one config file and one controller.
저자: Phil Sturgeon, Chris Kacerguis
상속: extends MX_Controller
파일 보기 프로젝트 열기: chriskacerguis/codeigniter-restserver 1 사용 예제들

보호된 프로퍼티들

프로퍼티 타입 설명
$_allow boolean If the request is allowed based on the API key provided
$_apiuser object Information about the current API user
$_args array The arguments from GET, POST, PUT, DELETE, PATCH, HEAD and OPTIONS request methods combined
$_delete_args array The arguments for the DELETE request method
$_enable_xss boolean Enable XSS flag Determines whether the XSS filter is always active when GET, OPTIONS, HEAD, POST, PUT, DELETE and PATCH data is encountered Set automatically based on config setting
$_end_rtime string The end of the response time from the server
$_get_args array The arguments for the GET request method
$_head_args array The arguments for the HEAD request method
$_insert_id string The insert_id of the log entry (if we have one)
$_options_args array The arguments for the OPTIONS request method
$_patch_args array The arguments for the PATCH request method
$_post_args array The arguments for the POST request method
$_put_args array The arguments for the PUT request method
$_query_args array The arguments for the query parameters
$_start_rtime string The start of the response time from the server
$_supported_formats array List all supported methods, the first will be the default format
$_user_ldap_dn string The LDAP Distinguished Name of the User post authentication
$allowed_http_methods array List of allowed HTTP methods
$check_cors boolean Whether or not to perform a CORS check and apply CORS headers to the request
$http_status_codes array HTTP status codes and their respective description Note: Only the widely used HTTP status codes are used
$methods array Defines the list of method properties such as limit, log and level
$request object Contains details about the request Fields: body, format, method, ssl Note: This is a dynamic object (stdClass)
$response object Contains details about the response Fields: format, lang Note: This is a dynamic object (stdClass)
$rest object Contains details about the REST API Fields: db, ignore_limits, key, level, user_id Note: This is a dynamic object (stdClass)
$rest_format string | null This defines the rest format Must be overridden it in a controller so that it is set

공개 메소드들

메소드 설명
__construct ( string $config = 'rest' ) Constructor for the REST API
__destruct ( ) : void Deconstructor
_remap ( string $object_called, array $arguments = [] ) Requests are not made to methods directly, the request will be for an "object". This simply maps the object and method to the correct Controller method
delete ( null $key = NULL, null $xss_clean = NULL ) : array | string | null Retrieve a value from a DELETE request
get ( null $key = NULL, null $xss_clean = NULL ) : array | string | null Retrieve a value from a GET request
head ( null $key = NULL, null $xss_clean = NULL ) : array | string | null Retrieve a value from a HEAD request
options ( null $key = NULL, null $xss_clean = NULL ) : array | string | null Retrieve a value from a OPTIONS request
patch ( null $key = NULL, null $xss_clean = NULL ) : array | string | null Retrieve a value from a PATCH request
post ( null $key = NULL, null $xss_clean = NULL ) : array | string | null Retrieve a value from a POST request
put ( null $key = NULL, null $xss_clean = NULL ) : array | string | null Retrieve a value from a PUT request
query ( null $key = NULL, null $xss_clean = NULL ) : array | string | null Retrieve a value from the query parameters
response ( array | null $data = NULL, integer | null $http_code = NULL, boolean $continue = FALSE ) Takes mixed data and optionally a status code, then creates the response
set_response ( array | null $data = NULL, integer | null $http_code = NULL ) Takes mixed data and optionally a status code, then creates the response within the buffers of the Output class. The response is sent to the client lately by the framework, after the current controller's method termination.
validation_errors ( ) : array Retrieve the validation errors

보호된 메소드들

메소드 설명
_auth_override_check ( ) : boolean Check if there is a specific auth type set for the current class/method/HTTP-method being called
_check_access ( ) : boolean Check to see if the API key has access to the controller and methods
_check_blacklist_auth ( ) : void Checks if the client's ip is in the 'rest_ip_blacklist' config and generates a 401 response
_check_cors ( ) : void Checks allowed domains, and adds appropriate headers for HTTP access control (CORS)
_check_limit ( string $controller_method ) : boolean Check if the requests to a controller method exceed a limit
_check_login ( string $username = NULL, boolean | string $password = FALSE ) : boolean Check if the user is logged in
_check_php_session ( ) : void Check to see if the user is logged in with a PHP session key
_check_whitelist_auth ( ) : void Check if the client's ip is in the 'rest_ip_whitelist' config and generates a 401 response
_detect_api_key ( ) : boolean See if the user has provided an API key
_detect_input_format ( ) : string | null Get the input format e.g. json or xml
_detect_lang ( ) : string | null Preferred return language
_detect_method ( ) : string | null Get the HTTP request string e.g. get or post
_detect_output_format ( ) : mixed | null | string Detect which format should be used to output the data
_force_login ( string $nonce = '' ) : void Force logging in by setting the WWW-Authenticate header
_get_default_output_format ( ) : string Gets the default format from the configuration. Fallbacks to 'json' if the corresponding configuration option $config['rest_default_format'] is missing or is empty
_log_access_time ( ) : boolean Updates the log table with the total access time
_log_request ( boolean $authorized = FALSE ) : boolean Add the request to the log table
_log_response_code ( $http_code ) : boolean Updates the log table with HTTP response code
_parse_delete ( ) : void Parse the DELETE request arguments
_parse_get ( ) : void Parse the GET request arguments
_parse_head ( ) : void Parse the HEAD request arguments
_parse_options ( ) : void Parse the OPTIONS request arguments
_parse_patch ( ) : void Parse the PATCH request arguments
_parse_post ( ) : void Parse the POST request arguments
_parse_put ( ) : void Parse the PUT request arguments
_parse_query ( ) : void Parse the query parameters
_perform_ldap_auth ( string $username = '', string $password = NULL ) : boolean Perform LDAP Authentication
_perform_library_auth ( string $username = '', string $password = NULL ) : boolean Perform Library Authentication - Override this function to change the way the library is called
_prepare_basic_auth ( ) : void Prepares for basic authentication
_prepare_digest_auth ( ) : void Prepares for digest authentication
_xss_clean ( string $value, boolean $xss_clean ) : string Sanitizes data so that Cross Site Scripting Hacks can be prevented
early_checks ( ) : void Extend this function to apply additional checking early on in the process
preflight_checks ( ) Checks to see if we have everything we need to run this library.

메소드 상세

__construct() 공개 메소드

Constructor for the REST API
public __construct ( string $config = 'rest' )
$config string Configuration filename minus the file extension e.g: my_rest.php is passed as 'my_rest'

__destruct() 공개 메소드

Deconstructor
저자: Chris Kacerguis
public __destruct ( ) : void
리턴 void

_auth_override_check() 보호된 메소드

Check if there is a specific auth type set for the current class/method/HTTP-method being called
protected _auth_override_check ( ) : boolean
리턴 boolean

_check_access() 보호된 메소드

Check to see if the API key has access to the controller and methods
protected _check_access ( ) : boolean
리턴 boolean TRUE the API key has access; otherwise, FALSE

_check_blacklist_auth() 보호된 메소드

Checks if the client's ip is in the 'rest_ip_blacklist' config and generates a 401 response
protected _check_blacklist_auth ( ) : void
리턴 void

_check_cors() 보호된 메소드

Checks allowed domains, and adds appropriate headers for HTTP access control (CORS)
protected _check_cors ( ) : void
리턴 void

_check_limit() 보호된 메소드

Check if the requests to a controller method exceed a limit
protected _check_limit ( string $controller_method ) : boolean
$controller_method string The method being called
리턴 boolean TRUE the call limit is below the threshold; otherwise, FALSE

_check_login() 보호된 메소드

Check if the user is logged in
protected _check_login ( string $username = NULL, boolean | string $password = FALSE ) : boolean
$username string The user's name
$password boolean | string The user's password
리턴 boolean

_check_php_session() 보호된 메소드

Check to see if the user is logged in with a PHP session key
protected _check_php_session ( ) : void
리턴 void

_check_whitelist_auth() 보호된 메소드

Check if the client's ip is in the 'rest_ip_whitelist' config and generates a 401 response
protected _check_whitelist_auth ( ) : void
리턴 void

_detect_api_key() 보호된 메소드

See if the user has provided an API key
protected _detect_api_key ( ) : boolean
리턴 boolean

_detect_input_format() 보호된 메소드

Get the input format e.g. json or xml
protected _detect_input_format ( ) : string | null
리턴 string | null Supported input format; otherwise, NULL

_detect_lang() 보호된 메소드

Preferred return language
protected _detect_lang ( ) : string | null
리턴 string | null The language code

_detect_method() 보호된 메소드

Get the HTTP request string e.g. get or post
protected _detect_method ( ) : string | null
리턴 string | null Supported request method as a lowercase string; otherwise, NULL if not supported

_detect_output_format() 보호된 메소드

Detect which format should be used to output the data
protected _detect_output_format ( ) : mixed | null | string
리턴 mixed | null | string Output format

_force_login() 보호된 메소드

Force logging in by setting the WWW-Authenticate header
protected _force_login ( string $nonce = '' ) : void
$nonce string A server-specified data string which should be uniquely generated each time
리턴 void

_get_default_output_format() 보호된 메소드

Gets the default format from the configuration. Fallbacks to 'json' if the corresponding configuration option $config['rest_default_format'] is missing or is empty
protected _get_default_output_format ( ) : string
리턴 string The default supported input format

_log_access_time() 보호된 메소드

Updates the log table with the total access time
저자: Chris Kacerguis
protected _log_access_time ( ) : boolean
리턴 boolean TRUE log table updated; otherwise, FALSE

_log_request() 보호된 메소드

Add the request to the log table
protected _log_request ( boolean $authorized = FALSE ) : boolean
$authorized boolean TRUE the user is authorized; otherwise, FALSE
리턴 boolean TRUE the data was inserted; otherwise, FALSE

_log_response_code() 보호된 메소드

Updates the log table with HTTP response code
저자: Justin Chen
protected _log_response_code ( $http_code ) : boolean
$http_code int HTTP status code
리턴 boolean TRUE log table updated; otherwise, FALSE

_parse_delete() 보호된 메소드

Parse the DELETE request arguments
protected _parse_delete ( ) : void
리턴 void

_parse_get() 보호된 메소드

Parse the GET request arguments
protected _parse_get ( ) : void
리턴 void

_parse_head() 보호된 메소드

Parse the HEAD request arguments
protected _parse_head ( ) : void
리턴 void

_parse_options() 보호된 메소드

Parse the OPTIONS request arguments
protected _parse_options ( ) : void
리턴 void

_parse_patch() 보호된 메소드

Parse the PATCH request arguments
protected _parse_patch ( ) : void
리턴 void

_parse_post() 보호된 메소드

Parse the POST request arguments
protected _parse_post ( ) : void
리턴 void

_parse_put() 보호된 메소드

Parse the PUT request arguments
protected _parse_put ( ) : void
리턴 void

_parse_query() 보호된 메소드

Parse the query parameters
protected _parse_query ( ) : void
리턴 void

_perform_ldap_auth() 보호된 메소드

Perform LDAP Authentication
protected _perform_ldap_auth ( string $username = '', string $password = NULL ) : boolean
$username string The username to validate
$password string The password to validate
리턴 boolean

_perform_library_auth() 보호된 메소드

Perform Library Authentication - Override this function to change the way the library is called
protected _perform_library_auth ( string $username = '', string $password = NULL ) : boolean
$username string The username to validate
$password string The password to validate
리턴 boolean

_prepare_basic_auth() 보호된 메소드

Prepares for basic authentication
protected _prepare_basic_auth ( ) : void
리턴 void

_prepare_digest_auth() 보호된 메소드

Prepares for digest authentication
protected _prepare_digest_auth ( ) : void
리턴 void

_remap() 공개 메소드

Requests are not made to methods directly, the request will be for an "object". This simply maps the object and method to the correct Controller method
public _remap ( string $object_called, array $arguments = [] )
$object_called string
$arguments array The arguments passed to the controller method

_xss_clean() 보호된 메소드

Sanitizes data so that Cross Site Scripting Hacks can be prevented
protected _xss_clean ( string $value, boolean $xss_clean ) : string
$value string Input data
$xss_clean boolean Whether to apply XSS filtering
리턴 string

delete() 공개 메소드

Retrieve a value from a DELETE request
public delete ( null $key = NULL, null $xss_clean = NULL ) : array | string | null
$key null Key to retrieve from the DELETE request If NULL an array of arguments is returned
$xss_clean null Whether to apply XSS filtering
리턴 array | string | null Value from the DELETE request; otherwise, NULL

early_checks() 보호된 메소드

Extend this function to apply additional checking early on in the process
protected early_checks ( ) : void
리턴 void

get() 공개 메소드

Retrieve a value from a GET request
public get ( null $key = NULL, null $xss_clean = NULL ) : array | string | null
$key null Key to retrieve from the GET request If NULL an array of arguments is returned
$xss_clean null Whether to apply XSS filtering
리턴 array | string | null Value from the GET request; otherwise, NULL

head() 공개 메소드

Retrieve a value from a HEAD request
public head ( null $key = NULL, null $xss_clean = NULL ) : array | string | null
$key null Key to retrieve from the HEAD request If NULL an array of arguments is returned
$xss_clean null Whether to apply XSS filtering
리턴 array | string | null Value from the HEAD request; otherwise, NULL

options() 공개 메소드

Retrieve a value from a OPTIONS request
public options ( null $key = NULL, null $xss_clean = NULL ) : array | string | null
$key null Key to retrieve from the OPTIONS request. If NULL an array of arguments is returned
$xss_clean null Whether to apply XSS filtering
리턴 array | string | null Value from the OPTIONS request; otherwise, NULL

patch() 공개 메소드

Retrieve a value from a PATCH request
public patch ( null $key = NULL, null $xss_clean = NULL ) : array | string | null
$key null Key to retrieve from the PATCH request If NULL an array of arguments is returned
$xss_clean null Whether to apply XSS filtering
리턴 array | string | null Value from the PATCH request; otherwise, NULL

post() 공개 메소드

Retrieve a value from a POST request
public post ( null $key = NULL, null $xss_clean = NULL ) : array | string | null
$key null Key to retrieve from the POST request If NULL an array of arguments is returned
$xss_clean null Whether to apply XSS filtering
리턴 array | string | null Value from the POST request; otherwise, NULL

preflight_checks() 보호된 메소드

Checks to see if we have everything we need to run this library.
protected preflight_checks ( )

put() 공개 메소드

Retrieve a value from a PUT request
public put ( null $key = NULL, null $xss_clean = NULL ) : array | string | null
$key null Key to retrieve from the PUT request If NULL an array of arguments is returned
$xss_clean null Whether to apply XSS filtering
리턴 array | string | null Value from the PUT request; otherwise, NULL

query() 공개 메소드

Retrieve a value from the query parameters
public query ( null $key = NULL, null $xss_clean = NULL ) : array | string | null
$key null Key to retrieve from the query parameters If NULL an array of arguments is returned
$xss_clean null Whether to apply XSS filtering
리턴 array | string | null Value from the query parameters; otherwise, NULL

response() 공개 메소드

Takes mixed data and optionally a status code, then creates the response
public response ( array | null $data = NULL, integer | null $http_code = NULL, boolean $continue = FALSE )
$data array | null Data to output to the user
$http_code integer | null HTTP status code
$continue boolean TRUE to flush the response to the client and continue running the script; otherwise, exit

set_response() 공개 메소드

All the hooks after the controller's method termination are executable
public set_response ( array | null $data = NULL, integer | null $http_code = NULL )
$data array | null Data to output to the user
$http_code integer | null HTTP status code

validation_errors() 공개 메소드

Retrieve the validation errors
public validation_errors ( ) : array
리턴 array

프로퍼티 상세

$_allow 보호되어 있는 프로퍼티

If the request is allowed based on the API key provided
protected bool $_allow
리턴 boolean

$_apiuser 보호되어 있는 프로퍼티

Information about the current API user
protected object $_apiuser
리턴 object

$_args 보호되어 있는 프로퍼티

The arguments from GET, POST, PUT, DELETE, PATCH, HEAD and OPTIONS request methods combined
protected array $_args
리턴 array

$_delete_args 보호되어 있는 프로퍼티

The arguments for the DELETE request method
protected array $_delete_args
리턴 array

$_enable_xss 보호되어 있는 프로퍼티

Enable XSS flag Determines whether the XSS filter is always active when GET, OPTIONS, HEAD, POST, PUT, DELETE and PATCH data is encountered Set automatically based on config setting
protected bool $_enable_xss
리턴 boolean

$_end_rtime 보호되어 있는 프로퍼티

The end of the response time from the server
protected string $_end_rtime
리턴 string

$_get_args 보호되어 있는 프로퍼티

The arguments for the GET request method
protected array $_get_args
리턴 array

$_head_args 보호되어 있는 프로퍼티

The arguments for the HEAD request method
protected array $_head_args
리턴 array

$_insert_id 보호되어 있는 프로퍼티

The insert_id of the log entry (if we have one)
protected string $_insert_id
리턴 string

$_options_args 보호되어 있는 프로퍼티

The arguments for the OPTIONS request method
protected array $_options_args
리턴 array

$_patch_args 보호되어 있는 프로퍼티

The arguments for the PATCH request method
protected array $_patch_args
리턴 array

$_post_args 보호되어 있는 프로퍼티

The arguments for the POST request method
protected array $_post_args
리턴 array

$_put_args 보호되어 있는 프로퍼티

The arguments for the PUT request method
protected array $_put_args
리턴 array

$_query_args 보호되어 있는 프로퍼티

The arguments for the query parameters
protected array $_query_args
리턴 array

$_start_rtime 보호되어 있는 프로퍼티

The start of the response time from the server
protected string $_start_rtime
리턴 string

$_supported_formats 보호되어 있는 프로퍼티

List all supported methods, the first will be the default format
protected array $_supported_formats
리턴 array

$_user_ldap_dn 보호되어 있는 프로퍼티

The LDAP Distinguished Name of the User post authentication
protected string $_user_ldap_dn
리턴 string

$allowed_http_methods 보호되어 있는 프로퍼티

List of allowed HTTP methods
protected array $allowed_http_methods
리턴 array

$check_cors 보호되어 있는 프로퍼티

Whether or not to perform a CORS check and apply CORS headers to the request
protected bool $check_cors
리턴 boolean

$http_status_codes 보호되어 있는 프로퍼티

HTTP status codes and their respective description Note: Only the widely used HTTP status codes are used
protected array $http_status_codes
리턴 array

$methods 보호되어 있는 프로퍼티

Defines the list of method properties such as limit, log and level
protected array $methods
리턴 array

$request 보호되어 있는 프로퍼티

Contains details about the request Fields: body, format, method, ssl Note: This is a dynamic object (stdClass)
protected object $request
리턴 object

$response 보호되어 있는 프로퍼티

Contains details about the response Fields: format, lang Note: This is a dynamic object (stdClass)
protected object $response
리턴 object

$rest 보호되어 있는 프로퍼티

Contains details about the REST API Fields: db, ignore_limits, key, level, user_id Note: This is a dynamic object (stdClass)
protected object $rest
리턴 object

$rest_format 보호되어 있는 프로퍼티

This defines the rest format Must be overridden it in a controller so that it is set
protected string|NULL $rest_format
리턴 string | null