mirror of
https://github.com/flextype/flextype.git
synced 2025-08-08 06:06:45 +02:00
feat(flextype): new Flextype core #199
New Methods: - `app` - Returns Flextype Application. - `container` - Returns Flextype Application Container. BREAKING CHANGES `container` method only returns Flextype Application Container based on PHP-DI documentation: https://php-di.org/doc/container.html
This commit is contained in:
@@ -9,25 +9,11 @@ declare(strict_types=1);
|
||||
|
||||
namespace Flextype\Foundation;
|
||||
|
||||
use Exception;
|
||||
use DI\Bridge\Slim\Bridge;
|
||||
use DI\Container;
|
||||
use Slim\App;
|
||||
use Slim\Middleware\ContentLengthMiddleware;
|
||||
use Slim\Middleware\OutputBufferingMiddleware;
|
||||
use Slim\Middleware\RoutingMiddleware;
|
||||
use Slim\Psr7\Factory\StreamFactory;
|
||||
use Atomastic\Csrf\Csrf;
|
||||
use Atomastic\Registry\Registry;
|
||||
use Atomastic\Session\Session;
|
||||
use Cocur\Slugify\Slugify;
|
||||
use DateTimeZone;
|
||||
use Flextype\Foundation\Actions;
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
use Exception;
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
use function is_null;
|
||||
use Slim\App;
|
||||
|
||||
final class Flextype
|
||||
{
|
||||
@@ -37,16 +23,21 @@ final class Flextype
|
||||
public const VERSION = '0.9.16';
|
||||
|
||||
/**
|
||||
* The Flextype's instance is stored in a static field. This field is an
|
||||
* array, because we'll allow our Flextype to have subclasses. Each item in
|
||||
* this array will be an instance of a specific Flextype's subclass.
|
||||
* The Flextype Application instances.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private static array $instances = [];
|
||||
|
||||
private App $app;
|
||||
private Container $container;
|
||||
/**
|
||||
* The Flextype Application.
|
||||
*/
|
||||
private static App $app;
|
||||
|
||||
/**
|
||||
* The Flextype Application Container.
|
||||
*/
|
||||
private static Container $container;
|
||||
|
||||
/**
|
||||
* Flextype should not be cloneable.
|
||||
@@ -65,29 +56,49 @@ final class Flextype
|
||||
}
|
||||
|
||||
/**
|
||||
* Flextype construct
|
||||
* Flextype construct.
|
||||
*/
|
||||
protected function __construct(ContainerInterface $container = null)
|
||||
protected function __construct(?ContainerInterface $container = null)
|
||||
{
|
||||
$this->app = Bridge::create($container);
|
||||
$this->container = $this->app->getContainer();
|
||||
}
|
||||
// Set Application with PHP-DI Bridge
|
||||
self::$app = Bridge::create($container);
|
||||
|
||||
public function app()
|
||||
{
|
||||
return $this->app;
|
||||
// Set Application Container
|
||||
self::$container = self::$app->getContainer();
|
||||
}
|
||||
|
||||
public function container()
|
||||
{
|
||||
return $this->container;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns Flextype Instance
|
||||
* Get Flextype Application.
|
||||
*
|
||||
* @return App Returns Flextype Application.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public static function getInstance(ContainerInterface $container = null): Flextype
|
||||
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.
|
||||
*
|
||||
* @return Flextype Returns the current Flextype Instance.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public static function getInstance(?ContainerInterface $container = null): Flextype
|
||||
{
|
||||
$cls = static::class;
|
||||
if (! isset(self::$instances[$cls])) {
|
||||
@@ -98,7 +109,11 @@ final class Flextype
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current Flextype version
|
||||
* Get the current Flextype version.
|
||||
*
|
||||
* @return string Returns the current Flextype version.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function getVersion(): string
|
||||
{
|
||||
|
Reference in New Issue
Block a user