BUGFIX: using standard symfony framework

This commit is contained in:
Jeroen De Meerleer 2022-04-26 14:57:59 +02:00
parent a870a4a58c
commit ccb77c95fe
Signed by: JeroenED
GPG Key ID: 28CCCB8F62BFADD6
32 changed files with 2091 additions and 2611 deletions

View File

@ -1,27 +0,0 @@
################
### DATADIR ###
################
## This link defines where the files for the website should de located. It is a zip folder containing markdown files and assets in the assets dir
## All of this contained in a folder Website
DATADIR=
###################
### ENVIRONMENT ###
###################
## Debug mode is solely for development purposes only. It disables caching and enables your webcam to stream it to the web
DEBUG=true
## Cookies are used for saving autologin credentials. This sets the amount of time in seconds the credentials are saved.
## Grandma probably has a calculator somewhere if you need to check how many seconds are in a week :)
COOKIE_LIFETIME=2592000
## Unfortunatly, not everyone has the same timezone. 3:00PM in Sydney, does not mean it is 15:00 in Brussels.
## You can change this here. Need help? https://www.php.net/timezones
TZ=Europe/Brussels
## TRUSTED_PROXIES is a useful variable when using Docker and/or a reverse proxy.
## Set it to the IP address of your proxy. You can set to multiple proxies by comma-separating them
TRUSTED_PROXIES=127.0.0.1
## Now that everything is set up: go to your friends and get wasted!

27
.gitignore vendored
View File

