eyo / fw-php
EyoPHP - Educational PHP framework with permissions system, dynamic routing and middleware
Installs: 15
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:project
Requires
- php: >=8.1
- vlucas/phpdotenv: ^5.6
Suggests
- phpdocumentor/shim: To generate API documentation
- phpunit/phpunit: To run framework tests and have test examples
This package is auto-updated.
Last update: 2025-08-08 09:40:07 UTC
README
A minimalist PHP framework that gets you from zero to working web app in 5 minutes
๐ซ๐ท Note for French learners: This framework was created by a French developer for educational purposes. While documentation is in English for international reach, you'll find extensive French comments in the code and detailed French tutorials in the
/docs
folder.
โก Quick Start
Get a working web application in 2 commands:
# Choose your installation mode by project name: composer create-project eyo/fw-php my-app-complete # Full features composer create-project eyo/fw-php my-app-minimal # Lightweight composer create-project eyo/fw-php my-app # Interactive choice cd my-app && php -S localhost:8000 -t public
Open http://localhost:8000 โ You have a working app with authentication! ๐
๐ฆ Installation
๐ง Smart Installation (Auto-detects from project name)
โก Minimal Mode - Just add -minimal
to your project name:
composer create-project eyo/fw-php blog-minimal composer create-project eyo/fw-php api-minimal composer create-project eyo/fw-php myapp-minimal
๐ Complete Mode - Add -complete
to your project name:
composer create-project eyo/fw-php cms-complete composer create-project eyo/fw-php website-complete composer create-project eyo/fw-php myapp-complete
๐ค Interactive Choice - Use any other name:
composer create-project eyo/fw-php myproject
# Will ask you to choose between Complete/Minimal modes
๐ง Change Mode Later
cd myproject php scripts/setup.php minimal # Switch to minimal php scripts/setup.php complete # Switch to complete
๐ Advanced: Environment Variables (Optional)
EYOPHP_MODE=minimal composer create-project eyo/fw-php my-project EYOPHP_MODE=complete composer create-project eyo/fw-php my-project
Alternative Installation Methods
Option 2: Add to Existing Project
composer require eyo/fw-php
Option 3: Git Clone
git clone https://github.com/APlouzeau/framework-php.git my-project
cd my-project
composer install
โ๏ธ Configuration
1. Environment Setup
# Copy the environment template cp .env.example .env # Edit your database credentials # .env DB_HOST=localhost DB_NAME=my_project DB_USER=root DB_PSW=your_password
2. Database Setup
# Import the provided SQL schema mysql -u root -p < database/users.sql
3. Start Development Server
php -S localhost:8000 -t public
Visit http://localhost:8000 and you're ready! ๐
๐ฏ Why EyoPHP?
Perfect for learning, teaching, and rapid prototyping
โ What you get out of the box:
- ๐ Working homepage immediately after installation
- ๐ Complete authentication (register/login/logout)
- ๐ฃ๏ธ Simple routing with clean URLs
- ๐๏ธ Database integration with PDO
- ๐ MVC structure without over-engineering
- ๐ User permissions system
- โ Input validation with customizable rules
- ๐จ Template system with layouts
- ๐งช PHPUnit tests included
๐ Educational Philosophy:
- Pure PHP - No magic, you understand every line
- Modern standards - PSR-4 autoloading, Composer, .env
- Real-world patterns - MVC, Router, Middleware
- Progressive learning - Start simple, add complexity when needed
๐ Developer Experience:
// Simple routing with permission levels $router->addPublicRoute('GET', BASE_URL . 'about', 'EyoPHP\\Framework\\Controller\\AppController', 'aboutPage'); $router->addUserRoute('GET', BASE_URL . 'home', 'EyoPHP\\Framework\\Controller\\AppController', 'homePage'); // Easy database access $user = UserModel::findByEmail($email); // Clean validation $validator = new Validator($data); $validator->required('email')->email();
๐ Project Structure
my-project/
โโโ public/ # Web root
โ โโโ index.php # Application entry point
โ โโโ .htaccess # URL rewriting rules
โโโ src/ # Framework core (PSR-4)
โ โโโ Controller/ # Application controllers
โ โโโ Model/ # Data models
โ โโโ Core/ # Framework core classes
โ โโโ Validation/ # Input validation
โโโ views/ # HTML templates
โ โโโ head.php # HTML head
โ โโโ header.php # Site header
โ โโโ home.php # Homepage
โ โโโ footer.php # Site footer
โโโ config/ # Configuration files
โ โโโ config.php # Main configuration
โ โโโ routes.php # Route definitions
โ โโโ middleware.php # Middleware setup
โโโ database/ # SQL scripts
โ โโโ users.sql # User table schema
โโโ .env.example # Environment template
โโโ composer.json # Dependencies
๐ ๏ธ Key Features
Router with Clean URLs
// config/routes.php - Real EyoPHP routing system $router->addPublicRoute('GET', BASE_URL, 'EyoPHP\\Framework\\Controller\\AppController', 'homePage'); $router->addPublicRoute('GET', BASE_URL . 'about', 'EyoPHP\\Framework\\Controller\\AppController', 'aboutPage'); $router->addPublicRoute('POST', BASE_URL . 'login', 'EyoPHP\\Framework\\Controller\\AuthController', 'login'); $router->addUserRoute('GET', BASE_URL . 'home', 'EyoPHP\\Framework\\Controller\\AppController', 'homePage');
Database with PDO
// src/Model/UserModel.php - Real EyoPHP method public function findByEmail(string $email): ?User { $query = "SELECT * FROM users WHERE email = :email"; $stmt = $this->db->prepare($query); $stmt->execute(['email' => $email]); $result = $stmt->fetch(); return $result ? User::fromArray($result) : null; }
Permission-Based Routing
// EyoPHP's unique 3-level permission system $router->addPublicRoute('GET', BASE_URL . 'about', 'Controller', 'method'); // Anyone can access $router->addUserRoute('GET', BASE_URL . 'profile', 'Controller', 'method'); // Logged users only $router->addAdminRoute('GET', BASE_URL . 'admin', 'Controller', 'method'); // Admins only
Input Validation
// Validate user registration $validator = new Validator($_POST); $validator->required('email')->email() ->required('password')->minLength(8) ->required('name')->minLength(2); if ($validator->isValid()) { // Process registration }
Template System
// src/Controller/AppController.php - Real method public function homePage(): void { $this->renderView('home', [ 'title' => 'Welcome to EyoPHP', 'message' => 'Your framework is ready!' ]); }
๐ Usage Examples
Creating a New Controller
<?php namespace EyoPHP\Framework\Controller; class ProductController { public function listProducts(): void { // Example: Get products from database $products = [ ['id' => 1, 'name' => 'Product 1', 'price' => 99.99], ['id' => 2, 'name' => 'Product 2', 'price' => 149.99] ]; $this->renderView('products/list', [ 'title' => 'Our Products', 'products' => $products ]); } public function showProduct(int $id): void { // Example: Get single product $product = ['id' => $id, 'name' => 'Product ' . $id, 'price' => 99.99]; $this->renderView('products/show', [ 'title' => 'Product Details', 'product' => $product ]); } }
Adding Routes
// config/routes.php - Add your new routes $router->addPublicRoute('GET', BASE_URL . 'products', 'EyoPHP\\Framework\\Controller\\ProductController', 'listProducts'); $router->addPublicRoute('GET', BASE_URL . 'products/{id}', 'EyoPHP\\Framework\\Controller\\ProductController', 'showProduct'); // User-only routes (require login) $router->addUserRoute('GET', BASE_URL . 'dashboard', 'EyoPHP\\Framework\\Controller\\AppController', 'dashboard');
Creating a Model
<?php namespace EyoPHP\Framework\Model; use EyoPHP\Framework\Core\Database; class ProductModel { public static function getAll(): array { $db = Database::getInstance(); $stmt = $db->query("SELECT * FROM products ORDER BY name ASC"); return $stmt->fetchAll(); } public static function findById(int $id): ?array { $db = Database::getInstance(); $stmt = $db->prepare("SELECT * FROM products WHERE id = :id"); $stmt->execute(['id' => $id]); return $stmt->fetch() ?: null; } public static function create(array $data): bool { $db = Database::getInstance(); $stmt = $db->prepare("INSERT INTO products (name, price, description) VALUES (:name, :price, :description)"); return $stmt->execute([ 'name' => $data['name'], 'price' => $data['price'], 'description' => $data['description'] ]); } }
๐ง Development Tools
Testing
# Run tests composer test # With coverage composer test-coverage
Documentation
# Generate API docs composer docs # Serve documentation composer docs-serve
Development Server
# Quick start php -S localhost:8000 -t public # With automatic restart (if you have nodemon) nodemon --exec "php -S localhost:8000 -t public" --ext php
๐ Learning Path
Beginner
- ๐ Follow the Quick Start guide
- ๐ Explore the code structure
- ๐ Modify the homepage template
- โ Add a new route and controller
Intermediate
- ๐๏ธ Create custom models
- โ Add input validation to forms
- ๐ Implement user permissions
- ๐งช Write unit tests
Advanced
- ๐ง Create custom middleware
- ๐ Add logging and monitoring
- ๐ Deploy to production
- ๐ Migrate to Symfony/Laravel
๐ Perfect For
- ๐ Learning PHP and web development basics
- ๐ซ Teaching MVC patterns in schools
- โก Rapid prototyping of web applications
- ๐ฌ Understanding how frameworks work internally
- ๐ Starting projects that might grow into larger frameworks
๐ซ Not For You If
- You need a battle-tested production framework โ Use Symfony or Laravel
- You want advanced features out-of-the-box โ Use CodeIgniter or CakePHP
- You're building complex enterprise applications โ Use Zend/Laminas
๐ Migration Path
EyoPHP uses standard PHP patterns. When you're ready to scale:
- To Symfony: Controllers and routing concepts are similar
- To Laravel: Model and validation patterns translate well
- To any framework: You'll understand the underlying concepts
๐ค Contributing
This framework is designed for educational purposes. Contributions welcome!
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
๐ License
MIT License - Free for personal and commercial use.
"The best way to learn how something works is to build it yourself"
Ready to start? Run composer create-project eyo/fw-php my-app
and begin your journey! ๐