[
Class Tree: teeple
] [
Index: teeple
] [
All elements
]
teeple
teeple
·
Packages:
teeple
teeple-converter
teeple-filter
teeple-validator
Source for file Request.php
Documentation is available at
Request.php
<?php
/**
* Teeple2 - PHP5 Web Application Framework inspired by Seasar2
*
* PHP versions 5
*
* LICENSE: This source file is subject to version 3.0 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to license@php.net so we can mail you a copy immediately.
*
*
@package
teeple
*
@author
Mitsutaka Sato <miztaka@gmail.com>
*
@license
http://www.php.net/license/3_0.txt PHP License 3.0
*/
/**
* POST/GETで受け取った値を格納する
*
*
@package
teeple
*/
class
Teeple_Request
{
/**
* POT/GETで受け取った値を保持する
*
@var
array
*/
private
$_params
;
/**
*
@var
array
*/
private
$errorList
=
array
(
)
;
/**
*
@var
string
*/
private
$filterError
;
/**
*
@var
string
*/
private
$actionMethod
;
/**
* Actionの実行が完了したかどうか
*
@var
boolean
*/
private
$completeActionFlg
=
FALSE
;
/**
* Responseの返却が完了したかどうか
*
@var
boolean
*/
private
$completeResponseFlg
=
FALSE
;
/**
*
*
@var
boolean
*/
public
$isRedirect
=
FALSE
;
/**
*
@var
Logger
*/
private
$log
;
/**
* コンストラクタ
*
*/
public
function
__construct
(
)
{
$this
->
log
=
LoggerManager
::
getLogger
(
get_class
(
$this
))
;
$request
=
array_merge
(
$_POST
,
$_GET
)
;
if
(
get_magic_quotes_gpc
(
))
{
$request
=
$this
->
_stripSlashesDeep
(
$request
)
;
}
if
(
!
ini_get
(
"mbstring.encoding_translation"
)
&&
(
INPUT_CODE
!=
INTERNAL_CODE
))
{
mb_convert_variables
(
INTERNAL_CODE
,
INPUT_CODE
,
$request
)
;
}
// action:~ではじまるパラメータがあればactionMethodをセットする
$methodName
=
"execute"
;
$key
=
NULL
;
foreach
(
$request
as
$k
=>
$val
)
{
if
(
preg_match
(
'/^action:(.+)$/'
,
$k
,
$m
))
{
$methodName
=
$m
[
1
]
;
$this
->
log
->
debug
(
"
actionMethodが指定されました。 {
$methodName
}
"
)
;
$key
=
$k
;
break
;
}
}
$this
->
actionMethod
=
$methodName
;
if
(
$key
!=
NULL
)
{
unset
(
$request
[
$key
]
)
;
}
$this
->
_params
=
$request
;
return
;
}
/**
* stripslashes() 関数を再帰的に実行する
*
*
@param
mixed
$value
処理する変数
*
@return
mixed
処理結果
*
@see
http://www.php.net/manual/ja/function.stripslashes.php#AEN181588
*/
private
function
_stripSlashesDeep
(
$value
)
{
if
(
is_array
(
$value
))
{
$value
=
array_map
(
array
(
$this
,
'_stripSlashesDeep'
)
,
$value
)
;
}
else
{
$value
=
stripslashes
(
$value
)
;
}
return
$value
;
}
/**
* REQUEST_METHODの値を返却
*
*
@return
string
REQUEST_METHODの値
*/
public
function
getMethod
(
)
{
return
$_SERVER
[
"REQUEST_METHOD"
]
;
}
/**
* POST/GETの値を返却
*
*
@param
string
$key
パラメータ名
*
@return
string
パラメータの値
*/
public
function
getParameter
(
$key
)
{
return
isset
(
$this
->
_params
[
$key
]
)
?
$this
->
_params
[
$key
]
:
NULL
;
}
/**
* POST/GETの値をセット
*
*
@param
string
$key
パラメータ名
*
@param
string
$value
パラメータの値
*/
function
setParameter
(
$key
,
$value
)
{
$this
->
_params
[
$key
]
=
$value
;
}
/**
* リクエストパラメータを削除する
*
*
@param
string
$key
*/
function
removeParameter
(
$key
)
{
unset
(
$this
->
_params
[
$key
]
)
;
}
/**
* POST/GETの値を返却(配列で返却)
*
*
@param
string
$key
パラメータ名
*
@return
array
パラメータの値(配列)
*/
function
getParameters
(
)
{
return
$this
->
_params
;
}
/**
* エラーメッセージを追加します。
*
*
@param
string
$message
*
@param
string
$target
*/
public
function
addErrorMessage
(
$message
,
$target
=
"__DEFAULT"
)
{
if
(
!
isset
(
$this
->
errorList
[
$target
]
))
{
$this
->
errorList
[
$target
]
=
array
(
)
;
}
$this
->
errorList
[
$target
]
[
]
=
$message
;
return
;
}
/**
* エラーがあるかどうか
*
*
@return
boolean
*/
public
function
isError
(
)
{
return
count
(
$this
->
errorList
)
>
0
;
}
/**
* 指定されたtargetのエラーメッセージを取得します。
*
*
@param
string
$target
*
@return
array
*/
public
function
getErrorMessages
(
$target
=
NULL
)
{
if
(
$target
==
NULL
)
{
return
$this
->
getAllErrorMessages
(
)
;
}
return
isset
(
$this
->
errorList
[
$target
]
)
?
$this
->
errorList
[
$target
]
:
array
(
)
;
}
/**
* 全てのエラーメッセージを取得します。
*
*
@return
array
*/
public
function
getAllErrorMessages
(
)
{
$allmessages
=
array
(
)
;
foreach
(
$this
->
errorList
as
$target
=>
$errors
)
{
$allmessages
=
array_merge
(
$allmessages
,
$errors
)
;
}
return
$allmessages
;
}
/**
* エラーメッセージをクリアします。
*
*/
public
function
resetErrorMessages
(
)
{
$this
->
errorList
=
array
(
)
;
return
;
}
public
function
setFilterError
(
$errorType
)
{
$this
->
filterError
=
$errorType
;
return
;
}
public
function
getFilterError
(
)
{
return
$this
->
filterError
;
}
public
function
isFilterError
(
)
{
return
isset
(
$this
->
filterError
)
&&
strlen
(
$this
->
filterError
)
;
}
public
function
getActionMethod
(
)
{
return
$this
->
actionMethod
;
}
public
function
setActionMethod
(
$method
)
{
$this
->
actionMethod
=
$method
;
}
/**
* Actionの完了をセットします。
*
*/
public
function
completeAction
(
)
{
$this
->
completeActionFlg
=
TRUE
;
}
/**
* Responseの完了をセットします。
*
*/
public
function
completeResponse
(
)
{
$this
->
completeActionFlg
=
TRUE
;
$this
->
completeResponseFlg
=
TRUE
;
}
/**
* Actionが完了したかどうか?
*
@return
boolean
*/
public
function
isCompleteAction
(
)
{
return
$this
->
completeActionFlg
;
}
/**
* Responseが完了したかどうか?
*
@return
boolean
*/
public
function
isCompleteResponse
(
)
{
return
$this
->
completeResponseFlg
;
}
public
function
resetCompleteFlag
(
)
{
$this
->
completeActionFlg
=
FALSE
;
$this
->
completeResponseFlg
=
FALSE
;
}
}
?>
Documentation generated on Mon, 26 Apr 2010 08:59:54 +0900 by
phpDocumentor 1.4.3