Skip to content

Commit

Permalink
Initial
Browse files Browse the repository at this point in the history
  • Loading branch information
alexgarrettsmith committed Apr 8, 2017
0 parents commit ae00afe
Show file tree
Hide file tree
Showing 12 changed files with 148 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
APP_NAME=app
APP_DEBUG=true
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
vendor/
.env
25 changes: 25 additions & 0 deletions app/Controllers/Controller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace App\Controllers;

use Interop\Container\ContainerInterface;

abstract class Controller
{
/**
* The container instance.
*
* @var \Interop\Container\ContainerInterface
*/
protected $c;

/**
* Set up controllers to have access to the container.
*
* @param \Interop\Container\ContainerInterface $container
*/
public function __construct(ContainerInterface $container)
{
$this->c = $container;
}
}
28 changes: 28 additions & 0 deletions app/Controllers/HomeController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace App\Controllers;

use App\Controllers\Controller;
use Psr\Http\Message\{
ServerRequestInterface as Request,
ResponseInterface as Response
};

class HomeController extends Controller
{
/**
* Render the homepage.
*
* @param \Psr\Http\Message\ServerRequestInterface $request
* @param \Psr\Http\Message\ResponseInterface $response
* @param array $args
*
* @return mixed
*/
public function index(Request $request, Response $response, $args)
{
return $this->c->view->render($response, 'home/index.twig', [
'appName' => $this->c->settings['app']['name'],
]);
}
}
38 changes: 38 additions & 0 deletions bootstrap/app.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

require_once __DIR__ . '/../vendor/autoload.php';

try {
(new Dotenv\Dotenv(__DIR__ . '/../'))->load();
} catch (Dotenv\Exception\InvalidPathException $e) {
//
}

$app = new Slim\App([
'settings' => [
'displayErrorDetails' => getenv('APP_DEBUG') === 'true',

'app' => [
'name' => getenv('APP_NAME')
],

'views' => [
'cache' => __DIR__ . '/../storage/views'
]
],
]);

$container = $app->getContainer();

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

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

return $view;
};

require_once __DIR__ . '/../routes/web.php';
24 changes: 24 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "codecourse/slender",
"description": "A slender starter structure for Slim",
"keywords": ["framework", "slim", "codecourse"],
"license": "MIT",
"type": "project",
"require": {
"php": ">=7.0.0",
"slim/slim": "^3.8",
"slim/twig-view": "^2.2",
"symfony/var-dumper": "^3.2",
"vlucas/phpdotenv": "^2.4"
},
"autoload": {
"psr-4": {
"App\\": "app"
}
},
"scripts": {
"post-root-package-install": [
"php -r \"file_exists('.env') || copy('.env.example', '.env');\""
]
}
}
4 changes: 4 additions & 0 deletions public/.htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]
5 changes: 5 additions & 0 deletions public/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

require_once __DIR__ . '/../bootstrap/app.php';

$app->run();
10 changes: 10 additions & 0 deletions resources/views/app.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>App</title>
</head>
<body>
{% block content %}{% endblock %}
</body>
</html>
3 changes: 3 additions & 0 deletions resources/views/home/index.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{% block content %}
Hello from {{ appName }}!
{% endblock %}
5 changes: 5 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

use App\Controllers\HomeController;

$app->get('/', HomeController::class . ':index');
2 changes: 2 additions & 0 deletions storage/views/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore

0 comments on commit ae00afe

Please sign in to comment.