2024.8.23
Loading...
Searching...
No Matches
ActionExt Class Reference

Public Member Functions

 __construct ($args)
 

Data Fields

const REFRESH = 'refresh'
 
const RELOAD = 'reload'
 
const START = 'start'
 
const STATUS_ERROR = 2
 
const STATUS_SUCCESS = 0
 
const STATUS_WARNING = 1
 
const STOP = 'stop'
 

Private Member Functions

 addLog ($data)
 
 getProcs ()
 
 procRefresh ($args)
 
 procReload ($args)
 
 procStart ($args)
 
 procStop ($args)
 
 sendLogs ()
 
 setStatus ($status)
 

Private Attributes

 $logs = ''
 
 $status = self::STATUS_SUCCESS
 

Detailed Description

Class ActionExt handles the execution of various extended actions.

Definition at line 13 of file class.action.ext.php.

Constructor & Destructor Documentation

◆ __construct()

ActionExt::__construct ( $args)

Constructor for the ActionExt class.

Parameters
array$argsThe command line arguments passed to the action.

Definition at line 41 of file class.action.ext.php.

42 {
43 if (!isset($args[0]) || empty($args[0])) {
44 $this->addLog('No args defined');
45 $this->addLog('Available args:');
46 foreach ($this->getProcs() as $proc) {
47 $this->addLog('- ' . $proc);
48 }
49 $this->setStatus(self::STATUS_ERROR);
50 $this->sendLogs();
51 return;
52 }
53
54 $action = $args[0];
55
56 $newArgs = array();
57 foreach ($args as $key => $arg) {
58 if ($key > 0) {
59 $newArgs[] = $arg;
60 }
61 }
62
63 $method = 'proc' . ucfirst($action);
64 if (!method_exists($this, $method)) {
65 $this->addLog('Unknown arg: ' . $action);
66 $this->addLog('Available args:');
67 foreach ($this->getProcs() as $procName => $procDesc) {
68 $this->addLog('- ' . $procName . ': ' . $procDesc);
69 }
70 $this->setStatus(self::STATUS_ERROR);
71 $this->sendLogs();
72 return;
73 }
74
75 call_user_func(array($this, $method), $newArgs);
76 $this->sendLogs();
77 }
$proc
Definition ajax.php:43
setStatus($status)

References $proc, addLog(), getProcs(), sendLogs(), and setStatus().

Member Function Documentation

◆ addLog()

ActionExt::addLog ( $data)
private

Adds a log entry to the logs.

Parameters
string$dataThe log entry to add.

Definition at line 99 of file class.action.ext.php.

100 {
101 $this->logs .= $data . "\n";
102 }

Referenced by __construct(), procRefresh(), procReload(), procStart(), and procStop().

+ Here is the caller graph for this function:

◆ getProcs()

ActionExt::getProcs ( )
private

Retrieves the list of available actions.

Returns
array The list of available actions.

Definition at line 84 of file class.action.ext.php.

85 {
86 return array(
87 self::START,
88 self::STOP,
89 self::RELOAD,
90 self::REFRESH
91 );
92 }

Referenced by __construct().

+ Here is the caller graph for this function:

◆ procRefresh()

ActionExt::procRefresh ( $args)
private

Refreshes the application by calling the reload action.

Parameters
array$argsThe command line arguments passed to the action.

Definition at line 217 of file class.action.ext.php.

218 {
219 global $bearsamppAction;
220
221 if (!Util::isLaunched()) {
222 $this->addLog(APP_TITLE . ' is not started.');
223 $this->setStatus(self::STATUS_ERROR);
224 return;
225 }
226
228 }
const RELOAD
$bearsamppAction
Definition root.php:32
const APP_TITLE
Definition root.php:12

References $bearsamppAction, addLog(), APP_TITLE, Action\RELOAD, and setStatus().

◆ procReload()

ActionExt::procReload ( $args)
private

Reloads the application by stopping and starting services.

Parameters
array$argsThe command line arguments passed to the action.

Definition at line 176 of file class.action.ext.php.

177 {
178 global $bearsamppRoot, $bearsamppBins, $bearsamppWinbinder;
179
180 if (!Util::isLaunched()) {
181 $this->addLog(APP_TITLE . ' is not started.');
182 $bearsamppWinbinder->exec($bearsamppRoot->getExeFilePath(), null, false);
183 $this->addLog('Start ' . APP_TITLE);
184 $this->setStatus(self::STATUS_WARNING);
185 return;
186 }
187
188 $this->addLog('Remove services');
189 foreach ($bearsamppBins->getServices() as $sName => $service) {
190 if ($service->delete()) {
191 $this->addLog('- ' . $sName . ': OK');
192 } else {
193 $this->addLog('- ' . $sName . ': KO');
194 $this->setStatus(self::STATUS_ERROR);
195 }
196 }
197
199
200 $this->addLog('Start services');
201 foreach ($bearsamppBins->getServices() as $sName => $service) {
202 $service->create();
203 if ($service->start()) {
204 $this->addLog('- ' . $sName . ': OK');
205 } else {
206 $this->addLog('- ' . $sName . ': KO');
207 $this->setStatus(self::STATUS_ERROR);
208 }
209 }
210 }
global $bearsamppBins
global $bearsamppRoot
static killBins($refreshProcs=false)

References $bearsamppBins, $bearsamppRoot, addLog(), APP_TITLE, Win32Ps\killBins(), and setStatus().

◆ procStart()

ActionExt::procStart ( $args)
private

Starts the application.

Parameters
array$argsThe command line arguments passed to the action.

Definition at line 130 of file class.action.ext.php.

131 {
132 global $bearsamppRoot, $bearsamppWinbinder;
133
134 if (!Util::isLaunched()) {
135 $this->addLog('Starting ' . APP_TITLE);
136 $bearsamppWinbinder->exec($bearsamppRoot->getExeFilePath(), null, false);
137 } else {
138 $this->addLog(APP_TITLE . ' already started');
139 $this->setStatus(self::STATUS_WARNING);
140 }
141 }

References $bearsamppRoot, addLog(), APP_TITLE, and setStatus().

◆ procStop()

ActionExt::procStop ( $args)
private

Stops the application and removes services.

Parameters
array$argsThe command line arguments passed to the action.

Definition at line 148 of file class.action.ext.php.

149 {
150 global $bearsamppBins;
151
152 if (Util::isLaunched()) {
153 $this->addLog('Remove services');
154 foreach ($bearsamppBins->getServices() as $sName => $service) {
155 if ($service->delete()) {
156 $this->addLog('- ' . $sName . ': OK');
157 } else {
158 $this->addLog('- ' . $sName . ': KO');
159 $this->setStatus(self::STATUS_ERROR);
160 }
161 }
162
163 $this->addLog('Stop ' . APP_TITLE);
164 Batch::exitAppStandalone();
165 } else {
166 $this->addLog(APP_TITLE . ' already stopped');
167 $this->setStatus(self::STATUS_WARNING);
168 }
169 }

References $bearsamppBins, addLog(), APP_TITLE, and setStatus().

◆ sendLogs()

ActionExt::sendLogs ( )
private

Sends the logs as a JSON-encoded response.

Definition at line 117 of file class.action.ext.php.

118 {
119 echo json_encode(array(
120 'status' => $this->status,
121 'response' => $this->logs
122 ));
123 }

Referenced by __construct().

+ Here is the caller graph for this function:

◆ setStatus()

ActionExt::setStatus ( $status)
private

Sets the status of the action.

Parameters
int$statusThe status code to set.

Definition at line 109 of file class.action.ext.php.

110 {
111 $this->status = $status;
112 }

References $status.

Referenced by __construct(), procRefresh(), procReload(), procStart(), and procStop().

+ Here is the caller graph for this function:

Field Documentation

◆ $logs

ActionExt::$logs = ''
private

Definition at line 34 of file class.action.ext.php.

◆ $status

ActionExt::$status = self::STATUS_SUCCESS
private

Definition at line 29 of file class.action.ext.php.

Referenced by setStatus().

◆ REFRESH

const ActionExt::REFRESH = 'refresh'

Definition at line 19 of file class.action.ext.php.

◆ RELOAD

const ActionExt::RELOAD = 'reload'

Definition at line 18 of file class.action.ext.php.

◆ START

const ActionExt::START = 'start'

Definition at line 16 of file class.action.ext.php.

◆ STATUS_ERROR

const ActionExt::STATUS_ERROR = 2

Definition at line 22 of file class.action.ext.php.

◆ STATUS_SUCCESS

const ActionExt::STATUS_SUCCESS = 0

Definition at line 24 of file class.action.ext.php.

◆ STATUS_WARNING

const ActionExt::STATUS_WARNING = 1

Definition at line 23 of file class.action.ext.php.

◆ STOP

const ActionExt::STOP = 'stop'

Definition at line 17 of file class.action.ext.php.


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