HEX
Server: Apache
System: Linux server1.myinter.net 4.18.0-553.147.1.el8_10.x86_64 #1 SMP Fri Jul 24 08:29:05 EDT 2026 x86_64
User: internet (1005)
PHP: 8.4.23
Disabled: passthru,system
Upload Files
File: /home/internet/public_html/app/core/Middleware.php
<?php

namespace Fir\Middleware;

/**
 * The App middleware which run services before the core software is being executed
 */
class Middleware {

    /**
     * @var array   The list of routes to be excluded from being affected by middleware
     *              Array Map: Key(Middleware) => Array(Routes)
     */
    protected $except = [
        'CsrfToken'     => [],
        'Authorize'     => [],
        'UserSettings'  => []
    ];

    /**
     * Middleware to be loaded
     * @var array
     */
    private $middleware = [];

    public function __construct() {
        $this->getAll();
        foreach($this->middleware as $name) {
            // If a middleware exception exists
            if(isset($this->except[$name])) {
                foreach($this->except[$name] as $route) {
                    // If the route has match anything rule (*)
                    if(substr($route, -1) == '*') {
                        // If the current path matches a route exception
                        if(stripos($_GET['url'], str_replace('*', '', $route)) === 0) {
                            return;
                        }
                    }
                    // If the current path matches a route exception
                    elseif(isset($_GET['url']) && $_GET['url'] == $route) {
                        return;
                    }
                }
            }
            require_once(__DIR__ . '/../middleware/' . $name . '.php');

            $class = 'Fir\Middleware\\' . $name;

            new $class;
        }
    }

    private function getAll() {
        if($handle = opendir(__DIR__ . '/../middleware/')) {
            while(false !== ($entry = readdir($handle))) {
                if($entry != '.' && $entry != '..' && substr($entry, -4, 4) == '.php') {
                    $name = pathinfo($entry);
                    $this->middleware[] = $name['filename'];
                }
            }
            closedir($handle);
        }
    }
}