<?php

spl_autoload_register(function ($class) {

    $prefix = 'App\\';

    if (
        strncmp(
            $prefix,
            $class,
            strlen($prefix)
        ) !== 0
    ) {
        return;
    }

    $relative =
        substr(
            $class,
            strlen($prefix)
        );

    $relative =
        str_replace(
            '\\',
            '/',
            $relative
        );

    $parts =
        explode(
            '/',
            $relative
        );

    /*
    Linux filesystem
    app/services
    app/controllers
    app/core
    app/helpers
    */

    if (!empty($parts[0])) {

        $parts[0] =
            strtolower(
                $parts[0]
            );

    }

    $file =
        BASE_PATH .
        '/app/' .
        implode('/', $parts) .
        '.php';

    if (file_exists($file)) {

        require_once $file;

    }

});
