PHP 클래스 CakeRequest

Provides methods commonly used to introspect on the request headers and request body. Has both an Array and Object interface. You can access framework parameters using indexes: $request['controller'] or $request->controller.
상속: implements ArrayAccess
파일 보기 프로젝트 열기: baserproject/basercms 1 사용 예제들

공개 프로퍼티들

프로퍼티 타입 설명
$base string Base URL path.
$data array Inputs prefixed with 'data' will have the data prefix removed. If there is overlap between an input prefixed with data and one without, the 'data' prefixed value will take precedence.
$here string The full address to the current request
$params array Array of parameters parsed from the URL.
$query array Array of querystring arguments
$url string The URL string used for the request.
$webroot string webroot path segment for the request.

보호된 프로퍼티들

프로퍼티 타입 설명
$_detectors array There are several ways to specify a detector, see CakeRequest::addDetector() for the various formats and ways to define detectors.
$_input string Copy of php://input. Since this stream can only be read once in most SAPI's keep a copy of it so users don't need to know about that detail.

공개 메소드들

메소드 설명
__call ( string $name, array $params ) : mixed Missing method handler, handles wrapping older style isAjax() type methods
__construct ( string $url = null, boolean $parseEnvironment = true ) Constructor
__get ( string $name ) : mixed Magic get method allows access to parsed routing parameters directly on the object.
__isset ( string $name ) : boolean Magic isset method allows isset/empty checks on routing parameters.
acceptLanguage ( string $language = null ) : mixed Get the languages accepted by the client, or check if a specific language is accepted.
accepts ( string $type = null ) : mixed Find out which content types the client accepts or check if they accept a particular type of content.
addDetector ( string $name, array $options ) : void Add a new detector to the list of detectors that a request can use.
addParams ( array $params ) : self Add parameters to the request's parsed parameter set. This will overwrite any existing parameters.
addPaths ( array $paths ) : self Add paths to the requests' paths vars. This will overwrite any existing paths.
allowMethod ( string | array $methods ) : boolean Allow only certain HTTP request methods. If the request method does not match a 405 error will be shown and the required "Allow" response header will be set.
clientIp ( boolean $safe = true ) : string Get the IP the client is using, or says they are using.
contentType ( ) : string Get the content type used in this request.
data ( string $name ) : mixed | self Provides a read/write accessor for $this->data. Allows you to use a syntax similar to CakeSession for reading post data.
domain ( integer $tldLength = 1 ) : string Get the domain name and include $tldLength segments of the tld.
header ( string $name ) : mixed Read an HTTP header from the Request information.
here ( boolean $base = true ) : string Get the value of the current requests URL. Will include named parameters and querystring arguments.
host ( boolean $trustProxy = false ) : string Get the host that the request was handled on.
input ( string $callback = null ) : The Read data from php://input. Useful when interacting with XML or JSON request body content.
is ( string | array $type ) : boolean Check whether or not a Request is a certain type.
isAll ( array $types ) : boolean Check that a request matches all the given types.
method ( ) : string Get the HTTP method used for this request.
normalizedHere ( ) : string 現在のURLを正規化して取得する
offsetExists ( string $name ) : boolean Array access isset() implementation
offsetGet ( string $name ) : mixed Array access read implementation
offsetSet ( string $name, mixed $value ) : void Array access write implementation
offsetUnset ( string $name ) : void Array access unset() implementation
onlyAllow ( string | array $methods ) : boolean Alias of CakeRequest::allowMethod() for backwards compatibility.
param ( string $name ) : mixed Safely access the values in $this->params.
parseAccept ( ) : array Parse the HTTP_ACCEPT header and return a sorted array with content types as the keys, and pref values as the values.
query ( string $name ) : mixed Provides a read accessor for $this->query. Allows you to use a syntax similar to CakeSession for reading URL query data.
referer ( boolean $local = false ) : string Returns the referer that referred this request.
setInput ( string $input ) : void Modify data originally from php://input. Useful for altering json/xml data in middleware or DispatcherFilters before it gets to RequestHandlerComponent
subdomains ( integer $tldLength = 1 ) : array Get the subdomains for a host.

보호된 메소드들

메소드 설명
_acceptHeaderDetector ( array $detect ) : boolean Detects if a specific accept header is present.
_base ( ) : string Returns a base URL and sets the proper webroot
_environmentDetector ( array $detect ) : boolean Detects if a specific environment variable is present.
_extensionDetector ( array $detect ) : boolean Detects if a URL extension is present.
_headerDetector ( array $detect ) : boolean Detects if a specific header is present.
_paramDetector ( array $detect ) : boolean Detects if a specific request parameter is present.
_parseAcceptWithQualifier ( string $header ) : array Parse Accept* headers with qualifier options.
_processFileData ( string $path, array $data, string $field ) : void Recursively walks the FILES array restructuring the data into something sane and useable.
_processFiles ( ) : void Process $_FILES and move things into the object.
_processGet ( ) : void Process the GET parameters and move things into the object.
_processPost ( ) : void process the post data and set what is there into the object.
_readInput ( ) : string Read data from php://input, mocked in tests.
_url ( ) : string Get the request uri. Looks in PATH_INFO first, as this is the exact value we need prepared by PHP. Following that, REQUEST_URI, PHP_SELF, HTTP_X_REWRITE_URL and argv are checked in that order.

메소드 상세

__call() 공개 메소드

Missing method handler, handles wrapping older style isAjax() type methods
public __call ( string $name, array $params ) : mixed
$name string The method called
$params array Array of parameters for the method call
리턴 mixed

__construct() 공개 메소드

Constructor
public __construct ( string $url = null, boolean $parseEnvironment = true )
$url string Trimmed URL string to use. Should not contain the application base path.
$parseEnvironment boolean Set to false to not auto parse the environment. ie. GET, POST and FILES.

__get() 공개 메소드

Allows access to $this->params['controller'] via $this->controller
public __get ( string $name ) : mixed
$name string The property being accessed.
리턴 mixed Either the value of the parameter or null.

__isset() 공개 메소드

Magic isset method allows isset/empty checks on routing parameters.
public __isset ( string $name ) : boolean
$name string The property being accessed.
리턴 boolean Existence

_acceptHeaderDetector() 보호된 메소드

Detects if a specific accept header is present.
protected _acceptHeaderDetector ( array $detect ) : boolean
$detect array Detector options array.
리턴 boolean Whether or not the request is the type you are checking.

_base() 보호된 메소드

If CakePHP is called with index.php in the URL even though URL Rewriting is activated (and thus not needed) it swallows the unnecessary part from $base to prevent issue #3318.
protected _base ( ) : string
리턴 string Base URL

_environmentDetector() 보호된 메소드

Detects if a specific environment variable is present.
protected _environmentDetector ( array $detect ) : boolean
$detect array Detector options array.
리턴 boolean Whether or not the request is the type you are checking.

_extensionDetector() 보호된 메소드

Detects if a URL extension is present.
protected _extensionDetector ( array $detect ) : boolean
$detect array Detector options array.
리턴 boolean Whether or not the request is the type you are checking.

_headerDetector() 보호된 메소드

Detects if a specific header is present.
protected _headerDetector ( array $detect ) : boolean
$detect array Detector options array.
리턴 boolean Whether or not the request is the type you are checking.

_paramDetector() 보호된 메소드

Detects if a specific request parameter is present.
protected _paramDetector ( array $detect ) : boolean
$detect array Detector options array.
리턴 boolean Whether or not the request is the type you are checking.

_parseAcceptWithQualifier() 보호된 정적인 메소드

Only qualifiers will be extracted, any other accept extensions will be discarded as they are not frequently used.
protected static _parseAcceptWithQualifier ( string $header ) : array
$header string Header to parse.
리턴 array

_processFileData() 보호된 메소드

Recursively walks the FILES array restructuring the data into something sane and useable.
protected _processFileData ( string $path, array $data, string $field ) : void
$path string The dot separated path to insert $data into.
$data array The data to traverse/insert.
$field string The terminal field name, which is the top level key in $_FILES.
리턴 void

_processFiles() 보호된 메소드

Process $_FILES and move things into the object.
protected _processFiles ( ) : void
리턴 void

_processGet() 보호된 메소드

Process the GET parameters and move things into the object.
protected _processGet ( ) : void
리턴 void

_processPost() 보호된 메소드

processed data is available at $this->data Will merge POST vars prefixed with data, and ones without into a single array. Variables prefixed with data will overwrite those without. If you have mixed POST values be careful not to make any top level keys numeric containing arrays. Hash::merge() is used to merge data, and it has possibly unexpected behavior in this situation.
protected _processPost ( ) : void
리턴 void

_readInput() 보호된 메소드

Read data from php://input, mocked in tests.
protected _readInput ( ) : string
리턴 string contents of php://input

_url() 보호된 메소드

Each of these server variables have the base path, and query strings stripped off
protected _url ( ) : string
리턴 string URI The CakePHP request path that is being accessed.

acceptLanguage() 공개 정적인 메소드

Get the list of accepted languages: CakeRequest::acceptLanguage(); Check if a specific language is accepted: CakeRequest::acceptLanguage('es-es');
public static acceptLanguage ( string $language = null ) : mixed
$language string The language to test.
리턴 mixed If a $language is provided, a boolean. Otherwise the array of accepted languages.

accepts() 공개 메소드

