-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add helper class to integrate with the container
Signed-off-by: Fery Wardiyanto <ferywardiyanto@gmail.com>
- Loading branch information
1 parent
0b86b4f
commit 249b35a
Showing
5 changed files
with
83 additions
and
34 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Projek\Container; | ||
|
||
trait ContainerAware | ||
{ | ||
/** | ||
* @var ContainerInterface | ||
*/ | ||
private $container = null; | ||
|
||
/** | ||
* @see ContainerAwareInterface::setContainer() | ||
*/ | ||
public function setContainer(ContainerInterface $container): void | ||
{ | ||
$this->container = $container; | ||
} | ||
|
||
/** | ||
* @see ContainerAwareInterface::getContainer() | ||
*/ | ||
public function getContainer(?string $name = null) | ||
{ | ||
if ($name) { | ||
return $this->container->get($name); | ||
} | ||
|
||
return $this->container; | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Projek\Container; | ||
|
||
interface ContainerAwareInterface | ||
{ | ||
/** | ||
* Assign a container to the instance. | ||
* | ||
* @param ContainerInterface $container | ||
* @return void | ||
*/ | ||
public function setContainer(ContainerInterface $container): void; | ||
|
||
/** | ||
* Get container instance or the instance of registered service. | ||
* | ||
* @param null|string $name Optionally pass a container name, if needed. | ||
* @return null|mixed|ContainerInterface | ||
*/ | ||
public function getContainer(?string $name = null); | ||
} |
This file contains 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
This file contains 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