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/02-views.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
@@ -8,7 +8,7 @@ keywords: "Experimental"
8
8
9
9
Views in Tempest are parsed by Tempest View, our own templating engine. Tempest View uses a syntax that can be thought of as a superset of HTML. If you prefer using a templating engine with more widespread support, [you may also use Blade, Twig, or any other](#using-other-engines) — as long as you provide a way to initialize it.
10
10
11
-
If you'd like to Tempest View as a standalone component in your project, you can read the documentation on how to do so [here](../5-extra-topics/02-standalone-components.md#tempest-view).
11
+
If you'd like to Tempest View as a standalone component in your project, you can read the documentation on how to do so [here](../5-extra-topics/02-standalone-components.md#tempest-view).
12
12
13
13
### Syntax overview
14
14
@@ -447,7 +447,7 @@ $title = 'foo';
447
447
<!-- $title will need to be passed in explicitly,
448
448
otherwise `x-post` wouldn't know about it: -->
449
449
450
-
<x-post:title="$title"></x-post>
450
+
<x-post:title="$title"></x-post>
451
451
```
452
452
453
453
```php
@@ -463,7 +463,6 @@ final class HomeController
463
463
```
464
464
465
465
```html x-base.view.php
466
-
467
466
<h1>{{ $siteTitle }}</h1>
468
467
```
469
468
@@ -680,7 +679,7 @@ use Tempest\View\Renderers\TempestViewRenderer;
680
679
use Tempest\View\ViewCache;
681
680
682
681
$renderer = TempestViewRenderer::make(
683
-
cache: ViewCache::enabled(),
682
+
cache: ViewCache::create(),
684
683
);
685
684
```
686
685
@@ -690,8 +689,7 @@ It's recommended to turn view caching on in production environments. To clear th
Copy file name to clipboardExpand all lines: docs/1-essentials/03-database.md
+27-20Lines changed: 27 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -147,7 +147,7 @@ final class Book
147
147
Because model objects aren't tied to the database specifically, Tempest's [mapper](../2-features/01-mapper.md) can map data from many different sources to them. For instance, you can persist your models as JSON instead of a database, if you want to:
148
148
149
149
```php
150
-
use function Tempest\map;
150
+
use function Tempest\Mapper\map;
151
151
152
152
$books = map($json)->collection()->to(Book::class); // from JSON source to Book collection
153
153
$json = map($books)->toJson(); // from Book collection to JSON
@@ -308,34 +308,41 @@ final class User
308
308
309
309
The encryption key is taken from the `SIGNING_KEY` environment variable.
310
310
311
-
### DTO properties
311
+
### Data transfer object properties
312
312
313
-
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).
313
+
You can store arbitrary objects directly in a `json` column when they don’t need to be part of the relational schema.
314
+
315
+
To do this, annotate the class with `#[Tempest\Mapper\SerializeAs]` and provide a unique identifier for the object’s serialized form. The identifier must map to a single, distinct class.
314
316
315
317
```php
316
-
use Tempest\Database\IsDatabaseModel;
317
-
use Tempest\Mapper\CastWith;
318
-
use Tempest\Mapper\SerializeWith;
319
-
use Tempest\Mapper\Casters\DtoCaster;
320
-
use Tempest\Mapper\Serializers\DtoSerializer;
318
+
use Tempest\Mapper\SerializeAs;
321
319
322
-
final class DebugItem
320
+
final class User implements Authenticatable
323
321
{
324
-
use IsDatabaseModel;
325
-
326
-
/* … */
327
-
328
-
public Backtrace $backtrace,
322
+
public PrimaryKey $id;
323
+
324
+
public function __construct(
325
+
public string $email,
326
+
#[Hashed, SensitiveParameter]
327
+
public ?string $password,
328
+
public Settings $settings,
329
+
) {}
329
330
}
330
331
331
-
#[CastWith(DtoCaster::class)]
332
-
#[SerializeWith(DtoSerializer::class)]
333
-
final class Backtrace
332
+
#[SerializeAs('user_settings')]
333
+
final class Settings
334
334
{
335
-
// This object won't be considered a relation,
336
-
// but rather serialized and stored in a JSON column.
0 commit comments