Skip to content

Commit

Permalink
[HttpKernel] Remove magic on MapSessionContext and store the object i…
Browse files Browse the repository at this point in the history
…tself in session
  • Loading branch information
jtattevin committed Apr 4, 2024
1 parent 158e8cd commit eaa2741
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 437 deletions.
21 changes: 0 additions & 21 deletions src/Symfony/Component/HttpKernel/Attribute/SessionKey.php

This file was deleted.

2 changes: 1 addition & 1 deletion src/Symfony/Component/HttpKernel/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ CHANGELOG
* Add `HttpException::fromStatusCode()`
* Add `$validationFailedStatusCode` argument to `#[MapQueryParameter]` that allows setting a custom HTTP status code when validation fails
* Add `NearMissValueResolverException` to let value resolvers report when an argument could be under their watch but failed to be resolved
* Add `MapSessionContext` to map multiple session value to an object
* Add `MapSessionContext` to map an object to the session

7.0
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,17 @@ public function resolve(Request $request, ArgumentMetadata $argument): array
throw new \LogicException(sprintf('#[MapSessionContext] cannot be used on controller argument "$%s" of type "%s"; a class must be provided.', $argument->getName(), $type));
}

$class = eval(<<<SUBCLASS
return (
new class() extends $type {
use Symfony\Component\HttpKernel\Controller\SessionContextTrait;
}
);
SUBCLASS
);
$class->initSessionContext($request->getSession(), new $type());
if ($request->getSession()->has($type)) {
return [
$request->getSession()->get($type),
];
}

$object = new $type();
$request->getSession()->set($type, $object);

return [
$class,
$object,
];
}
}
100 changes: 0 additions & 100 deletions src/Symfony/Component/HttpKernel/Controller/SessionContextTrait.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ public function testResolvingSuccessfully(ArgumentMetadata $metadata, string $ex
$result = $this->resolver->resolve($this->request, $metadata);
$this->assertCount(1, $result);

$this->assertTrue((new \ReflectionClass($result[0]))->isAnonymous());
$this->assertInstanceOf($expectedType, $result[0]);
}

Expand Down

0 comments on commit eaa2741

Please sign in to comment.