Skip to content

Commit 7ca7d78

Browse files
authored
chore(docs): updates (#1683)
1 parent f50af80 commit 7ca7d78

File tree

5 files changed

+37
-33
lines changed

5 files changed

+37
-33
lines changed

docs/0-getting-started/01-introduction.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ final class ConsoleCommandDiscovery implements Discovery
9696

9797
Discovery makes Tempest truly understand your codebase so that you don't have to explain the framework how to use it. Of course, discovery is heavily optimized for local development and entirely cached in production, so there's no performance overhead. Even better: discovery isn't just a core framework feature, you're encouraged to write your own project-specific discovery classes wherever they make sense. That's the Tempest way.
9898

99+
:::info
100+
Read the [getting started with discovery](/blog/discovery-explained) guide if you are new to Tempest.
101+
:::
102+
99103
Besides Discovery, Tempest is designed to be extensible. You'll find that any part of the framework can be replaced and hooked into by implementing an interface and plugging it into the container. No fighting the framework, Tempest gets out of your way.
100104

101105
```php

docs/1-essentials/01-routing.md

Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -336,44 +336,19 @@ Whenever a validation error occurs, Tempest will redirect back to the page the r
336336
- As a JSON encoded string in the `{txt}X-Validation` header
337337
- Within the session with the `Session::VALIDATION_ERRORS` key
338338

339-
The JSON encoded header is available for when you're building APIs with Tempest. The session errors are available for when you're building web pages. In the case of the latter, you need a way to actually show the errors on a web page. Tempest's recommended way to do so is by creating a custom [view component](/docs/essentials/views#view-components):
340-
341-
```html app/x-error.view.php
342-
<?php
343-
use Tempest\Http\Session\Session;
344-
use Tempest\Validation\Validator;
345-
use function Tempest\get;
346-
347-
/** @var Session $session */
348-
$session = get(Session::class);
349-
350-
/** @var Validator $validator */
351-
$validator = get(Validator::class);
352-
353-
$errors = $session->getErrorsFor($name ?? '');
354-
355-
?><ul :if="$errors !== []" :class="$class ?? ''">
356-
<li :foreach="$errors as $error">
357-
{{ $validator->getErrorMessage($error) }}
358-
</li>
359-
</ul>
360-
```
361-
362-
This view component will be discovered and can then be used to display validation errors likes so:
339+
The JSON encoded header is available for when you're building APIs with Tempest. The session errors are available for when you're building web pages. For web pages, you also need a way to show the errors when they occur; Tempest comes with some built-in view components to help you with that.
363340

364341
```html
365-
<form action="/register" method="post">
366-
<label for="name">Name</label>
367-
<input type="text" name="name" id="name" autofocus class="border"/>
368-
<x-error name="name" class="text-red-400 …" />
342+
<x-form :action="uri(StorePostController::class)">
343+
<x-input name="name" />
344+
345+
<x-input type="email" name="email" />
369346

370-
<!---->
371-
</form>
347+
<x-submit />
348+
</x-form>
372349
```
373350

374-
:::info
375-
Currently, Tempest doesn't include built-in view components to handle form validation. That's because we don't have a strategy yet for dealing with different frontend frameworks. We rather give control to the user to build their own form components for maximum flexibility. This is likely to change in the future, but for now you'll have to make your own `x-error` component.
376-
:::
351+
`{html}<x-form>` is a view component that will automatically include the CSRF token, as well as default to sending `POST` requests. `{html}<x-input>` is a view component that renders a label, input field, and validation errors all at once. In practice, you'll likely want to make changes to these built-in view components. That's why you can run `./tempest install view-components` and select the components you want to pull into your project. You can [read more about installing view components here](/2.x/essentials/views#built-in-components).
377352

378353
## Route middleware
379354

docs/1-essentials/02-views.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,23 @@ Tempest views are always compiled to plain PHP code before being rendered. Durin
622622

623623
During deployments, that cache must be cleared in order to not serve outdated views to users. You may do that by running `tempest view:clear` on every deploy.
624624

625+
## Separate view directories
626+
627+
View files can live in any directory that is discoverable by Tempest. That means: a directory with a PSR-4 namespace associated with it. If you want your view files to live outside of `src` or `app`, you can add a namespace for it in composer.json:
628+
629+
```json composer.json
630+
"autoload": {
631+
"psr-4": {
632+
"App\\": "src/",
633+
"Views\\": "views/"
634+
},
635+
}
636+
```
637+
638+
Don't forget to run `composer up` after making changes to your composer.json file.
639+
640+
Note that view files themselves don't need a namespace; this namespace is only here to tell Tempest that `views/` is a directory it should scan. If you want to add a class in the `Views` namespace (like, for example, a [custom view object](/2.x/essentials/views#using-dedicated-view-objects)), then that is possible as well.
641+
625642
## Using other engines
626643

627644
While Tempest View is simple to use, it currently lacks tooling support from editors and IDEs. You may also simply prefer other templating engines. For these reasons, you may use any other engine of your choice.

docs/2-features/15-datetime.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ PHP provides multiple date and time implementations. There is [`DateTime`](https
1010

1111
Tempest provides an alternative to [`DateTimeInterface`](https://www.php.net/manual/en/class.datetimeinterface.php), partially based on [`IntlCalendar`](https://www.php.net/manual/en/class.intlcalendar.php). This implementation provides a better API with a more consistent interface. It was initially created by {x:azjezz} for the [PSL](https://github.com/azjezz/psl), and was ported to Tempest so it could be deeply integrated.
1212

13+
:::info
14+
You're not required to use Tempest's DateTime implementation, and may as well use PHP's native datetime, Carbon, or any other. If you rely on third-party libraries like Carbon, you should read about [global casters and serializers](/2.x/features/mapper#registering-casters-and-serializers-globally) as well to ensure model support.
15+
:::
16+
1317
## Creating date instances
1418

1519
The {`Tempest\DateTime\DateTime`} class provides a `DateTime::parse()` method to create a date from a string, a timestamp, or another datetime instance. This is the most flexible way to create a date instance.

docs/4-internals/02-discovery.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ title: Discovery
33
description: "Learn how Tempest automatically locates controller actions, event handlers, console commands, and other components of your application."
44
---
55

6+
:::info
7+
Read the [getting started with discovery](/blog/discovery-explained) guide if you are new to Tempest.
8+
:::
9+
610
## Overview
711

812
Tempest introduces a unique approach to bootstrapping an application. Instead of requiring manual registration of project code and packages, Tempest automatically scans the codebase and detects the components that should be loaded. This process is called **discovery**.

0 commit comments

Comments
 (0)