-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: switch api install to leaf mvc
- Loading branch information
1 parent
8809aca
commit 3a70974
Showing
6 changed files
with
257 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
<?php | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Switch to root path | ||
|-------------------------------------------------------------------------- | ||
| | ||
| Point to the application root directory so leaf can accurately | ||
| resolve app paths. | ||
| | ||
*/ | ||
chdir(dirname(__DIR__)); | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Register The Auto Loader | ||
|-------------------------------------------------------------------------- | ||
| | ||
| Composer provides a convenient, automatically generated class loader | ||
| for our application. We just need to utilize it! We'll require it | ||
| into the script here so that we do not have to worry about the | ||
| loading of any our classes "manually". Feels great to relax. | ||
| | ||
*/ | ||
require dirname(__DIR__) . '/vendor/autoload.php'; | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Bring in (env) | ||
|-------------------------------------------------------------------------- | ||
| | ||
| Quickly use our environment variables | ||
| | ||
*/ | ||
try { | ||
\Dotenv\Dotenv::createUnsafeImmutable(dirname(__DIR__))->load(); | ||
} catch (\Throwable $th) { | ||
trigger_error($th); | ||
} | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Load application paths | ||
|-------------------------------------------------------------------------- | ||
| | ||
| Decline static file requests back to the PHP built-in webserver | ||
| | ||
*/ | ||
if (php_sapi_name() === 'cli-server') { | ||
$path = realpath(__DIR__ . parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)); | ||
|
||
if (is_string($path) && __FILE__ !== $path && is_file($path)) { | ||
return false; | ||
} | ||
|
||
unset($path); | ||
} | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Attach blade view | ||
|-------------------------------------------------------------------------- | ||
| | ||
| Templating has been disabled because you chose the MVC for APIs starter. | ||
| If you want to use blade in your application, | ||
| you can uncomment the line below. | ||
| | ||
*/ | ||
// Leaf\Config::attachView(\Leaf\Blade::class); | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Load Leaf configuration | ||
|-------------------------------------------------------------------------- | ||
| | ||
| Leaf MVC allows you to customize Leaf and it's modules using | ||
| configuration files defined in the config folder. This line | ||
| loads the configuration files and makes them available to | ||
| your application. | ||
| | ||
*/ | ||
Leaf\Core::loadApplicationConfig(); | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Sync Leaf Db with ORM and connect | ||
|-------------------------------------------------------------------------- | ||
| | ||
| Sync Leaf Db with ORM and connect to the database | ||
| This allows you to use Leaf Db without having | ||
| to initialize it in your controllers. | ||
| | ||
| If you want to use a different connection from those | ||
| used in your models, you can remove the line below and | ||
| add your own connection with: | ||
| db()->connect(...) | ||
| | ||
| **Uncomment the line below to use Leaf Db** | ||
| **You don't need this line to use Leaf Auth** | ||
*/ | ||
// \Leaf\Database::initDb(); | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Load custom libraries | ||
|-------------------------------------------------------------------------- | ||
| | ||
| You can load your custom libraries here. If you have | ||
| anything defined in your lib folder, you can load | ||
| them here. Simply uncomment the line below. | ||
| | ||
*/ | ||
// \Leaf\Core::loadLibs(); | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Run your Leaf MVC application | ||
|-------------------------------------------------------------------------- | ||
| | ||
| This line brings in all your routes and starts your application | ||
| | ||
*/ | ||
\Leaf\Core::runApplication(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
|
||
app()->get('/', function () { | ||
response()->json(['message' => 'Congrats!! You\'re on Leaf MVC']); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Set up 404 handler | ||
|-------------------------------------------------------------------------- | ||
| | ||
| Leaf provides a default 404 page, but you can also create your | ||
| own 404 handler by calling app()->set404(). Whatever function | ||
| you set will be called when a 404 error is encountered | ||
| | ||
*/ | ||
app()->set404(function () { | ||
response()->json('Resource not found', 404, true); | ||
}); | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Set up 500 handler | ||
|-------------------------------------------------------------------------- | ||
| | ||
| Leaf provides a default 500 page, but you can create your own error | ||
| 500 handler by calling the setErrorHandler() method. The function | ||
| you set will be called when a 500 error is encountered | ||
| | ||
*/ | ||
app()->setErrorHandler(function () { | ||
response()->json('An error occured, our team has been notified', 500, true); | ||
}); | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Set up Controller namespace | ||
|-------------------------------------------------------------------------- | ||
| | ||
| This allows you to directly use controller names instead of typing | ||
| the controller namespace first. | ||
| | ||
*/ | ||
app()->setNamespace('\App\Controllers'); | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Your application routes | ||
|-------------------------------------------------------------------------- | ||
| | ||
| Leaf MVC automatically loads all files in the routes folder that | ||
| start with "_". We call these files route partials. An example | ||
| partial has been created for you. | ||
| | ||
| If you want to manually load routes, you can | ||
| create a file that doesn't start with "_" and manually require | ||
| it here like so: | ||
| | ||
*/ | ||
// require __DIR__ . '/custom-route.php'; |