-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
123 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,16 @@ | ||
# Brick | ||
|
||
In Archict a Brick is a composer package consisting of a collection of [Service](./services.md) and [Event](./events.md). Through [Archict/Core](../bricks/core.md) (which is also a Brick) they can be loaded and interact between them. | ||
|
||
In the rest of this documentation all core features are described. Some features from official Bricks are also detailled. | ||
|
||
## Create a Brick | ||
|
||
Creating a Brick is pretty simple. A template is provided on Github <https://github.com/Archict/brick-template>, but it is also possible to begin from scratch. | ||
|
||
As said previously, a Brick is a composer package. But there is 2 points to respect: | ||
|
||
1. The composer package type MUST be `archict-brick`. Unless Core will not be able to load it | ||
2. It SHOULD require package `archict/brick`. It's not mandatory but interface to create Service will not be available. | ||
|
||
And that's all! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Events | ||
|
||
## Listening | ||
|
||
A Service can listen to events and it's very simple: | ||
|
||
```php | ||
use Archict\Brick\ListeningEvent; | ||
use Archict\Brick\Service; | ||
|
||
#[Service] | ||
class MyService | ||
{ | ||
#[ListeningEvent] | ||
public function listenToSomeEvent(MyEvent $event): void | ||
{ | ||
} | ||
} | ||
``` | ||
|
||
It just need a method with the attribute `ListeningEvent`. Archict will infer which event is listened by getting type of first parameter. Note that the method MUST have one and only one parameter, the event listened which is an object. | ||
|
||
## Dispatching | ||
|
||
Dispatching of Events is done by using `Archict\Core\Event\EventDispatcher::dispatch(object)`. `EventDispatcher` is a Service provided by `Archict/Core`, it can be retrieved from the dependency injection of another Service. The dispatcher will returns the object passed to the method modified by all the listeners. The calling order of listeners cannot be predicted, be vigilant on that. |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,81 @@ | ||
# Services | ||
|
||
A Service is a PHP class with attribute `Archict\Brick\Service`: | ||
|
||
```php | ||
<?php | ||
|
||
use Archict\Brick\Service; | ||
|
||
#[Service] | ||
class MyService | ||
{ | ||
} | ||
``` | ||
|
||
When Core will load Bricks, this class will be instantiate. If it depends on other Service, by adding them to the constructor Archict will inject them. | ||
|
||
```php | ||
# AnotherService.php | ||
#[Service] | ||
class AnotherService | ||
{ | ||
} | ||
|
||
# MyService.php | ||
#[Service] | ||
class MyService | ||
{ | ||
public function __construct(AnotherService $another_service) | ||
{ | ||
} | ||
} | ||
``` | ||
|
||
Root package will always be considered as a Brick (independently of its package type) and loaded by Core. | ||
|
||
## Configuration | ||
|
||
Services can be configured via a yaml config file. This file MUST be located in root `config` dir. By default it will be named with the lowered class name (`myservice.yml` for example). | ||
|
||
Configuration of a Service is defined with a data class, for example | ||
|
||
```php | ||
class MyConfiguration | ||
{ | ||
public string $foo; | ||
} | ||
``` | ||
|
||
And then specified in Service attribute | ||
|
||
```php | ||
#[Service(MyConfiguration::class, 'my_config.yml')] | ||
class MyService | ||
{ | ||
public function __construct(MyConfiguration $configuration) | ||
{ | ||
} | ||
} | ||
``` | ||
|
||
The configuration can be injected in the Service constructor. Default config file name can also be overrided with the second argument of Service attribute. | ||
|
||
When defining a configuration for a Service, a default configuration MUST be provided. In the previous example case, the file `config/my_config.yml` MUST exists and contains a default configuration. For example: | ||
|
||
```yml | ||
foo: "bar" | ||
``` | ||
The file can be empty if a default value is provided in the configuration class | ||
```php | ||
class MyConfiguration | ||
{ | ||
public string $foo = 'bar'; | ||
} | ||
``` | ||
|
||
Archict uses [`symfony/yaml`](https://packagist.org/packages/symfony/yaml) and [`cuyz/valinor`](https://packagist.org/packages/cuyz/valinor) to parse then map yaml file. It a problem occur during this process, the thrown exception is not catch to let the developer fix it. | ||
|
||
When a Brick in dependencies is loaded, it will first try to get configuration file in `config` directory of the root package and then get the default one in Brick package. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters