geekmusclay / skeleton
Installs: 2
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:project
Requires
- php: ^8.0
- geekmusclay/framework: ^0.2
- geekmusclay/orm: ^0.4.1
- guzzlehttp/psr7: ^2.4
- http-interop/response-sender: ^1.0
- monolog/monolog: ^3.3
- robmorgan/phinx: ^0.13.4
- symfony/yaml: ^6.2
- tracy/tracy: ^2.10
- twig/twig: ^3.4
Requires (Dev)
- laminas/laminas-coding-standard: ^2.4
- phpstan/phpstan: ^1.8
- phpunit/phpunit: ^9.5
- symfony/var-dumper: ^5.4
This package is auto-updated.
Last update: 2024-10-31 00:27:38 UTC
README
Setup
In a public directory
Create a .htaccess
file with :
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [QSA,L,NC]
Create a .env
file with :
APP_ENV=dev
DATABASE_URL=mysql:host=localhost;dbname=skeleton
DATABASE_USER=root
DATABASE_PASSWORD=
In an index.php
file :
declare(strict_types=1); require "../vendor/autoload.php"; use Monolog\Level; use Monolog\Logger; use Monolog\Handler\StreamHandler; use Monolog\Handler\FirePHPHandler; use Tracy\Debugger; use Geekmusclay\ORM\Builder\DB; use function Http\Response\send; use Geekmusclay\DI\Core\Container; use GuzzleHttp\Psr7\ServerRequest; use Geekmusclay\Framework\Core\App; use Geekmusclay\Router\Core\Router; use Geekmusclay\Framework\Core\DotEnv; use Geekmusclay\Framework\Renderer\TwigRenderer; use Geekmusclay\Router\Interfaces\RouterInterface; use Geekmusclay\Framework\Factory\TwigRendererFactory; use Geekmusclay\Framework\Interfaces\RendererInterface; use Psr\Log\LoggerInterface; Debugger::enable(); $env = getenv('APP_ENV'); $path = __DIR__ . '/.env'; if ((false === $env || $env === 'dev') && is_file($path)) { // Loading environement variables DotEnv::load($path); Debugger::$productionMode = false; } // Instanciate application DI Container $container = new Container(); // Create the logger $logger = new Logger('app_logger'); // Now add some handlers $logger->pushHandler(new StreamHandler(__DIR__ . DS . '..' . DS . 'var' . DS . 'log/app.log', Level::Debug)); $logger->pushHandler(new FirePHPHandler()); // Add logger to container $container->set(LoggerInterface::class, $logger); // Instanciate db connector $db = new DB(getenv('DATABASE_URL'), getenv('DATABASE_USER'), getenv('DATABASE_PASSWORD')); $container->set(DB::class, $db); // Register application router into container $router = $container->get(Router::class, [$container]); // Register our router as RouterInterface for injections $container->set(RouterInterface::class, $router); // Register views root dir $container->set('view.path', __DIR__ . DS . '..' . DS .'templates'); // Register twig configuration $container->set('twig.config', []); // Instnciating TwigRenderer by factory $renderer = $container->get(TwigRendererFactory::class); // Register TwigRenderer for injections $container->set(TwigRenderer::class, $renderer); // Default renderer $container->set(RendererInterface::class, $renderer); $app = new App($container); $path = __DIR__ . DS . '..' . DS . 'src' . DS . 'Controller'; $app->registerDir( $path, 'App\\Controller' ); try { $response = $app->run(ServerRequest::fromGlobals()); } catch (Throwable $e) { $logger->critical($e->getMessage(), [ __FUNCTION__, __METHOD__, $e->getTrace() ]); } send($response);