autoWireIOL

main
Robert 3 weeks ago
parent c405cd67aa
commit 54b12120f6
  1. 34
      protected/src/Classes/BaseController.php

@ -10,8 +10,10 @@ declare(strict_types = 1);
namespace Project\Classes;
use IOcornerstone\Framework\Http\HttpFactory;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\{
ServerRequestInterface,
ResponseInterface,
};
use IOcornerstone\Framework\{
HtmlDocument,
View,
@ -26,6 +28,9 @@ class BaseController
public $view;
public $html;
public $outputHTML;
public $pdo;
public $inputs; // Set by Inputs and used in Logic/Outputs
public $logic; // Used in Logic for Outputs
protected string $footer = "";
protected string $authors = "";
@ -43,6 +48,31 @@ class BaseController
}
}
public function autoWireIOL(
string $root_folder,
string $file,
string $method = 'index',
): ResponseInterface {
$saferRootFolder = Common::getAlphaNumbric($root_folder, allow_dashes: true);
$saferFile = Common::getAlphaNumbric($file, allow_dashes: true);
$saferMethod = Common::getAlphaNumbric($method, allow_dashes: true);
unset($root_folder);
unset($file);
unset($method);
$classNameIn = "\\Project\\Classes\\Inputs\\{$saferRootFolder}\\{$saferFile}";
$this->inputs = $classNameIn::$saferMethod($this->request);
// Logic might not always exist, so check.
$classNameLogic = "\\Project\\Classes\\Logic\\{$saferRootFolder}\\{$saferFile}";
if (method_exists($classNameLogic, $saferMethod)) {
$classNameLogic::$saferMethod($this);
}
$classNameOut= "\\Project\\Classes\\Outputs\\{$saferRootFolder}\\{$saferFile}";
return $classNameOut::$saferMethod($this);
}
public function returnResponse(string|array $body, int $status = 200, array $headers = []): ResponseInterface
{
if (is_array($body)) {

Loading…
Cancel
Save