This repository has been archived by the owner on Jan 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
77 additions
and
0 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,57 @@ | ||
<?php | ||
/** | ||
* components | ||
* | ||
* @author Wolfy-J | ||
*/ | ||
|
||
namespace Spiral\Core\Container; | ||
|
||
use Interop\Container\ContainerInterface; | ||
|
||
/** | ||
* Provides ability to delegate option to container. | ||
*/ | ||
final class Autowire | ||
{ | ||
/** | ||
* Delegation target | ||
* | ||
* @var mixed | ||
*/ | ||
private $alias; | ||
|
||
/** | ||
* Autowire constructor. | ||
* | ||
* @param string $alias | ||
*/ | ||
public function __construct(string $alias) | ||
{ | ||
$this->alias = $alias; | ||
} | ||
|
||
/** | ||
* @param \Interop\Container\ContainerInterface $container | ||
* | ||
* @return mixed | ||
* | ||
* @throws \Interop\Container\Exception\NotFoundException No entry was found for this | ||
* identifier. | ||
* @throws \Interop\Container\Exception\ContainerException Error while retrieving the entry. | ||
*/ | ||
public function resolve(ContainerInterface $container) | ||
{ | ||
return $container->get($this->alias); | ||
} | ||
|
||
/** | ||
* @param $an_array | ||
* | ||
* @return static | ||
*/ | ||
public static function __set_state($an_array) | ||
{ | ||
return new static($an_array['alias']); | ||
} | ||
} |
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