Skip to content

Commit

Permalink
feat(flextype): new Flextype core #199
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Awilum committed Jul 29, 2021
1 parent 2886166 commit 6880d15
Showing 1 changed file with 48 additions and 33 deletions.
81 changes: 48 additions & 33 deletions src/flextype/Foundation/Flextype.php
Expand Up @@ -9,25 +9,11 @@

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
{
Expand All @@ -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.
Expand All @@ -65,29 +56,49 @@ public function __wakeup(): void
}

/**
* 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);

// Set Application Container
self::$container = self::$app->getContainer();
}

public function app()
/**
* Get Flextype Application.
*
* @return App Returns Flextype Application.
*
* @access public
*/
public function app(): App
{
return $this->app;
return self::$app;
}

public function container()
/**
* Get Flextype Application Container.
*
* @return Flextype Returns Flextype Application Container.
*
* @access public
*/
public function container(): Container
{
return $this->container;
return self::$container;
}


/**
* Returns Flextype Instance
* Returns Flextype Instance.
*
* @return Flextype Returns the current Flextype Instance.
*
* @access public
*/
public static function getInstance(ContainerInterface $container = null): Flextype
public static function getInstance(?ContainerInterface $container = null): Flextype
{
$cls = static::class;
if (! isset(self::$instances[$cls])) {
Expand All @@ -98,7 +109,11 @@ public static function getInstance(ContainerInterface $container = null): Flexty
}

/**
* Returns the current Flextype version
* Get the current Flextype version.
*
* @return string Returns the current Flextype version.
*
* @access public
*/
public function getVersion(): string
{
Expand Down

0 comments on commit 6880d15

Please sign in to comment.