This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
vbbs/app/Classes/Control.php

81 lines
1.7 KiB
PHP

<?php
namespace App\Classes;
use App\Classes\Control\EditFrame;
use App\Classes\Control\Register;
use App\Classes\Control\Telnet;
abstract class Control
{
const prefix = 'App\Classes\Control\';
// Has this control class finished with input
protected $complete = FALSE;
// The server object that is running this control class
protected $so = 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
*/
public $state = [];
public function __construct(Server $so,array $args=[]) {
$this->so = $so;
// Boot control, preparing anything before keyboard entry
$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;
}
public static function factory(string $name,Server $so,array $args=[]) {
switch ($name) {
case 'editframe':
return new EditFrame($so,$args);
case 'register':
return new Register($so);
case 'telnet':
return new Telnet($so);
default:
$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;
}
}
abstract public function handle(string $read);
/**
* 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;
}
}