swallowphp / framework
Swallow PHP framework
Installs: 195
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/swallowphp/framework
Requires
- league/container: ^4.2
- php-debugbar/php-debugbar: ^1.23
- phpmailer/phpmailer: ^6.9.1
- psr/simple-cache: ^3.0
Requires (Dev)
- pestphp/pest: ^4.3
README
A lightweight, modern PHP framework designed for simplicity and rapid development. SwallowPHP provides essential features for building web applications without the complexity of larger frameworks.
Features
- Dependency Injection - Built on League Container with auto-wiring support
- Fluent Query Builder - Intuitive database operations with PDO
- Eloquent-style ORM - Active Record pattern with relationships and events
- Routing - Simple, expressive route definitions with middleware support
- Authentication - Built-in authentication with remember me and brute-force protection
- Session Management - File-based sessions with flash messages
- Caching - PSR-16 compatible caching (file, SQLite drivers)
- Logging - PSR-3 compatible file-based logging
- CSRF Protection - Automatic cross-site request forgery protection
- Rate Limiting - Per-route request rate limiting
Requirements
- PHP 8.0 or higher
- PDO extension (for database)
- JSON extension
- mbstring extension
Installation
Install via Composer:
composer require swallowphp/framework
Quick Start
1. Create Entry Point
Create a public/index.php file:
<?php define('BASE_PATH', dirname(__DIR__)); require BASE_PATH . '/vendor/autoload.php'; // Load routes require BASE_PATH . '/routes/web.php'; // Run the application \SwallowPHP\Framework\Foundation\App::run();
2. Create Environment File
Create a .env file in your project root:
APP_NAME=MyApp APP_ENV=local APP_DEBUG=true APP_URL=http://localhost:8000 APP_KEY=your-32-character-secret-key-here DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=myapp DB_USERNAME=root DB_PASSWORD=
3. Create Configuration
Create config/app.php:
<?php return [ 'name' => env('APP_NAME', 'SwallowPHP'), 'env' => env('APP_ENV', 'production'), 'debug' => (bool) env('APP_DEBUG', false), 'url' => env('APP_URL', 'http://localhost'), 'timezone' => 'UTC', 'locale' => 'en', 'key' => env('APP_KEY'), 'storage_path' => BASE_PATH . '/storage', 'view_path' => BASE_PATH . '/resources/views', 'controller_namespace' => '\\App\\Controllers', ];
4. Define Routes
Create routes/web.php:
<?php use SwallowPHP\Framework\Routing\Router; use SwallowPHP\Framework\Http\Request; // Basic route Router::get('/', function () { return view('welcome'); })->name('home'); // Route with parameter Router::get('/users/{id}', function (Request $request) { return 'User ID: ' . $request->get('id'); })->name('users.show'); // Controller route Router::get('/posts', [App\Controllers\PostController::class, 'index']) ->name('posts.index'); Router::post('/posts', [App\Controllers\PostController::class, 'store']) ->name('posts.store');
5. Create a Controller
Create app/Controllers/PostController.php:
<?php namespace App\Controllers; use SwallowPHP\Framework\Http\Request; class PostController { public function index() { $posts = \App\Models\Post::orderBy('created_at', 'DESC')->get(); return view('posts.index', ['posts' => $posts]); } public function store(Request $request) { \App\Models\Post::create([ 'title' => $request->get('title'), 'content' => $request->get('content'), ]); return redirectToRoute('posts.index'); } }
6. Create a Model
Create app/Models/Post.php:
<?php namespace App\Models; use SwallowPHP\Framework\Database\Model; class Post extends Model { protected static string $table = 'posts'; protected array $fillable = ['title', 'content']; }
7. Create a View
Create resources/views/welcome.php:
<!DOCTYPE html>
<html>
<head>
<title>Welcome</title>
</head>
<body>
<h1>Welcome to SwallowPHP!</h1>
</body>
</html>
8. Run the Application
php -S localhost:8000 -t public
Directory Structure
your-project/
├── app/
│ ├── Controllers/
│ └── Models/
├── config/
│ ├── app.php
│ ├── database.php
│ ├── auth.php
│ ├── session.php
│ └── cache.php
├── public/
│ └── index.php
├── resources/
│ └── views/
├── routes/
│ └── web.php
├── storage/
│ ├── cache/
│ ├── logs/
│ └── sessions/
├── .env
└── composer.json
Documentation
Detailed documentation is available in the docs/ directory:
- Configuration - Environment and configuration setup
- Routing - Defining routes and middleware
- Database - Query builder and ORM
- Authentication - User authentication
- Helpers - Global helper functions
- HTTP - Request, Response, and Cookies
- Views - View rendering and layouts
- Sessions - Session management
- Cache - Caching system
- Logging - Application logging
- Middleware - Custom middleware
Dependencies
SwallowPHP uses the following third-party packages:
| Package | Version | Purpose |
|---|---|---|
| league/container | ^4.2 | Dependency Injection Container |
| phpmailer/phpmailer | ^6.9.1 | Email sending |
| psr/simple-cache | ^3.0 | Cache interface |
| php-debugbar/php-debugbar | ^1.23 | Debug toolbar (dev) |
License
SwallowPHP is open-source software licensed under the MIT license.
Author
Fatih Zengin - fatihzengin654@outlook.com