| 1 |
<?php declare(strict_types=1); |
| 2 |
|
| 3 |
namespace Imagify\Dependencies\League\Container; |
| 4 |
|
| 5 |
use Imagify\Dependencies\League\Container\Exception\ContainerException; |
| 6 |
use Imagify\Dependencies\Psr\Container\ContainerInterface; |
| 7 |
|
| 8 |
trait ContainerAwareTrait |
| 9 |
{ |
| 10 |
/** |
| 11 |
* @var ContainerInterface |
| 12 |
*/ |
| 13 |
protected $container; |
| 14 |
|
| 15 |
/** |
| 16 |
* @var Container |
| 17 |
*/ |
| 18 |
protected $leagueContainer; |
| 19 |
|
| 20 |
/** |
| 21 |
* Set a container. |
| 22 |
* |
| 23 |
* @param ContainerInterface $container |
| 24 |
* |
| 25 |
* @return ContainerAwareInterface |
| 26 |
*/ |
| 27 |
public function setContainer(ContainerInterface $container) : ContainerAwareInterface |
| 28 |
{ |
| 29 |
$this->container = $container; |
| 30 |
|
| 31 |
return $this; |
| 32 |
} |
| 33 |
|
| 34 |
/** |
| 35 |
* Get the container. |
| 36 |
* |
| 37 |
* @return ContainerInterface |
| 38 |
*/ |
| 39 |
public function getContainer() : ContainerInterface |
| 40 |
{ |
| 41 |
if ($this->container instanceof ContainerInterface) { |
| 42 |
return $this->container; |
| 43 |
} |
| 44 |
|
| 45 |
throw new ContainerException('No container implementation has been set.'); |
| 46 |
} |
| 47 |
|
| 48 |
/** |
| 49 |
* Set a container. |
| 50 |
* |
| 51 |
* @param Container $container |
| 52 |
* |
| 53 |
* @return self |
| 54 |
*/ |
| 55 |
public function setLeagueContainer(Container $container) : ContainerAwareInterface |
| 56 |
{ |
| 57 |
$this->container = $container; |
| 58 |
$this->leagueContainer = $container; |
| 59 |
|
| 60 |
return $this; |
| 61 |
} |
| 62 |
|
| 63 |
/** |
| 64 |
* Get the container. |
| 65 |
* |
| 66 |
* @return Container |
| 67 |
*/ |
| 68 |
public function getLeagueContainer() : Container |
| 69 |
{ |
| 70 |
if ($this->leagueContainer instanceof Container) { |
| 71 |
return $this->leagueContainer; |
| 72 |
} |
| 73 |
|
| 74 |
throw new ContainerException('No container implementation has been set.'); |
| 75 |
} |
| 76 |
} |
| 77 |
|