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: app/Front/Docs/Content/internals/05-package-development.md
+27-1Lines changed: 27 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ title: Package Development
4
4
5
5
Tempest comes with a handful of tools to help third-party package developers.
6
6
7
-
## `#[DoNotDiscover]`
7
+
## DoNotDiscover
8
8
9
9
Tempest has an attribute called `#[DoNotDiscover]`, which you can add on classes. Any class within your package that has this attribute won't be discovered by Tempest. You can still use that class internally, or allow you package to publish it (see [installers](#installers)).
10
10
@@ -139,6 +139,32 @@ Finally, Installers will be discovered by Tempest, so you only need to implement
139
139
140
140
As you can see in the previous examples, `$this->publishImports()` is always called within the `install()` method. Calling this method will loop over all published files, and adjust any imports that reference to published files.
141
141
142
+
## Provider classes
143
+
144
+
Unlike Symfony or Laravel, Tempest doesn't have a dedicated "service provider" concept. Instead, you're encouraged to rely on discovery and initializers. However, there might be cases where you need to "set up a bunch of things for your package", and you need a place to put that code.
145
+
146
+
In order to do that, you're encouraged to simply have an event listener for the `KernelEvent::BOOTED` event. This event is triggered when Tempest's kernel has booted, but before any application code is run. It's the perfect place to hook into Tempest's internals if you need to set up stuff specifically for your package.
147
+
148
+
```php
149
+
use Tempest\Core\KernelEvent;
150
+
use Tempest\EventBus\EventHandler;
151
+
152
+
final readonly class MyPackageProvider
153
+
{
154
+
public function __construct(
155
+
// You can inject any dependency you like
156
+
private Container $container,
157
+
) {}
158
+
159
+
#[EventHandler(KernelEvent::BOOTED)]
160
+
public function init(): void
161
+
{
162
+
// Do whatever needs to be done
163
+
$this->container->…
164
+
}
165
+
}
166
+
```
167
+
142
168
## Testing helpers
143
169
144
170
Tempest provides a class called `\Tempest\Framework\Testing\IntegrationTest`. Your PHPUnit tests can extend from it. By doing so, your tests will automatically boot the framework, and have a range of helper methods available.
0 commit comments