Typesetter-Original-gtbu/include/Base.php

92 lines
1.5 KiB
PHP
Raw Normal View History

2021-09-08 19:52:21 +02:00
<?php
namespace gp;
defined('is_running') or die('Not an entry point...');
#[\AllowDynamicProperties]
2021-09-08 19:52:21 +02:00
abstract class Base{
//executable commands
protected $cmds = [];
protected $cmds_post = [];
public function RunScript(){
$cmd = \gp\tool::GetCommand();
$this->RunCommands($cmd);
}
/**
* Run Commands
*
*/
public function RunCommands($cmd){
// POST commands
2021-10-06 21:01:02 +02:00
if( ($_SERVER['REQUEST_METHOD'] === 'POST') && isset($_POST['cmd']) && $_POST['cmd'] === $cmd ){
2021-09-08 19:52:21 +02:00
if( $this->_RunCommands($cmd, $this->cmds_post) ){
return;
}
}
// All others
if( $this->_RunCommands($cmd, $this->cmds) ){
return;
}
$this->DefaultDisplay();
}
private function _RunCommands($cmd, $avail_cmds){
if( !is_string($cmd) ){
$cmd = '';
}
$avail_cmds = array_change_key_case($avail_cmds, CASE_LOWER);
$cmd = strtolower($cmd);
if( !isset($avail_cmds[$cmd]) ){
return false;
}
$methods = (array)$avail_cmds[$cmd];
array_unshift($methods, $cmd);
foreach($methods as $method){
if( method_exists($this,$method) ){
$this->$method();
}elseif( is_callable($method) ){
call_user_func($method, $this);
}
}
return true;
}
/**
* The method to execute if RunCommands()
*
*/
public function DefaultDisplay(){
}
/**
* Get a property value
* @param string $property Name of the object property to get
*/
public function GetValue($property) {
if( property_exists($this, $property) ){
return $this->$property;
}
}
}