@ -1,9 +1,20 @@
cache/*
!cache/.gitkeep
vendor/
node_modules/
public/build/
public/assets/
\.idea/
.env
.DS_Store
.idea/
public/assets/
###> symfony/framework-bundle ###
/.env.local
/.env.local.php
/.env.*.local
/config/secrets/prod/prod.decrypt.private.php
/public/bundles/
/var/
/vendor/
###< symfony/framework-bundle ###
###> symfony/webpack-encore-bundle ###
/node_modules/
/public/build/
npm-debug.log
yarn-error.log
###< symfony/webpack-encore-bundle ###

View File

@ -1,4 +1,4 @@
# Webcron Management
(c) 2021 Jeroen De Meerleer <me@jeroened.be>
# Website
(c) 2021- Jeroen De Meerleer <me@jeroened.be>
Source code of my personal website

17
bin/console Executable file
View File

@ -0,0 +1,17 @@
#!/usr/bin/env php
<?php
use App\Kernel;
use Symfony\Bundle\FrameworkBundle\Console\Application;
if (!is_file(dirname(__DIR__).'/vendor/autoload_runtime.php')) {
throw new LogicException('Symfony Runtime is missing. Try running "composer require symfony/runtime".');
}
require_once dirname(__DIR__).'/vendor/autoload_runtime.php';
return function (array $context) {
$kernel = new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);
return new Application($kernel);
};

View File

@ -1,11 +0,0 @@
<?php
require_once "vendor/autoload.php";
if( ini_get('safe_mode') ){
die("Cannot run in safe mode");
}
if (!file_exists(__DIR__ . "/.env")) {
die ("Cannot find config file");
}

View File

@ -1,35 +1,71 @@
{
"name": "jeroened/website",
"description": "My personal webstie",
"authors": [
{
"name": "Jeroen De Meerleer",
"email": "me@jeroened.be"
}
],
"type": "project",
"license": "proprietary",
"minimum-stability": "stable",
"prefer-stable": true,
"require": {
"guzzlehttp/guzzle": "^7.4",
"mehrkanal/twig-encore-extension": "^1.3",
"php": ">=8.0.2",
"ext-ctype": "*",
"ext-iconv": "*",
"erusev/parsedown": "^1.7",
"symfony/config": "^6.0",
"symfony/console": "^6.0",
"symfony/dotenv": "^6.0",
"symfony/http-foundation": "^6.0",
"symfony/routing": "^6.0",
"symfony/yaml": "^6.0",
"twig/intl-extra": "^3.3",
"twig/twig": "^3.3"
"symfony/console": "6.0.*",
"symfony/dotenv": "6.0.*",
"symfony/flex": "^2",
"symfony/framework-bundle": "6.0.*",
"symfony/runtime": "6.0.*",
"symfony/twig-bundle": "6.0.*",
"symfony/webpack-encore-bundle": "^1.14",
"symfony/yaml": "6.0.*"
},
"config": {
"allow-plugins": {
"composer/package-versions-deprecated": true,
"symfony/flex": true,
"symfony/runtime": true
},
"optimize-autoloader": true,
"preferred-install": {
"*": "dist"
},
"sort-packages": true
},
"autoload": {
"psr-4": {
"JeroenED\\Framework\\": "lib/Framework/",
"JeroenED\\Website\\": "src/"
"App\\": "src/"
}
},
"config": {
"sort-packages": true,
"allow-plugins": {
"composer/package-versions-deprecated": true
"autoload-dev": {
"psr-4": {
"App\\Tests\\": "tests/"
}
},
"replace": {
"symfony/polyfill-ctype": "*",
"symfony/polyfill-iconv": "*",
"symfony/polyfill-php72": "*",
"symfony/polyfill-php73": "*",
"symfony/polyfill-php74": "*",
"symfony/polyfill-php80": "*"
},
"scripts": {
"auto-scripts": {
"cache:clear": "symfony-cmd",
"assets:install %PUBLIC_DIR%": "symfony-cmd"
},
"post-install-cmd": [
"@auto-scripts"
],
"post-update-cmd": [
"@auto-scripts"
]
},
"conflict": {
"symfony/symfony": "*"
},
"extra": {
"symfony": {
"allow-contrib": false,
"require": "6.0.*"
}
}
}

1832
composer.lock generated

File diff suppressed because it is too large Load Diff

7
config/bundles.php Normal file
View File

@ -0,0 +1,7 @@
<?php
return [
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true],
Symfony\WebpackEncoreBundle\WebpackEncoreBundle::class => ['all' => true],
];

View File

@ -0,0 +1,19 @@
framework:
cache:
# Unique name of your app: used to compute stable namespaces for cache keys.
#prefix_seed: your_vendor_name/app_name
# The "app" cache stores to the filesystem by default.
# The data in this cache should persist between deploys.
# Other options include:
# Redis
#app: cache.adapter.redis
#default_redis_provider: redis://localhost
# APCu (not recommended with heavy random-write workloads as memory fragmentation can cause perf issues)
#app: cache.adapter.apcu
# Namespaced pools use the above "app" backend by default
#pools:
#my.dedicated.cache: null

View File

@ -0,0 +1,24 @@
# see https://symfony.com/doc/current/reference/configuration/framework.html
framework:
secret: '%env(APP_SECRET)%'
#csrf_protection: true
http_method_override: false
# Enables session support. Note that the session will ONLY be started if you read or write from it.
# Remove or comment this section to explicitly disable session support.
session:
handler_id: null
cookie_secure: auto
cookie_samesite: lax
storage_factory_id: session.storage.factory.native
#esi: true
#fragments: true
php_errors:
log: true
when@test:
framework:
test: true
session:
storage_factory_id: session.storage.factory.mock_file

View File

@ -0,0 +1,12 @@
framework:
router:
utf8: true
# Configure how to generate URLs in non-HTTP contexts, such as CLI commands.
# See https://symfony.com/doc/current/routing.html#generating-urls-in-commands
#default_uri: http://localhost
when@prod:
framework:
router:
strict_requirements: null

View File

@ -0,0 +1,6 @@
twig:
default_path: '%kernel.project_dir%/templates'
when@test:
twig:
strict_variables: true

View File

@ -0,0 +1,49 @@
webpack_encore:
# The path where Encore is building the assets - i.e. Encore.setOutputPath()
output_path: '%kernel.project_dir%/public/build'
# If multiple builds are defined (as shown below), you can disable the default build:
# output_path: false
# Set attributes that will be rendered on all script and link tags
script_attributes:
defer: true
# Uncomment (also under link_attributes) if using Turbo Drive
# https://turbo.hotwired.dev/handbook/drive#reloading-when-assets-change
# 'data-turbo-track': reload
# link_attributes:
# Uncomment if using Turbo Drive
# 'data-turbo-track': reload
# If using Encore.enableIntegrityHashes() and need the crossorigin attribute (default: false, or use 'anonymous' or 'use-credentials')
# crossorigin: 'anonymous'
# Preload all rendered script and link tags automatically via the HTTP/2 Link header
# preload: true
# Throw an exception if the entrypoints.json file is missing or an entry is missing from the data
# strict_mode: false
# If you have multiple builds:
# builds:
# pass "frontend" as the 3rg arg to the Twig functions
# {{ encore_entry_script_tags('entry1', null, 'frontend') }}
# frontend: '%kernel.project_dir%/public/frontend/build'
# Cache the entrypoints.json (rebuild Symfony's cache when entrypoints.json changes)
# Put in config/packages/prod/webpack_encore.yaml
# cache: true
framework:
assets:
json_manifest_path: '%kernel.project_dir%/public/build/manifest.json'
#when@prod:
# webpack_encore:
# # Cache the entrypoints.json (rebuild Symfony's cache when entrypoints.json changes)
# # Available in version 1.2
# cache: true
#when@test:
# webpack_encore:
# strict_mode: false

5
config/preload.php Normal file
View File

@ -0,0 +1,5 @@
<?php
if (file_exists(dirname(__DIR__).'/var/cache/prod/App_KernelProdContainer.preload.php')) {
require dirname(__DIR__).'/var/cache/prod/App_KernelProdContainer.preload.php';
}

View File

@ -1,13 +1,13 @@
error:
path: '/error/{status}'
defaults:
_controller: JeroenED\Website\Controller\DefaultController::ErrorAction
_controller: App\Controller\DefaultController::ErrorAction
status: '404'
default:
path: '/{page}'
path: '/{slug}'
defaults:
_controller: JeroenED\Website\Controller\DefaultController::DefaultAction
page: 'index'
_controller: App\Controller\DefaultController::DefaultAction
slug: 'index'
requirements:
page: "[a-zA-Z0-9\/]+"
slug: "[a-zA-Z0-9\/]+"

View File

@ -0,0 +1,4 @@
when@dev:
_errors:
resource: '@FrameworkBundle/Resources/config/routing/errors.xml'
prefix: /_error

24
config/services.yaml Normal file
View File

@ -0,0 +1,24 @@
# This file is the entry point to configure your own services.
# Files in the packages/ subdirectory configure your dependencies.
# Put parameters here that don't need to change on each machine where the app is deployed
# https://symfony.com/doc/current/best_practices.html#use-parameters-for-application-configuration
parameters:
services:
# default configuration for services in *this* file
_defaults:
autowire: true # Automatically injects dependencies in your services.
autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
# makes classes in src/ available to be used as services
# this creates a service per class whose id is the fully-qualified class name
App\:
resource: '../src/'
exclude:
- '../src/DependencyInjection/'
- '../src/Entity/'
- '../src/Kernel.php'
# add more service definitions when explicit configuration is needed
# please note that last definitions always *replace* previous ones

22
console
View File

@ -1,22 +0,0 @@
#!/usr/bin/env php
<?php
require_once 'bootstrap.php';
use JeroenED\Framework\Kernel;
use JeroenED\Website\Command\RefreshCommand;
use Symfony\Component\Console\Application;
$application = new Application();
$kernel = new Kernel();
chdir(__DIR__);
$kernel->setProjectDir(getcwd());
$kernel->setConfigDir(getcwd() . '/config/');
$kernel->setCacheDir(getcwd() . '/cache/');
$kernel->setTemplateDir(getcwd() . '/templates/');
$kernel->parseDotEnv($kernel->getProjectDir() . '/.env');
$application->add(new RefreshCommand($kernel));
$application->run();

View File

@ -1,71 +0,0 @@
<?php
namespace JeroenED\Framework;
use Doctrine\DBAL\Connection;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Twig\Environment;
use Twig\Loader\FilesystemLoader;
abstract class Controller
{
private $twig;
private $request;
private $database;
private $kernel;
public function __construct(Request $request, Kernel $kernel)
{
$this->twig = new Twig($kernel);
$this->request = $request;
$this->kernel = $kernel;
}
public function getDbCon(): Connection
{
return $this->kernel->getDbCon();
}
/**
* @return Request
*/
public function getRequest(): Request
{
return $this->request;
}
/**
* @param Request $request
*/
public function setRequest(Request $request): void
{
$this->request = $request;
}
/**
* @param string $template
* @param array $vars
* @return Response
*/
public function render(string $template, array $vars = [], $status = 200): Response
{
if(empty($_SERVER['HTTP_X_REQUESTED_WITH']) || strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest') {
$vars['flashes'] = $_SESSION['flashes'] ?? [] ;
$_SESSION['flashes'] = [];
}
$response = new Response($this->twig->render($template, $vars), $status);
return $response;
}
public function generateRoute(string $route): string
{
return $this->kernel->getRouter()->getUrlForRoute($route);
}
public function addFlash(string $category, string $content): void
{
$_SESSION['flashes'][] = ['category' => $category, 'content' => $content];
}
}

