Initial PHP project structure
This commit is contained in:
		
							
								
								
									
										19
									
								
								src/Controllers/Controller.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								src/Controllers/Controller.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,19 @@ | ||||
| <?php | ||||
|  | ||||
| namespace BitGoblin\Overseer\Controllers; | ||||
|  | ||||
| use Psr\Container\ContainerInterface; | ||||
|  | ||||
| class Controller { | ||||
|  | ||||
|   protected $container; | ||||
|  | ||||
|   public function __construct(ContainerInterface $container) { | ||||
|     $this->container = $container; | ||||
|   } | ||||
|  | ||||
|   public function get(string $name) { | ||||
|     return $this->container->get($name); | ||||
|   } | ||||
|  | ||||
| } | ||||
							
								
								
									
										16
									
								
								src/Controllers/HomeController.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								src/Controllers/HomeController.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,16 @@ | ||||
| <?php | ||||
|  | ||||
| namespace BitGoblin\Overseer\Controllers; | ||||
|  | ||||
| use Psr\Http\Message\ResponseInterface as Response; | ||||
| use Psr\Http\Message\ServerRequestInterface as Request; | ||||
| use Slim\Views\Twig; | ||||
|  | ||||
| class HomeController extends Controller { | ||||
|  | ||||
|   public function getIndex(Request $request, Response $response): Response { | ||||
|     $view = Twig::fromRequest($request); | ||||
|     return $view->render($response, 'index.twig'); | ||||
|   } | ||||
|  | ||||
| } | ||||
							
								
								
									
										25
									
								
								src/app.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								src/app.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,25 @@ | ||||
| <?php | ||||
|  | ||||
| use DI\Container; | ||||
| use Slim\Factory\AppFactory; | ||||
| use Slim\Views\Twig; | ||||
| use Slim\Views\TwigMiddleware; | ||||
|  | ||||
| require __DIR__ . '/../vendor/autoload.php'; | ||||
|  | ||||
| // Create new container object and add our config object to it | ||||
| $container = new Container(); | ||||
|  | ||||
| // Set container to create App with on AppFactory | ||||
| AppFactory::setContainer($container); | ||||
| $app = AppFactory::create(); | ||||
|  | ||||
| // create Twig instance | ||||
| $twig = Twig::create('views', ['cache' => false]); | ||||
| // add Twig-View Middleware | ||||
| $app->add(TwigMiddleware::create($app, $twig)); | ||||
|  | ||||
| // load routes | ||||
| require_once __DIR__ . '/routes.php'; | ||||
|  | ||||
| // app starts in public/index.php | ||||
							
								
								
									
										7
									
								
								src/routes.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								src/routes.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,7 @@ | ||||
| <?php | ||||
|  | ||||
| use Psr\Http\Message\ResponseInterface as Response; | ||||
| use Psr\Http\Message\ServerRequestInterface as Request; | ||||
|  | ||||
| // index GET route - this page should welcome the user and direct them to the available actions | ||||
| $app->get('/', '\\BitGoblin\\Overseer\\Controllers\\HomeController:getIndex')->setName('index'); | ||||
		Reference in New Issue
	
	Block a user