diff --git a/docs/002_facade.md b/docs/002_facade.md index 30c22333..53bc1832 100644 --- a/docs/002_facade.md +++ b/docs/002_facade.md @@ -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) diff --git a/docs/003_factory.md b/docs/003_factory.md index 6ef6a3ae..bf398ce7 100644 --- a/docs/003_factory.md +++ b/docs/003_factory.md @@ -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) diff --git a/docs/004_config.md b/docs/004_config.md index 4225e335..c5371fb3 100644 --- a/docs/004_config.md +++ b/docs/004_config.md @@ -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) diff --git a/docs/005_dependency_provider.md b/docs/005_dependency_provider.md index 608254aa..cd1f8eac 100644 --- a/docs/005_dependency_provider.md +++ b/docs/005_dependency_provider.md @@ -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)