View File

@ -1,124 +0,0 @@
<?php
namespace JeroenED\Framework;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DriverManager;
use http\Exception\InvalidArgumentException;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\Routing\Loader\YamlFileLoader;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\Routing\Matcher\UrlMatcher;
use Symfony\Component\Dotenv\Dotenv;
class Kernel
{
private string $configDir;
private string $projectDir;
private string $templateDir;
private string $cacheDir;
private Router $router;
/**
* @return string
*/
public function getConfigDir(): string
{
return $this->configDir;
}
/**
* @param string $configDir
*/
public function setConfigDir(string $configDir): void
{
$this->configDir = $configDir;
}
/**
* @return string
*/
public function getProjectDir(): string
{
return $this->projectDir;
}
/**
* @param string $projectDir
*/
public function setProjectDir(string $projectDir): void
{
$this->projectDir = $projectDir;
}
/**
* @return string
*/
public function getTemplateDir(): string
{
return $this->templateDir;
}
/**
* @param string $templateDir
*/
public function setTemplateDir(string $templateDir): void
{
$this->templateDir = $templateDir;
}
/**
* @return string
*/
public function getCacheDir(): string
{
return $this->cacheDir;
}
/**
* @param string $cacheDir
*/
public function setCacheDir(string $cacheDir): void
{
$this->cacheDir = $cacheDir;
}
/**
* @return Router
*/
public function getRouter(): Router
{
return $this->router;
}
public function handle(): Response
{
$this->router = new Router();
$this->router->parseRoutes($this->getConfigDir(), 'routes.yaml');
$request = $this->parseRequest();
if($request->isSecure()) {
ini_set('session.cookie_httponly', true);
ini_set('session.cookie_secure', true);
}
session_start();
return $this->router->route($request, $this);
}
public function parseDotEnv(string $path): void
{
$dotenv = new Dotenv();
$dotenv->loadEnv($path);
}
private function parseRequest(): Request
{
Request::setTrustedProxies(explode(',', $_ENV['TRUSTED_PROXIES']), Request::HEADER_X_FORWARDED_FOR | Request::HEADER_X_FORWARDED_HOST | Request::HEADER_X_FORWARDED_PORT | Request::HEADER_X_FORWARDED_PROTO);
$request = Request::createFromGlobals();
return $request;
}
}

