yasser-elgammal / green
Green Framework Skeleton
Requires
- php: ^8.2
- firebase/php-jwt: ^7.0
- yasser-elgammal/green-core: ^2.0
Requires (Dev)
- phpunit/phpunit: ^12.5
README
Green is a lightweight, modern PHP framework built with PHP 8.2+ features, focusing on simplicity, speed, and developer experience. It leverages PHP Attributes for routing and follows a Table Gateway architecture.
Note: This repository contains the application skeleton. The core framework engine is located at YasserElgammal/green-core.
⚡ Quick Start
1. Installation
composer create-project yasser-elgammal/green app-name
cd app-name
cp .env.example .env
php green serve
2. Define a Route
class PostController { #[Route('GET', '/posts/{id}', name: 'posts.show', middleware: [AuthMiddleware::class, LocaleMiddleware::class])] public function show(int $id) { return view('posts/show', ['id' => $id]); } }
Pass route middleware as an array; add multiple middleware classes in the order they should run. Generate named route URLs with route('posts.show', ['id' => 1]).
3. Database Access
$posts = new PostTable(); $post = $posts->fetchById(1);
4. Database Querying
$activePosts = $posts ->query() ->where('status', 'published') ->whereGroup(fn ($query) => $query ->where('featured', true) ->orWhere('score', '>=', 90) ) ->latest() ->fetch();
Green queries support readable condition helpers such as whereIn(), whereNotIn(), whereNull(), whereBetween(), whereLike(), their orWhere... counterparts, aggregates like count(), exists(), sum(), avg(), min(), max(), and table aliases like all(), find(), and findRequired().
📖 Master Documentation
The framework is divided into several powerful subsystems. Please refer to the Master Documentation for detailed guides on:
- Core Architecture: Lifecycle and DI patterns.
- Routing & Middleware: Attribute-based routing and pipelines.
- Database & Relations: Eager loading and Table Gateways.
- Database Querying: Fluent Green queries, condition helpers, aggregates, table aliases, and transactions.
- API Layer: Smart Transformers and Pagination.
- Logic & Validation: Payload-based validation.
- Security & Sessions: State management and hashing.
- Global Exception Handling: Debug Mode and API errors.
- Debugging with
leaf(): Native PHP helper for dumping a value and stopping execution. - Helper Reference: Glossary of global functions.
- Console Commands: CLI tools and generators.
- Migrations & Schema Builder: Migration workflow, schema operations, dry-run mode, and safe mode.
- Translation & Localization: Global helpers, multiple providers, caching, and pluralization.
- Include Query Language: Advanced relation loading with limits, ordering, filtering, and column selection.
- Connect: Outgoing HTTP requests for third-party APIs and services.
- Cache: Cache manager, stores, drivers, and remember().
- Events & Signals: Signal dispatcher, listeners, and event generators.
- Authorization: Authorizer, policies, and controller
PolicyAttributechecks.
🛠 Features at a Glance
- ✅ PHP 8.2+ Attributes: No more clunky routing files.
- ✅ Named Routes: Generate URLs with
route()from named Route attributes. - ✅ Signals, Cache & Policies: Core providers expose signal(), cache(), and authorizer().
- ✅ Table Gateway: Clean separation of state (Model) and logic (Table).
- ✅ Eager Loading & IQL: Simple
include('relation')to solve N+1, with an advanced query language for limits, ordering, filtering, and column selection. - ✅ Smart Transformers: Nested API responses made easy.
- ✅ Auto-Validation: Type-hint payloads for instant validation.
- ✅ Twig Templates: Native Twig integration for clean views.
- ✅ Connect: Simple outgoing HTTP requests for payments, CRMs, messaging APIs, and other services.
- ✅ Debug UI: Premium dark-mode error pages.
- ✅
leaf()Debugging: Native formatted dump-and-die output for focused PHP debugging.
Contributing
Contributions are welcome. Please read the Contributing Guide before opening an issue or pull request.
📜 License
Green Framework is open-sourced under the MIT License.