You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/1-essentials/01-routing.md
+54-7Lines changed: 54 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -162,10 +162,10 @@ public function docsRedirect(string $path): Redirect
162
162
163
163
## Generating URIs
164
164
165
-
Tempest provides a `\Tempest\uri` function that can be used to generate an URI to a controller method. This function accepts the FQCN of the controller or a callable to a method as its first argument, and named parameters as [the rest of its arguments](https://www.php.net/manual/en/functions.arguments.php#functions.variable-arg-list).
165
+
Tempest provides a `\Tempest\uri` function that can be used to generate a URI to a controller method. This function accepts the FQCN of the controller or a callable to a method as its first argument, and named parameters as [the rest of its arguments](https://www.php.net/manual/en/functions.arguments.php#functions.variable-arg-list).
Note that Tempest does not have named routes, and currently doesn't plan on adding them. However, if you have an argument for them, feel free to hop on our [Discord server](/discord){:ssg-ignore="true"} to discuss it.
184
+
URI-related methods are also available by injecting the {b`Tempest\Router\UriGenerator`} class into your controller.
185
185
:::
186
186
187
-
##Matching the current URI
187
+
### Signed URIs
188
188
189
-
To determine whether the current request matches a specific controller action, Tempest provides the `\Tempest\is_current_uri` function. This function accepts the same arguments as `uri`, and returns a boolean.
189
+
A signed URI may be used to ensure that the URI was not modified after it was created. This is useful for implementing login links, or other endpoints that need protection against tampering.
190
+
191
+
To create a signed URI, you may use the `signed_uri` function. This function accepts the same arguments as `uri`, and returns the URI with a `signature` parameter:
To ensure the validity of a signed URL, you should call the `hasValidSignature` method on the {`Tempest\Router\UriGenerator`} class.
215
+
216
+
```php
217
+
final class PasswordlessAuthenticationController
218
+
{
219
+
public function __construct(
220
+
private readonly UriGenerator $uri,
221
+
) {}
222
+
223
+
public function __invoke(Request $request): Response
224
+
{
225
+
if (! $this->uri->hasValidSignature($request)) {
226
+
return new Invalid();
227
+
}
228
+
229
+
// ...
230
+
}
231
+
}
232
+
```
233
+
234
+
### Matching the current URI
235
+
236
+
To determine whether the current request matches a specific controller action, Tempest provides the `is_current_uri` function. This function accepts the same arguments as `uri`, and returns a boolean.
190
237
191
238
```php
192
-
use function Tempest\is_current_uri;
239
+
use function Tempest\Router\is_current_uri;
193
240
194
241
// Current URI is: /aircraft/1
195
242
@@ -243,7 +290,7 @@ Once you have created a request class, you may simply inject it into a controlle
Copy file name to clipboardExpand all lines: docs/1-essentials/03-database.md
+34Lines changed: 34 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -270,6 +270,40 @@ final class Book
270
270
}
271
271
```
272
272
273
+
### Hashed properties
274
+
275
+
The {`#[Tempest\Database\Hashed]`} attribute will hash the model's property during serialization. If the property was already hashed, Tempest will detect that and avoid re-hashing it.
276
+
277
+
```php
278
+
final class User
279
+
{
280
+
public PrimaryKey $id;
281
+
282
+
public string $email;
283
+
284
+
#[Hashed]
285
+
public ?string $password;
286
+
}
287
+
```
288
+
289
+
Hashing requires the `SIGNING_KEY` environment variable to be set, as it's used as the hashing key.
290
+
291
+
### Encrypted properties
292
+
293
+
The {`#[Tempest\Database\Encrypted]`} attribute will encrypt the model's property during serialization and decrypt it during deserialization. If the property was already encrypted, Tempest will detect that and avoid re-encrypting it.
294
+
295
+
```php
296
+
final class User
297
+
{
298
+
// ...
299
+
300
+
#[Encrypted]
301
+
public ?string $accessToken;
302
+
}
303
+
```
304
+
305
+
The encryption key is taken from the `SIGNING_KEY` environment variable.
306
+
273
307
### DTO properties
274
308
275
309
Sometimes, you might want to store data objects as-is in a table, without there needing to be a relation to another table. To do so, it's enough to add a serializer and caster to the data object's class, and Tempest will know that these objects aren't meant to be treated as database models. Next, you can store the object's data as a json field on the table (see [migrations](#migrations) for more info).
Copy file name to clipboardExpand all lines: docs/1-essentials/07-testing.md
+4-6Lines changed: 4 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -22,7 +22,7 @@ composer phpunit
22
22
23
23
## Test-specific discovery locations
24
24
25
-
Tempest will only discover non-dev namespaces defined in composer.json automatically. That means that `{:hl-keyword:require-dev:}` namespaces aren't discovered automatically. Whenever you need Tempest to discover test-specific locations, you may specify them within the `discoverTestLocations()` method of the provided `IntegrationTest` class.
25
+
Tempest will only discover non-dev namespaces defined in composer.json automatically. That means that `{:hl-keyword:require-dev:}` namespaces aren't discovered automatically. Whenever you need Tempest to discover test-specific locations, you may specify them within the `discoverTestLocations()` method of the provided `IntegrationTest` class.
26
26
27
27
On top of that, Tempest _will_ look for files in the `tests/Fixtures` directory and discover them by default. You can override this behavior by providing your own implementation of `discoverTestLocations()`, where you can return an array of `DiscoveryLocation` objects (or nothing).
28
28
@@ -46,7 +46,7 @@ final class HomeControllerTest extends IntegrationTest
46
46
If you want to test code that interacts with the database, your test class can call the `setupDatabase()` method. This method will create and migrate a clean database for you on the fly.
47
47
48
48
```php
49
-
class TodoControllerTest extends IntegrationTest
49
+
final class TodoControllerTest extends IntegrationTest
50
50
{
51
51
protected function setUp(): void
52
52
{
@@ -60,8 +60,6 @@ class TodoControllerTest extends IntegrationTest
60
60
Most likely, you'll want to use a test-specific database connection. You can create a `database.config.php` file anywhere within test-specific discovery locations, and Tempest will use that connection instead of the project's default. For example, you can create a file `tests/Fixtures/database.config.php` like so:
61
61
62
62
```php tests/Fixtures/database.config.php
63
-
<?php
64
-
65
63
use Tempest\Database\Config\SQLiteConfig;
66
64
67
65
return new SQLiteConfig(
@@ -72,7 +70,7 @@ return new SQLiteConfig(
72
70
By default, no tables will be migrated. You can choose to provide a list of migrations that will be run for every test that calls `setupDatabase()`, or you can run specific migrations on a per-test basis.
73
71
74
72
```php
75
-
class TodoControllerTest extends IntegrationTest
73
+
final class TodoControllerTest extends IntegrationTest
76
74
{
77
75
protected function migrateDatabase(): void
78
76
{
@@ -85,7 +83,7 @@ class TodoControllerTest extends IntegrationTest
85
83
```
86
84
87
85
```php
88
-
class TodoControllerTest extends IntegrationTest
86
+
final class TodoControllerTest extends IntegrationTest
0 commit comments