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-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
|
|
|
|
|
|
|
// The frame applicable for this control (not the current rendered frame, thats in $so)
|
|
|
|
protected $fo = NULL;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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-07-12 03:42:01 +00:00
|
|
|
public function __construct(Server $so,Frame $fo=NULL) {
|
2018-12-25 01:48:57 +00:00
|
|
|
$this->so = $so;
|
2019-07-12 03:42:01 +00:00
|
|
|
$this->fo = $fo;
|
2018-12-25 01:48:57 +00:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
// @todo Change to Dynamic Calls by the existence of files in App\Classes\Control
|
2019-07-12 03:42:01 +00:00
|
|
|
public static function factory(string $name,Server $so,Frame $fo=NULL) {
|
2018-12-25 01:48:57 +00:00
|
|
|
switch ($name) {
|
2019-07-12 03:42:01 +00:00
|
|
|
case 'editframe':
|
|
|
|
return new EditFrame($so,$fo);
|
|
|
|
|
2018-12-25 01:48:57 +00:00
|
|
|
case 'register':
|
|
|
|
return new Register($so);
|
|
|
|
|
|
|
|
case 'telnet':
|
|
|
|
return new Telnet($so);
|
|
|
|
|
|
|
|
default:
|
|
|
|
throw new \Exception('Unknown control method: '.$name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-12 03:42:01 +00:00
|
|
|
abstract public function handle(string $read);
|
2018-12-25 01:48:57 +00:00
|
|
|
}
|