From 712792006fdeed036ff5f4a38b373d9f3e874d14 Mon Sep 17 00:00:00 2001 From: fadrian06 Date: Sun, 23 Aug 2026 16:44:07 -0400 Subject: [PATCH] refactor Loader@load with better names and docblock --- flight/core/Loader.php | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/flight/core/Loader.php b/flight/core/Loader.php index 4b048b7..ce71f1d 100644 --- a/flight/core/Loader.php +++ b/flight/core/Loader.php @@ -64,39 +64,39 @@ class Loader } /** - * Loads a registered class. + * Gets an instance of a registered class. * - * @param string $name Method name. - * @param bool $shared Shared instance. - * @return ?object Class instance + * @param string $name Class alias. + * @param bool $shared Whether to return a shared instance or create a new one. + * @return ?object * @throws Throwable */ public function load(string $name, bool $shared = true): ?object { - $obj = null; + $instance = null; if (!isset($this->classes[$name])) { return null; } - [$class, $params, $callback] = $this->classes[$name]; + [$factory, $constructorArguments, $onAfterInstantiating] = $this->classes[$name]; $exists = isset($this->instances[$name]); if ($shared) { - $obj = $exists + $instance = $exists ? $this->getInstance($name) - : $this->newInstance($class, $params); + : $this->newInstance($factory, $constructorArguments); - $this->instances[$name] ??= $obj; + $this->instances[$name] ??= $instance; } else { - $obj = $this->newInstance($class, $params); + $instance = $this->newInstance($factory, $constructorArguments); } - if ($callback && (!$shared || !$exists)) { - $callback($obj); + if ($onAfterInstantiating && (!$shared || !$exists)) { + $onAfterInstantiating($instance); } - return $obj; + return $instance; } /**