Skip to content

Commit 1b23fd4

Browse files
authored
fix(core): optional dependency guards (#1630)
1 parent 930e7ee commit 1b23fd4

File tree

4 files changed

+259
-251
lines changed

4 files changed

+259
-251
lines changed

docs/1-essentials/02-views.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@ description: "Tempest provides a modern templating engine with syntax inspired b
44
keywords: "Experimental"
55
---
66

7-
:::warning
8-
Tempest View is currently experimental and is not covered by our backwards compatibility promise.
9-
:::
10-
117
## Overview
128

13-
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.
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+
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).
1412

1513
### Syntax overview
1614

docs/5-extra-topics/02-standalone-components.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ ld($variable);
9797

9898
## `tempest/view`
9999

100-
Tempest's view renderer can be used to render views.
100+
Tempest View can be used as a standalone package:
101101

102102
```
103103
composer require tempest/view
@@ -111,6 +111,12 @@ $view = view(__DIR__ . '/src/b.view.php');
111111
echo $container->get(ViewRenderer::class)->render($view);
112112
```
113113

114+
There are a couple of notes to make when running Tempest View as a standalone component:
115+
116+
- Any view files and components will be discovered and must be in a directory with a valid PSR-4 namespace. View files themselves don't need to have a namespace, though.
117+
- View files are compiled and cached. You can manually enable or disable this cache by setting the `{env}{:hl-keyword:VIEW_CACHE:}` environment variable to `true` or `false`. By default, the view cache is disabled.
118+
- Optionally, you can require `tempest/console`, which will provide you with the `vendor/bin/tempest view:clear` command to clear view caches. If you don't install `tempest/console`, you'll have to manually clear view caches on deployment by removing the `.tempest/cache/views` directory.
119+
114120
## `tempest/event-bus`
115121

116122
Tempest's event bus can be used as a standalone package, in order for event handlers to be discovered, you'll have to boot Tempest's kernel and resolve the event bus from the container:

packages/core/src/IsComponentInstaller.php

Lines changed: 44 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -7,57 +7,59 @@
77
use function Tempest\root_path;
88
use function Tempest\Support\str;
99

10-
/**
11-
* @phpstan-require-implements \Tempest\Core\Installer
12-
*/
13-
trait IsComponentInstaller
14-
{
15-
use PublishesFiles;
16-
17-
private function installMainNamespace(): void
10+
if (trait_exists(PublishesFiles::class)) {
11+
/**
12+
* @phpstan-require-implements \Tempest\Core\Installer
13+
*/
14+
trait IsComponentInstaller
1815
{
19-
if ($this->composer->mainNamespace !== null) {
20-
return;
21-
}
16+
use PublishesFiles;
2217

23-
if (! $this->confirm('Tempest detected no main project namespace. Do you want to create it?', default: true)) {
24-
return;
25-
}
18+
private function installMainNamespace(): void
19+
{
20+
if ($this->composer->mainNamespace !== null) {
21+
return;
22+
}
2623

27-
$appPath = root_path($this->ask('Which path do you wish to use as your main project directory?', default: 'app/'));
24+
if (! $this->confirm('Tempest detected no main project namespace. Do you want to create it?', default: true)) {
25+
return;
26+
}
2827

29-
$defaultAppNamespace = str($appPath)
30-
->replaceStart(root_path(), '')
31-
->trim('/')
32-
->explode('/')
33-
->map(fn (string $part) => ucfirst($part))
34-
->implode('\\')
35-
->append('\\')
36-
->toString();
28+
$appPath = root_path($this->ask('Which path do you wish to use as your main project directory?', default: 'app/'));
3729

38-
$appNamespace = str($this->ask('Which namespace do you wish to use?', default: $defaultAppNamespace))
39-
->trim('\\')
40-
->append('\\')
41-
->toString();
30+
$defaultAppNamespace = str($appPath)
31+
->replaceStart(root_path(), '')
32+
->trim('/')
33+
->explode('/')
34+
->map(fn (string $part) => ucfirst($part))
35+
->implode('\\')
36+
->append('\\')
37+
->toString();
4238

43-
if (! is_dir($appPath)) {
44-
mkdir($appPath, recursive: true);
45-
}
39+
$appNamespace = str($this->ask('Which namespace do you wish to use?', default: $defaultAppNamespace))
40+
->trim('\\')
41+
->append('\\')
42+
->toString();
4643

47-
$this->composer
48-
->addNamespace(
49-
$appNamespace,
50-
$appPath,
51-
)
52-
->save();
44+
if (! is_dir($appPath)) {
45+
mkdir($appPath, recursive: true);
46+
}
5347

54-
$this->success("Project namespace created: {$appPath}");
55-
}
48+
$this->composer
49+
->addNamespace(
50+
$appNamespace,
51+
$appPath,
52+
)
53+
->save();
5654

57-
private function updateComposer(): void
58-
{
59-
if ($this->confirm(question: 'Run composer update?', default: true)) {
60-
$this->composer->executeUpdate();
55+
$this->success("Project namespace created: {$appPath}");
56+
}
57+
58+
private function updateComposer(): void
59+
{
60+
if ($this->confirm(question: 'Run composer update?', default: true)) {
61+
$this->composer->executeUpdate();
62+
}
6163
}
6264
}
6365
}

0 commit comments

Comments
 (0)