/swift

A modern, slim, lightweight, flat file or serverless micro framework.

Primary LanguageCSSMIT LicenseMIT

Swift

Version Total Downloads License

A modern, slim, lightweight, simple, flat file or serverless micro framework.
Serverless (No database required) and secured with CSRF.

Dependencies

  • CSRF Guard >> slim/csrf
  • TWIG Template >> slim/twig-view
  • HTTP Cache >> slim/http-cache
  • Flash Messages >> slim/flash
  • Logger >> monolog/monolog
  • Filebase >> aalfiann/filebase
  • Validation >> davidepastore/slim-validation
  • Mailer >> phpmailer/phpmailer

Installation

Install this package via Composer.

composer create-project aalfiann/swift [my-app-name]

Getting Started

How to create new application

  • Go to modules directory
  • Create new folder my-app
  • To create routes, you should follow this pattern >> *.router.php
  • Put the view template to templates/default directory
  • Done

How to activate CSRF

CSRF is already integrated in this skeleton :

  1. Create same two routes, GET and POST
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;

// load contact page
$app->get('/contact', function (Request $request, Response $response) {
    $body = $response->getBody();
    return $this->view->render($response, "contact.twig", []);
})->setName("/contact")->add($container->get('csrf'));

// send message
$app->post('/contact', function (Request $request, Response $response) {
    $body = $response->getBody();
    return $this->view->render($response, "contact.twig", []);
})->add($container->get('csrf'));
  1. Put hidden input value in contact form HTML
<input type="hidden" name="{{csrf.keys.name}}" value="{{csrf.name}}">
<input type="hidden" name="{{csrf.keys.value}}" value="{{csrf.value}}">
  1. Done

Note: