The TryingToScale PHP framework.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
tts_framework/src/classes/page_not_found.php

69 lines
1.8 KiB

<?php
declare(strict_types=1);
/**
* @author Robert Strutts <Robert@TryingToScale.com>
* @copyright Copyright (c) 2022, Robert Strutts.
* @license MIT
*/
namespace tts;
class page_not_found {
/**
* Command Line Route - Invalid Error
*/
public static function error404_cli(): void {
$err = "CLI 404 Page not found! Invalid Route/Method." . PHP_EOL;
$argv = (isset($GLOBALS['argv'])) ? $GLOBALS['argv'] : array();
$num_args = count($argv);
if ( $num_args > 1 ) {
$err .= $argv[1];
}
$exists = \main_tts\registry::get('di')->exists('log');
if ($exists) {
$log = \main_tts\registry::get('di')->get_service('log', ['CLI_404s']);
$log->write($err);
}
echo $err;
exit(1);
}
/**
* Displays 404 Page not Found
*/
public static function error404(): void {
if (\tts\console_app::is_cli()) {
self::error404_cli();
} else {
$use_api = \tts\misc::is_api();
}
if ($use_api === true) {
self::api_method_not_found();
}
// Show 404, Page Not Found Error Page!
if (\bs_tts\requires::secure_include('404_page.php', 'on_error') === false) {
$loaded = \bs_tts\requires::secure_include('views/on_error/404_page.php', 'tts');
if ($loaded === false) {
echo "<h1>404 Page Not Found!</h1>";
}
}
exit(1);
}
/**
* API Method was not found do API 400 Error
*/
private static function api_method_not_found(): void {
$status = 400; // Bad Request
$bad_request = \tts\api::BAD_REQUEST;
\tts\api::error(array('response' => $bad_request, 'code' => $status, 'reason' => 'Command not found'));
}
}