Repository navigation
Expand file tree
/
Copy pathFormRequestController.php
More file actions
74 lines (64 loc) · 2.04 KB
/
Copy pathFormRequestController.php
File metadata and controls
74 lines (64 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
declare(strict_types=1);
/**
* This file is part of CodeIgniter 4 framework.
*
* (c) CodeIgniter Foundation <admin@codeigniter.com>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Tests\Support\Controllers;
use CodeIgniter\Controller;
use Tests\Support\HTTP\Requests\UnauthorizedFormRequest;
use Tests\Support\HTTP\Requests\ValidPostFormRequest;
/**
* Controller used in FormRequest integration tests.
*/
class FormRequestController extends Controller
{
/**
* Optional trailing param after a FormRequest - verifies that the optional
* param gets its default value when the corresponding URI segment is absent.
*/
public function index(string $id, ValidPostFormRequest $request, string $format = 'json'): string
{
return json_encode(['id' => $id, 'format' => $format, 'data' => $request->getValidated()]);
}
/**
* Receives only a FormRequest (no route params).
*/
public function store(ValidPostFormRequest $request): string
{
return json_encode($request->getValidated());
}
/**
* Receives a route param alongside a FormRequest.
*/
public function update(string $id, ValidPostFormRequest $request): string
{
return json_encode(['id' => $id, 'data' => $request->getValidated()]);
}
/**
* No FormRequest - verifies BC with plain route params.
*/
public function show(string $id): string
{
return 'item-' . $id;
}
/**
* Variadic route params alongside a FormRequest - verifies that all extra
* URI segments are collected into the variadic array.
*/
public function search(ValidPostFormRequest $request, string ...$tags): string
{
return json_encode(['tags' => $tags, 'data' => $request->getValidated()]);
}
/**
* Uses an always-unauthorized FormRequest.
*/
public function restricted(UnauthorizedFormRequest $request): string
{
return 'should-not-reach';
}
}