Skip to content

Commit 1102240

Browse files
committed
[HttpKernel] Remove magic on MapSessionContext and store the object itself in session
1 parent 158e8cd commit 1102240

File tree

5 files changed

+9
-436
lines changed

5 files changed

+9
-436
lines changed

src/Symfony/Component/HttpKernel/Attribute/SessionKey.php

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

src/Symfony/Component/HttpKernel/Controller/ArgumentResolver/SessionContextValueResolver.php

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,17 @@ public function resolve(Request $request, ArgumentMetadata $argument): array
3939
throw new \LogicException(sprintf('#[MapSessionContext] cannot be used on controller argument "$%s" of type "%s"; a class must be provided.', $argument->getName(), $type));
4040
}
4141

42-
$class = eval(<<<SUBCLASS
43-
return (
44-
new class() extends $type {
45-
use Symfony\Component\HttpKernel\Controller\SessionContextTrait;
46-
}
47-
);
48-
SUBCLASS
49-
);
50-
$class->initSessionContext($request->getSession(), new $type());
42+
if ($request->getSession()->has($type)) {
43+
return [
44+
$request->getSession()->get($type),
45+
];
46+
}
47+
48+
$object = new $type();
49+
$request->getSession()->set($type, $object);
5150

5251
return [
53-
$class,
52+
$object,
5453
];
5554
}
5655
}

src/Symfony/Component/HttpKernel/Controller/SessionContextTrait.php

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

src/Symfony/Component/HttpKernel/Tests/Controller/ArgumentResolver/SessionContextValueResolverTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ public function testResolvingSuccessfully(ArgumentMetadata $metadata, string $ex
6868
$result = $this->resolver->resolve($this->request, $metadata);
6969
$this->assertCount(1, $result);
7070

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

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy