Skip to content

Commit

Permalink
add Container::new()
Browse files Browse the repository at this point in the history
  • Loading branch information
klimov-paul committed Jul 28, 2023
1 parent 80d7763 commit 4b462c2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/Container.php
Expand Up @@ -291,4 +291,16 @@ public function config(string $id, array $config = []): self

return $this;
}

/**
* Creates new self instance.
* This method can be useful when writing chain methods calls.
*
* @param mixed ...$args constructor arguments.
* @return static new self instance.
*/
public static function new(...$args): self
{
return new static(...$args);
}
}
7 changes: 7 additions & 0 deletions tests/ContainerTest.php
Expand Up @@ -144,4 +144,11 @@ public function testCircularDependency(): void

$container->get('one');
}

public function testNew(): void
{
$container = Container::new();

$this->assertTrue($container instanceof Container);
}
}

0 comments on commit 4b462c2

Please sign in to comment.