PHP code example of celarius / spin-framework

1. Go to this page and download the library: Download celarius/spin-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/ */

    

celarius / spin-framework example snippets


 declare(strict_types=1);

namespace App\Controllers;

use \App\Controllers\AbstractPlatesController;

class IndexController extends AbstractPlatesController
{
    public function handleGET(array $args)
    {
        $model = ['title' => 'Welcome to SPIN', 'user' => 'Guest'];
        $html = $this->engine->render('pages::index', $model);
        return response($html);
    }
}

 declare(strict_types=1);

namespace App\Middlewares;

use Spin\Core\Middleware;

class AuthMiddleware extends Middleware
{
    public function initialize(array $args): bool
    {
        $this->secret = config('application.secret');
        return true;
    }

    public function handle(array $args): bool
    {
        $token = getRequest()->getHeaderLine('Authorization');
        if (!$this->validateToken($token)) {
            responseJson(['error' => 'Unauthorized'], 401);
            return false;
        }
        return true;
    }
}
json
{
  "application": {
    "global": {
      "maintenance": false,
      "timezone": "Europe/Stockholm"
    },
    "secret": "${env:APPLICATION_SECRET}"
  },
  "session": {
    "cookie": "SID",
    "timeout": 3600,
    "driver": "apcu"
  },
  "logger": {
    "level": "notice",
    "driver": "php"
  }
}
nginx
server {
    listen 80;
    server_name mydomain.com;
    root /path/to/your/app/src/public;
    index bootstrap.php;

    location / {
        try_files $uri $uri/ /bootstrap.php?$query_string;
    }

    location ~ \.php$ {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index bootstrap.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;