@@ -32,6 +32,9 @@ class SimpleContainer implements ArrayAccess, ContainerInterface, IContainer {
3232
3333 protected Container $ container ;
3434
35+ /** @var array<string,string> */
36+ private array $ aliases = [];
37+
3538 public function __construct () {
3639 $ this ->container = new Container ();
3740 }
@@ -49,7 +52,7 @@ public function get(string $id): mixed {
4952 #[\Override]
5053 public function has (string $ id ): bool {
5154 // If a service is no registered but is an existing class, we can probably load it
52- return isset ($ this ->container [$ id ]) || class_exists ($ id );
55+ return isset ($ this ->aliases [ $ id ]) || isset ( $ this -> container [$ id ]) || class_exists ($ id );
5356 }
5457
5558 /**
@@ -152,6 +155,7 @@ public function resolve(string $name, array $chain = []): mixed {
152155 * @param list<class-string> $chain
153156 */
154157 protected function query (string $ name , bool $ autoload = true , array $ chain = []): mixed {
158+ $ name = $ this ->resolveAlias ($ name );
155159 if (isset ($ this ->container [$ name ])) {
156160 return $ this ->container [$ name ];
157161 }
@@ -195,6 +199,9 @@ public function registerService(string $name, Closure $closure, bool $shared = t
195199 if (isset ($ this ->container [$ name ])) {
196200 unset($ this ->container [$ name ]);
197201 }
202+ if (isset ($ this ->aliases [$ name ])) {
203+ unset($ this ->aliases [$ name ]);
204+ }
198205 if ($ shared ) {
199206 $ this ->container [$ name ] = $ wrapped ;
200207 } else {
@@ -210,11 +217,14 @@ public function registerService(string $name, Closure $closure, bool $shared = t
210217 * @param string $target the target that should be resolved instead
211218 */
212219 public function registerAlias (string $ alias , string $ target ): void {
213- $ this ->registerService (
214- $ alias ,
215- static fn (ContainerInterface $ container ): mixed => $ container ->get ($ target ),
216- false ,
217- );
220+ $ this ->aliases [$ alias ] = $ target ;
221+ }
222+
223+ protected function resolveAlias (string $ name ) : string {
224+ while (isset ($ this ->aliases [$ name ])) {
225+ $ name = $ this ->aliases [$ name ];
226+ }
227+ return $ name ;
218228 }
219229
220230 protected function registerDeprecatedAlias (string $ alias , string $ target ): void {
0 commit comments