View File

@ -1,17 +0,0 @@
<?php
namespace JeroenED\Framework;
use Doctrine\DBAL\Connection;
class Repository
{
protected Connection $dbcon;
public function __construct(Connection $dbcon)
{
$this->dbcon = $dbcon;
}
}

View File

@ -1,69 +0,0 @@
<?php
namespace JeroenED\Framework;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\Filesystem\Exception\InvalidArgumentException;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
use Symfony\Component\Routing\Generator\UrlGenerator;
use Symfony\Component\Routing\Loader\YamlFileLoader;
use Symfony\Component\Routing\Matcher\UrlMatcher;
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\Routing\RouteCollection;
class Router
{
private RouteCollection $routes;
private RequestContext $requestContext;
public function route(Request $request, Kernel $kernel): Response
{
try {
// Here be dragons
$requestContext = new RequestContext();
$this->requestContext = $requestContext->fromRequest($request);
$matcher = new UrlMatcher($this->routes, $this->requestContext);
$method = $matcher->match($request->getPathInfo());
$controller = explode('::', $method['_controller']);
$controllerObj = new ('\\' . $controller[0])($request, $kernel);
$action = $controller[1];
unset($method['_controller']);
unset($method['_route']);
$response = $controllerObj->$action(...$method);
if ($response instanceof Response) {
$response->headers->add([
"Content-Security-Policy" => "default-src 'none'; font-src 'self'; style-src 'self'; script-src 'self'; img-src 'self'; form-action 'none'; frame-ancestors 'none'; require-trusted-types-for 'script'; base-uri 'none'; ",
"Referrer-Policy" => "same-origin"
]);
return $response;
} else {
throw new InvalidArgumentException();
}
} catch(ResourceNotFoundException $e) {
return new RedirectResponse($this->getUrlForRoute('error', ['status' => '404']));
} catch (\Throwable $e) {
return new RedirectResponse($this->getUrlForRoute('error', ['status' => (method_exists($e,'getStatusCode')) ? $e->getStatusCode() : '500']));
}
}
public function parseRoutes(string $dir, string $file): void
{
$routeloader = new YamlFileLoader(new FileLocator($dir));
$this->routes = $routeloader->load($file);
}
public function getUrlForRoute(string $route, array $params = []): string
{
$matcher = new UrlGenerator($this->routes, $this->requestContext);
return $matcher->generate($route, $params, UrlGenerator::ABSOLUTE_URL);
}
}

View File

@ -1,90 +0,0 @@
<?php
namespace JeroenED\Framework;
use Mehrkanal\EncoreTwigExtension\Extensions\EntryFilesTwigExtension;
use Symfony\WebpackEncoreBundle\Asset\EntrypointLookup;
use Twig\Cache\FilesystemCache;
use Twig\Environment;
use Twig\Extra\Intl\IntlExtension;
use Twig\Loader\FilesystemLoader;
use Twig\TwigFilter;
use Twig\TwigFunction;
class Twig
{
private Environment $environment;
private Kernel $kernel;
public function __construct(Kernel $kernel)
{
$loader = new FilesystemLoader([$kernel->getTemplateDir()]);
$this->environment = new Environment($loader);
if(!$_ENV['DEBUG']) {
$cache = new FilesystemCache($kernel->getCacheDir() . '/twig');
$this->environment->setCache($cache);
}
$this->kernel = $kernel;
$this->addExtensions();
$this->addFunctions();
$this->addFilters();
}
public function render(string $template, array $vars = []): string
{
return $this->environment->render($template, $vars);
}
public function addExtensions()
{
$this->environment->addExtension(new IntlExtension());
$this->environment->addExtension(new EntryFilesTwigExtension(new EntrypointLookup('./public/build/entrypoints.json')));
}
public function addFunctions()
{
$path = new TwigFunction('path', function(string $route, array $params = []) {
return $this->kernel->getRouter()->getUrlForRoute($route, $params);
});
$randombits = new TwigFunction('randombits', function($length) {
$characters = '01';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
});
$this->environment->addFunction($path);
$this->environment->addFunction($randombits);
}
public function addFilters() {
$secondsToInterval = new TwigFilter('interval', function(int $time) {
$days = floor($time / (60 * 60 * 24));
$time -= $days * (60 * 60 * 24);
$hours = floor($time / (60 * 60));
$time -= $hours * (60 * 60);
$minutes = floor($time / 60);
$time -= $minutes * 60;
$seconds = floor($time);
$time -= $seconds;
return "{$days}d {$hours}h {$minutes}m {$seconds}s";
});
$markdown = new TwigFilter('markdown', function(string $markdown) {
$parsedown = new \Parsedown();
return $parsedown->text($markdown);
});
$this->environment->addFilter($secondsToInterval);
$this->environment->addFilter($markdown);
}
}

1812
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,18 +1,9 @@
<?php
error_reporting(E_ALL);
ini_set('display_errors', true);
use JeroenED\Framework\Kernel;
chdir(__DIR__ . '/..');
require_once 'bootstrap.php';
use App\Kernel;
$kernel = new Kernel();
$kernel->setProjectDir(getcwd());
$kernel->setConfigDir(getcwd() . '/config/');
$kernel->setTemplateDir(getcwd() . '/templates/');
$kernel->setCacheDir(getcwd() . '/cache/');
$kernel->parseDotEnv($kernel->getProjectDir() . '/.env');
require_once dirname(__DIR__).'/vendor/autoload_runtime.php';
ini_set('date.timezone', $_ENV['TZ']);
$kernel->handle()->send();
return function (array $context) {
return new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);
};

View File

@ -1,50 +1,50 @@
<?php
namespace JeroenED\Website\Command;
namespace App\Command;
use JeroenED\Framework\Kernel;
use Boa\GeneralBundle\Service\Mailer;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
class RefreshCommand extends Command
{
protected static $defaultName = 'refresh';
protected $kernel;
private $kernel;
public function __construct(Kernel $kernel)
public function __construct(KernelInterface $kernel)
{
$this->kernel = $kernel;
parent::__construct();
}
protected function configure()
{
$this
->setName('refresh')
->setDescription('Cleanup runs')
->setHelp('This command cleans the runs table');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
global $kernel;
$zip = $kernel->getCacheDir() . 'website.zip';
$mddir = $kernel->getCacheDir() . 'pages';
$assetdir = $kernel->getProjectDir() . '/public/assets/';
$zip = $this->kernel->getCacheDir() . '/website.zip';
$mddir = $this->kernel->getCacheDir() . '/pages';
$assetdir = $this->kernel->getProjectDir() . '/public/assets/';
file_put_contents($zip, file_get_contents($_ENV['DATADIR']));
$zipobj = new \ZipArchive();
$res = $zipobj->open($zip);
if ($res === TRUE) {
if(is_dir($mddir)) $this->recursiveRemoveDirectory($mddir);
if(is_dir($assetdir)) $this->recursiveRemoveDirectory($assetdir);
$zipobj->extractTo($kernel->getCacheDir());
$zipobj->extractTo($this->kernel->getCacheDir());
$zipobj->close();
rename($kernel->getCacheDir() . 'Website/assets', $assetdir);
rename($kernel->getCacheDir() . 'Website', $mddir);
rename($this->kernel->getCacheDir() . '/Website/assets', $assetdir);
rename($this->kernel->getCacheDir() . '/Website', $mddir);
return Command::SUCCESS;
}
return Command::FAILURE;

View File

@ -1,37 +1,38 @@
<?php
namespace JeroenED\Website\Controller;
namespace App\Controller;
use JeroenED\Framework\Controller;
use JeroenED\Framework\Repository;
use JeroenED\Website\Repository\Page;
use App\Repository\Page;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\KernelInterface;
class DefaultController extends Controller
class DefaultController extends AbstractController
{
public function DefaultAction($page)
public function DefaultAction(Request $request, Page $page, KernelInterface $kernel, string $slug = 'index')
{
$pageRepo = new Page();
$page = $pageRepo->getPage($page);
$return = $page->getPage($kernel, $slug);
$response = new Response('', (int)$return['status']);
return $this->render('/page.html.twig', [
'header' => $page['header'],
'content' => $page['content'],
'title' => $page['title'],
'header' => $return['header'],
'content' => $return['content'],
'title' => $return['title'],
'nineties' => (isset($_COOKIE['nineties']))
], $page['status']);
], $response);
}
public function ErrorAction($status)
public function ErrorAction(Request $request, Page $page, KernelInterface $kernel, string $status)
{
$pageRepo = new Page();
$page = $pageRepo->getPage('error/' . $status);
$return = $page->getPage($kernel, 'error/' . $status);
$response = new Response('', (int)$status);
return $this->render('/page.html.twig', [
'header' => $page['header'],
'content' => $page['content'],
'title' => $page['title'],
'header' => $return['header'],
'content' => $return['content'],
'title' => $return['title'],
'nineties' => (isset($_COOKIE['nineties']))
], $status);
], $response);
}
}

11
src/Kernel.php Normal file
View File

@ -0,0 +1,11 @@
<?php
namespace App;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
class Kernel extends BaseKernel
{
use MicroKernelTrait;
}

View File

