Skip to content

Commit

Permalink
Update Symfony Console recipe
Browse files Browse the repository at this point in the history
Hierbij is ook de manier waarop de app geladen wordt veranderd,
configuratie.include.php wordt op dit moment niet geladen

TODO: We moeten deze hele logica veranderen om een beetje overeen te
komen met best practices.
  • Loading branch information
NathanHuisman committed Oct 26, 2024
1 parent 50c39ba commit 2bdab24
Show file tree
Hide file tree
Showing 9 changed files with 162 additions and 121 deletions.
3 changes: 3 additions & 0 deletions .symfony.local.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
http:
document_root: htdocs/
passthru: index.php
46 changes: 10 additions & 36 deletions bin/console
Original file line number Diff line number Diff line change
@@ -1,48 +1,22 @@
#!/usr/bin/env php
<?php

use CsrDelft\common\ContainerFacade;
use CsrDelft\Kernel;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\ErrorHandler\Debug;

if (false === in_array(\PHP_SAPI, ['cli', 'phpdbg', 'embed'], true)) {
echo 'Warning: The console should be invoked via the CLI version of PHP, not the '.\PHP_SAPI.' SAPI'.\PHP_EOL;
if (!is_dir(dirname(__DIR__).'/vendor')) {
throw new LogicException('Dependencies are missing. Try running "composer install".');
}

set_time_limit(0);

require dirname(__DIR__).'/vendor/autoload.php';

if (!class_exists(Application::class)) {
throw new RuntimeException('You need to add "symfony/framework-bundle" as a Composer dependency.');
}

$input = new ArgvInput();
if (null !== $env = $input->getParameterOption(['--env', '-e'], null, true)) {
putenv('APP_ENV='.$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = $env);
}

if ($input->hasParameterOption('--no-debug', true)) {
putenv('APP_DEBUG='.$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = '0');
if (!is_file(dirname(__DIR__).'/vendor/autoload_runtime.php')) {
throw new LogicException('Symfony Runtime is missing. Try running "composer require symfony/runtime".');
}

require __DIR__ . '/../config/bootstrap.php';

$kernel = new Kernel($_SERVER['APP_ENV'], (bool)$_SERVER['APP_DEBUG']);
$kernel->boot();
$container = $kernel->getContainer();

ContainerFacade::init($container);
require_once dirname(__DIR__).'/lib/defines.include.php';
require_once dirname(__DIR__).'/vendor/autoload_runtime.php';

if ($_SERVER['APP_DEBUG']) {
umask(0000);

if (class_exists(Debug::class)) {
Debug::enable();
}
}
return function (array $context) {
$kernel = new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);

$application = new Application($kernel);
$application->run($input);
return new Application($kernel);
};
7 changes: 5 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,18 @@
"twig/extra-bundle": "^3.2",
"twig/intl-extra": "^3.2",
"twig/string-extra": "^3.5",
"zumba/json-serializer": "^3.0"
"zumba/json-serializer": "^3.0",
"symfony/runtime": "^6.0",
"symfony/console": "^6.0"
},
"config": {
"platform": {
"php": "8.2"
},
"allow-plugins": {
"symfony/flex": true,
"php-http/discovery": true
"php-http/discovery": true,
"symfony/runtime": true
}
},
"autoload": {
Expand Down
124 changes: 102 additions & 22 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 0 additions & 31 deletions config/bootstrap.php

This file was deleted.

38 changes: 21 additions & 17 deletions htdocs/index.php
Original file line number Diff line number Diff line change
@@ -1,33 +1,37 @@
<?php

use CsrDelft\Kernel;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\ErrorHandler\Debug;

/**
* Ga niet verder als de stek in onderhoudsmodus staat.
*/
if (file_exists(__DIR__ . '/../.onderhoud')) {
http_response_code(503);
echo <<<'HTML'
<!doctype html>
<html lang=nl>
<title>C.S.R. Delft - Onderhoud</title>
<meta charset=utf-8>
<meta name=viewport content="width=device-width, initial-scale=1.0">
<meta http-equiv="refresh" content="5">
<!DOCTYPE HTML>
<html lang="nl">
<head>
<title>C.S.R. Delft - Onderhoud</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="refresh" content="5">
</head>
<body style="font-family: sans-serif; text-align: center;">
<h1>Onderhoud</h1>
<p>De website is momenteel in onderhoud. Dit duurt meestal niet lang.</p>
<img alt="Beeldmerk van de Vereniging" src="/plaetjes/layout-extern/Logo.svg" width="200">
<h1>Onderhoud</h1>
<p>De website is momenteel in onderhoud. Dit duurt meestal niet lang.</p>
<img alt="Beeldmerk van de Vereniging" src="/images/c.s.r.logo.svg" width="200">
</body>
HTML;
exit;
}

/** @var Kernel $kernel */
$kernel = require dirname(__DIR__) . '/lib/configuratie.include.php';
require_once dirname(__DIR__).'/lib/defines.include.php';
require_once dirname(__DIR__).'/vendor/autoload_runtime.php';

$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
return function (array $context) {
if ($context['APP_DEBUG']) {
Debug::enable();
}
return new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);
};
Loading

0 comments on commit 2bdab24

Please sign in to comment.