mirror of
https://code.castopod.org/adaures/castopod.git
synced 2024-09-10 20:43:22 +02:00
- update .devcontainer settings: remove auto-formatting for php + set intelephense as default formatter - remove prettier php plugin as it lacks php 8 support - add captain hook action for checking style pre-commit - fix style with ecs on all files except views
52 lines
1.2 KiB
PHP
52 lines
1.2 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @copyright 2020 Podlibre
|
|
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
|
|
* @link https://castopod.org/
|
|
*/
|
|
|
|
namespace App\Controllers;
|
|
|
|
use App\Entities\Page;
|
|
use App\Models\PageModel;
|
|
use CodeIgniter\Exceptions\PageNotFoundException;
|
|
|
|
class PageController extends BaseController
|
|
{
|
|
protected Page $page;
|
|
|
|
public function _remap(string $method, string ...$params): mixed
|
|
{
|
|
if (count($params) === 0) {
|
|
throw PageNotFoundException::forPageNotFound();
|
|
}
|
|
|
|
if (
|
|
$this->page = (new PageModel())->where('slug', $params[0])->first()
|
|
) {
|
|
return $this->{$method}();
|
|
}
|
|
|
|
throw PageNotFoundException::forPageNotFound();
|
|
}
|
|
|
|
public function index(): string
|
|
{
|
|
$cacheName = "page-{$this->page->slug}";
|
|
if (! ($found = cache($cacheName))) {
|
|
$data = [
|
|
'page' => $this->page,
|
|
];
|
|
|
|
$found = view('page', $data);
|
|
|
|
// The page cache is set to a decade so it is deleted manually upon page update
|
|
cache()
|
|
->save($cacheName, $found, DECADE);
|
|
}
|
|
|
|
return $found;
|
|
}
|
|
}
|