PHPackages                             feras\_altaleb/mvc\_php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. feras\_altaleb/mvc\_php

ActiveLibrary[Framework](/categories/framework)

feras\_altaleb/mvc\_php
=======================

MVC PHP Small Framework

00PHP

Since Mar 21Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/AltalebFeras/template_empty_mvc_for_any_new_project_php_native)[ Packagist](https://packagist.org/packages/feras_altaleb/mvc_php)[ RSS](/packages/feras-altaleb-mvc-php/feed)WikiDiscussions main Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

Template Empty MVC for Any New Project (PHP Native)
===================================================

[](#template-empty-mvc-for-any-new-project-php-native)

> **MVC PHP Framework**
> Created by [Feras Altaleb](https://github.com/AltalebFeras) — for educational purposes only.

---

A lightweight, extensible MVC framework built with native PHP to help you kickstart web applications quickly and efficiently.

> **Requires PHP 8.0+** (uses native PHP Attributes for routing).

---

🚀 Features
----------

[](#-features)

- **MVC Architecture** — Clean separation of concerns using the Model-View-Controller pattern.
- **Attribute-Based Routing** — Symfony-style `#[Route]` attributes declared directly on controller methods. No central routes file needed.
- **Database Abstraction** — Easy database interactions via PDO with a built-in `AbstractRepository`.
- **Security** — Session hijacking protection, method spoofing, HTTPS detection, and real IP resolution.
- **Extensible** — Easily add new controllers; routes are auto-discovered via Reflection.
- **Lightweight** — Minimal dependencies for optimal performance.

---

🛠️ Getting Started
------------------

[](#️-getting-started)

### 1. Clone the Repository

[](#1-clone-the-repository)

```
git clone https://github.com/AltalebFeras/template_empty_mvc_for_any_new_project_php_native.git
```

### 2. Install Dependencies

[](#2-install-dependencies)

```
composer install
```

### 3. Configure Your Environment

[](#3-configure-your-environment)

- Copy `config_example.php` and rename it to `config.php`.
- Update the settings as needed for your environment (development or production):
    - Set up your **database connection** in `config.php`.
    - Set your **base URL** (`HOME_URL`) in `config.php`.
    - Configure **mail settings** in `config.php`.
    - Set your **timezone** in `src/init.php`.

### 4. Define Your Routes

[](#4-define-your-routes)

Routes are defined with the `#[Route]` attribute directly above each controller method — no central routes file.

```
use src\Services\Route;

class UserController
{
    // Public page — GET only
    #[Route('/login', methods: ['GET'])]
    public function showLoginForm(): void
    {
        // render login view
    }

    // Form submission — POST only
    #[Route('/login', methods: ['POST'])]
    public function handleLogin(): void
    {
        // process credentials
    }

    // Protected page — requires active session
    #[Route('/dashboard', methods: ['GET'], authRequired: true)]
    public function showDashboard(): void
    {
        // render dashboard view
    }
}
```

**`#[Route]` parameters:**

ParameterTypeDefaultDescription`$path``string`*(required)*URL path to match (e.g. `'/login'`)`$methods``string|array``['GET']`Allowed HTTP methods`$name``string``''`Optional route name`$authRequired``bool``false`Redirect to `/login` if not authenticated> The router auto-discovers every class inside `src/Controllers/` — just create a new controller and add `#[Route]` attributes.

### 5. HTML Form Method Spoofing

[](#5-html-form-method-spoofing)

HTML forms only support `GET` and `POST`. To send `PUT`, `PATCH`, or `DELETE`, add a hidden field:

```

    ...

```

`ConfigRouter::getMethod()` will resolve the effective method automatically.

### 6. Run the Application

[](#6-run-the-application)

Access your application in the browser:

```
http://localhost/path-to-your-project/public

```

---

📁 Directory Structure
---------------------

[](#-directory-structure)

```
public/                   # Web root — point your server / virtual host here
│   index.php             # Single entry point
│   .htaccess             # URL rewriting (Apache)
└── assets/               # CSS, JS, images

src/
├── init.php              # Bootstrap: session, autoloader, config, router
├── Abstracts/
│   ├── AbstractController.php   # render() and redirect() helpers
│   └── AbstractRepository.php  # CRUD helpers (getAll, getById, create, …)
├── Controllers/          # Your controllers — add #[Route] attributes here
├── Entities/             # Plain PHP entity classes (hydrated via Hydration trait)
├── Migrations/           # SQL migration files
├── Repositories/         # Repository classes extending AbstractRepository
├── Services/
│   ├── Route.php         # #[Route] PHP attribute definition
│   ├── router.php        # Auto-discovers and dispatches routes via Reflection
│   ├── ConfigRouter.php  # HTTP utilities: getMethod, redirect, isAjax, getClientIp…
│   ├── Database.php      # PDO connection wrapper
│   ├── Encrypt_decrypt.php
│   ├── Hydration.php     # Trait for automatic entity hydration
│   ├── Mail.php          # PHPMailer wrapper
│   └── Validator.php
└── Views/                # PHP view templates

```

---

🔒 Security Utilities (`ConfigRouter`)
-------------------------------------

[](#-security-utilities-configrouter)

MethodDescription`ConfigRouter::getMethod()`Returns the real HTTP method, supporting `PUT`/`PATCH`/`DELETE` spoofing via `_method` POST field`ConfigRouter::checkOriginConnection()`Validates session IP &amp; user-agent to detect session hijacking — returns `false` on mismatch`ConfigRouter::redirect($url, $code)`Safe redirect with HTTP status code (default 302)`ConfigRouter::isAjax()`Detects `XMLHttpRequest` / `fetch` requests`ConfigRouter::isHttps()`Returns `true` if the connection is HTTPS`ConfigRouter::getClientIp()`Resolves the real client IP (proxy-aware, validated)---

🧰 Best Practices
----------------

[](#-best-practices)

- Use `$authRequired: true` on routes that require a logged-in user.
- Never expose the `src/` directory — only `public/` should be the web root.
- Store passwords with `password_hash()` / `password_verify()`.
- Validate and sanitize all user input at the controller level.
- Test your application thoroughly before deploying to production.

---

🤝 Contributing
--------------

[](#-contributing)

Contributions are welcome!
If you have suggestions for improvements or new features, please [open an issue](https://github.com/AltalebFeras/template_empty_mvc_for_any_new_project_php_native/issues) or submit a pull request.

---

👤 Author
--------

[](#-author)

**Feras Altaleb**
[GitHub](https://github.com/AltalebFeras)

---

⭐️ Enjoy building amazing web applications with this simple MVC framework!
--------------------------------------------------------------------------

[](#️-enjoy-building-amazing-web-applications-with-this-simple-mvc-framework)

###  Health Score

18

—

LowBetter than 8% of packages

Maintenance54

Moderate activity, may be stable

Popularity0

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity12

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/134638192?v=4)[Feras Altaleb](/maintainers/AltalebFeras)[@AltalebFeras](https://github.com/AltalebFeras)

---

Top Contributors

[![AltalebFeras](https://avatars.githubusercontent.com/u/134638192?v=4)](https://github.com/AltalebFeras "AltalebFeras (19 commits)")

### Embed Badge

![Health badge](/badges/feras-altaleb-mvc-php/health.svg)

```
[![Health](https://phpackages.com/badges/feras-altaleb-mvc-php/health.svg)](https://phpackages.com/packages/feras-altaleb-mvc-php)
```

###  Alternatives

[laravel/dusk

Laravel Dusk provides simple end-to-end testing and browser automation.

1.9k39.6M300](/packages/laravel-dusk)[nineinchnick/edatatables

Grid widget for the Yii Framework, wrapper for the DataTables jQuery plugin

173.2k](/packages/nineinchnick-edatatables)[link-cloud/fast-hyperf

LinkCloud Fast Hyperf

241.2k1](/packages/link-cloud-fast-hyperf)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
