| 1 | <?php |
||
| 10 | class Application |
||
| 11 | {
|
||
| 12 | /** @var Registry $registry */ |
||
| 13 | private $registry; |
||
| 14 | |||
| 15 | /** @var Container $registry */ |
||
| 16 | private $treasureChest; |
||
| 17 | |||
| 18 | /** @var string $configFolder */ |
||
| 19 | private $configFolder = 'config'; |
||
| 20 | |||
| 21 | /** @var string $environment */ |
||
| 22 | private $environment = 'production'; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * There be nay feckin wi' constructors on board this ship |
||
| 26 | * There be nay copyin' o' th'ship either |
||
| 27 | * This ship is a singleton! |
||
| 28 | */ |
||
| 29 | public function __construct(){}
|
||
| 31 | |||
| 32 | |||
| 33 | /** |
||
| 34 | * Ahoy! There nay be boardin without yer configuration |
||
| 35 | * |
||
| 36 | * @param array $config |
||
| 37 | * @return Application |
||
| 38 | */ |
||
| 39 | 2 | public static function ahoy(array $config = []) |
|
| 40 | 2 | {
|
|
| 41 | 2 | static $inst = null; |
|
| 42 | 2 | if ($inst === null) |
|
| 43 | {
|
||
| 44 | 1 | $inst = new Application(); |
|
| 45 | 1 | $inst->registry = Registry::ahoy(); |
|
| 46 | 1 | $inst->treasureChest = new Container(); |
|
| 47 | 1 | $inst->setConfig($config); |
|
| 48 | 1 | $env = getenv('APPLICATION_ENV');
|
|
| 49 | 1 | if ($env) {
|
|
| 50 | 1 | $inst->setEnvironment($env); |
|
| 51 | } |
||
| 52 | } |
||
| 53 | 2 | return $inst; |
|
| 54 | } |
||
| 55 | |||
| 56 | /** |
||
| 57 | * @param array $config |
||
| 58 | */ |
||
| 59 | 1 | private function setConfig(array $config) |
|
| 67 | |||
| 68 | /** |
||
| 69 | * T' the high seas! Garrr! |
||
| 70 | * |
||
| 71 | * @throws \Exception |
||
| 72 | */ |
||
| 73 | 1 | public function setSail() |
|
| 85 | |||
| 86 | /** |
||
| 87 | * @return Container |
||
| 88 | */ |
||
| 89 | public function getContainer(): Container |
||
| 93 | |||
| 94 | /** |
||
| 95 | * @param string $configFolder |
||
| 96 | */ |
||
| 97 | public function setConfigFolder(string $configFolder) |
||
| 101 | |||
| 102 | /** |
||
| 103 | * @param string $environment |
||
| 104 | */ |
||
| 105 | 1 | public function setEnvironment(string $environment) |
|
| 109 | } |