Skip to content

A minimalist PHP framework for building REST APIs and web applications

License

Notifications You must be signed in to change notification settings

jdanielcmedina/lapa

Repository files navigation

🚀 Lapa Framework

A minimalist PHP framework for building REST APIs and web applications.

Tests License

Requirements

  • PHP 7.4 or higher
  • MySQL/MariaDB, SQLite, PostgreSQL, MS SQL or Sybase
  • Composer

Quick Start

  1. Clone the repository:
git clone https://github.com/jdanielcmedina/lapa.git my-app
  1. Enter the project directory:
cd my-app
  1. Install dependencies:
composer install
  1. Copy configuration file:
cp config.example.php config.php
  1. Configure your database and other settings in config.php

  2. Start development server:

php -S localhost:8000 -t public

Features

🛣️ Routing

  • Simple and intuitive route definition
  • Support for multiple HTTP methods (GET, POST, PUT, PATCH, DELETE, OPTIONS)
  • Route parameters (/:id, /:slug)
  • Route grouping
  • Virtual hosts (subdomains)
  • 404 handlers
  • Wildcard routes
  • Auto-loading routes from /routes directory

🔒 Security

  • Session protection
  • HTTPS enforcement
  • Password hashing
  • Access control
  • CSRF protection
  • Secure file permissions
  • Custom authentication handlers

💾 Storage

  • File uploads with validation
  • File downloads
  • File moving/renaming
  • Secure file permissions
  • Organized directory structure
  • Automatic cleanup
  • Disk space monitoring
  • Public/private storage areas

🗄️ Database (via Medoo)

  • MySQL/MariaDB support
  • SQLite support
  • PostgreSQL support
  • MS SQL Server support
  • Sybase support
  • Safe query building
  • Multiple database types

🔄 Responses

  • JSON responses
  • Text responses
  • XML responses
  • HTML/View responses
  • File downloads
  • Redirects
  • Status codes
  • Custom headers
  • CORS support

🍪 State Management

  • Session handling
  • Cookie management
  • Cache system
  • Flash messages
  • Headers management

📨 Email (via PHPMailer)

  • SMTP support
  • HTML emails
  • Attachments
  • Multiple configurations

🛠️ Utilities

  • Logging system
  • Debug mode
  • String slugification
  • Time ago formatting
  • Request validation
  • Configuration management
  • Random string generation
  • String cleaning
  • Distance calculation
  • Auto-loading configuration

Installation

composer require jdanielcmedina/lapa

Basic Usage

<?php
require 'vendor/autoload.php';

// Initialize app (config.php is auto-loaded)
$app = new Lapa();

// Simple route
$app->on('GET /', function() {
    return 'Hello World';
});

// Route with parameters
$app->on('GET /users/:id', function() {
    return $this->db->select('users', '*', [
        'id' => $this->param('id')
    ]);
});

// Protected route
$app->on('GET /admin', function() {
    $this->protect();
    return ['status' => 'admin area'];
});

// Route group
$app->group('/api', function($app) {
    $app->on('GET /status', function() {
        return ['status' => 'online'];
    });
    
    $app->notFound(function() {
        return ['error' => 'API endpoint not found'];
    });
});

Directory Structure

/your-app
  /routes
    api.php
    admin.php
    web.php
  /storage
    /app
      /public
      /private
    /logs
    /cache
    /temp
    /uploads
  /public
    index.php
  config.php
  composer.json

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Testing

composer test

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Changelog

Please see CHANGELOG for more information on what has changed recently.

Credits

Support

License

The MIT License (MIT). Please see License File for more information.

Author

About

A minimalist PHP framework for building REST APIs and web applications

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages