-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApplication.php
More file actions
75 lines (65 loc) · 2.14 KB
/
Copy pathApplication.php
File metadata and controls
75 lines (65 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
namespace Ptf;
if (!ini_get('date.timezone')) {
date_default_timezone_set('UTC');
}
mb_internal_encoding('UTF-8');
const BASEDIR = __DIR__;
require_once 'Util/functions.php';
require_once 'Core/Autoloader.php';
/**
* Base class for all Ptf applications.
*/
abstract class Application
{
/**
* Run the application.
*/
public static function run(): void
{
static::initAutoloader(Core\Autoloader::getInstance());
$context = static::getContext();
try {
if (!Core\Router::matchRequestRoute($context)) {
$context->getController()->forward404(); // This will throw a SystemExit exception
}
$response = $context->getResponse();
if (!$response->hasContent()) {
$response->setContent($context->getView()->fetch());
}
$response->send();
} catch (Core\Exception\SystemExit $e) {
}
}
/**
* Return the application's context object.<br>
* Overwrite this method to return a custom context.
*
* @return App\Context The context of the application
*/
public static function getContext(): App\Context
{
return App\Context::getInstance();
}
/**
* Initialize the autoloader.<br>
* Overwrite this method to set an application specific autoload configuration.
*
* @param Core\Autoloader $autoloader The autoloader to initialize
*/
protected static function initAutoloader(Core\Autoloader $autoloader): void
{
$autoloader->setCacheFilename(dirname($_SERVER['SCRIPT_FILENAME']) . '/var/autoload_cache.php');
}
/**
* Compile the given config INI file into \Ptf\App\Config class files.
*
* @param string $configName The filename of the config file
* @param string $configDir The target directory for the generated class files
* @param string $namespace The namespace of the application
*/
public static function compileConfig(string $configName, string $configDir, string $namespace): void
{
Util\ConfigCompiler::compile($configName, $configDir, $namespace);
}
}