Skip to content

Commit

Permalink
Use MappingFactoryInterface everywhere instead of MappingFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
priyadi committed Jan 11, 2024
1 parent a3555e5 commit 5b14931
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 75 deletions.
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
# CHANGELOG

## 0.5.1
## 0.5.3

* Use `MappingFactoryInterface` everywhere instead of `MappingFactory`

## 0.5.2

* Support Symfony 7
* Fix service definition for MapperFactory
* Fix service definition for `MapperFactory`

## 0.5.0

Expand Down
152 changes: 87 additions & 65 deletions config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,112 +40,134 @@
use function Symfony\Component\DependencyInjection\Loader\Configurator\tagged_locator;

return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services()
$services = $containerConfigurator->services();

# Property info

$services
->set('rekalogika.mapper.property_info', PropertyInfoExtractor::class)
->args([
'$listExtractors' => [
service('property_info.reflection_extractor')
],
'$typeExtractors' => [
service('property_info.phpstan_extractor'),
service('property_info.reflection_extractor'),
],
'$accessExtractors' => [
service('property_info.reflection_extractor')
],
'$initializableExtractors' => [
service('property_info.reflection_extractor')
],

])

->args([
'$listExtractors' => [
service('property_info.reflection_extractor')
],
'$typeExtractors' => [
service('property_info.phpstan_extractor'),
service('property_info.reflection_extractor'),
],
'$accessExtractors' => [
service('property_info.reflection_extractor')
],
'$initializableExtractors' => [
service('property_info.reflection_extractor')
],

]);

$services
->set('rekalogika.mapper.cache.property_info')
->parent('cache.system')
->tag('cache.pool')
->parent('cache.system')
->tag('cache.pool');

$services
->set('rekalogika.mapper.property_info.cache', PropertyInfoCacheExtractor::class)
->decorate('rekalogika.mapper.property_info')
->args([
service('rekalogika.mapper.property_info.cache.inner'),
service('rekalogika.mapper.cache.property_info')
])
->decorate('rekalogika.mapper.property_info')
->args([
service('rekalogika.mapper.property_info.cache.inner'),
service('rekalogika.mapper.cache.property_info')
]);

# transformers

$services
->set('rekalogika.mapper.transformer.scalar_to_scalar', ScalarToScalarTransformer::class)
->tag('rekalogika.mapper.transformer', ['priority' => -550])
->tag('rekalogika.mapper.transformer', ['priority' => -550]);

$services
->set('rekalogika.mapper.transformer.datetime', DateTimeTransformer::class)
->tag('rekalogika.mapper.transformer', ['priority' => -600])
->tag('rekalogika.mapper.transformer', ['priority' => -600]);

$services
->set('rekalogika.mapper.transformer.string_to_backed_enum', StringToBackedEnumTransformer::class)
->tag('rekalogika.mapper.transformer', ['priority' => -650])
->tag('rekalogika.mapper.transformer', ['priority' => -650]);

$services
->set('rekalogika.mapper.transformer.object_to_string', ObjectToStringTransformer::class)
->tag('rekalogika.mapper.transformer', ['priority' => -700])
->tag('rekalogika.mapper.transformer', ['priority' => -700]);

$services
->set('rekalogika.mapper.transformer.traversable_to_arrayaccess', TraversableToArrayAccessTransformer::class)
->tag('rekalogika.mapper.transformer', ['priority' => -750])
->tag('rekalogika.mapper.transformer', ['priority' => -750]);

$services
->set('rekalogika.mapper.transformer.traversable_to_traversable', TraversableToTraversableTransformer::class)
->tag('rekalogika.mapper.transformer', ['priority' => -800])
->tag('rekalogika.mapper.transformer', ['priority' => -800]);

$services
->set('rekalogika.mapper.transformer.object_to_array', ObjectToArrayTransformer::class)
->args([service(NormalizerInterface::class)])
->tag('rekalogika.mapper.transformer', ['priority' => -850])
->args([service(NormalizerInterface::class)])
->tag('rekalogika.mapper.transformer', ['priority' => -850]);

$services
->set('rekalogika.mapper.transformer.array_to_object', ArrayToObjectTransformer::class)
->args([service(DenormalizerInterface::class)])
->tag('rekalogika.mapper.transformer', ['priority' => -900])
->args([service(DenormalizerInterface::class)])
->tag('rekalogika.mapper.transformer', ['priority' => -900]);

$services
->set('rekalogika.mapper.transformer.object_to_object', ObjectToObjectTransformer::class)
->args([
'$propertyListExtractor' => service('rekalogika.mapper.property_info'),
'$propertyTypeExtractor' => service('rekalogika.mapper.property_info'),
'$propertyInitializableExtractor' => service('rekalogika.mapper.property_info'),
'$propertyAccessExtractor' => service('rekalogika.mapper.property_info'),
'$propertyAccessor' => service('property_accessor'),
])
->tag('rekalogika.mapper.transformer', ['priority' => -950])

->args([
'$propertyListExtractor' => service('rekalogika.mapper.property_info'),
'$propertyTypeExtractor' => service('rekalogika.mapper.property_info'),
'$propertyInitializableExtractor' => service('rekalogika.mapper.property_info'),
'$propertyAccessExtractor' => service('rekalogika.mapper.property_info'),
'$propertyAccessor' => service('property_accessor'),
])
->tag('rekalogika.mapper.transformer', ['priority' => -950]);

$services
->set('rekalogika.mapper.transformer.null', NullTransformer::class)
->tag('rekalogika.mapper.transformer', ['priority' => -1000])

# other services
->tag('rekalogika.mapper.transformer', ['priority' => -1000]);

