From 1fa0bc4394c29219a310782da37af11d902b0242 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Sat, 27 Apr 2024 17:44:00 +0200 Subject: [PATCH] Container: $methods are not filtered For speed up --- src/Bridges/DITracy/ContainerPanel.php | 13 +++++++------ src/DI/Container.php | 7 ++----- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/Bridges/DITracy/ContainerPanel.php b/src/Bridges/DITracy/ContainerPanel.php index f8301b062..9a0f361d0 100644 --- a/src/Bridges/DITracy/ContainerPanel.php +++ b/src/Bridges/DITracy/ContainerPanel.php @@ -50,11 +50,13 @@ public function getTab(): string */ public function getPanel(): string { - $methods = (fn() => $this->methods)->bindTo($this->container, Container::class)(); + $rc = (new \ReflectionClass($this->container)); $services = []; - foreach ($methods as $name => $foo) { - $name = lcfirst(str_replace('__', '.', substr($name, 13))); - $services[$name] = $this->container->getServiceType($name); + foreach ($rc->getMethods() as $method) { + if (preg_match('#^createService.#', $method->getName())) { + $name = lcfirst(str_replace('__', '.', substr($method->getName(), 13))); + $services[$name] = $this->container->getServiceType($name); + } } ksort($services, SORT_NATURAL); @@ -66,9 +68,8 @@ public function getPanel(): string } } - return Nette\Utils\Helpers::capture(function () use ($tags, $services) { + return Nette\Utils\Helpers::capture(function () use ($rc, $tags, $services) { $container = $this->container; - $rc = (new \ReflectionClass($this->container)); $file = $rc->getFileName(); $instances = (fn() => $this->instances)->bindTo($this->container, Container::class)(); $wiring = (fn() => $this->wiring)->bindTo($this->container, $this->container)(); diff --git a/src/DI/Container.php b/src/DI/Container.php index 20f99302a..b726587ca 100644 --- a/src/DI/Container.php +++ b/src/DI/Container.php @@ -48,10 +48,7 @@ class Container public function __construct(array $params = []) { $this->parameters = $params + $this->getStaticParameters(); - $this->methods = array_flip(array_filter( - get_class_methods($this), - fn($s) => preg_match('#^createService.#', $s), - )); + $this->methods = array_flip(get_class_methods($this)); } @@ -372,7 +369,7 @@ private function autowireArguments(\ReflectionFunctionAbstract $function, array /** * Returns the method name for creating a service. */ - public static function getMethodName(string $name): string + final public static function getMethodName(string $name): string { if ($name === '') { throw new Nette\InvalidArgumentException('Service name must be a non-empty string.');