Skip to content

Commit

Permalink
Link the docs to the website
Browse files Browse the repository at this point in the history
  • Loading branch information
Chemaclass committed Jul 14, 2021
1 parent 391939f commit 25cd5d2
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 215 deletions.
34 changes: 2 additions & 32 deletions docs/002_facade.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,10 @@

# Facade

The Facade is the entry point of your module. See an example:
Check the full `Facade` documentation here: [https://gacela-project.com/docs/facade/](https://gacela-project.com/docs/facade/)

```php
# src/Calculator/FacadeInterface.php
interface FacadeInterface
{
public function sum(): void;
}
```

```php
# src/Calculator/Facade.php
/**
* @method Factory getFactory()
*/
final class Facade extends AbstractFacade implements FacadeInterface
{
public function sum(int ...$numbers): int
{
$this->getFactory()
->createAdder()
->add(...$numbers);
}
}
```

A Facade is a "ready to use" thing:

```php
$facade = new Facade();
$result = $facade->sum(2, 3);
```
A Facade is the entry point of your module.

The Facade uses the Factory to create the module's domain instances and executes the desired behaviour from them.
Nothing less, nothing more.

[<< Basic Concepts](../docs/001_basic_concepts.md) | [Factory >>](../docs/003_factory.md)
34 changes: 2 additions & 32 deletions docs/003_factory.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,9 @@

# Factory

Check the full `Factory` documentation here: [https://gacela-project.com/docs/factory/](https://gacela-project.com/docs/factory/)

The Factory is the place where you create your domain services and objects.
The Facade is the class that can access the Factory.

```php
# src/Calculator/Factory.php
/**
* @method Config getConfig()
*/
final class Factory extends AbstractFactory
{
public function createAdder(): AdderInterface
{
return new Adder(
// ...
);
}
}
```

```php
# src/Calculator/Facade.php
/**
* @method Factory getFactory()
*/
final class Facade extends AbstractFacade implements FacadeInterface
{
public function sum(int ...$numbers): int
{
return $this->getFactory()
->createAdder()
->add(...$numbers);
}
}
```

[<< Facade](../docs/002_facade.md) | [Config >>](../docs/004_config.md)
113 changes: 3 additions & 110 deletions docs/004_config.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,118 +2,11 @@

# Config

Check the full `Config` documentation here: [https://gacela-project.com/docs/config/](https://gacela-project.com/docs/config/)

Use a Config Class to construct your business domain classes by injecting the data from the Config using the Factory
when you do the creation of your domain classes.

In order to achieve that, you need to create a `gacela.json` file in your application root with the following values:

### gacela.json examples

Using PHP config files:

```json
{
"config": {
"type": "php",
"path": "config/*.php",
"path_local": "config/local.php"
}
}
```

Using `.env` config files:

```json
{
"config": {
"type": "env",
"path": ".env*",
"path_local": ".env.local"
}
}
```

Or even multiple types of config files:

```json
{
"config": [
{
"type": "php",
"path": "config/*.php",
"path_local": "config/local.php"
},
{
"type": "env",
"path": ".env*",
"path_local": ".env.local"
}
]
}
```

- `"type"`: possible values `php` or `env`
- `"path"`: the path of the folder which contains your application configuration.
You can use `?` or `*` in order to match 1 or multiple characters.
Check [`glob()`](https://www.php.net/manual/en/function.glob.php) function for more info.
- `"path_local"`: this is the last file loaded, which means, it will override the previous configuration,
so you can add it to your `.gitignore` and set your own local config values.
---

> This is tightly coupled with the infrastructure layer, because there is I/O involved.
> It's not bad itself, you just need to be aware of potential risks, though. Don't
> access data from your `config` files (files under the gacela.json `path` directory) directly in your domain services.
> In this way, you would couple your logic with infrastructure code, and not be able to unit test it.
### An example

```json
# gacela.json
{
"config": {
"type": "php",
"path": "config/*.php",
"path_local": "config/local.php"
}
}
```

```php
# config/default.php
use src\Calculator\Config;

return [
Config::MAX_ADDITIONS => 20,
];
```

```php
# src/Calculator/Config.php
final class Config extends AbstractConfig
{
public const MAX_ADDITIONS = 'MAX_ADDITIONS';

public function getMaxAdditions(): int
{
return $this->get(self::MAX_ADDITIONS, $default = 0);
}
}
```

```php
# src/Calculator/Factory.php
/**
* @method Config getConfig()
*/
final class Factory extends AbstractFactory
{
public function createAdder(): AdderInterface
{
return new Adder(
$this->getConfig()->getMaxAdditions()
);
}
}
```
In order to achieve that, you need to create a `gacela.json` file in your application root.

[<< Factory](../docs/003_factory.md) | [Dependency Provider >>](../docs/005_dependency_provider.md)
43 changes: 2 additions & 41 deletions docs/005_dependency_provider.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,8 @@

# Dependency Provider

This is the place where you can define the dependencies that a particular module has with other modules.

In this example you can see that in the `Calculator` we have a service (`Adder`) which needs the `AnotherModuleFacade`
as a dependency. In this case, we can define the dependency inside the `DependencyProvider`.

```php
# src/Calculator/Factory.php
final class Factory extends AbstractFactory
{
public function createAdder(): AdderInterface
{
return new Adder(
$this->getAnotherModuleFacade()
);
}

private function getAnotherModuleFacade(): AnotherModuleFacade
{
return $this->getProvidedDependency(DependencyProvider::FACADE_ANOTHER_MODULE);
}
}
```
Check the full `DependencyProvider` documentation here: [https://gacela-project.com/docs/dependency-provider/](https://gacela-project.com/docs/dependency-provider/)

```php
# src/Calculator/DependencyProvider.php
final class DependencyProvider extends AbstractDependencyProvider
{
public const FACADE_ANOTHER_MODULE = 'FACADE_ANOTHER_MODULE';

public function provideModuleDependencies(Container $container): void
{
$this->addFacadeAnotherModule($container);
}

private function addFacadeAnotherModule(Container $container): void
{
$container->set(self::FACADE_ANOTHER_MODULE, function (Container $container): AnotherModuleFacade {
return $container->getLocator()->get(AnotherModuleFacade::class);
});
}
}
```
This is the place where you can define the dependencies that a particular module has with other modules.

[<< Config](../docs/004_config.md) | [Code Generator >>](../docs/006_code_generator.md)

0 comments on commit 25cd5d2

Please sign in to comment.