#### Get all types: $this->request->accepts(); #### Check for a single type: $this->request->accepts('application/json'); This method will order the returned content types by the preference values indicated by the client.
public accepts ( string $type = null ) : mixed
$type string The content type to check for. Leave null to get all types a client accepts.
리턴 mixed Either an array of all the types the client accepts or a boolean if they accept the provided type.

addDetector() 공개 메소드

There are several different formats and types of detectors that can be set. ### Environment value comparison An environment value comparison, compares a value fetched from env() to a known value the environment value is equality checked against the provided value. e.g addDetector('post', array('env' => 'REQUEST_METHOD', 'value' => 'POST')) ### Pattern value comparison Pattern value comparison allows you to compare a value fetched from env() to a regular expression. e.g addDetector('iphone', array('env' => 'HTTP_USER_AGENT', 'pattern' => '/iPhone/i')); ### Option based comparison Option based comparisons use a list of options to create a regular expression. Subsequent calls to add an already defined options detector will merge the options. e.g addDetector('mobile', array('env' => 'HTTP_USER_AGENT', 'options' => array('Fennec'))); ### Callback detectors Callback detectors allow you to provide a 'callback' type to handle the check. The callback will receive the request object as its only parameter. e.g addDetector('custom', array('callback' => array('SomeClass', 'somemethod'))); ### Request parameter detectors Allows for custom detectors on the request parameters. e.g addDetector('requested', array('param' => 'requested', 'value' => 1) You can also make parameter detectors that accept multiple values using the options key. This is useful when you want to check if a request parameter is in a list of options. addDetector('extension', array('param' => 'ext', 'options' => array('pdf', 'csv'))
public addDetector ( string $name, array $options ) : void
$name string The name of the detector.
$options array The options for the detector definition. See above.
리턴 void

addParams() 공개 메소드

This modifies the parameters available through $request->params.
public addParams ( array $params ) : self
$params array Array of parameters to merge in
리턴 self

addPaths() 공개 메소드

Provides an easy way to modify, here, webroot and base.
public addPaths ( array $paths ) : self
$paths array Array of paths to merge in
리턴 self

allowMethod() 공개 메소드

Example: $this->request->allowMethod('post', 'delete'); or $this->request->allowMethod(array('post', 'delete')); If the request would be GET, response header "Allow: POST, DELETE" will be set and a 405 error will be returned.
public allowMethod ( string | array $methods ) : boolean
$methods string | array Allowed HTTP request methods.
리턴 boolean true

clientIp() 공개 메소드

Get the IP the client is using, or says they are using.
public clientIp ( boolean $safe = true ) : string
$safe boolean Use safe = false when you think the user might manipulate their HTTP_CLIENT_IP header. Setting $safe = false will also look at HTTP_X_FORWARDED_FOR
리턴 string The client IP.

contentType() 공개 메소드

Get the content type used in this request.
public contentType ( ) : string
리턴 string

data() 공개 메소드

## Reading values. $request->data('Post.title'); When reading values you will get null for keys/values that do not exist. ## Writing values $request->data('Post.title', 'New post!'); You can write to any value, even paths/keys that do not exist, and the arrays will be created for you.
public data ( string $name ) : mixed | self
$name string Dot separated name of the value to read/write, one or more args.
리턴 mixed | self Either the value being read, or $this so you can chain consecutive writes.

domain() 공개 메소드

Get the domain name and include $tldLength segments of the tld.
public domain ( integer $tldLength = 1 ) : string
$tldLength integer Number of segments your tld contains. For example: `example.com` contains 1 tld. While `example.co.uk` contains 2.
리턴 string Domain name without subdomains.

header() 공개 정적인 메소드

Read an HTTP header from the Request information.
public static header ( string $name ) : mixed
$name string Name of the header you want.
리턴 mixed Either false on no header being set or the value of the header.

here() 공개 메소드

Get the value of the current requests URL. Will include named parameters and querystring arguments.
public here ( boolean $base = true ) : string
$base boolean Include the base path, set to false to trim the base path off.
리턴 string the current request URL including query string args.

host() 공개 메소드

Get the host that the request was handled on.
public host ( boolean $trustProxy = false ) : string
$trustProxy boolean Whether or not to trust the proxy host.
리턴 string

input() 공개 메소드

Getting input with a decoding function: $this->request->input('json_decode'); Getting input using a decoding function, and additional params: $this->request->input('Xml::build', array('return' => 'DOMDocument')); Any additional parameters are applied to the callback in the order they are given.
public input ( string $callback = null ) : The
$callback string A decoding callback that will convert the string data to another representation. Leave empty to access the raw input data. You can also supply additional parameters for the decoding callback using var args, see above.
리턴 The decoded/processed request data.

is() 공개 메소드

Uses the built in detection rules as well as additional rules defined with CakeRequest::addDetector(). Any detector can be called as is($type) or is$Type().
public is ( string | array $type ) : boolean
$type string | array The type of request you want to check. If an array this method will return true if the request matches any type.
리턴 boolean Whether or not the request is the type you are checking.

isAll() 공개 메소드

Allows you to test multiple types and union the results. See CakeRequest::is() for how to add additional types and the built-in types.
또한 보기: CakeRequest::is()
public isAll ( array $types ) : boolean
$types array The types to check.
리턴 boolean Success.

method() 공개 메소드

There are a few ways to specify a method. - If your client supports it you can use native HTTP methods. - You can set the HTTP-X-Method-Override header. - You can submit an input with the name _method Any of these 3 approaches can be used to set the HTTP method used by CakePHP internally, and will effect the result of this method.
public method ( ) : string
리턴 string The name of the HTTP method used.

normalizedHere() 공개 메소드

$this->request->here は、ビューキャッシュの命名規則に影響する為、 CacheHelper 等で、このメソッドを利用する事で、同一ページによる複数キャッシュの生成を防ぐ (例) news/ → /news/index company/ → /company/index
public normalizedHere ( ) : string
리턴 string

offsetExists() 공개 메소드

Array access isset() implementation
public offsetExists ( string $name ) : boolean
$name string thing to check.
리턴 boolean

offsetGet() 공개 메소드

Array access read implementation
public offsetGet ( string $name ) : mixed
$name string Name of the key being accessed.
리턴 mixed

offsetSet() 공개 메소드

Array access write implementation
public offsetSet ( string $name, mixed $value ) : void
$name string Name of the key being written
$value mixed The value being written.
리턴 void

offsetUnset() 공개 메소드

Array access unset() implementation
public offsetUnset ( string $name ) : void
$name string Name to unset.
리턴 void

onlyAllow() 공개 메소드

Alias of CakeRequest::allowMethod() for backwards compatibility.
또한 보기: CakeRequest::allowMethod()
사용 중단: 3.0.0 Since 2.5, use CakeRequest::allowMethod() instead.
public onlyAllow ( string | array $methods ) : boolean
$methods string | array Allowed HTTP request methods.
리턴 boolean true

param() 공개 메소드

Safely access the values in $this->params.
public param ( string $name ) : mixed
$name string The name of the parameter to get.
리턴 mixed The value of the provided parameter. Will return false if the parameter doesn't exist or is falsey.

parseAccept() 공개 메소드

Generally you want to use CakeRequest::accept() to get a simple list of the accepted content types.
public parseAccept ( ) : array
리턴 array An array of prefValue => array(content/types)

query() 공개 메소드

Provides a read accessor for $this->query. Allows you to use a syntax similar to CakeSession for reading URL query data.
public query ( string $name ) : mixed
$name string Query string variable name
리턴 mixed The value being read

referer() 공개 메소드

Returns the referer that referred this request.
public referer ( boolean $local = false ) : string
$local boolean Attempt to return a local address. Local addresses do not contain hostnames.
리턴 string The referring address for this request.

setInput() 공개 메소드

Modify data originally from php://input. Useful for altering json/xml data in middleware or DispatcherFilters before it gets to RequestHandlerComponent
public setInput ( string $input ) : void
$input string A string to replace original parsed data from input()
리턴 void

subdomains() 공개 메소드

Get the subdomains for a host.
public subdomains ( integer $tldLength = 1 ) : array
$tldLength integer Number of segments your tld contains. For example: `example.com` contains 1 tld. While `example.co.uk` contains 2.
리턴 array An array of subdomains.

프로퍼티 상세

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

There are several ways to specify a detector, see CakeRequest::addDetector() for the various formats and ways to define detectors.
protected array $_detectors
리턴 array

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

Copy of php://input. Since this stream can only be read once in most SAPI's keep a copy of it so users don't need to know about that detail.
protected string $_input
리턴 string

$base 공개적으로 프로퍼티

Base URL path.
public string $base
리턴 string

$data 공개적으로 프로퍼티

Inputs prefixed with 'data' will have the data prefix removed. If there is overlap between an input prefixed with data and one without, the 'data' prefixed value will take precedence.
public array $data
리턴 array

$here 공개적으로 프로퍼티

The full address to the current request
public string $here
리턴 string

$params 공개적으로 프로퍼티

Array of parameters parsed from the URL.
public array $params
리턴 array

$query 공개적으로 프로퍼티

Array of querystring arguments
public array $query
리턴 array

$url 공개적으로 프로퍼티

The URL string used for the request.
public string $url
리턴 string

$webroot 공개적으로 프로퍼티

webroot path segment for the request.
public string $webroot
리턴 string