-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit ae00afe
Showing
12 changed files
with
148 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
APP_NAME=app | ||
APP_DEBUG=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
vendor/ | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'], | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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');\"" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
|
||
require_once __DIR__ . '/../bootstrap/app.php'; | ||
|
||
$app->run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{% block content %} | ||
Hello from {{ appName }}! | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
|
||
use App\Controllers\HomeController; | ||
|
||
$app->get('/', HomeController::class . ':index'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
* | ||
!.gitignore |