This repository was archived by the owner on Jun 23, 2024. It is now read-only.
Conversation
lstrojny
reviewed
Jan 25, 2024
| { | ||
| self::init(); | ||
| if (!isset(self::$shell)) { | ||
| throw new RuntimeException('Cannot initialize the facade without a container.'); |
There was a problem hiding this comment.
Message should mention the shell, not the container
+ Use psysh 0.12 + Use symfony/yaml component since symfony/symfony can'tinstalled on 7
aszenz
force-pushed
the
chore/fix-deprecation-on-symfony-6.4
branch
from
January 26, 2024 15:50
18a4e73 to
edbdf0a
Compare
Author
|
@theofidry Could you check this pr |
|
I’ve been running this patch in the real world for some time and I noticed a performance regression of up to 40ms on every request in environments where the bundle is enabled. Because But: replacing it with a service closure works and makes it lazy again and removes the performance penalty. diff --git a/resources/config/services.xml b/resources/config/services.xml
index 12617b5..4191ba1 100644
--- a/resources/config/services.xml
+++ b/resources/config/services.xml
@@ -21,8 +21,8 @@
</service>
<service id="psysh.facade" class="Fidry\PsyshBundle\PsyshFacade" public="true">
- <call method="setShell">
- <argument type="service" id="psysh.shell" />
+ <call method="setShellInitializer">
+ <argument type="service_closure" id="psysh.shell" />
</call>
</service>
diff --git a/src/PsyshFacade.php b/src/PsyshFacade.php
index c39f9a3..1a9c933 100644
--- a/src/PsyshFacade.php
+++ b/src/PsyshFacade.php
@@ -11,6 +11,7 @@
namespace Fidry\PsyshBundle;
+use Closure;
use Psy\Shell;
use RuntimeException;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
@@ -23,10 +24,15 @@ use function array_merge;
final class PsyshFacade
{
private static Shell $shell;
+ private static Closure $shellInitializer;
public static function init(): void
{
- // noop ... keeping the method as is for backward compatibility
+ if (isset(self::$shell)) {
+ return;
+ }
+
+ self::$shell = (self::$shellInitializer)();
}
public static function debug(array $variables = [], $bind = null): void
@@ -40,8 +46,8 @@ final class PsyshFacade
self::$shell::debug($_variables, $bind);
}
- public function setShell(Shell $shell): void
+ public function setShellInitializer(Closure $shellInitializer): void
{
- self::$shell = $shell;
+ self::$shellInitializer = $shellInitializer;
}
} |
Owner
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Partially fixes #79
#SymfonyHackday