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

69 lines
1.5 KiB
PHP

<?php
namespace App\Classes;
use App\Classes\Control\EditFrame;
use App\Classes\Control\Register;
use App\Classes\Control\Telnet;
abstract class Control
{
// Has this control class finished with input
protected $complete = FALSE;
// The server object that is running this control class
protected $so = NULL;
// 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
*/
public $state = [];
public function __construct(Server $so,Frame $fo=NULL) {
$this->so = $so;
$this->fo = $fo;
// 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;
}
// @todo Change to Dynamic Calls by the existence of files in App\Classes\Control
public static function factory(string $name,Server $so,Frame $fo=NULL) {
switch ($name) {
case 'editframe':
return new EditFrame($so,$fo);
case 'register':
return new Register($so);
case 'telnet':
return new Telnet($so);
default:
throw new \Exception('Unknown control method: '.$name);
}
}
abstract public function handle(string $read);
}