/** * @param string $name : the name of the route to link * @param array $namedParams : a map of parameter names => values * @return null|Uri the link to the named route with the parameters replaced, or null if no route was found */ public static function link(string $name, array $namedParams = []) { if (isset(self::$routes[$name])) { $route = self::$routes[$name]->generateLink($namedParams); $uri = App::getRequest()->getUri()->copy()->setPath($route)->setQuery(''); if (self::$routes[$name]->getRequireHttps()) { $uri->setScheme('https'); } return $uri; } return null; }
public function __construct(string $name, array $data = []) { $this->template = App::getTemplatingEngine()->getTemplate($name, $data); }
<?php // Put any custom startup actions here, like initializing database connections, registering shutdown handlers, etc. // This ensures maximum flexibility as you can use whatever tools you want and are not bound by the framework. use app\classes\ExampleConsoleHandler; use app\classes\Session; use js\tools\commons\http\Request; use simpleframe\App; use simpleframe\EventHandler; use simpleframe\responses\RedirectResponse; use simpleframe\routing\Route; use simpleframe\routing\Router; EventHandler::on(EventHandler::ON_ROUTE_MATCH, function (Route $route, array $parameters, Request $request) { if ($route->getRequireHttps() && !$request->isSecure()) { $url = Router::link($route->getName(), $parameters)->setScheme('https'); (new RedirectResponse($url))->render(); } if (substr($route->getName(), 0, 5) === 'admin') { if (!Session::isLoggedIn() && $route->getName() !== 'admin.login') { (new RedirectResponse(Router::link('admin.login')))->render(); } } }); App::registerConsoleHandler(ExampleConsoleHandler::class); session_start();
<?php if (!file_exists(__DIR__ . '/../vendor/autoload.php')) { throw new RuntimeException('Execute `composer install` in project root directory'); } require __DIR__ . '/../vendor/autoload.php'; \simpleframe\App::run(realpath(__DIR__ . '/../'));