Skip to content

Commit

Permalink
Make container and capsule protected static properties
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanNerd committed May 21, 2021
1 parent 2296e4a commit d4f58a4
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions app/Main/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

use DI\ContainerBuilder;
use Illuminate\Database\Capsule\Manager as Capsule;
use Psr\Container\ContainerInterface;
use Slim\Factory\AppFactory;
use Slim\Routing\RouteCollectorProxy;
use Willow\Middleware\JsonBodyParser;
Expand All @@ -13,10 +14,8 @@

class App
{
/**
* @var Capsule
*/
protected $capsule = null;
protected static Capsule $capsule;
protected static ContainerInterface $container;

public function __construct(bool $run = true)
{
Expand All @@ -28,15 +27,14 @@ public function __construct(bool $run = true)
$builder->addDefinitions(realpath($definitions));
}
}
$container = $builder->build();

// Establish an instance of the Illuminate database capsule (if not already established)
if ($this->capsule === null) {
$this->capsule = $container->get(Capsule::class);
}
$container = $builder->build();
self::$container = $container;
self::$capsule = $container->get(Capsule::class);

// Get an instance of Slim\App
$app = AppFactory::createFromContainer($container);
AppFactory::setContainer(self::$container);
$app = AppFactory::create();
$app->addRoutingMiddleware();

// Register the routes via the controllers
Expand Down

0 comments on commit d4f58a4

Please sign in to comment.