-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
140 lines (117 loc) · 4.5 KB
/
index.php
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?php
// MIT License
// Copyright (c) 2024 Andrew Rout
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
/**
* An open source application development framework designed for PHP 7
*
* @package Rhapsody Framwework
* @author Andrew Rout [ arout@diamondphp.org ]
* @copyright Copyright (c) 2024, Andrew Rout
* @license https://diamondphp.org/support/license
* @link https://diamondphp.org
* @since Version 1.0.0
* @filesource
*
*/
declare ( strict_types = 1 );
define( 'DS', DIRECTORY_SEPARATOR );
// Defines the location of the front controller (this file)
// For security purposes, we recommend the front controller
// to be the only PHP file stored in a publicly accessible folder
if ( !defined( 'BASE_PATH' ) )
{
$dir = dirname( __FILE__ );
$dir = chop( $dir );
$dir = chop( $dir, "/" );
define( 'BASE_PATH', $dir . DS );
}
// If you moved your .env file to another directory,
// remove BASE_PATH . below and enter the full file path
define( 'ENV_PATH', BASE_PATH . '.env' );
// Check for and attempt to fix read permissions to the .env file
// Will not work on all servers
$fp = fileperms( ENV_PATH );
if ( file_exists( ENV_PATH ) )
{
if ( substr( sprintf( '%o', $fp ), -4 ) != 0644 )
{
chmod( ENV_PATH, 0644 );
}
}
// Either the ENV_PATH variable above is set incorrectly,
// or we just cannot read the file. Alert user and abort.
if ( !is_readable( ENV_PATH ) )
{
exit( '<h3>Either the <span style="color: red;">.env</span> global configuration file was not found,
or the file does not have read permissions. Exiting...</h3>' );
}
unset( $fp );
require_once BASE_PATH . 'vendor' . DS . 'autoload.php';
// If you moved the /src folder, erase the default value below and enter
// the file path to the new location of the 'src' folder.
// Be sure to include the trailing slash.
// Example::
// $system_folder = '/usr/home/foobar/src/';
$system_folder = BASE_PATH . 'src' . DS;
// Import service locator
require_once $system_folder . 'Factory.php';
// Load path definitions
require_once $system_folder . 'Paths.php';
// Check if system check was requested
if ( $app['config']->setting( 'system_startup_check' ) == 'TRUE' )
{
require_once SYSTEM_PATH . 'system_startup_check.php';
}
// Needed for router to build routes
$subdir = $app['config']->setting( 'subdir' );
/*-------------------------------------------
* Process the request
*
* Nothing at all has actually been done yet,
* aside from setting some global definitions
* -----------------------------------------*/
# Get and set currently used controller, action and parameters
$app['router']->getRoute( $subdir );
if ( $_POST )
{
// $token = filter_input(INPUT_POST, 'token', FILTER_SANITIZE_STRING);
// if (!$token || $token !== $_SESSION['token']) {
// // return 405 http status code
// header($_SERVER['SERVER_PROTOCOL'] . ' 405 Method Not Allowed');
// exit;
// }
// $app['router']->interceptPost($_POST, $app);
}
if ( $_GET )
{
// $app['router']->interceptGet($app);
}
/*-------------------------------------------
* Start session
* -----------------------------------------*/
// Be sure to only make changes to session options
// within the .env configuration file.
$app['session']->start();
/*-------------------------------------------
* Instantiate requested URL
* -----------------------------------------*/
# Display the requested page
require_once $app['config']->setting( 'system_path' ) . 'Run.php';
$app['base_controller']->__construct( $app );
$app['base_controller']->parse();
unset( $subdir );