Skip to content

Commit

Permalink
Merge pull request #150 from gacela-project/feat/change-phpdoc-extern…
Browse files Browse the repository at this point in the history
…alservices

Change PhpDoc from $externalServices
  • Loading branch information
Chemaclass authored May 14, 2022
2 parents 81b86f9 + 38b53bd commit 826ded2
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 27 deletions.
4 changes: 2 additions & 2 deletions src/Framework/Bootstrap/AbstractSetupGacela.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function buildConfig(ConfigBuilder $configBuilder): ConfigBuilder
/**
* Define the mapping between interfaces and concretions, so Gacela services will auto-resolve them automatically.
*
* @param array<string,mixed> $externalServices
* @param array<string,class-string|object|callable> $externalServices
*/
public function buildMappingInterfaces(MappingInterfacesBuilder $mappingInterfacesBuilder, array $externalServices): MappingInterfacesBuilder
{
Expand All @@ -37,7 +37,7 @@ public function buildSuffixTypes(SuffixTypesBuilder $suffixTypesBuilder): Suffix
}

/**
* @return array<string,mixed>
* @return array<string,class-string|object|callable>
*/
public function externalServices(): array
{
Expand Down
10 changes: 5 additions & 5 deletions src/Framework/Bootstrap/GacelaConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ final class GacelaConfig

private MappingInterfacesBuilder $mappingInterfacesBuilder;

/** @var array<string,mixed> */
/** @var array<string,class-string|object|callable> */
private array $externalServices;

/**
* @param array<string,mixed> $externalServices
* @param array<string,class-string|object|callable> $externalServices
*/
public function __construct(array $externalServices = [])
{
Expand Down Expand Up @@ -83,15 +83,15 @@ public function addMappingInterface(string $key, $value): self
}

/**
* @return mixed
* @return class-string|object|callable
*/
public function getExternalService(string $key)
{
return $this->externalServices[$key];
}

/**
* @param mixed $value
* @param class-string|object|callable $value
*/
public function addExternalService(string $key, $value): self
{
Expand All @@ -104,7 +104,7 @@ public function addExternalService(string $key, $value): self
* @internal
*
* @return array{
* external-services:array<string,mixed>,
* external-services:array<string,class-string|object|callable>,
* config-builder:ConfigBuilder,
* suffix-types-builder:SuffixTypesBuilder,
* mapping-interfaces-builder:MappingInterfacesBuilder,
Expand Down
8 changes: 4 additions & 4 deletions src/Framework/Bootstrap/SetupGacela.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class SetupGacela extends AbstractSetupGacela
/** @var ?callable(SuffixTypesBuilder):void */
private $suffixTypesFn = null;

/** @var array<string,mixed> */
/** @var array<string,class-string|object|callable> */
private array $externalServices = [];

private ?ConfigBuilder $configBuilder = null;
Expand Down Expand Up @@ -105,7 +105,7 @@ public function setMappingInterfacesFn(callable $callable): self
/**
* Define the mapping between interfaces and concretions, so Gacela services will auto-resolve them automatically.
*
* @param array<string,mixed> $externalServices
* @param array<string,class-string|object|callable> $externalServices
*/
public function buildMappingInterfaces(
MappingInterfacesBuilder $mappingInterfacesBuilder,
Expand Down Expand Up @@ -148,7 +148,7 @@ public function buildSuffixTypes(SuffixTypesBuilder $suffixTypesBuilder): Suffix
}

/**
* @param array<string,mixed> $array
* @param array<string,class-string|object|callable> $array
*/
public function setExternalServices(array $array): self
{
Expand All @@ -158,7 +158,7 @@ public function setExternalServices(array $array): self
}

/**
* @return array<string,mixed>
* @return array<string,class-string|object|callable>
*/
public function externalServices(): array
{
Expand Down
4 changes: 2 additions & 2 deletions src/Framework/Bootstrap/SetupGacelaInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function buildConfig(ConfigBuilder $configBuilder): ConfigBuilder;
/**
* Define the mapping between interfaces and concretions, so Gacela services will auto-resolve them automatically.
*
* @param array<string,mixed> $externalServices
* @param array<string,class-string|object|callable> $externalServices
*/
public function buildMappingInterfaces(MappingInterfacesBuilder $mappingInterfacesBuilder, array $externalServices): MappingInterfacesBuilder;

Expand All @@ -30,7 +30,7 @@ public function buildSuffixTypes(SuffixTypesBuilder $suffixTypesBuilder): Suffix
/**
* Define global services that can be accessible via the mapping interfaces.
*
* @return array<string,mixed>
* @return array<string,class-string|object|callable>
*/
public function externalServices(): array;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@

use Gacela\Framework\Bootstrap\GacelaConfig;
use Gacela\Framework\Gacela;
use GacelaTest\Feature\Framework\BindingInterfacesWithInnerDependencies\LocalConfig\Domain\Greeter\CorrectCompanyGenerator;
use PHPUnit\Framework\TestCase;

final class FeatureTest extends TestCase
{
public function setUp(): void
{
Gacela::bootstrap(__DIR__, static fn (GacelaConfig $config) => $config
->addExternalService('isWorking?', 'yes!'));
->addExternalService('greeterGenerator', CorrectCompanyGenerator::class));
}

public function test_mapping_interfaces_from_config(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,13 @@
declare(strict_types=1);

use Gacela\Framework\Bootstrap\GacelaConfig;
use GacelaTest\Feature\Framework\BindingInterfacesWithInnerDependencies\LocalConfig\Domain\Greeter\CorrectCompanyGenerator;
use GacelaTest\Feature\Framework\BindingInterfacesWithInnerDependencies\LocalConfig\Domain\Greeter\IncorrectCompanyGenerator;
use GacelaTest\Feature\Framework\BindingInterfacesWithInnerDependencies\LocalConfig\Domain\GreeterGeneratorInterface;

/**
* This Feature-test does two things:
*
* - 1: Check the "externalService" variable was properly defined in the 'Gacela::bootstrap()' with the key `isWorking?`.
*
* - 2: Let Gacela resolve in the factory the mapping from `GreeterGeneratorInterface` to `CorrectCompanyGenerator`
* AND auto-resolve the class `CustomNameGenerator` from the `CorrectCompanyGenerator` constructor.
*/

return static function (GacelaConfig $config): void {
$config->addMappingInterface(GreeterGeneratorInterface::class, IncorrectCompanyGenerator::class);

if ($config->getExternalService('isWorking?') === 'yes!') {
$config->addMappingInterface(GreeterGeneratorInterface::class, CorrectCompanyGenerator::class);
}
// Overriding the `GreeterGeneratorInterface` with the proper external service.
// Check the FeatureTest class to see how the external service with key `greeterGenerator` is defined.
$config->addMappingInterface(GreeterGeneratorInterface::class, $config->getExternalService('greeterGenerator'));
};

0 comments on commit 826ded2

Please sign in to comment.