Files
filegator/configuration/router.html
2022-09-19 21:02:24 +02:00

95 lines
3.5 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title></title>
<link rel="stylesheet" href="/css/bootstrap.min.css">
<link rel="stylesheet" href="/css/font-awesome.min.css">
<link rel="stylesheet" href="/css/highlight.dark.css">
<link rel="stylesheet" href="/css/main.css">
</head>
<body>
<header class="navbar navbar-default navbar-fixed-top">
<a class="navbar-brand" href="/">
The title
<small class="hidden-xs hidden-sm">
This is the default subtitle!
</small>
</a>
</header>
<main class="container">
<div class="row">
<section id="content" class="col-sm-12">
<h2 id="router-service">Router service</h2>
<p>Router service is using well-known <a href="https://github.com/nikic/FastRoute">FastRoute</a> library. There is no need to change this service unless you're extending the script.</p>
<p>The router uses unique query parameter <code>?r=</code> to pass the route info. Because of this feature, this (single-page) application does not require rewrite rules, .htaccess or similar tweaks.</p>
<p>Example routes:</p>
<ul>
<li><code>http://example.com/?r=/some/route&amp;param1=val1&amp;param2=val2</code></li>
<li><code>http://example.com/?r=/user/{user_id}&amp;param1=val1</code></li>
</ul>
<h2 id="routes-file">Routes file</h2>
<p>Routes file is located here <code>backend/Controllers/routes.php</code> Each route in the routes array looks like this:</p>
<pre><code> [
'route' =&gt; [
'GET', '/download/{path_encoded}', '\Filegator\Controllers\DownloadController@download',
],
'roles' =&gt; [
'guest', 'user', 'admin',
],
'permissions' =&gt; [
'download',
],
],</code></pre>
<p>As you can see in the example, you can assign required user roles and permissions for each route.</p>
<h2 id="controllers">Controllers</h2>
<p>Since FileGator is using an awesome dependency injection <a href="https://github.com/PHP-DI/PHP-DI">container</a> you can type-hint dependencies directly in your controllers. </p>
<p>You can also mix route parameters and dependencies in any order like in this example:</p>
<pre><code>
public function __construct(Config $config, Session $session, AuthInterface $auth, Filesystem $storage)
{
// ...
}
public function download($path_encoded, Request $request, Response $response, StreamedResponse $streamedResponse)
{
// ...
}</code></pre>
</section>
</div>
</main>
<footer>
<div class="container">
<p class="text-muted">
website generated with <a href="http://couscous.io" title="Markdown website generator">Couscous</a>
</p>
</div>
</footer>
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
<script src="//yastatic.net/highlightjs/8.2/highlight.min.js"></script>
<script>
$(function() {
$("section>h1").wrap('<div class="page-header" />');
// Syntax highlighting
hljs.initHighlightingOnLoad();
});
</script>
</body>
</html>