Tutorial Extension  1.0.0
SellerDeck Extensions - Tutorial Extension
Public Member Functions | Protected Attributes | List of all members
CControllerBase Class Reference

Public Member Functions

 __call ($sName, $aArguments)
 
 __construct ()
 
 Run ()
 
 SetOutputFormat ($nOutputFormat=FORMAT_JSON)
 
 GetStandardResponse ($sAction= '', $sStatus=STATUS_SUCCESS, $aData=[], $sView= '')
 
 GetOutput ($nOutputFormat=null)
 

Protected Attributes

 $m_sAction = ""
 
 $m_aResponse = []
 
 $m_nOutputFormat = FORMAT_JSON
 

Detailed Description

Definition at line 14 of file CControllerBase.php.

Constructor & Destructor Documentation

__construct ( )

__construct - Run process

public

Parameters
$aInputarray Input data
Returns
bool Success

Definition at line 47 of file CControllerBase.php.

48  {
49 
50  $this->m_sAction = filter_input(INPUT_GET, CONTROLLER_PARAMETER_ACTION);
51  if (null != $this->m_sAction)
52  {
53  $this->m_sAction = ucfirst($this->m_sAction);
54  }
55  else
56  {
57  $this->m_sAction = CONTROLLER_DEFAULT_ACTION;
58  }
59  $this->m_nOutputFormat = filter_input(INPUT_GET, CONTROLLER_PARAMETER_FORMAT);
60  if (null != $this->m_nOutputFormat)
61  {
62  $this->m_nOutputFormat = strtolower($this->m_nOutputFormat);
63  }
64  else
65  {
66  $this->m_nOutputFormat = FORMAT_JSON;
67  }
68  }

Member Function Documentation

GetOutput (   $nOutputFormat = null)

GetOutput - Get Output

public

Returns
bool Success

Definition at line 123 of file CControllerBase.php.

124  {
125  if (null == $nOutputFormat)
126  {
127  $nOutputFormat = $this->m_nOutputFormat;
128  }
129  switch ($nOutputFormat)
130  {
131  case FORMAT_ARRAY:
132  return $this->m_aResponse;
133  case FORMAT_TEXT:
134  header('Content-Type: text/plain');
135  return print_r($this->m_aResponse, true);
136  case FORMAT_STREAM:
137  return "data: " . json_encode($this->m_aResponse);
138  case FORMAT_PHP:
139  header('Content-Type: text/plain');
140  return var_export($this->m_aResponse, true);
141  case FORMAT_HTML:
142  header('Content-Type: text/html');
143  return arr_get($this->m_aResponse, 'view', '');
144 // case FORMAT_YAML:
145 // header('Content-Type: application/xml');
146 // return Array2XML($this->m_aResponse);
147 // case FORMAT_XML:
148 // header('Content-Type: application/xml');
149 // return Array2XML($this->m_aResponse);
150  case FORMAT_JSON:
151  default:
152  header('Content-Type: application/json');
153  return json_encode($this->m_aResponse);
154  }
155  return $this->m_aResponse;
156  }
GetStandardResponse (   $sAction = '',
  $sStatus = STATUS_SUCCESS,
  $aData = [],
  $sView = '' 
)

GetStandardResponse - Get Standard Response

public

Parameters
$sActionstring Action name
$sStatusstring Status
$aDataarray Data
$sViewstring View
Returns
array Response data

Definition at line 107 of file CControllerBase.php.

108  {
109  return [
110  'action' => $sAction,
111  'status' => $sStatus,
112  'data' => $aData,
113  'view' => $sView,
114  ];
115  }
Run ( )

Run - Run process

public

Returns
bool Success

Definition at line 76 of file CControllerBase.php.

77  {
78  if (FORMAT_STREAM == $this->m_nOutputFormat)
79  {
80  sse_header();
81  }
82  $this->m_aResponse = $this->{"Action" . $this->m_sAction}();
83  return $this;
84  }
SetOutputFormat (   $nOutputFormat = FORMAT_JSON)

SetOutputFormat - Set Output Format

public

Returns
bool Success

Definition at line 92 of file CControllerBase.php.

93  {
94  $this->m_nOutputFormat = $nOutputFormat;
95  }

The documentation for this class was generated from the following file: