|
11 | 11 | /** |
12 | 12 | * Initialize the application. |
13 | 13 | * |
14 | | - * @param string $ConfigPath |
| 14 | + * @param string $configPath |
15 | 15 | * @return Application |
16 | 16 | * @throws \Exception |
17 | 17 | */ |
18 | 18 |
|
19 | | -function boot( string $ConfigPath ) : Application |
| 19 | +function boot( string $configPath ) : Application |
20 | 20 | { |
21 | | - /** @var Neuron\Data\Setting\Source\ISettingSource $Settings */ |
| 21 | + /** @var Neuron\Data\Setting\Source\ISettingSource $settings */ |
22 | 22 |
|
23 | 23 | try |
24 | 24 | { |
25 | | - $Settings = new Yaml( "$ConfigPath/config.yaml" ); |
26 | | - $BasePath = $Settings->get( 'system', 'base_path' ); |
| 25 | + $settings = new Yaml( "$configPath/config.yaml" ); |
| 26 | + $basePath = $settings->get( 'system', 'base_path' ); |
27 | 27 | } |
28 | 28 | catch( \Exception $e ) |
29 | 29 | { |
30 | | - $Settings = null; |
31 | | - $BasePath = getenv( 'SYSTEM_BASE_PATH' ) ? : '.'; |
| 30 | + $settings = null; |
| 31 | + $basePath = getenv( 'SYSTEM_BASE_PATH' ) ? : '.'; |
32 | 32 | } |
33 | 33 |
|
34 | | - $Version = new Version(); |
35 | | - $Version->loadFromFile( "$BasePath/.version.json" ); |
| 34 | + $version = new Version(); |
| 35 | + $version->loadFromFile( "$basePath/.version.json" ); |
36 | 36 |
|
37 | 37 | try |
38 | 38 | { |
39 | | - $App = new Application( $Version->getAsString(), $Settings ); |
| 39 | + $app = new Application( $version->getAsString(), $settings ); |
40 | 40 | } |
41 | 41 | catch( \Throwable $e ) |
42 | 42 | { |
43 | 43 | echo Application::beautifyException( $e ); |
44 | 44 | exit( 1 ); |
45 | 45 | } |
46 | 46 |
|
47 | | - return $App; |
| 47 | + return $app; |
48 | 48 | } |
49 | 49 |
|
50 | 50 | /** |
51 | 51 | * Dispatches the current route mapped in the 'route' GET variable. |
52 | 52 | * |
53 | | - * @param Application $App |
| 53 | + * @param Application $app |
54 | 54 | */ |
55 | 55 |
|
56 | | -function dispatch( Application $App ) : void |
| 56 | +function dispatch( Application $app ) : void |
57 | 57 | { |
58 | | - $Route = Get::filterScalar( 'route' ) ?? ""; |
| 58 | + $route = Get::filterScalar( 'route' ) ?? ""; |
59 | 59 |
|
60 | 60 | try |
61 | 61 | { |
62 | | - $Type = Server::filterScalar( 'REQUEST_METHOD' ) ?? "GET"; |
| 62 | + $type = Server::filterScalar( 'REQUEST_METHOD' ) ?? "GET"; |
63 | 63 |
|
64 | 64 | // Support HTML form method spoofing via _method field |
65 | 65 | // HTML forms can only submit GET/POST, so frameworks use a hidden _method field |
66 | 66 | // to indicate PUT/DELETE/PATCH requests |
67 | | - if( $Type === 'POST' && isset( $_POST['_method'] ) ) |
| 67 | + if( $type === 'POST' && isset( $_POST['_method'] ) ) |
68 | 68 | { |
69 | | - $SpoofedMethod = strtoupper( $_POST['_method'] ); |
70 | | - if( in_array( $SpoofedMethod, [ 'PUT', 'DELETE', 'PATCH' ] ) ) |
| 69 | + $spoofedMethod = strtoupper( $_POST['_method'] ); |
| 70 | + if( in_array( $spoofedMethod, [ 'PUT', 'DELETE', 'PATCH' ] ) ) |
71 | 71 | { |
72 | | - $Type = $SpoofedMethod; |
| 72 | + $type = $spoofedMethod; |
73 | 73 | } |
74 | 74 | } |
75 | 75 |
|
76 | | - $App->run( |
| 76 | + $app->run( |
77 | 77 | [ |
78 | | - "type" => $Type, |
79 | | - "route" => $Route |
| 78 | + "type" => $type, |
| 79 | + "route" => $route |
80 | 80 | ] |
81 | 81 | ); |
82 | 82 | } |
83 | 83 | catch( \Throwable $e ) |
84 | 84 | { |
85 | | - echo $App->handleException( $e ); |
| 85 | + echo $app->handleException( $e ); |
86 | 86 | } |
87 | 87 | } |
88 | 88 |
|
89 | 89 | /** |
90 | 90 | * Clear expired cache entries |
91 | 91 | * |
92 | | - * @param Application $App |
| 92 | + * @param Application $app |
93 | 93 | * @return int Number of entries removed |
94 | 94 | */ |
95 | | -function clearExpiredCache( Application $App ) : int |
| 95 | +function clearExpiredCache( Application $app ) : int |
96 | 96 | { |
97 | | - return $App->clearExpiredCache(); |
| 97 | + return $app->clearExpiredCache(); |
98 | 98 | } |
99 | 99 |
|
100 | 100 | /** |
101 | 101 | * Render a partial view from the shared directory. |
102 | 102 | * This function looks for a file named _{name}.php in the shared views directory. |
103 | 103 | * @param string $name The name of the partial (without underscore prefix or .php extension) |
104 | | - * @param array $Data Optional data array to pass to the partial as variables |
| 104 | + * @param array $data Optional data array to pass to the partial as variables |
105 | 105 | * @return void |
106 | 106 | * @throws NotFound |
107 | 107 | */ |
108 | | -function partial( string $name, array $Data = [] ) : void |
| 108 | +function partial( string $name, array $data = [] ) : void |
109 | 109 | { |
110 | | - $Path = Registry::getInstance() |
| 110 | + $path = Registry::getInstance() |
111 | 111 | ->get( "Views.Path" ); |
112 | 112 |
|
113 | | - if( !$Path ) |
| 113 | + if( !$path ) |
114 | 114 | { |
115 | | - $BasePath = Registry::getInstance()->get( "Base.Path" ); |
116 | | - $Path = "$BasePath/resources/views"; |
| 115 | + $basePath = Registry::getInstance()->get( "Base.Path" ); |
| 116 | + $path = "$basePath/resources/views"; |
117 | 117 | } |
118 | 118 |
|
119 | | - $View = "$Path/shared/_$name.php"; |
| 119 | + $view = "$path/shared/_$name.php"; |
120 | 120 |
|
121 | | - if( !file_exists( $View ) ) |
| 121 | + if( !file_exists( $view ) ) |
122 | 122 | { |
123 | | - throw new NotFound( "Partial not found: $View" ); |
| 123 | + throw new NotFound( "Partial not found: $view" ); |
124 | 124 | } |
125 | 125 |
|
126 | 126 | // Extract data array as variables in the partial's scope |
127 | | - extract( $Data ); |
| 127 | + extract( $data ); |
128 | 128 |
|
129 | 129 | ob_start(); |
130 | | - require( $View ); |
131 | | - $Content = ob_get_contents(); |
| 130 | + require( $view ); |
| 131 | + $content = ob_get_contents(); |
132 | 132 | ob_end_clean(); |
133 | 133 |
|
134 | | - echo $Content; |
| 134 | + echo $content; |
135 | 135 | } |
0 commit comments