mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Added return type hinting to comments
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@40596 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
8d7494ff20
commit
3007fa55d5
@ -38,6 +38,9 @@ class Controller extends ViewableData {
|
|||||||
$this->urlParams = $urlParams;
|
$this->urlParams = $urlParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
function getURLParams() {
|
function getURLParams() {
|
||||||
return $this->urlParams;
|
return $this->urlParams;
|
||||||
}
|
}
|
||||||
@ -46,8 +49,10 @@ class Controller extends ViewableData {
|
|||||||
* Execute the appropriate action handler. If none is given, use defaultAction to display
|
* Execute the appropriate action handler. If none is given, use defaultAction to display
|
||||||
* a template. The default action will be appropriate in most cases where displaying data
|
* a template. The default action will be appropriate in most cases where displaying data
|
||||||
* is the core goal; the Viewer can call methods on the controller to get the data it needs.
|
* is the core goal; the Viewer can call methods on the controller to get the data it needs.
|
||||||
|
*
|
||||||
* @param array $urlParams named parameters extracted from the URL, including Action.
|
* @param array $urlParams named parameters extracted from the URL, including Action.
|
||||||
* @param array $requestParams GET and POST variables.
|
* @param array $requestParams GET and POST variables.
|
||||||
|
* @return HTTPResponse The response that this controller produces, including HTTP headers such as redirection info
|
||||||
*/
|
*/
|
||||||
protected $baseInitCalled = false;
|
protected $baseInitCalled = false;
|
||||||
function run($requestParams) {
|
function run($requestParams) {
|
||||||
@ -214,6 +219,7 @@ class Controller extends ViewableData {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Return an SSViewer object to process the data
|
* Return an SSViewer object to process the data
|
||||||
|
* @return SSViewer The viewer identified being the default handler for this Controller/Action combination
|
||||||
*/
|
*/
|
||||||
function getViewer($action) {
|
function getViewer($action) {
|
||||||
// Hard-coded templates
|
// Hard-coded templates
|
||||||
@ -270,12 +276,17 @@ class Controller extends ViewableData {
|
|||||||
$this->baseInitCalled = true;
|
$this->baseInitCalled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deprecated - use Controller::curr() instead
|
||||||
|
* @returns Controller
|
||||||
|
*/
|
||||||
public static function currentController() {
|
public static function currentController() {
|
||||||
return self::curr();
|
return self::curr();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the current controller
|
* Returns the current controller
|
||||||
|
* @returns Controller
|
||||||
*/
|
*/
|
||||||
public static function curr() {
|
public static function curr() {
|
||||||
if(Controller::$controller_stack) {
|
if(Controller::$controller_stack) {
|
||||||
@ -287,6 +298,7 @@ class Controller extends ViewableData {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests whether we have a currently active controller or not
|
* Tests whether we have a currently active controller or not
|
||||||
|
* @return boolean True if there is at least 1 controller in the stack.
|
||||||
*/
|
*/
|
||||||
public static function has_curr() {
|
public static function has_curr() {
|
||||||
return Controller::$controller_stack ? true : false;
|
return Controller::$controller_stack ? true : false;
|
||||||
@ -297,6 +309,7 @@ class Controller extends ViewableData {
|
|||||||
* @param perm The permission to be checked, such as 'View'.
|
* @param perm The permission to be checked, such as 'View'.
|
||||||
* @param member The member whose permissions need checking. Defaults to the currently logged
|
* @param member The member whose permissions need checking. Defaults to the currently logged
|
||||||
* in user.
|
* in user.
|
||||||
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
function can($perm, $member = null) {
|
function can($perm, $member = null) {
|
||||||
if(!$member) $member = Member::currentUser();
|
if(!$member) $member = Member::currentUser();
|
||||||
@ -312,6 +325,7 @@ class Controller extends ViewableData {
|
|||||||
/**
|
/**
|
||||||
* returns a date object for use within a template
|
* returns a date object for use within a template
|
||||||
* Usage: $Now.Year - Returns 2006
|
* Usage: $Now.Year - Returns 2006
|
||||||
|
* @return Date The current date
|
||||||
*/
|
*/
|
||||||
function Now() {
|
function Now() {
|
||||||
$d = new Date(null);
|
$d = new Date(null);
|
||||||
@ -339,6 +353,7 @@ class Controller extends ViewableData {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the visitor has been here before
|
* Returns true if the visitor has been here before
|
||||||
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
function PastVisitor() {
|
function PastVisitor() {
|
||||||
return Cookie::get("PastVisitor") ? true : false;
|
return Cookie::get("PastVisitor") ? true : false;
|
||||||
@ -346,6 +361,7 @@ class Controller extends ViewableData {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Return true if the visitor has signed up for a login account before
|
* Return true if the visitor has signed up for a login account before
|
||||||
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
function PastMember() {
|
function PastMember() {
|
||||||
return Cookie::get("PastMember") ? true : false;
|
return Cookie::get("PastMember") ? true : false;
|
||||||
@ -390,6 +406,7 @@ class Controller extends ViewableData {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the Session object representing this Controller's session
|
* Get the Session object representing this Controller's session
|
||||||
|
* @return Session
|
||||||
*/
|
*/
|
||||||
function getSession() {
|
function getSession() {
|
||||||
return $this->session;
|
return $this->session;
|
||||||
@ -404,6 +421,7 @@ class Controller extends ViewableData {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if this controller is processing an ajax request
|
* Returns true if this controller is processing an ajax request
|
||||||
|
* @return boolean True if this controller is processing an ajax request
|
||||||
*/
|
*/
|
||||||
function isAjax() {
|
function isAjax() {
|
||||||
return (
|
return (
|
||||||
|
@ -129,10 +129,17 @@ class Form extends ViewableData {
|
|||||||
$this->validator->removeValidation();
|
$this->validator->removeValidation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the {@link Validator} attached to this form.
|
||||||
|
* @return Validator
|
||||||
|
*/
|
||||||
function getValidator() {
|
function getValidator() {
|
||||||
return $this->validator;
|
return $this->validator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the {@link Validator} on this form.
|
||||||
|
*/
|
||||||
function setValidator( Validator $validator ) {
|
function setValidator( Validator $validator ) {
|
||||||
if($validator) {
|
if($validator) {
|
||||||
$this->validator = $validator;
|
$this->validator = $validator;
|
||||||
@ -140,6 +147,9 @@ class Form extends ViewableData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove the {@link Validator} from this from.
|
||||||
|
*/
|
||||||
function unsetValidator(){
|
function unsetValidator(){
|
||||||
$this->validator = null;
|
$this->validator = null;
|
||||||
}
|
}
|
||||||
@ -161,10 +171,18 @@ class Form extends ViewableData {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the form's fields - used by the templates
|
* Return the form's fields - used by the templates
|
||||||
|
* @return FieldSet The form fields
|
||||||
*/
|
*/
|
||||||
function Fields() {
|
function Fields() {
|
||||||
return $this->fields;
|
return $this->fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a named field from this form's fields.
|
||||||
|
* It will traverse into composite fields for you, to find the field you want.
|
||||||
|
* It will only return a data field.
|
||||||
|
* @return FormField
|
||||||
|
*/
|
||||||
function dataFieldByName($name) {
|
function dataFieldByName($name) {
|
||||||
return $this->fields->dataFieldByName($name);
|
return $this->fields->dataFieldByName($name);
|
||||||
}
|
}
|
||||||
@ -172,6 +190,7 @@ class Form extends ViewableData {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the form's action buttons - used by the templates
|
* Return the form's action buttons - used by the templates
|
||||||
|
* @return FieldSet The action list
|
||||||
*/
|
*/
|
||||||
function Actions() {
|
function Actions() {
|
||||||
return $this->actions;
|
return $this->actions;
|
||||||
@ -220,6 +239,7 @@ class Form extends ViewableData {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the attributes of the form tag - used by the templates
|
* Return the attributes of the form tag - used by the templates
|
||||||
|
* @return string The attribute string
|
||||||
*/
|
*/
|
||||||
function FormAttributes() {
|
function FormAttributes() {
|
||||||
// Forms shouldn't be cached, cos their error messages won't be shown
|
// Forms shouldn't be cached, cos their error messages won't be shown
|
||||||
@ -242,6 +262,11 @@ class Form extends ViewableData {
|
|||||||
$this->target = $target;
|
$this->target = $target;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the encoding type of the form.
|
||||||
|
* This will be either multipart/form-data - if there are field fields - or application/x-www-form-urlencoded
|
||||||
|
* @return string The encoding mime type
|
||||||
|
*/
|
||||||
function FormEncType() {
|
function FormEncType() {
|
||||||
if(is_array($this->fields->dataFields())){
|
if(is_array($this->fields->dataFields())){
|
||||||
foreach($this->fields->dataFields() as $field) {
|
foreach($this->fields->dataFields() as $field) {
|
||||||
@ -251,14 +276,27 @@ class Form extends ViewableData {
|
|||||||
return "application/x-www-form-urlencoded";
|
return "application/x-www-form-urlencoded";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the form method.
|
||||||
|
* @return string 'get' or 'post'
|
||||||
|
*/
|
||||||
function FormMethod() {
|
function FormMethod() {
|
||||||
return $this->formMethod;
|
return $this->formMethod;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the form method - get or post
|
||||||
|
*/
|
||||||
function setFormMethod($method) {
|
function setFormMethod($method) {
|
||||||
$this->formMethod = strtolower($method);
|
$this->formMethod = strtolower($method);
|
||||||
if($this->formMethod == 'get') $this->fields->push(new HiddenField('executeForm', '', $this->name));
|
if($this->formMethod == 'get') $this->fields->push(new HiddenField('executeForm', '', $this->name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the form's action attribute.
|
||||||
|
* This is build by adding an executeForm get variable to the parent controller's Link() value
|
||||||
|
* @return string The
|
||||||
|
*/
|
||||||
function FormAction() {
|
function FormAction() {
|
||||||
// "get" form needs ?executeForm added as a hidden field
|
// "get" form needs ?executeForm added as a hidden field
|
||||||
if($this->formMethod == 'post') {
|
if($this->formMethod == 'post') {
|
||||||
@ -282,6 +320,7 @@ class Form extends ViewableData {
|
|||||||
/**
|
/**
|
||||||
* Returns the field referenced by $_GET[fieldName].
|
* Returns the field referenced by $_GET[fieldName].
|
||||||
* Used for embedding entire extra helper forms inside complex field types (such as ComplexTableField)
|
* Used for embedding entire extra helper forms inside complex field types (such as ComplexTableField)
|
||||||
|
* @return FormField The field referenced by $_GET[fieldName]
|
||||||
*/
|
*/
|
||||||
function ReferencedField() {
|
function ReferencedField() {
|
||||||
return $this->dataFieldByName($_GET['fieldName']);
|
return $this->dataFieldByName($_GET['fieldName']);
|
||||||
@ -350,6 +389,11 @@ class Form extends ViewableData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected $record;
|
protected $record;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the DataObject that has given this form its data.
|
||||||
|
* @return DataObject
|
||||||
|
*/
|
||||||
function getRecord() {
|
function getRecord() {
|
||||||
return $this->record;
|
return $this->record;
|
||||||
}
|
}
|
||||||
@ -642,6 +686,10 @@ class Form extends ViewableData {
|
|||||||
// TESTING HELPERS
|
// TESTING HELPERS
|
||||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test a submission of this form.
|
||||||
|
* @return HTTPResponse the response object that the handling controller produces. You can interrogate this in your unit test.
|
||||||
|
*/
|
||||||
function testSubmission($action, $data) {
|
function testSubmission($action, $data) {
|
||||||
$data['action_' . $action] = true;
|
$data['action_' . $action] = true;
|
||||||
$data['executeForm'] = $this->name;
|
$data['executeForm'] = $this->name;
|
||||||
@ -652,6 +700,10 @@ class Form extends ViewableData {
|
|||||||
//return $response;
|
//return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test an ajax submission of this form.
|
||||||
|
* @return HTTPResponse the response object that the handling controller produces. You can interrogate this in your unit test.
|
||||||
|
*/
|
||||||
function testAjaxSubmission($action, $data) {
|
function testAjaxSubmission($action, $data) {
|
||||||
$data['ajax'] = 1;
|
$data['ajax'] = 1;
|
||||||
return $this->testSubmission($action, $data);
|
return $this->testSubmission($action, $data);
|
||||||
|
Loading…
Reference in New Issue
Block a user