eyo/fw-php

EyoPHP - Educational PHP framework with permissions system, dynamic routing and middleware

0.1.6 2025-08-08 09:39 UTC

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

Latest Version License

๐Ÿ‡ซ๐Ÿ‡ท 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

  1. ๐Ÿ“– Follow the Quick Start guide
  2. ๐Ÿ” Explore the code structure
  3. ๐Ÿ“ Modify the homepage template
  4. โž• Add a new route and controller

Intermediate

  1. ๐Ÿ—ƒ๏ธ Create custom models
  2. โœ… Add input validation to forms
  3. ๐Ÿ” Implement user permissions
  4. ๐Ÿงช Write unit tests

Advanced

  1. ๐Ÿ”ง Create custom middleware
  2. ๐Ÿ“Š Add logging and monitoring
  3. ๐Ÿš€ Deploy to production
  4. ๐Ÿ”„ 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!

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. 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! ๐Ÿš€