Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 08407c0

Browse files
committed
Use array for context and provide helper class
1 parent ad29210 commit 08407c0

11 files changed

+320
-314
lines changed

src/Symfony/Component/AutoMapper/AutoMapper.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public function hasMapper(string $source, string $target): bool
112112
/**
113113
* {@inheritdoc}
114114
*/
115-
public function map($sourceData, $targetData, Context $context = null)
115+
public function map($sourceData, $targetData, array $context = [])
116116
{
117117
$source = null;
118118
$target = null;
@@ -133,18 +133,14 @@ public function map($sourceData, $targetData, Context $context = null)
133133
throw new NoMappingFoundException('Cannot map this value, source is neither an object or an array.');
134134
}
135135

136-
if (null === $context) {
137-
$context = new Context();
138-
}
139-
140136
if (\is_object($targetData)) {
141137
$target = \get_class($targetData);
142-
$context->setObjectToPopulate($targetData);
138+
$context[MapperContext::TARGET_TO_POPULATE] = $targetData;
143139
}
144140

145141
if (\is_array($targetData)) {
146142
$target = 'array';
147-
$context->setObjectToPopulate($targetData);
143+
$context[MapperContext::TARGET_TO_POPULATE] = $targetData;
148144
}
149145

150146
if (\is_string($targetData)) {

src/Symfony/Component/AutoMapper/AutoMapperInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ interface AutoMapperInterface
2525
*
2626
* @param array|object $source Any data object, which may be an object or an array
2727
* @param string|array|object $target To which type of data, or data, the source should be mapped
28-
* @param Context $context Options mappers have access to
28+
* @param array $context Mapper context
2929
*
3030
* @return array|object The mapped object
3131
*/
32-
public function map($source, $target, Context $context = null);
32+
public function map($source, $target, array $context = []);
3333
}

src/Symfony/Component/AutoMapper/AutoMapperNormalizer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,15 @@ public function hasCacheableSupportsMethod(): bool
6464
return true;
6565
}
6666

67-
private function createAutoMapperContext(array $serializerContext = []): Context
67+
private function createAutoMapperContext(array $serializerContext = []): MapperContext
6868
{
6969
$circularReferenceLimit = 1;
7070

7171
if (isset($serializerContext[AbstractNormalizer::CIRCULAR_REFERENCE_LIMIT]) && \is_int($serializerContext[AbstractNormalizer::CIRCULAR_REFERENCE_LIMIT])) {
7272
$circularReferenceLimit = $serializerContext[AbstractNormalizer::CIRCULAR_REFERENCE_LIMIT];
7373
}
7474

75-
$context = new Context(
75+
$context = new MapperContext(
7676
$serializerContext[AbstractNormalizer::GROUPS] ?? null,
7777
$serializerContext[AbstractNormalizer::ATTRIBUTES] ?? null,
7878
$serializerContextContext[AbstractNormalizer::IGNORED_ATTRIBUTES] ?? null

src/Symfony/Component/AutoMapper/Context.php

Lines changed: 0 additions & 256 deletions
This file was deleted.

src/Symfony/Component/AutoMapper/GeneratedMapper.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ public function addCallback(string $name, callable $callback): void
4242
$this->callbacks[$name] = $callback;
4343
}
4444

45-
abstract public function &map($value, Context $context);
46-
4745
/**
4846
* Inject sub mappers.
4947
*/

0 commit comments

Comments
 (0)