Skip to content

Commit

Permalink
Add general documentation (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gashmob authored Jun 6, 2024
2 parents eaebceb + 7387a93 commit dcdfdb7
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 16 deletions.
4 changes: 0 additions & 4 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
version: 2
updates:
- package-ecosystem: composer
directory: /
schedule:
interval: daily
- package-ecosystem: github-actions
directory: /
schedule:
Expand Down
6 changes: 2 additions & 4 deletions src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@

# Documentation

- [Routing](./documentation/routing.md)
- [Route]()
- [Middleware]()
- [Services](./documentation/services.md)
- [Brick](./documentation/brick.md)
- [Services](./documentation/services.md)
- [Events](./documentation/events.md)

# Existing Bricks

Expand Down
15 changes: 15 additions & 0 deletions src/documentation/brick.md
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!
25 changes: 25 additions & 0 deletions src/documentation/events.md
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.
1 change: 0 additions & 1 deletion src/documentation/routing.md

This file was deleted.

80 changes: 80 additions & 0 deletions src/documentation/services.md
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.
8 changes: 1 addition & 7 deletions src/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,10 @@

Let's create together a small website in this tutorial.

## [Documentation](./documentation/routing.md)

> [!WARNING]
> This documentation is under implementation. We are sorry for the inconvenience.
## [Documentation](./documentation/brick.md)

Wants to go further? Read detailed documentation of each available features.

## [Existing Bricks](./bricks/core.md)

> [!WARNING]
> This documentation is under implementation. We are sorry for the inconvenience.
Documentation of each official Bricks.

0 comments on commit dcdfdb7

Please sign in to comment.