Skip to content

Commit

Permalink
4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
alexgarrettsmith committed Jul 24, 2019
1 parent aaff4f0 commit 5619f3a
Show file tree
Hide file tree
Showing 5 changed files with 1,297 additions and 21 deletions.
4 changes: 2 additions & 2 deletions app/Controllers/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Controllers;

use Interop\Container\ContainerInterface;
use DI\Container;

abstract class Controller
{
Expand All @@ -18,7 +18,7 @@ abstract class Controller
*
* @param \Interop\Container\ContainerInterface $container
*/
public function __construct(ContainerInterface $container)
public function __construct(Container $container)
{
$this->c = $container;
}
Expand Down
12 changes: 10 additions & 2 deletions app/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,18 @@

class HomeController extends Controller
{
/**
* Render the home page
*
* @param Request $request
* @param Response $response
* @param [type] $args
* @return void
*/
public function index(Request $request, Response $response, $args)
{
return $this->c->view->render($response, 'home/index.twig', [
'appName' => $this->c->settings['app']['name'],
return $this->c->get('view')->render($response, 'home/index.twig', [
'appName' => $this->c->get('settings')['app']['name'],
]);
}
}
33 changes: 19 additions & 14 deletions bootstrap/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@
//
}

$app = new Slim\App([
'settings' => [
$container = new DI\Container();

Slim\Factory\AppFactory::setContainer($container);

$app = Slim\Factory\AppFactory::create();

$container->set('settings', function () {
return [
'displayErrorDetails' => getenv('APP_DEBUG') === 'true',

'app' => [
Expand All @@ -19,20 +25,19 @@
'views' => [
'cache' => getenv('VIEW_CACHE_DISABLED') === 'true' ? false : __DIR__ . '/../storage/views'
]
],
]);

$container = $app->getContainer();
];
});

$container['view'] = function ($container) {
$view = new \Slim\Views\Twig(__DIR__ . '/../resources/views', [
'cache' => $container->settings['views']['cache']
]);
$twig = new Slim\Views\Twig(__DIR__ . '/../resources/views', [
'cache' => $container->get('settings')['views']['cache']
]);

$basePath = rtrim(str_ireplace('index.php', '', $container['request']->getUri()->getBasePath()), '/');
$view->addExtension(new Slim\Views\TwigExtension($container['router'], $basePath));
$twigMiddleware = new Slim\Views\TwigMiddleware(
$twig,
$container,
$app->getRouteCollector()->getRouteParser()
);

return $view;
};
$app->add($twigMiddleware);

require_once __DIR__ . '/../routes/web.php';
8 changes: 5 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
"type": "project",
"require": {
"php": ">=7.0.0",
"slim/slim": "^3.8",
"slim/twig-view": "^2.2",
"slim/slim": "4.0.0-beta",
"slim/twig-view": "3.0.0-alpha",
"symfony/var-dumper": "^3.2",
"vlucas/phpdotenv": "^2.4"
"vlucas/phpdotenv": "^2.4",
"slim/psr7": "^0.3.0",
"php-di/php-di": "^6.0"
},
"autoload": {
"psr-4": {
Expand Down
Loading

0 comments on commit 5619f3a

Please sign in to comment.