http = new HttpFactory(); $this->view = new View(); $this->html = new HtmlDocument(); $this->outputHTML = SaferOutput::class; // If the child controller has an init() method, call it automatically if (method_exists($this, 'init')) { $this->init(); } } 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)) { if (! in_array("Content-Type", $headers)) { $headers = ['Content-Type'=>'application/json']; } return $this->http->createResponse($status, $headers, json_encode($body)); } return $this->http->createResponse($status, $headers, $body); } public function setFooterAndAuthors() { if (defined('\Project\MyPage::MyFooter')) { $this->footer = \Project\MyPage::MyFooter; } else { $this->footer = ""; } if (defined('\Project\MyPage::MyAuthors')) { $this->authors = \Project\MyPage::MyAuthors; } else { $this->authors = ""; } $this->html->setFooter($this->footer); $this->html->setAuthor($this->authors); } }