->set('rekalogika.mapper.type_string_helper', TypeStringHelper::class)
# mappingfactory

$services
->set('rekalogika.mapper.mapping_factory', MappingFactory::class)
->args([tagged_iterator('rekalogika.mapper.transformer', 'key')])
->args([tagged_iterator('rekalogika.mapper.transformer', 'key')]);

$services
->alias(MappingFactoryInterface::class, 'rekalogika.mapper.mapping_factory');

# other services

->alias(MappingFactoryInterface::class, 'rekalogika.mapper.mapping_factory')
$services
->set('rekalogika.mapper.type_string_helper', TypeStringHelper::class);

$services
->set('rekalogika.mapper.main_transformer', MainTransformer::class)
->args([
'$transformersLocator' => tagged_locator('rekalogika.mapper.transformer'),
'$typeStringHelper' => service('rekalogika.mapper.type_string_helper'),
'$mappingFactory' => service('rekalogika.mapper.mapping_factory'),
])
->args([
'$transformersLocator' => tagged_locator('rekalogika.mapper.transformer'),
'$typeStringHelper' => service('rekalogika.mapper.type_string_helper'),
'$mappingFactory' => service('rekalogika.mapper.mapping_factory'),
]);

$services
->set('rekalogika.mapper.mapper', Mapper::class)
->args([service('rekalogika.mapper.main_transformer')])
->args([service('rekalogika.mapper.main_transformer')]);

->alias(MapperInterface::class, 'rekalogika.mapper.mapper')
$services
->alias(MapperInterface::class, 'rekalogika.mapper.mapper');

# console command

$services
->set('rekalogika.mapper.command.mapping', MappingCommand::class)
->args([service('rekalogika.mapper.mapping_factory')])
->tag('console.command')
->args([service('rekalogika.mapper.mapping_factory')])
->tag('console.command');

$services
->set('rekalogika.mapper.command.try', TryCommand::class)
->args([
service('rekalogika.mapper.main_transformer'),
service('rekalogika.mapper.type_string_helper'),
])
->tag('console.command')
;
->args([
service('rekalogika.mapper.main_transformer'),
service('rekalogika.mapper.type_string_helper'),
])
->tag('console.command');
};
4 changes: 2 additions & 2 deletions src/Command/MappingCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace Rekalogika\Mapper\Command;

use Rekalogika\Mapper\Mapping\MappingFactory;
use Rekalogika\Mapper\Mapping\MappingFactoryInterface;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\Table;
Expand All @@ -26,7 +26,7 @@
class MappingCommand extends Command
{
public function __construct(
private MappingFactory $mappingFactory
private MappingFactoryInterface $mappingFactory
) {
parent::__construct();
}
Expand Down
4 changes: 2 additions & 2 deletions src/MainTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
use Rekalogika\Mapper\Exception\LogicException;
use Rekalogika\Mapper\Exception\UnableToFindSuitableTransformerException;
use Rekalogika\Mapper\Mapping\MappingEntry;
use Rekalogika\Mapper\Mapping\MappingFactory;
use Rekalogika\Mapper\Mapping\MappingFactoryInterface;
use Rekalogika\Mapper\Model\MixedType;
use Rekalogika\Mapper\Model\ObjectCache;
use Rekalogika\Mapper\Util\TypeUtil;
Expand All @@ -33,7 +33,7 @@ class MainTransformer implements MainTransformerInterface
public function __construct(
private ContainerInterface $transformersLocator,
private TypeStringHelper $typeStringHelper,
private MappingFactory $mappingFactory
private MappingFactoryInterface $mappingFactory
) {
}

Expand Down
5 changes: 3 additions & 2 deletions src/MapperFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Rekalogika\Mapper\Command\TryCommand;
use Rekalogika\Mapper\Contracts\TransformerInterface;
use Rekalogika\Mapper\Mapping\MappingFactory;
use Rekalogika\Mapper\Mapping\MappingFactoryInterface;
use Rekalogika\Mapper\Model\ServiceLocator;
use Rekalogika\Mapper\Transformer\ArrayToObjectTransformer;
use Rekalogika\Mapper\Transformer\DateTimeTransformer;
Expand Down Expand Up @@ -73,7 +74,7 @@ class MapperFactory
private ?TypeStringHelper $typeStringHelper = null;
private ?MainTransformer $mainTransformer = null;
private ?MapperInterface $mapper = null;
private ?MappingFactory $mappingFactory = null;
private ?MappingFactoryInterface $mappingFactory = null;

private ?MappingCommand $mappingCommand = null;
private ?TryCommand $tryCommand = null;
Expand Down Expand Up @@ -372,7 +373,7 @@ protected function getMainTransformer(): MainTransformer
return $this->mainTransformer;
}

protected function getMappingFactory(): MappingFactory
protected function getMappingFactory(): MappingFactoryInterface
{
if (null === $this->mappingFactory) {
$this->mappingFactory = new MappingFactory(
Expand Down
4 changes: 2 additions & 2 deletions tests/Common/MapperTestFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

use Rekalogika\Mapper\MainTransformer;
use Rekalogika\Mapper\MapperFactory;
use Rekalogika\Mapper\Mapping\MappingFactory;
use Rekalogika\Mapper\Mapping\MappingFactoryInterface;
use Rekalogika\Mapper\TypeStringHelper;

class MapperTestFactory extends MapperFactory
Expand All @@ -35,7 +35,7 @@ public function getMainTransformer(): MainTransformer
return parent::getMainTransformer();
}

public function getMappingFactory(): MappingFactory
public function getMappingFactory(): MappingFactoryInterface
{
return parent::getMappingFactory();
}
Expand Down

0 comments on commit 5b14931

Please sign in to comment.