Skip to content

Commit fda0d15

Browse files
committed
feat: update unclear items
1 parent f963e7a commit fda0d15

File tree

3 files changed

+57
-9
lines changed

3 files changed

+57
-9
lines changed

src/docs/auth/protected-routes.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,16 +126,10 @@ app()->get('/login', ['middleware' => 'auth.guest', function () {
126126

127127
This middleware will run before the route is executed. If a user is logged in, the callback function you defined will be executed. This means you can remove the check for a guest user from your route handler.
128128

129-
```php
130-
app()->get('/login', ['auth.guest', function () {
131-
// no need to check if the user is a guest
132-
}]);
133-
```
134-
135129
## Session Guards <Badge type="danger" text="DEPRECATED" />
136130

137131
The previous version of Leaf Auth had a feature called session guards. This feature has been deprecated in the latest version of Leaf Auth. If you were using session guards in your app, you can switch to the new middleware system to protect your routes.
138132

139-
The middleware system is more flexible and allows you to define more complex authentication logic using the middleware callback functions.
133+
The middleware system is more flexible and allows you to define more complex authentication logic using the middleware callback functions.
140134

141135
You can also use the middleware system to protect routes for both logged in and guest users, which is essentially what session guards were used for.

src/docs/routing/middleware/index.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,15 @@ Middleware is a piece of code that runs before or after your application process
44

55
Middleware can be used for a variety of tasks, such as authentication, authorization, logging, error handling, session management, and more.
66

7-
Note that Leaf has modules that offer most of these functionalities out of the box, so you might not need to write your own middleware for them.
7+
## Middleware in Leaf
88

9-
This page only covers how to use middleware in Leaf Core, if you are using Leaf MVC, you can check the [Leaf MVC Middleware](/docs/routing/middleware/mvc) page.
9+
Leaf is a modular framework, so we don't throw everything into the core. However, some common middleware are built into respective modules like the Auth module which has middleware for authentication, the CORS module, and the CSRF module which come with their own implementation.
10+
11+
We recommend that you always check the module documentation to see if it offers the functionality you need before attempting to write your own middleware. You'll find just what you need in a module about 90% of the time.
12+
13+
Also, this page only covers how to use middleware in Leaf Core, if you are using Leaf MVC, you can check the [Leaf MVC Middleware](/docs/routing/middleware/mvc) page.
14+
15+
With that out of the way, let's see how to use middleware in Leaf.
1016

1117
## Creating Middleware
1218

src/docs/why.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,51 @@ From the outset, Leaf has been designed to integrate seamlessly with other libra
5757
### Scalability
5858

5959
One of Leaf's most impressive qualities is its scalability. Regardless of the package you're using with Leaf, if it works in development, it will work in production with minimal configuration—unless you require specific features. Leaf's core, along with its ecosystem of frameworks and libraries, makes it suitable for projects of any size.
60+
61+
## Functional Mode
62+
63+
Leaf, just like any other framework, is made of many individual classes and components that work together to make your app work. These classes are usually instantiated and used in your app to make it work. However, using classes can sometimes be a bit too much for simple apps or APIs.
64+
65+
Classes are powerful, but easily get bulky and lengthy, difficult to scope, and plain annoying especially when you have to declare lengthy namespaces in every file you use them in. This is where functional mode comes in.
66+
67+
![image](https://github.com/user-attachments/assets/a8ae49d4-b4bc-42ac-b578-951ebe6ebb75)
68+
69+
Functional mode is just an elegant way to use Leaf without having to import classes or instantiate them. It's a way to use Leaf in a more functional way, without having to rely on classes. Leaf does all the class instantiation and importing for you under the hood.
70+
71+
Functional mode is 100% optional and requires zero setup or configuration since it's available right after installing Leaf.
72+
73+
```php
74+
<?php
75+
76+
require __DIR__ . '/vendor/autoload.php';
77+
78+
app()->get('/', function () {
79+
response()->json(['message' => 'Leaf is amazing!']);
80+
});
81+
82+
app()->run();
83+
```
84+
85+
Using classes, the above code would look like this:
86+
87+
```php
88+
<?php
89+
90+
use Leaf\App;
91+
92+
require __DIR__ . '/vendor/autoload.php';
93+
94+
$app = new App;
95+
96+
$app->get('/', function () use ($app) {
97+
$app->response()->json(['message' => 'Leaf is amazing!']);
98+
});
99+
100+
$app->run();
101+
```
102+
103+
As seen in the examples above, functional mode makes your code much shorter and cleaner since you don't even have to manage the instances of the classes you're using. Most Leaf modules are built to work in both functional and class modes.
104+
105+
You can use the functional mode functions or the class methods interchangeably, although the functional mode functions are usually shorter and more concise.
106+
107+
<!-- The documentation will usually show you how to use modules in functional mode, but will also show you how to use them in class mode if you prefer that. -->

0 commit comments

Comments
 (0)