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

fix: Proxy generation under opcache and/or classmap-authoritative #45

Merged
merged 1 commit into from
Mar 4, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## 1.1.1

* fix: Fix missing `kernel.reset` tags.
* fix: Proxy generation under `opcache` and/or `classmap-authoritative`

## 1.1.0

Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"symfony/property-access": "^6.4 || ^7.0",
"symfony/property-info": "^6.4 || ^7.0",
"symfony/serializer": "^6.4 || ^7.0",
"symfony/service-contracts": "^3.0",
"symfony/var-exporter": "^6.4.1 || ^6.5 || ^7.0.1 || ^7.1"
},
"require-dev": {
Expand Down
6 changes: 5 additions & 1 deletion src/Proxy/Implementation/ProxyFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,15 @@ public function createProxy(
): object {
$targetProxyClass = ProxyNamer::generateProxyClassName($class);

if (!class_exists($targetProxyClass, false)) {
if (!class_exists($targetProxyClass)) {
$sourceCode = $this->proxyGenerator
->generateProxyCode($class, $targetProxyClass);
$this->proxyRegistry->registerProxy($targetProxyClass, $sourceCode);

// @phpstan-ignore-next-line
eval($sourceCode);

// @phpstan-ignore-next-line
if (!class_exists($targetProxyClass)) {
throw new LogicException(
sprintf('Unable to find target proxy class "%s".', $targetProxyClass),
Expand Down
6 changes: 1 addition & 5 deletions src/Proxy/Implementation/ProxyGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ private function generateProxySourceCode(string $realClass, string $proxyClass):
sprintf('namespace %s;', $namespace) . "\n\n" .
sprintf(
'final %sclass %s%s',
$targetReflection->isReadOnly() ? 'readonly ' : ' ',
$targetReflection->isReadOnly() ? 'readonly ' : '',
$shortName,
ProxyHelper::generateLazyGhost($targetReflection)
);
Expand All @@ -62,10 +62,6 @@ private function generateProxySourceCode(string $realClass, string $proxyClass):
private function getClassHeader(): string
{
return <<<'PHP'
<?php

declare(strict_types=1);

/*
* This is a proxy class automatically generated by the rekalogika/mapper
* package. Do not edit it manually.
Expand Down
5 changes: 5 additions & 0 deletions src/Proxy/Implementation/ProxyRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ public function registerProxy(string $class, string $sourceCode): void
self::getProxyFileName($class)
);

$sourceCode = sprintf(
'<?php declare(strict_types=1);' . "\n\n" . '%s',
$sourceCode
);

file_put_contents($proxyFile, $sourceCode);
}

Expand Down
Loading