PHP code example of dupot / static-management-framework
1. Go to this page and download the library: Download dupot/static-management-framework library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
dupot / static-management-framework example snippets
upot\StaticManagementFramework\Application;
use Dupot\StaticManagementFramework\Http\Request;
use Dupot\StaticManagementFramework\Http\Response;
use Dupot\StaticManagementFramework\Setup\ConfigManager;
use Dupot\StaticManagementFramework\Setup\RouteManager;
define('ROOT_PATH', __DIR__ . '/../');
$debug = true;
try {
session_start();
$request = new Request([
Request::SOURCE_GET => $_GET,
Request::SOURCE_POST => $_POST,
Request::SOURCE_SESSION => $_SESSION,
Request::SOURCE_SERVER => $_SERVER,
]);
$routeManager = new RouteManager();
$routeManager->loadConfigFromJson(ROOT_PATH . 'src/conf/routing.json');
$configManager = new ConfigManager();
// $configManager->loadConfigFromIni(ROOT_PATH . 'src/conf/config.ini');
$configManager->setSectionParam('path', 'root', ROOT_PATH);
$application = new Application([
Application::CONFIG_MANAGER => $configManager,
Application::ROUTE_MANAGER => $routeManager,
Application::REQUEST => $request,
Application::RESPONSE => new Response(),
]);
$application->run();
} catch (Exception $e) {
if ($debug) {
echo '<pre>' . htmlspecialchars((string) $e) . '</pre>';
}
}
public function edit(string $id)
{
// /news_edit_42.html → $id === '42'
}
namespace App\Infrastructure\Pages;
use Dupot\StaticManagementFramework\Page\PageAbstract;
use Dupot\StaticManagementFramework\Render\Layout;
use Dupot\StaticManagementFramework\Render\View;
class HomePage extends PageAbstract
{
protected $layout = null;
public function __construct()
{
$this->layout = new Layout(__DIR__ . '/Layout/default.php');
}
public function index()
{
$view = new View(__DIR__ . '/View/home.php', [
'title' => 'Welcome!',
]);
$this->layout->appendContext('contentList', $view);
echo $this->layout->render();
}
}
namespace App\Infrastructure\Pages;
use Dupot\StaticManagementFramework\Page\PageAbstract;
use Dupot\StaticManagementFramework\Render\Layout;
use Dupot\StaticManagementFramework\Render\View;
class AboutPage extends PageAbstract
{
protected $layout = null;
public function __construct()
{
$this->layout = new Layout(__DIR__ . '/Layout/default.php');
}
public function index()
{
$this->layout->appendContext('contentList', new View(__DIR__ . '/View/about.php'));
echo $this->layout->render();
}
}
public function before()
{
if (!$this->getRequest()->getSessionParamOr('isLogged', false)) {
$this->getResponse()->redirect('/login.html');
}
}