phastasf / framework
A lightweight PHP framework for building CLI, web and API applications
Installs: 1
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/phastasf/framework
Requires
- php: ^8.2
- vaibhavpandeyvpz/ank: ^2.0
- vaibhavpandeyvpz/clip: ^1.0
- vaibhavpandeyvpz/dakiya: ^3.0
- vaibhavpandeyvpz/databoss: ^2.1
- vaibhavpandeyvpz/datum: ^1.1
- vaibhavpandeyvpz/drishti: ^1.1
- vaibhavpandeyvpz/envelope: ^1.0
- vaibhavpandeyvpz/filtr: ^2.0
- vaibhavpandeyvpz/godam: ^2.0
- vaibhavpandeyvpz/jweety: ^2.0
- vaibhavpandeyvpz/katora: ^2.0
- vaibhavpandeyvpz/kram: ^1.0
- vaibhavpandeyvpz/kunfig: ^2.0
- vaibhavpandeyvpz/phew: ^2.0
- vaibhavpandeyvpz/phlash: ^3.0
- vaibhavpandeyvpz/qatar: ^1.0
- vaibhavpandeyvpz/samay: ^1.0
- vaibhavpandeyvpz/sandesh: ^3.0
- vaibhavpandeyvpz/soochak: ^2.0
- vaibhavpandeyvpz/tez: ^3.0
- vaibhavpandeyvpz/vidyut: ^3.0
README
A lightweight, modern PHP framework for building CLI, web, and API applications. Phast is built on PSR standards and provides a clean, intuitive API for rapid development.
Features
🚀 Core Features
- PSR Standards: Full compliance with PSR-7, PSR-11, PSR-15, PSR-3, PSR-6, PSR-16, and PSR-20
- Dependency Injection: Built-in service container with automatic dependency resolution
- Routing: Fast, flexible routing with parameter binding and middleware support
- Middleware Pipeline: PSR-15 compliant middleware for request/response processing
- Configuration Management: Flexible configuration system with environment variable support
- Error Handling: Centralized exception handling with JSON/HTML response formatting
🗄️ Database & ORM
- Multi-Database Support: MySQL, PostgreSQL, SQLite, and SQL Server
- ORM: Active Record pattern with Datum
- Migrations: Database schema versioning with Kram
- Query Builder: Fluent query builder with Databoss
🎨 Views & Templates
- Template Engine: Phew template engine with layout inheritance
- Multiple View Paths: Support for namespaced view directories
- Template Inheritance: Extend layouts and override blocks
🔐 Authentication & Security
- JWT Authentication: Token-based authentication with Jweety
- CAPTCHA: Text and math-based CAPTCHA generation with Ank
- Flash Messages: Session-based flash messages with Phlash
- Input Validation: Powerful validation with Filtr
📦 Additional Features
- Caching: Multiple cache backends (File, Memory, Redis, Predis, Memcache)
- Logging: Flexible logging with multiple backends (File, Daily, Stdio)
- Queue System: Job queues with Redis and ElasticMQ/SQS support
- Email: SMTP, Mailgun, and Resend email transports
- Sessions: Session management with configurable drivers
- Events: Event-driven architecture with Soochak
- Console Commands: Built-in CLI commands and code generators
Requirements
- PHP 8.2 or higher
- Composer
Installation
Install via Composer:
composer require phastasf/framework
Quick Start
Web Application
Create a public/index.php file:
<?php require __DIR__.'/../vendor/autoload.php'; define('BASE_PATH', __DIR__.'/..'); $framework = new Phast\Framework; $entrypoint = $framework->getWebEntrypoint(); $entrypoint->handle();
Console Application
Create a console file:
#!/usr/bin/env php <?php require __DIR__.'/vendor/autoload.php'; define('BASE_PATH', __DIR__); $framework = new Phast\Framework; $entrypoint = $framework->getConsoleEntrypoint(); exit($entrypoint->run());
Make it executable:
chmod +x console
Configuration
Configuration files are located in the config/ directory. The framework loads default configurations from the package and allows you to override them in your project's config/ directory.
Application Configuration
// config/app.php return [ 'debug' => env('APP_DEBUG', false), 'controllers' => [ 'namespace' => 'App\\Controllers', ], ];
Database Configuration
// config/database.php return [ 'driver' => env('DB_DRIVER', 'mysql'), 'migrations' => BASE_PATH.'/database/migrations', 'mysql' => [ 'host' => env('DB_HOST', 'localhost'), 'port' => env('DB_PORT', 3306), 'database' => env('DB_DATABASE', ''), 'username' => env('DB_USERNAME', 'root'), 'password' => env('DB_PASSWORD', ''), 'charset' => 'utf8mb4', ], ];
Routing
Define routes in routes/web.php:
<?php use Tez\Router; return function (Router $router) { $router->get('/', 'HomeController@index'); $router->get('/users/{id}', 'UserController@show'); $router->post('/users', 'UserController@store'); };
Controllers
Controllers extend the base Phast\Controller class:
<?php namespace App\Controllers; use Phast\Controller; use Psr\Http\Message\ServerRequestInterface; class HomeController extends Controller { public function index(ServerRequestInterface $request) { return $this->render('welcome', [ 'message' => 'Hello, Phast!', ]); } }
Middleware
Create custom middleware by implementing Psr\Http\Server\MiddlewareInterface:
<?php namespace App\Middleware; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\MiddlewareInterface; use Psr\Http\Server\RequestHandlerInterface; class CustomMiddleware implements MiddlewareInterface { public function process( ServerRequestInterface $request, RequestHandlerInterface $handler ): ResponseInterface { // Your middleware logic here return $handler->handle($request); } }
Database & Migrations
Creating Migrations
php console g:migration create_users_table
Running Migrations
php console migrate
Using the ORM
use Datum\Model; class User extends Model { protected string $table = 'users'; } // Find a user $user = User::find(1); // Create a user $user = new User; $user->name = 'John Doe'; $user->email = 'john@example.com'; $user->save();
Queue Jobs
Creating Jobs
php console g:job SendEmail
Job Implementation
<?php namespace App\Jobs; use Qatar\Job; class SendEmailJob extends Job { public function handle(array $payload): void { // Send email logic mail($payload['to'], $payload['subject'], $payload['body']); } public function retries(): int { return 3; // Retry 3 times on failure } }
Running Workers
php console worker
Caching
use Psr\SimpleCache\CacheInterface; // Get cache from container $cache = $container->get(CacheInterface::class); // Store a value $cache->set('key', 'value', 3600); // TTL: 1 hour // Retrieve a value $value = $cache->get('key');
Logging
use Psr\Log\LoggerInterface; // Get logger from container $logger = $container->get(LoggerInterface::class); $logger->info('User logged in', ['user_id' => 123]); $logger->error('Something went wrong', ['exception' => $e]);
Validation
use Filtr\Validator; $validator = new Validator; $validator->required('email')->email(); $validator->required('password')->min(8); $result = $validator->validate($data); if ($result->isValid()) { // Process valid data } else { // Handle errors $errors = $result->errors(); }
JWT Authentication
Configure JWT in config/auth.php:
return [ 'jwt' => [ 'secret' => env('JWT_SECRET'), 'algorithm' => 'HS256', ], 'middleware' => [ 'include' => ['/api/*'], 'exclude' => ['/api/auth/*'], 'required' => true, 'header' => 'Authorization', 'prefix' => 'Bearer', ], ];
Console Commands
Phast includes several built-in commands:
g:controller- Generate a new controllerg:migration- Generate a new migrationg:job- Generate a new job classserve- Start the development serverworker- Run queue workersmigrate- Run database migrations
Service Providers
The framework uses service providers to register services in the container. All providers are automatically registered when you instantiate Phast\Framework.
Error Handling
The framework includes a centralized error handler that:
- Catches all exceptions
- Returns JSON responses for API requests (when
Accept: application/json) - Renders HTML error pages for web requests
- Logs 5xx errors automatically
- Shows debug information when
app.debugis enabled
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
Phast Framework is open-sourced software licensed under the MIT license.
Credits
Phast Framework is built on top of excellent PSR-compliant libraries:
- Katora - Dependency Injection Container
- Tez - Routing
- Vidyut - Middleware Pipeline
- Sandesh - HTTP Messages
- Datum - ORM
- Databoss - Database Abstraction
- Kram - Migrations
- Phew - Template Engine
- Filtr - Validation
- Drishti - Logging
- Godam - Caching
- Qatar - Job Queues
- Envelope - Email
- Jweety - JWT
- Ank - CAPTCHA
- Phlash - Flash Messages
- Soochak - Events
- Samay - Clock
- Kunfig - Configuration
- Clip - Console Commands