|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | +|-------------------------------------------------------------------------- |
| 5 | +| Switch to root path |
| 6 | +|-------------------------------------------------------------------------- |
| 7 | +| |
| 8 | +| Point to the application root directory so leaf can accurately |
| 9 | +| resolve app paths. |
| 10 | +| |
| 11 | +*/ |
| 12 | +chdir(dirname(__DIR__)); |
| 13 | + |
| 14 | +/* |
| 15 | +|-------------------------------------------------------------------------- |
| 16 | +| Register The Auto Loader |
| 17 | +|-------------------------------------------------------------------------- |
| 18 | +| |
| 19 | +| Composer provides a convenient, automatically generated class loader |
| 20 | +| for our application. We just need to utilize it! We'll require it |
| 21 | +| into the script here so that we do not have to worry about the |
| 22 | +| loading of any our classes "manually". Feels great to relax. |
| 23 | +| |
| 24 | +*/ |
| 25 | +require_once dirname(__DIR__) . '/vendor/autoload.php'; |
| 26 | + |
| 27 | +/* |
| 28 | +|-------------------------------------------------------------------------- |
| 29 | +| Bring in (env) |
| 30 | +|-------------------------------------------------------------------------- |
| 31 | +| |
| 32 | +| Quickly use our environment variables |
| 33 | +| |
| 34 | +*/ |
| 35 | +try { |
| 36 | + \Dotenv\Dotenv::createUnsafeImmutable(dirname(__DIR__))->load(); |
| 37 | +} catch (\Throwable $th) { |
| 38 | + trigger_error($th); |
| 39 | +} |
| 40 | + |
| 41 | +/* |
| 42 | +|-------------------------------------------------------------------------- |
| 43 | +| Attach blade view |
| 44 | +|-------------------------------------------------------------------------- |
| 45 | +| |
| 46 | +| Since blade no longer ships with Leaf by default, we |
| 47 | +| can attach blade back to Leaf so you can use Leaf MVC |
| 48 | +| as you've always used it. |
| 49 | +| |
| 50 | +*/ |
| 51 | +Leaf\View::attach(\Leaf\Blade::class); |
| 52 | + |
| 53 | +/* |
| 54 | +|-------------------------------------------------------------------------- |
| 55 | +| Initialise Config |
| 56 | +|-------------------------------------------------------------------------- |
| 57 | +| |
| 58 | +| Pass your application configuration into your leaf app. |
| 59 | +| |
| 60 | +*/ |
| 61 | +Leaf\Config::set(AppConfig()); |
| 62 | + |
| 63 | +/* |
| 64 | +|-------------------------------------------------------------------------- |
| 65 | +| Load application paths |
| 66 | +|-------------------------------------------------------------------------- |
| 67 | +| |
| 68 | +| Decline static file requests back to the PHP built-in webserver |
| 69 | +| |
| 70 | +*/ |
| 71 | +if (php_sapi_name() === 'cli-server') { |
| 72 | + $path = realpath(__DIR__ . parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)); |
| 73 | + |
| 74 | + if (is_string($path) && __FILE__ !== $path && is_file($path)) { |
| 75 | + return false; |
| 76 | + } |
| 77 | + |
| 78 | + unset($path); |
| 79 | +} |
| 80 | + |
| 81 | +/* |
| 82 | +|-------------------------------------------------------------------------- |
| 83 | +| Load application paths |
| 84 | +|-------------------------------------------------------------------------- |
| 85 | +| |
| 86 | +| Tell Leaf MVC Core where to locate application paths |
| 87 | +| |
| 88 | +*/ |
| 89 | +Leaf\Core::paths(PathsConfig()); |
| 90 | + |
| 91 | +/* |
| 92 | +|-------------------------------------------------------------------------- |
| 93 | +| Default fix for CORS |
| 94 | +|-------------------------------------------------------------------------- |
| 95 | +| |
| 96 | +| This just prevents the connection client from throwing |
| 97 | +| CORS errors at you. |
| 98 | +| |
| 99 | +*/ |
| 100 | +app()->cors(CorsConfig()); |
| 101 | + |
| 102 | +/* |
| 103 | +|-------------------------------------------------------------------------- |
| 104 | +| Additional Leaf Database Config |
| 105 | +|-------------------------------------------------------------------------- |
| 106 | +| |
| 107 | +| Load leaf database configuration |
| 108 | +| |
| 109 | +*/ |
| 110 | +Leaf\Database::config(DatabaseConfig()); |
| 111 | + |
| 112 | +/* |
| 113 | +|-------------------------------------------------------------------------- |
| 114 | +| Route Config |
| 115 | +|-------------------------------------------------------------------------- |
| 116 | +| |
| 117 | +| Require app routes. |
| 118 | +| |
| 119 | +*/ |
| 120 | +require dirname(__DIR__) . "/App/Routes/index.php"; |
| 121 | + |
| 122 | +/* |
| 123 | +|-------------------------------------------------------------------------- |
| 124 | +| Run Leaf Application |
| 125 | +|-------------------------------------------------------------------------- |
| 126 | +| |
| 127 | +| Require app routes |
| 128 | +| |
| 129 | +*/ |
| 130 | +app()->run(); |
0 commit comments