@ -1,32 +1,20 @@
<?php
namespace JeroenED\Website\Repository;
namespace App\Repository;
use DateTime;
use GuzzleHttp\Client;
use JeroenED\Framework\Repository;
use phpseclib3\Crypt\PublicKeyLoader;
use phpseclib3\Net\SSH2;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpKernel\KernelInterface;
class Page
{
private $root;
public function __construct()
public function getPage(KernelInterface $kernel, string $page)
{
global $kernel;
$this->root = $kernel->getCacheDir() . 'pages';
}
public function getPage(string $page)
{
$return['header'] = file_get_contents(strtolower($this->root . '/_main.md'));
$titles = json_decode(file_get_contents($this->root . '/titles.json'), true);
if(file_exists($this->root . '/' . $page . '.md')) {
$return['header'] = file_get_contents($kernel->getCacheDir() . '/pages/_main.md');
$titles = json_decode(file_get_contents($kernel->getCacheDir() . '/pages/titles.json'), true);
if(file_exists($kernel->getCacheDir() . '/pages/' . $page . '.md')) {
$return['title'] = $titles[$page] ?? '';
$return['content'] = file_get_contents(strtolower($this->root . '/' . $page . '.md'));
$return['content'] = file_get_contents($kernel->getCacheDir() . '/pages/' . $page . '.md');
$return['status'] = '200';
} else {
throw new NotFoundHttpException();

20
src/Twig/AppExtension.php Normal file
View File

@ -0,0 +1,20 @@
<?php
namespace App\Twig;
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;
class AppExtension extends AbstractExtension
{
public function getFilters()
{
return [
new TwigFilter('markdown', [$this, 'parseMarkdown']),
];
}
public function parseMarkdown(string $markdown) {
$parsedown = new \Parsedown();
return $parsedown->text($markdown);
}
}

186
symfony.lock Normal file
View File

@ -0,0 +1,186 @@
{
"erusev/parsedown": {
"version": "1.7.4"
},
"psr/cache": {
"version": "3.0.0"
},
"psr/container": {
"version": "2.0.2"
},
"psr/event-dispatcher": {
"version": "1.0.0"
},
"psr/log": {
"version": "3.0.0"
},
"symfony/asset": {
"version": "v6.0.7"
},
"symfony/cache": {
"version": "v6.0.6"
},
"symfony/cache-contracts": {
"version": "v3.0.1"
},
"symfony/config": {
"version": "v6.0.7"
},
"symfony/console": {
"version": "6.0",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "master",
"version": "5.3",
"ref": "da0c8be8157600ad34f10ff0c9cc91232522e047"
},
"files": [
"bin/console"
]
},
"symfony/dependency-injection": {
"version": "v6.0.7"
},
"symfony/deprecation-contracts": {
"version": "v3.0.1"
},
"symfony/dotenv": {
"version": "v6.0.5"
},
"symfony/error-handler": {
"version": "v6.0.7"
},
"symfony/event-dispatcher": {
"version": "v6.0.3"
},
"symfony/event-dispatcher-contracts": {
"version": "v3.0.1"
},
"symfony/filesystem": {
"version": "v6.0.7"
},
"symfony/finder": {
"version": "v6.0.3"
},
"symfony/flex": {
"version": "2.1",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "master",
"version": "1.0",
"ref": "c0eeb50665f0f77226616b6038a9b06c03752d8e"
},
"files": [
".env"
]
},
"symfony/framework-bundle": {
"version": "6.0",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "master",
"version": "5.4",
"ref": "3cd216a4d007b78d8554d44a5b1c0a446dab24fb"
},
"files": [
"config/packages/cache.yaml",
"config/packages/framework.yaml",
"config/preload.php",
"config/routes/framework.yaml",
"config/services.yaml",
"public/index.php",
"src/Controller/.gitignore",
"src/Kernel.php"
]
},
"symfony/http-foundation": {
"version": "v6.0.7"
},
"symfony/http-kernel": {
"version": "v6.0.7"
},
"symfony/polyfill-intl-grapheme": {
"version": "v1.25.0"
},
"symfony/polyfill-intl-normalizer": {
"version": "v1.25.0"
},
"symfony/polyfill-mbstring": {
"version": "v1.25.0"
},
"symfony/polyfill-php81": {
"version": "v1.25.0"
},
"symfony/routing": {
"version": "6.0",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "master",
"version": "6.0",
"ref": "eb3b377a4dc07006c4bdb2c773652cc9434f5246"
},
"files": [
"config/packages/routing.yaml",
"config/routes.yaml"
]
},
"symfony/runtime": {
"version": "v6.0.7"
},
"symfony/service-contracts": {
"version": "v3.0.1"
},
"symfony/string": {
"version": "v6.0.3"
},
"symfony/translation-contracts": {
"version": "v3.0.1"
},
"symfony/twig-bridge": {
"version": "v6.0.7"
},
"symfony/twig-bundle": {
"version": "6.0",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "master",
"version": "5.4",
"ref": "bb2178c57eee79e6be0b297aa96fc0c0def81387"
},
"files": [
"config/packages/twig.yaml",
"templates/base.html.twig"
]
},
"symfony/var-dumper": {
"version": "v6.0.6"
},
"symfony/var-exporter": {
"version": "v6.0.7"
},
"symfony/webpack-encore-bundle": {
"version": "1.14",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "master",
"version": "1.10",
"ref": "2858aeed7e1d81a45365c049eb533cc8827e380b"
},
"files": [
"assets/app.js",
"assets/bootstrap.js",
"assets/controllers.json",
"assets/controllers/hello_controller.js",
"assets/styles/app.css",
"config/packages/webpack_encore.yaml",
"package.json",
"webpack.config.js"
]
},
"symfony/yaml": {
"version": "v6.0.3"
},
"twig/twig": {
"version": "v3.3.10"
}
}