ebcore/framework

A Modern Entity Based PHP Framework

v1.0.0 2025-03-18 08:13 UTC

This package is auto-updated.

Last update: 2025-03-18 10:55:19 UTC


README

Ebcore Framework Logo

PHP Version License

Ebcore is a modern and powerful PHP framework inspired by Entity-Based architecture. It helps you build complex web applications with ease and elegance.

Key Features

  • 🏗️ Entity-Based Architecture
  • 🛣️ Modern Routing System
  • 🔒 Powerful Middleware System
  • ⚡ Advanced Caching
  • 🎯 Event System
  • 📝 Logging System
  • 🔐 Security Features
  • ⚙️ Flexible Configuration

Installation

Create a new project with Ebcore:

composer create-project ebcore/skeleton my-project
cd my-project

Project Structure

my-project/
├── app/
│   └── entities/
│       └── User/
│           ├── Controllers/
│           │   └── UserController.php
│           ├── Events/
│           │   └── UserRegisterEvent.php
│           └── Middlewares/
│               └── CheckUserPermissionMiddleware.php
├── config/
│   ├── app.json
│   ├── database.json
│   └── middleware.json
├── public/
│   ├── .htaccess
│   └── index.php
├── routes/
│   └── web.php
└── vendor/
    └── ebcore/
        ├── Core/
        ├── Middlewares/
        └── Packages/

Usage Examples

1. Defining Routes

// routes/web.php
use ebcore\Core\Router;

$router->map('GET', '/', 'User','UserController', 'index');
$router->map('GET', '/users', 'User','UserController', 'index', 'UserRegisterEvent', 'after');

$router->run();

2. Creating Controllers

// app/entities/User/Controllers/UserController.php
namespace App\entities\User\Controllers;

use ebcore\Core\Controller;
use ebcore\DB\DbContext;
use ebcore\Module\Response;
use ebcore\Packages\Dump\Dump;

class UserController 
{
    public function index() 
    {
        $users = DbContext::User()->all();
        // Dump::dd($users);
        if (empty($users)) {
            return Response::json(null, "No users found", 404, false);
        }
        return Response::json($users);
    }
}

3. Creating Middleware

// app/entities/User/Middlewares/CheckUserPermissionMiddleware.php
namespace app\entities\User\Middlewares;

use ebcore\Core\Middleware;

class CheckUserPermissionMiddleware extends BaseMiddleware
{
    public function handle($request, $next)
    {
        if (!$this->checkPermission()) {
            Logger::warning("Permission denied for user", [
                'permission' => $this->requiredPermission,
                'user_id' => $_SESSION['user_id'] ?? null
            ]);

            return $this->jsonResponse([
                'error' => 'Permission Denied',
                'message' => 'You do not have the required permission.'
            ], 403);
        }
        
        return $next($request);
    }
}

4. Creating Events

// app/entities/User/Events/UserRegisterEvent.php
namespace App\entities\User\Events;

use ebcore\Core\Events;
use ebcore\DB\DbContext;
use ebcore\Module\Response;

class UserRegisterEvent extends Events
{
    public function execute()
    {
        if ($this->isExecuted('UserRegisterEvent')) {
            return;
        }

        try {
            $user = array();
            $user["name"] = "test";
            $user["family"] = "test";
            $user["created_at"] = date("Y/m/d h:i:sa");
            DbContext::User()->create($user);
            $this->markAsExecuted('UserRegisterEvent');
        } catch (\Exception $e) {
            $this->resetExecution('UserRegisterEvent');
            throw $e;
        }
    }
}

5. Using Cache System

use ebcore\Core\Cache;

// Store in cache
Cache::put('key', 'value', 3600);

// Retrieve from cache
$value = Cache::get('key');

// Remove from cache
Cache::forget('key');

Configuration

Application Settings

// config/app.json
{
    "name": "Ebcore Framework",
    "version": "1.0.0",
    "debug": true,
    "timezone": "Asia/Tehran",
    "locale": "fa",
    "url": "http://localhost"
}

Middleware Settings

// config/middleware.json
{
    "throttle": {
        "max_requests": 60,
        "decay_minutes": 1,
        "enabled": true
    },
    "global_middlewares": [
        "ThrottleMiddleware"
    ]
} 

Security Features

  • Throttle System
  • Duplicate Request control system
  • Rate limiting
  • Input validation
  • Output sanitization

Contributing

Please read our Contributing Guide before submitting a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

Acknowledgments

Thank you to all contributors and developers who have helped build this framework.