Skip to content

Commit b456e90

Browse files
committed
docs: atualizar documentação para refletir a sintaxe de roteamento suportada e corrigir exemplos de uso
1 parent 6a68023 commit b456e90

File tree

7 files changed

+326
-24
lines changed

7 files changed

+326
-24
lines changed

README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,53 @@ $app->get('/posts/:year<\d{4}>/:month<\d{2}>/:slug<slug>', function($req, $res)
110110
$app->run();
111111
```
112112

113+
### 🛣️ Sintaxes de Roteamento Suportadas
114+
115+
O PivotPHP suporta múltiplas sintaxes para definir handlers de rota:
116+
117+
```php
118+
// ✅ Closure/Função Anônima (Recomendado)
119+
$app->get('/users', function($req, $res) {
120+
return $res->json(['users' => []]);
121+
});
122+
123+
// ✅ Array Callable com classe
124+
$app->get('/users', [UserController::class, 'index']);
125+
126+
// ✅ Função nomeada
127+
function getUsersHandler($req, $res) {
128+
return $res->json(['users' => []]);
129+
}
130+
$app->get('/users', 'getUsersHandler');
131+
132+
// ❌ NÃO suportado - String no formato Controller@method
133+
// $app->get('/users', 'UserController@index'); // ERRO!
134+
```
135+
136+
**Exemplo com Controller:**
137+
138+
```php
139+
<?php
140+
141+
class UserController
142+
{
143+
public function index($req, $res)
144+
{
145+
return $res->json(['users' => User::all()]);
146+
}
147+
148+
public function show($req, $res)
149+
{
150+
$id = $req->param('id');
151+
return $res->json(['user' => User::find($id)]);
152+
}
153+
}
154+
155+
// Registrar rotas com array callable
156+
$app->get('/users', [UserController::class, 'index']);
157+
$app->get('/users/:id', [UserController::class, 'show']);
158+
```
159+
113160
### 🔄 Suporte PSR-7 Híbrido
114161

115162
O PivotPHP oferece **compatibilidade híbrida** com PSR-7, mantendo a facilidade da API Express.js enquanto implementa completamente as interfaces PSR-7:

docs/releases/FRAMEWORK_OVERVIEW_v1.0.0.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,19 +103,19 @@ $app->run();
103103

104104
```php
105105
// Basic routing
106-
$app->get('/users', 'UserController@index');
107-
$app->post('/users', 'UserController@create');
108-
$app->put('/users/{id}', 'UserController@update');
109-
$app->delete('/users/{id}', 'UserController@delete');
106+
$app->get('/users', [UserController::class, 'index']);
107+
$app->post('/users', [UserController::class, 'create']);
108+
$app->put('/users/{id}', [UserController::class, 'update']);
109+
$app->delete('/users/{id}', [UserController::class, 'delete']);
110110

111111
// Route groups
112112
$app->group('/api/v1', function ($group) {
113-
$group->get('/users', 'UserController@index');
114-
$group->post('/users', 'UserController@create');
113+
$group->get('/users', [UserController::class, 'index']);
114+
$group->post('/users', [UserController::class, 'create']);
115115
});
116116

117117
// Middleware on routes
118-
$app->get('/admin', 'AdminController@dashboard')
118+
$app->get('/admin', [AdminController::class, 'dashboard'])
119119
->middleware(AuthMiddleware::class);
120120
```
121121

@@ -127,7 +127,7 @@ $app->use(new CorsMiddleware());
127127
$app->use(new SecurityHeadersMiddleware());
128128

129129
// Route-specific middleware
130-
$app->post('/login', 'AuthController@login')
130+
$app->post('/login', [AuthController::class, 'login'])
131131
->middleware(CsrfMiddleware::class);
132132

133133
// Custom middleware

docs/releases/FRAMEWORK_OVERVIEW_v1.0.1.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -177,19 +177,19 @@ $app->get('/posts/:category<alpha>/:slug<slug>', handler);
177177

178178
```php
179179
// Basic routing
180-
$app->get('/users', 'UserController@index');
181-
$app->post('/users', 'UserController@create');
182-
$app->put('/users/:id', 'UserController@update');
183-
$app->delete('/users/:id', 'UserController@delete');
180+
$app->get('/users', [UserController::class, 'index']);
181+
$app->post('/users', [UserController::class, 'create']);
182+
$app->put('/users/:id', [UserController::class, 'update']);
183+
$app->delete('/users/:id', [UserController::class, 'delete']);
184184

185185
// Route groups
186186
$app->group('/api/v1', function ($group) {
187-
$group->get('/users', 'UserController@index');
188-
$group->post('/users', 'UserController@create');
187+
$group->get('/users', [UserController::class, 'index']);
188+
$group->post('/users', [UserController::class, 'create']);
189189
});
190190

191191
// Middleware on routes
192-
$app->get('/admin', 'AdminController@dashboard')
192+
$app->get('/admin', [AdminController::class, 'dashboard'])
193193
->middleware(AuthMiddleware::class);
194194
```
195195

@@ -201,7 +201,7 @@ $app->use(new CorsMiddleware());
201201
$app->use(new SecurityHeadersMiddleware());
202202

203203
// Route-specific middleware
204-
$app->post('/login', 'AuthController@login')
204+
$app->post('/login', [AuthController::class, 'login'])
205205
->middleware(CsrfMiddleware::class);
206206

207207
// Custom middleware

docs/technical/authentication/usage_native.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ $app->group('/admin', function() use ($app) {
427427
'requiredRole' => 'admin'
428428
]));
429429

430-
$app->get('/users', 'AdminController@getUsers');
430+
$app->get('/users', [AdminController::class, 'getUsers']);
431431
});
432432

433433
// API Key para integrações externas
@@ -437,7 +437,7 @@ $app->group('/api/v1', function() use ($app) {
437437
'apiKeyCallback' => 'validateApiKey'
438438
]));
439439

440-
$app->get('/data', 'ApiController@getData');
440+
$app->get('/data', [ApiController::class, 'getData']);
441441
});
442442

443443
// Multi-método para rotas gerais
@@ -448,7 +448,7 @@ $app->group('/api', function() use ($app) {
448448
'bearerAuthCallback' => 'validateBearerToken'
449449
]));
450450

451-
$app->get('/profile', 'UserController@getProfile');
451+
$app->get('/profile', [UserController::class, 'getProfile']);
452452
});
453453
```
454454

docs/technical/extesions/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ class MyExtensionProvider extends ServiceProvider
144144
{
145145
// Registrar rotas da extensão
146146
$this->app->group('/extension', function() {
147-
$this->app->get('/status', 'MyExtension\\StatusController@index');
147+
$this->app->get('/status', [MyExtension\StatusController::class, 'index']);
148148
});
149149
}
150150

@@ -262,9 +262,9 @@ class PaymentExtensionProvider extends ServiceProvider
262262
{
263263
$this->app->group('/payments', function() {
264264
// Rotas de API de pagamento
265-
$this->app->post('/process', 'PaymentController@process');
266-
$this->app->post('/webhook', 'PaymentController@webhook');
267-
$this->app->get('/status/{id}', 'PaymentController@status');
265+
$this->app->post('/process', [PaymentController::class, 'process']);
266+
$this->app->post('/webhook', [PaymentController::class, 'webhook']);
267+
$this->app->get('/status/{id}', [PaymentController::class, 'status']);
268268
});
269269
}
270270

docs/technical/middleware/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ $app->group('/api/v1', function() use ($app) {
336336
$app->use(new RateLimitMiddleware(['maxRequests' => 100]));
337337
$app->use(new AuditMiddleware()); // Log de auditoria
338338

339-
$app->get('/users', 'AdminController@getUsers');
339+
$app->get('/users', [AdminController::class, 'getUsers']);
340340
});
341341
});
342342
```

0 commit comments

Comments
 (0)