2018-12-25 01:48:57 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Classes;
|
|
|
|
|
2019-07-12 03:42:01 +00:00
|
|
|
use App\Classes\Control\EditFrame;
|
2018-12-25 01:48:57 +00:00
|
|
|
use App\Classes\Control\Register;
|
|
|
|
use App\Classes\Control\Telnet;
|
|
|
|
|
|
|
|
abstract class Control
|
|
|
|
{
|
2019-10-02 05:47:56 +00:00
|
|
|
const prefix = 'App\Classes\Control\';
|
|
|
|
|
2019-07-12 03:42:01 +00:00
|
|
|
// Has this control class finished with input
|
2018-12-25 01:48:57 +00:00
|
|
|
protected $complete = FALSE;
|
2019-07-12 03:42:01 +00:00
|
|
|
|
|
|
|
// The server object that is running this control class
|
2018-12-25 01:48:57 +00:00
|
|
|
protected $so = NULL;
|
2019-07-12 03:42:01 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* What is the state of the server outside of this control.
|
|
|
|
* Should only contain
|
|
|
|
* + mode = Mode to follow outside of the control method
|
|
|
|
* + action = Action to run after leaving the control method
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2018-12-25 01:48:57 +00:00
|
|
|
public $state = [];
|
|
|
|
|
2019-10-02 05:47:56 +00:00
|
|
|
public function __construct(Server $so,array $args=[]) {
|
2018-12-25 01:48:57 +00:00
|
|
|
$this->so = $so;
|
|
|
|
|
2019-07-12 03:42:01 +00:00
|
|
|
// Boot control, preparing anything before keyboard entry
|
2018-12-25 01:48:57 +00:00
|
|
|
$this->boot();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Default boot method if a child class doesnt have one.
|
|
|
|
protected function boot() {
|
|
|
|
$this->state['mode'] = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Has control completed?
|
|
|
|
*/
|
|
|
|
public function complete()
|
|
|
|
{
|
|
|
|
return $this->complete;
|
|
|
|
}
|
|
|
|
|
2019-10-02 05:47:56 +00:00
|
|
|
public static function factory(string $name,Server $so,array $args=[]) {
|
2018-12-25 01:48:57 +00:00
|
|
|
switch ($name) {
|
2019-07-12 03:42:01 +00:00
|
|
|
case 'editframe':
|
2019-10-02 05:47:56 +00:00
|
|
|
return new EditFrame($so,$args);
|
2019-07-12 03:42:01 +00:00
|
|
|
|
2018-12-25 01:48:57 +00:00
|
|
|
case 'register':
|
|
|
|
return new Register($so);
|
|
|
|
|
|
|
|
case 'telnet':
|
|
|
|
return new Telnet($so);
|
|
|
|
|
|
|
|
default:
|
2019-10-02 05:47:56 +00:00
|
|
|
$c = self::prefix.$name;
|
|
|
|
$o = class_exists($c) ? new $c($so,$args) : FALSE;
|
|
|
|
|
|
|
|
$so->log('debug',sprintf(($o ? 'Executing: %s' : 'Class doesnt exist: %s'),$c));
|
|
|
|
|
|
|
|
return $o;
|
2018-12-25 01:48:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-12 03:42:01 +00:00
|
|
|
abstract public function handle(string $read);
|
2019-07-14 12:43:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* If completing an Action frame, this will be called to submit the data.
|
|
|
|
*
|
|
|
|
* Ideally this should be overridden in a child class.
|
|
|
|
*/
|
|
|
|
public function process()
|
|
|
|
{
|
|
|
|
$this->complete = TRUE;
|
|
|
|
}
|
2018-12-25 01:48:57 +00:00
|
|
|
}
|