Enabled ANSI and Videotex servers and frames

This commit is contained in:
Deon George
2018-12-09 09:43:18 +11:00
parent 6c91c69bd9
commit 0eb71ef7c6
11 changed files with 429 additions and 243 deletions

View File

@@ -25,22 +25,6 @@ class Frame extends Model
return $this->frame.$this->index;
}
/**
* Fetch a specific frame from the database
*
* @param int $page
* @param string $frame
* @return mixed
*/
public function fetch(int $frame,string $index='a'): \App\Classes\Frame
{
// Return our internal test frame.
if ($frame == '999' and $index == 'a')
return new \App\Classes\Frame(\App\Classes\Frame::testFrame());
return new \App\Classes\Frame($this->where('frame',$frame)->where('index',$index)->firstOrFail());
}
public function hasFlag(string $flag)
{
// @todo When flags is in the DB update this.

View File

@@ -5,24 +5,73 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use App\Classes\Frame as FrameClass;
use App\Classes\Frame\Ansi as AnsiFrame;
use App\Classes\Frame\Videotex as VideotexFrame;
use App\Classes\Server;
use App\Classes\Server\Ansi as AnsiServer;
use App\Classes\Server\Videotex as VideotexServer;
class Mode extends Model
{
public function frames()
{
return $this->hasMany(Frame::class);
}
/**
* Return a frame class for the Model
*
* @param Model $o
* @return FrameClass
* @throws \Exception
*/
public function frame(Model $o): FrameClass
{
switch (strtolower($this->name)) {
case 'ansi':
return new AnsiFrame($o);
case 'videotex':
return new VideotexFrame($o);
default:
throw new \Exception('Unknown Frame type: '.$mo->name);
}
}
/**
* Fetch a specific frame from the DB
*
* @param int $frame
* @param string $index
* @return FrameClass
* @throws \Exception
*/
//@todo Move Server $so first
public function frameLoad(int $frame,string $index='a',Server $so): FrameClass
{
return $this->frame(
// Return our internal test frame.
($frame == '999' and $index == 'a')
? $so->testFrame()
: $this->frames()
->where('frame','=',$frame)
->where('index','=',$index)
->firstOrFail()
);
}
/**
* Return our server instance
*/
public function server()
{
switch ($this->name) {
case 'Ansi':
case 'VideoTex':
$class = 'App\\Classes\\Server\\'.$this->name;
break;
switch (strtolower($this->name)) {
case 'ansi': return new AnsiServer($this);
case 'videotex': return new VideotexServer($this);
default:
throw new \Exception('Unknown server type: '.$this->name);
}
return new $class;
}
}