Skip to content

Commit 6a68023

Browse files
committed
refactor(docs): atualizar rotas na documentação para usar sintaxe de parâmetros consistentes
1 parent 064af89 commit 6a68023

File tree

5 files changed

+23
-25
lines changed

5 files changed

+23
-25
lines changed

docs/performance/DATABASE_PERFORMANCE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,13 @@ Comparando requisições diretas ao banco vs através do PivotPHP:
6262
Performance medida em requisições por segundo para APIs completas:
6363

6464
```
65-
GET /api/users/{id} (Simple SELECT)
65+
GET /api/users/:id (Simple SELECT)
6666
├─ SQLite: 7,812 req/s
6767
├─ MariaDB: 4,234 req/s
6868
├─ MySQL: 4,123 req/s
6969
└─ PostgreSQL: 3,567 req/s
7070
71-
GET /api/users/{id}/posts (JOIN)
71+
GET /api/users/:id/posts (JOIN)
7272
├─ SQLite: 3,123 req/s
7373
├─ PostgreSQL: 1,945 req/s
7474
├─ MariaDB: 1,789 req/s

docs/releases/FRAMEWORK_OVERVIEW_v1.0.1.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@ $app->get('/posts/:category<alpha>/:slug<slug>', handler);
179179
// Basic routing
180180
$app->get('/users', 'UserController@index');
181181
$app->post('/users', 'UserController@create');
182-
$app->put('/users/{id}', 'UserController@update');
183-
$app->delete('/users/{id}', 'UserController@delete');
182+
$app->put('/users/:id', 'UserController@update');
183+
$app->delete('/users/:id', 'UserController@delete');
184184

185185
// Route groups
186186
$app->group('/api/v1', function ($group) {

docs/technical/http/openapi_documentation.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use PivotPHP\Core\Utils\OpenApiExporter;
1313
$app = new Application();
1414

1515
/**
16-
* @api GET /users/{id}
16+
* @api GET /users/:id
1717
* @summary Buscar usuário por ID
1818
* @description Retorna os dados completos de um usuário específico
1919
* @param {integer} id.path.required - ID do usuário
@@ -65,7 +65,7 @@ $app->run();
6565
```
6666

6767
**Tipos de parâmetros:**
68-
- `path` - Parâmetros na URL (`/users/{id}`)
68+
- `path` - Parâmetros na URL (`/users/:id`)
6969
- `query` - Query strings (`?filter=value`)
7070
- `body` - Corpo da requisição
7171
- `header` - Headers HTTP
@@ -136,7 +136,7 @@ $app->get('/api/products', function($req, $res) {
136136
});
137137

138138
/**
139-
* @api GET /api/products/{id}
139+
* @api GET /api/products/:id
140140
* @summary Buscar produto específico
141141
* @description Retorna dados completos de um produto
142142
* @param {integer} id.path.required - ID do produto
@@ -185,7 +185,7 @@ $app->post('/api/products', function($req, $res) {
185185
});
186186

187187
/**
188-
* @api PUT /api/products/{id}
188+
* @api PUT /api/products/:id
189189
* @summary Atualizar produto
190190
* @description Atualiza dados de um produto existente
191191
* @param {integer} id.path.required - ID do produto
@@ -213,7 +213,7 @@ $app->put('/api/products/:id', function($req, $res) {
213213
});
214214

215215
/**
216-
* @api DELETE /api/products/{id}
216+
* @api DELETE /api/products/:id
217217
* @summary Deletar produto
218218
* @description Remove um produto do sistema
219219
* @param {integer} id.path.required - ID do produto
@@ -360,7 +360,7 @@ $docs = OpenApiExporter::export($app, [
360360
### **API com Upload de Arquivo**
361361
```php
362362
/**
363-
* @api POST /api/products/{id}/image
363+
* @api POST /api/products/:id/image
364364
* @summary Upload de imagem do produto
365365
* @description Faz upload da imagem principal do produto
366366
* @param {integer} id.path.required - ID do produto

src/Http/Response.php

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,12 @@ public function json(mixed $data): self
226226
} else {
227227
// Usar encoding tradicional para dados pequenos
228228
$encoded = json_encode($sanitizedData, self::JSON_ENCODE_FLAGS);
229-
if ($encoded === false) {
230-
error_log('JSON encoding failed: ' . json_last_error_msg());
231-
$encoded = '{}';
232-
}
229+
}
230+
231+
// Handle JSON encoding failures for both pooling and traditional paths
232+
if ($encoded === false) {
233+
error_log('JSON encoding failed: ' . json_last_error_msg());
234+
$encoded = '{}';
233235
}
234236

235237
$this->body = $encoded;
@@ -800,21 +802,16 @@ private function shouldUseJsonPooling(mixed $data): bool
800802
/**
801803
* Codifica JSON usando pooling para melhor performance
802804
*/
803-
private function encodeWithPooling(mixed $data): string
805+
private function encodeWithPooling(mixed $data): string|false
804806
{
805807
try {
806808
return JsonBufferPool::encodeWithPool($data, self::JSON_ENCODE_FLAGS);
807809
} catch (\Throwable $e) {
808810
// Fallback para encoding tradicional em caso de erro
809811
error_log('JSON pooling failed, falling back to traditional encoding: ' . $e->getMessage());
810812

811-
$encoded = json_encode($data, self::JSON_ENCODE_FLAGS);
812-
if ($encoded === false) {
813-
error_log('JSON encoding failed: ' . json_last_error_msg());
814-
return '{}';
815-
}
816-
817-
return $encoded;
813+
// Fallback to traditional encoding (let caller handle JSON encoding failures)
814+
return json_encode($data, self::JSON_ENCODE_FLAGS);
818815
}
819816
}
820817
}

tests/Json/JsonPoolingThresholdsTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ protected function tearDown(): void
3030
*/
3131
public function testPoolingConstantsExist(): void
3232
{
33-
$this->assertTrue(defined('PivotPHP\Core\Json\Pool\JsonBufferPool::POOLING_ARRAY_THRESHOLD'));
34-
$this->assertTrue(defined('PivotPHP\Core\Json\Pool\JsonBufferPool::POOLING_OBJECT_THRESHOLD'));
35-
$this->assertTrue(defined('PivotPHP\Core\Json\Pool\JsonBufferPool::POOLING_STRING_THRESHOLD'));
33+
$reflection = new \ReflectionClass(JsonBufferPool::class);
34+
$this->assertTrue($reflection->hasConstant('POOLING_ARRAY_THRESHOLD'));
35+
$this->assertTrue($reflection->hasConstant('POOLING_OBJECT_THRESHOLD'));
36+
$this->assertTrue($reflection->hasConstant('POOLING_STRING_THRESHOLD'));
3637

3738
// Verify values are reasonable
3839
$this->assertEquals(10, JsonBufferPool::POOLING_ARRAY_THRESHOLD);

0 commit comments

Comments
 (0)