1
1
<?php
2
+ $ dir = __DIR__ ;
3
+ require $ dir .'/../vendor/autoload.php ' ;
4
+ require $ dir .'/helpers.php ' ;
2
5
3
- require (__DIR__ .'/../vendor/autoload.php ' );
6
+ $ app = Base::instance ();
7
+ $ app ->config ($ dir .'/config.ini; ' );
8
+ _load (array ('config ' , 'routes ' ));
9
+ $ ver = $ app ->get ('APP.VER ' );
10
+ $ env = strtolower ($ app ->ENV );
11
+ $ isApi = is_api ();
4
12
5
- $ f3 = Base::instance ();
13
+ $ app ->mset (array (
14
+ 'AUTOLOAD ' => '../app/ ' ,
15
+ 'DEBUG ' => $ env === strtolower ($ app ->DEBUG_ENV ) ? 3 : 0
16
+ ));
6
17
7
- loadConfig ($ f3 );
8
- loadRoutes ($ f3 );
18
+ $ db_type = strtoupper ($ app ->DB_TYPE );
19
+ if (isset ($ db_type )) {
20
+ switch ($ db_type ) {
21
+ case 'JIG ' :
22
+ $ app ->set ('DB ' , new DB \Jig ($ app ->DB_PATH , DB \Jig::FORMAT_JSON ));
23
+ break ;
24
+ case 'SQL ' :
25
+ case 'MYSQL ' :
26
+ $ app ->set ('DB ' , new DB \SQL ('mysql:host= ' .$ app ->DB_HOST .';port= ' .$ app ->DB_PORT .';dbname= ' .$ app ->DB_PREFIX .$ app ->DB_NAME , $ app ->DB_USER , $ app ->DB_PSWD ));
27
+ break ;
28
+ case 'PGSQL ' :
29
+ $ app ->set ('DB ' , new DB \SQL ('pgsql:host= ' .$ app ->DB_HOST .';dbname= ' .$ app ->DB_PREFIX .$ app ->DB_NAME , $ app ->DB_USER , $ app ->DB_PSWD ));
30
+ break ;
31
+ case 'SQLSRV ' :
32
+ $ app ->set ('DB ' , new DB \SQL ('sqlsrv:SERVER= ' .$ app ->DB_HOST .';Database= ' .$ app ->DB_PREFIX .$ app ->DB_NAME , $ app ->DB_USER , $ app ->DB_PSWD ));
33
+ break ;
34
+ case 'SQLITE ' :
35
+ $ app ->set ('DB ' , new DB \SQL ('sqlite: ' .$ app ->DB_PATH ));
36
+ break ;
37
+ case 'MONGO ' :
38
+ $ app ->set ('DB ' , new DB \Mongo ('mongodb:// ' .$ app ->DB_HOST .': ' .$ app ->DB_PORT , $ app ->DB_PREFIX .$ app ->DB_NAME ));
39
+ break ;
40
+ }
41
+ }
9
42
10
- $ db = $ f3 ->set ('DB ' , new DB \Jig ($ f3 ->get ('DB_PATH ' ), DB \Jig::FORMAT_JSON ));
11
- $ session = new DB \Jig \Session ($ db , 'sessions ' , null , 'csrf ' );
43
+ $ type = _getDBType ($ db_type );
44
+ if ($ app ->CSRF && $ app ->DB && ('Jig ' == $ type || 'SQL ' == $ type || 'Mongo ' == $ type )) {
45
+ $ session = 'DB \\' .$ type .'\\Session ' ;
46
+ $ nsession = new $ session ($ app ->DB , 'SESSIONS ' , null , 'CSRF ' );
47
+ } elseif ($ app ->CSRF ) {
48
+ $ nsession = new Session (null , 'CSRF ' );
49
+ } else {
50
+ if ($ app ->DB && ($ type == 'Jig ' || $ type == 'Mongo ' || $ type == 'SQL ' )) {
51
+ $ session = str_ireplace ('/ ' , '' , 'DB\/ ' .$ type .'\Session ' );
52
+ $ nsession = new $ session ($ app ->DB );
53
+ } else {
54
+ $ nsession = new Session ();
55
+ }
56
+ }
57
+ $ app ->set ('SESSION ' , $ nsession );
12
58
13
- $ assets = Assets::instance ();
14
- $ f3 ->set ('ASSETS.onFileNotFound ' ,function ($ file ) use ($ f3 ){
15
- echo 'file not found: ' .$ file ;
16
- });
59
+ if (!$ isApi ) {
60
+ if ('dev ' === $ env ) {
61
+ Falsum \Run::handler ($ app ->DEBUG != 3 );
62
+ $ app ->route ('GET @reloadr: /reloadr ' , 'Controller->reloadr ' );
63
+ }else {
64
+ $ app ->set ('ONERROR ' , 'Controllers\Controller->error ' );
65
+ Assets::instance ();
66
+ $ app ->set ('ASSETS.onFileNotFound ' , function ($ file ) {
67
+ echo 'file not found: ' .$ file ;
68
+ });
69
+ }
70
+ }
17
71
18
- return $ f3 ;
72
+ if (!file_exists (base_path ('storage/app/installed ' ))) {
73
+ if ($ isApi ) {
74
+ json ('App is not installed yet! ' , 'error ' );
75
+ } else {
76
+ $ app ->route ('GET @install: /install ' , 'Controllers\IntallController->install ' );
77
+ }
78
+ }
79
+
80
+ return $ app ;
0 commit comments