-
-
Notifications
You must be signed in to change notification settings - Fork 80
/
Flextype.php
123 lines (106 loc) · 2.45 KB
/
Flextype.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php
declare(strict_types=1);
/**
* Flextype (https://flextype.org)
* Founded by Sergey Romanenko and maintained by Flextype Community.
*/
namespace Flextype\Foundation;
use DI\Bridge\Slim\Bridge;
use DI\Container;
use Exception;
use Psr\Container\ContainerInterface;
use Slim\App;
final class Flextype
{
/**
* Flextype version
*/
public const VERSION = '0.9.16';
/**
* The Flextype instance.
*
* @var array
*/
private static ?Flextype $instance = null;
/**
* The Flextype Application.
*/
private static App $app;
/**
* The Flextype Application Container.
*/
private static Container $container;
/**
* Flextype should not be cloneable.
*/
protected function __clone()
{
throw new Exception('Cannot clone a Flextype.');
}
/**
* Flextype should not be restorable from strings.
*/
public function __wakeup(): void
{
throw new Exception('Cannot unserialize a Flextype.');
}
/**
* Flextype construct.
*/
protected function __construct(?ContainerInterface $container = null)
{
// Set Application with PHP-DI Bridge
self::$app = Bridge::create($container);
// Set Application Container
self::$container = self::$app->getContainer();
}
/**
* Get Flextype Application.
*
* @return App Returns Flextype Application.
*
* @access public
*/
public function app(): App
{
return self::$app;
}
/**
* Get Flextype Application Container.
*
* @return Flextype Returns Flextype Application Container.
*
* @access public
*/
public function container(): Container
{
return self::$container;
}
/**
* Returns Flextype Instance.
*
* Gets the instance via lazy initialization (created on first usage)
*
* @return Flextype Returns the current Flextype Instance.
*
* @access public
*/
public static function getInstance(?ContainerInterface $container = null): Flextype
{
if (static::$instance === null) {
static::$instance = new self();
}
return static::$instance;
}
/**
* Get the current Flextype version.
*
* @return string Returns the current Flextype version.
*
* @access public
*/
public function getVersion(): string
{
return self::VERSION;
}
}