Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve names of some config options and parameters #3

Merged
merged 1 commit into from
May 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ return [

## Features

- [Auto-Register Custom Doctrine Type Mappings](#auto-register-custom-doctrine-types)
- [Auto-Register Carbon Doctrine Type Mappings](#auto-register-carbon-datetime-types)
- [Auto-Register Custom Doctrine Type Mappings](#auto-register-custom-doctrine-type-mappings)
- [Auto-Register Carbon Doctrine Type Mappings](#auto-register-carbon-datetime-type-mappings)

### Auto-Register Custom Doctrine Types
### Auto-Register Custom Doctrine Type Mappings

The bundle can auto-register custom Doctrine DBAL types, eliminating the need to specify them all in
`config/packages/doctrine.yaml`:
Expand All @@ -39,7 +39,7 @@ Define the directories to scan for Doctrine types:

```yaml
headsnet_doctrine_tools:
custom_types:
custom_mappings:
scan_dirs:
- 'src/Infra/Persistence/DBAL/Types'
```
Expand Down Expand Up @@ -70,7 +70,7 @@ final class ReservationIdType extends Type
}
```

### Auto-Register Carbon datetime types
### Auto-Register Carbon datetime type mappings

If the `nesbot/carbon` package is installed, this package will automatically register the Doctrine types provided by
Carbon.
Expand All @@ -94,7 +94,7 @@ If you wish to completely disable this behaviour, set `enabled: false` in the bu

```yaml
headsnet_doctrine_tools:
carbon_types:
carbon_mappings:
enabled: true
replace: true
```
Expand Down
18 changes: 9 additions & 9 deletions src/HeadsnetDoctrineToolsBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,34 @@ public function configure(DefinitionConfigurator $definition): void
{
$definition->rootNode()
->children()
->arrayNode('custom_types')
->arrayNode('custom_mappings')
->children()
->arrayNode('scan_dirs')
->scalarPrototype()->end()
->end()
->end()
->end() // End custom_types
->arrayNode('carbon_types')
->end() // End custom_mappings
->arrayNode('carbon_mappings')
->canBeDisabled()
->children()
->booleanNode('replace')->defaultTrue()->end()
->end()
->end() // End carbon_types
->end() // End carbon_mappings
;
}

/**
* @param array{
* custom_types: array{scan_dirs: array<string>},
* carbon_types: array{enabled: boolean, replace: boolean}
* custom_mappings: array{scan_dirs: array<string>},
* carbon_mappings: array{enabled: boolean, replace: boolean}
* } $config
*/
public function loadExtension(array $config, ContainerConfigurator $container, ContainerBuilder $builder): void
{
$container->parameters()
->set('headsnet_doctrine_tools.custom_types.scan_dirs', $config['custom_types']['scan_dirs'])
->set('headsnet_doctrine_tools.carbon_types.enabled', $config['carbon_types']['enabled'])
->set('headsnet_doctrine_tools.carbon_types.replace', $config['carbon_types']['replace'])
->set('headsnet_doctrine_tools.custom_mappings.scan_dirs', $config['custom_mappings']['scan_dirs'])
->set('headsnet_doctrine_tools.carbon_mappings.enabled', $config['carbon_mappings']['enabled'])
->set('headsnet_doctrine_tools.carbon_mappings.replace', $config['carbon_mappings']['replace'])
;
}

Expand Down
6 changes: 3 additions & 3 deletions src/Mapping/CarbonTypeMappingsCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ final class CarbonTypeMappingsCompilerPass implements CompilerPassInterface

public function process(ContainerBuilder $container): void
{
// Skip if carbon_types is disabled in the configuration
if (!$container->getParameter('headsnet_doctrine_tools.carbon_types.enabled')) {
// Skip if carbon_mappings is disabled in the configuration
if (!$container->getParameter('headsnet_doctrine_tools.carbon_mappings.enabled')) {
return;
}

Expand All @@ -34,7 +34,7 @@ public function process(ContainerBuilder $container): void
$typeDefinitions = $container->getParameter(self::TYPE_DEFINITION_PARAMETER);

// Use Carbon to upgrade standard datetime and datetime_immutable column types
if ($container->getParameter('headsnet_doctrine_tools.carbon_types.replace')) {
if ($container->getParameter('headsnet_doctrine_tools.carbon_mappings.replace')) {
$immutableName = 'datetime_immutable';
$mutableName = 'datetime';
}
Expand Down
2 changes: 1 addition & 1 deletion src/Mapping/DoctrineTypeMappingsCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function process(ContainerBuilder $container): void
/** @var array<string, array{class: class-string}> $typeDefinitions */
$typeDefinitions = $container->getParameter(self::TYPE_DEFINITION_PARAMETER);
/** @var array<string> $scanDirs */
$scanDirs = $container->getParameter('headsnet_doctrine_tools.custom_types.scan_dirs');
$scanDirs = $container->getParameter('headsnet_doctrine_tools.custom_mappings.scan_dirs');

$types = $this->findTypesInApplication($scanDirs);

Expand Down
2 changes: 1 addition & 1 deletion tests/Fixtures/config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
headsnet_doctrine_tools:
custom_types:
custom_mappings:
scan_dirs:
- 'src/Infra/Persistence/DBAL/Types'
2 changes: 1 addition & 1 deletion tests/HeadsnetDoctrineToolsBundleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ public function initialise_bundle(): void
$kernel = self::bootKernel();
$container = $kernel->getContainer();

$this->assertTrue($container->hasParameter('headsnet_doctrine_tools.custom_types.scan_dirs'));
$this->assertTrue($container->hasParameter('headsnet_doctrine_tools.custom_mappings.scan_dirs'));
}
}
14 changes: 7 additions & 7 deletions tests/Mapping/CarbonTypeMappingsCompilerPassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
class CarbonTypeMappingsCompilerPassTest extends TestCase
{
#[Test]
public function carbon_types_are_registered(): void
public function carbon_mappings_are_registered(): void
{
$container = new ContainerBuilder();
$container->setParameter('doctrine.dbal.connection_factory.types', []);
$container->setParameter('headsnet_doctrine_tools.carbon_types.enabled', true);
$container->setParameter('headsnet_doctrine_tools.carbon_types.replace', true);
$container->setParameter('headsnet_doctrine_tools.carbon_mappings.enabled', true);
$container->setParameter('headsnet_doctrine_tools.carbon_mappings.replace', true);
$sut = new CarbonTypeMappingsCompilerPass();

$sut->process($container);
Expand All @@ -38,12 +38,12 @@ public function carbon_types_are_registered(): void
}

#[Test]
public function carbon_types_are_registered_separately(): void
public function carbon_mappings_are_registered_separately(): void
{
$container = new ContainerBuilder();
$container->setParameter('doctrine.dbal.connection_factory.types', []);
$container->setParameter('headsnet_doctrine_tools.carbon_types.enabled', true);
$container->setParameter('headsnet_doctrine_tools.carbon_types.replace', false);
$container->setParameter('headsnet_doctrine_tools.carbon_mappings.enabled', true);
$container->setParameter('headsnet_doctrine_tools.carbon_mappings.replace', false);
$sut = new CarbonTypeMappingsCompilerPass();

$sut->process($container);
Expand All @@ -65,7 +65,7 @@ public function if_disabled_then_register_nothing(): void
{
$container = new ContainerBuilder();
$container->setParameter('doctrine.dbal.connection_factory.types', []);
$container->setParameter('headsnet_doctrine_tools.carbon_types.enabled', false);
$container->setParameter('headsnet_doctrine_tools.carbon_mappings.enabled', false);
$sut = new CarbonTypeMappingsCompilerPass();

$sut->process($container);
Expand Down
4 changes: 2 additions & 2 deletions tests/Mapping/DoctrineTypeMappingsCompilerPassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function can_find_and_register_types(): void
{
$container = new ContainerBuilder();
$container->setParameter('doctrine.dbal.connection_factory.types', []);
$container->setParameter('headsnet_doctrine_tools.custom_types.scan_dirs', [
$container->setParameter('headsnet_doctrine_tools.custom_mappings.scan_dirs', [
__DIR__ . '/Fixtures',
]);
$sut = new DoctrineTypeMappingsCompilerPass();
Expand Down Expand Up @@ -49,7 +49,7 @@ public function ignores_types_that_are_manually_registered(): void
'class' => DummyCustomType::class,
],
]);
$container->setParameter('headsnet_doctrine_tools.custom_types.scan_dirs', [
$container->setParameter('headsnet_doctrine_tools.custom_mappings.scan_dirs', [
__DIR__ . '/Fixtures',
]);
$sut = new DoctrineTypeMappingsCompilerPass();
Expand Down