PHPackages                             wardvisual/warvilphp - 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. wardvisual/warvilphp

ActiveProject[Framework](/categories/framework)

wardvisual/warvilphp
====================

A lightweight PHP framework inspired by Laravel

0.1.0-alpha(11mo ago)2141MITPHPPHP ^8.0CI passing

Since May 31Pushed 11mo ago1 watchersCompare

[ Source](https://github.com/wardvisual/warvilphp)[ Packagist](https://packagist.org/packages/wardvisual/warvilphp)[ GitHub Sponsors](https://github.com/wardvisual)[ RSS](/packages/wardvisual-warvilphp/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

WarvilPHP Framework
===================

[](#warvilphp-framework)

A **lightweight PHP framework** inspired by Laravel, designed for developers who appreciate simplicity and direct access to the PHP language.

[![WarvilPHP](https://raw.githubusercontent.com/wardvisual/warvilphp/refs/heads/main/public/assets/warvilphp.jpg)](https://raw.githubusercontent.com/wardvisual/warvilphp/refs/heads/main/public/assets/warvilphp.jpg)

 [![PHP Version](https://camo.githubusercontent.com/61db959311c6900dc73913c7cb7215fc1cea50eb7062b56d96809752d07ba7cd/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d76382e302b2d626c75652e737667)](https://camo.githubusercontent.com/61db959311c6900dc73913c7cb7215fc1cea50eb7062b56d96809752d07ba7cd/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d76382e302b2d626c75652e737667) [![License](https://camo.githubusercontent.com/784362b26e4b3546254f1893e778ba64616e362bd6ac791991d2c9e880a3a64e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d677265656e2e737667)](https://camo.githubusercontent.com/784362b26e4b3546254f1893e778ba64616e362bd6ac791991d2c9e880a3a64e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d677265656e2e737667) [![Status](https://camo.githubusercontent.com/4fd94d801908ac5d22608edaa763761f0fb767357609b4e0867aa05dfe9f7026/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5374617475732d416c7068612d7265642e737667)](https://camo.githubusercontent.com/4fd94d801908ac5d22608edaa763761f0fb767357609b4e0867aa05dfe9f7026/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5374617475732d416c7068612d7265642e737667) [![API Stability](https://camo.githubusercontent.com/8f1c74ff7119b0c9c85c7218b78db8350aa03b99e0289ae77ae79640344d4d1a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4150492d556e737461626c652d6f72616e67652e737667)](https://camo.githubusercontent.com/8f1c74ff7119b0c9c85c7218b78db8350aa03b99e0289ae77ae79640344d4d1a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4150492d556e737461626c652d6f72616e67652e737667)

📋 Table of Contents
-------------------

[](#-table-of-contents)

- [Introduction](#-introduction)
- [Project Status](#-project-status)
- [Roadmap to Production Readiness](#-roadmap-to-production-readiness)
- [Features](#-features)
- [Requirements](#-requirements)
- [Installation](#-installation)
- [Directory Structure](#-directory-structure)
- [Configuration](#-configuration)
- [Environment Variables](#-environment-variables)
- [Command Line Interface](#-command-line-interface)
- [Routing System](#-routing-system)
- [Controllers](#-controllers)
- [Views](#-views)
- [Models](#-models)
- [Components](#-components)
- [Middleware](#-middleware)
- [Database Migrations](#-database-migrations)
- [API Development](#-api-development)
- [File Storage](#-file-storage)
- [Contributing](#-contributing)
- [License](#-license)

🌟 Introduction
--------------

[](#-introduction)

WarvilPHP is a lightweight MVC framework for PHP applications. It provides a clean and elegant syntax similar to Laravel but with a smaller footprint and more direct access to PHP. The framework helps you build web applications quickly without the complexity of larger frameworks.

### The Story Behind WarvilPHP

[](#the-story-behind-warvilphp)

WarvilPHP was born out of necessity and a passion for efficient development. While working on numerous PHP projects, I found myself repeatedly recreating the same foundational structure - routing systems, database abstractions, and templating logic. This repetition felt inefficient, yet I wasn't satisfied with the complexity and overhead of existing frameworks.

I wanted something that maintained the directness and flexibility of pure PHP while providing the structure and convenience of a framework. Something that would embrace PHP's strengths rather than hide them behind layers of abstraction.

After refining this structure across multiple projects, I realized that this middle-ground approach could benefit other developers who shared my appreciation for PHP's simplicity. WarvilPHP represents that balance - a framework that provides helpful structure and tools without getting in your way or forcing you into restrictive patterns.

This framework is now open source, I'm open-sourcing WarvilPHP to help developers who want to build PHP applications with a clean architecture but without sacrificing the power and directness that made us fall in love with PHP in the first place.

🚦 Project Status
----------------

[](#-project-status)

> **⚠️ Development Status: Pre-release**
>
> WarvilPHP is currently in **pre-release development stage**. While the framework includes many functional features, it is not yet recommended for production environments or critical applications.
>
> Following semantic versioning standards:
>
> - Current releases (v0.x.x) are considered development/alpha versions
> - Future v1.0.0 will mark the first stable, production-ready release
>
> We encourage developers to explore WarvilPHP for personal projects, learning purposes, or non-critical applications. Your feedback during this phase is invaluable to the project's growth!

🗺️ Roadmap to Production Readiness
----------------------------------

[](#️-roadmap-to-production-readiness)

We're following semantic versioning (semver.org) with a clear path to a stable v1.0.0 release:

- **v0.1.0-alpha** (Current)

    - Initial framework architecture
    - Basic MVC implementation
    - Routing system for web and API
    - Command line interface
    - Development server via `php warvil serve`
    - View templating and components
- **v0.2.0-alpha**

    - Enhanced database ORM functionality
    - Improved middleware system
    - Extended validation capabilities
    - File storage improvements
    - Authentication scaffolding
- **v0.5.0-beta**

    - Complete test coverage for core components
    - Performance optimization
    - Security hardening
    - Comprehensive error handling
    - Extended documentation with examples
- **v0.9.0-rc** (Release Candidate)

    - Feature-complete implementation
    - Production deployment guides
    - API stabilization
    - Backward compatibility guarantees
- **v1.0.0** (Stable Release)

    - Production-ready code
    - Complete documentation
    - Long-term support plan
    - Community-tested in various environments

After v1.0.0, we will strictly follow semantic versioning:

- MAJOR version for incompatible API changes (v2.0.0)
- MINOR version for backwards-compatible functionality (v1.1.0)
- PATCH version for backwards-compatible bug fixes (v1.0.1)

We welcome contributors to help us reach these milestones faster! See our [Contributing](#-contributing) section for details on how to get involved.

✨ Features
----------

[](#-features)

- **🏗️ MVC Architecture**: Clean separation of Model, View and Controller
- **🌐 Routing System**: Simple and intuitive routing for both web and API endpoints
- **🗄️ Database ORM**: Lightweight database abstraction and query building
- **🔧 CLI Commands**: Built-in command line tools for scaffolding
- **🧩 Component-based Views**: Reusable view components
- **🛡️ Middleware Support**: Request filtering capabilities
- **🔁 API Response Handling**: Tools for building RESTful APIs
- **🔐 Environment Variables**: Secure configuration management
- **📁 File Storage**: Simple file storage management

🛠️ Requirements
---------------

[](#️-requirements)

- PHP 8.0 or higher
- Composer
- MySQL Database
- PDO PHP Extension
- JSON PHP Extension
- FileInfo PHP Extension

🚀 Installation
--------------

[](#-installation)

### Option 1: Via Composer Create-Project

[](#option-1-via-composer-create-project)

```
composer create-project wardvisual/warvilphp your-project-name
cd your-project-name
composer serve
```

📂 Directory Structure
---------------------

[](#-directory-structure)

```
warvilphp/
├── app/                  # Application code
│   ├── controllers/      # Controllers
│   ├── core/             # Framework core files
│   │   ├── utils/        # Framework utilities
│   ├── database/         # Database files
│   │   ├── sql/          # SQL migrations
│   │   ├── factories/    # Model factories
│   ├── middlewares/      # Middlewares
│   ├── models/           # Models
│   ├── routes/           # Route definitions
│   ├── services/         # Service classes
│   ├── shared/           # Shared components
│   │   ├── components/   # View components
│   │   ├── layouts/      # View layouts
│   │   ├── errors/       # Error pages
│   ├── traits/           # PHP traits
│   ├── views/            # Views
│   ├── [bootstrap.php]   # Application bootstrap
│   └── [init.php]        # Manual initialization
├── bin/                  # Binary/executable files
│   ├── install           # Installation script
│   ├── warvil            # CLI command runner
│   └── [warvil.bat]      # Windows CLI command runner
├── cli/                  # CLI command definitions
├── public/               # Publicly accessible files
│   ├── assets/           # Assets (images, fonts)
│   ├── js/               # JavaScript files
│   ├── styles/           # CSS files
│   └── uploads/          # Uploaded files
├── vendor/               # Composer packages
├── .env                  # Environment variables
├── [.env.example]        # Environment example
├── .gitignore            # Git ignored files
├── .htaccess             # Apache configuration
├── [composer.json]       # Composer configuration
├── [index.php]           # Application entry point
└── [warvil.json]         # Framework configuration

```

⚙️ Configuration
----------------

[](#️-configuration)

WarvilPHP uses a JSON configuration file (warvil.json) for application settings

```
  "name": "warvilphp",
  "version": "1.0.0",
  "description": "WarvilPHP, A lightweight PHP framework",
  "author": "Wardvisual ",
  "keywords": ["php", "framework", "warvilPHP"],
  "database": {
    "driver": "mysql",
    "host": "localhost",
    "dbname": "your_database",
    "username": "root",
    "password": ""
  },
  "paths": {
    "public": "public",
    "controllers": "app/controllers",
    "models": "app/models",
    "views": "app/views"
  }
}
```

🔐 Environment Variables
-----------------------

[](#-environment-variables)

Sensitive configuration like database credentials should be stored in the .env file:

```
APP_NAME=WarvilPHP
APP_ENV=local
APP_DEBUG=true
APP_URL=http://localhost
APP_KEY=base64:your-random-key-here

DB_DRIVER=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=warvilphp
DB_USERNAME=root
DB_PASSWORD=

STORAGE_DIRECTORY=/public/uploads
STORAGE_MAX_SIZE=1000000
```

Generate a secure application key:

```
php warvil key:generate
```

🖥️ Command Line Interface
-------------------------

[](#️-command-line-interface)

WarvilPHP comes with a command-line tool called warvil for scaffolding components:

#### Development

[](#development)

```
# Start development server
php warvil serve
# OR with custom host and port
php warvil serve localhost 3000

# Show help
php warvil help
```

#### Generator Commands

[](#generator-commands)

```
# Create a controller
php warvil make:controller UserController

# Create a model
php warvil make:model User

# Create a view
php warvil make:view users/index

# Create a middleware
php warvil make:middleware Auth

# Create a component
php warvil make:component buttons/primary

# Create a service
php warvil make:service UserService

# Create an API controller
php warvil make:api ProductController

# Create a layout
php warvil make:layout admin

# Create a database table schema
php warvil make:table Users
```

#### Database Commands

[](#database-commands)

```
php warvil migration:run User:up
```

#### Utility Commands

[](#utility-commands)

```
# Generate an application key
php warvil key:generate
```

🌐 Routing System
----------------

[](#-routing-system)

WarvilPHP has two types of routes: web routes and API routes.

Web Routes (app/routes/web.php)

```
use app\core\Router;

// Simple route with controller and method
Router::get('/', 'Home', 'index');

// Route with callback function
Router::get('/about', null, function() {
    echo 'About page';
});

// Route with POST method
Router::post('/contact', 'Contact', 'submit');
```

API Routes (app/routes/api.php)

```
use app\core\RouterApi;

// API routes are automatically prefixed with /api
RouterApi::get('/', 'HomeController', 'index');
RouterApi::post('/users', 'UserController', 'store');
```

🎮 Controllers
-------------

[](#-controllers)

Controllers handle request logic and return responses:

```
namespace app\controllers;

use app\core\Controller;
use app\core\Request;
use app\core\Response;
use app\models\User;

class UserController extends Controller
{
    public function index(): void
    {
        $users = (new User())->all();
        $this->view('users/index', ['users' => $users]);
    }

    public function store(): void
    {
        $data = Request::validate([
            'name' => 'required|min:3',
            'email' => 'required|email',
        ]);

        $user = new User();
        $user->create($data);

        Response::json([
            'success' => true,
            'message' => 'User created successfully'
        ]);
    }
}
```

👁️ Views
--------

[](#️-views)

Views are PHP files that contain HTML with embedded PHP code:

```

    Users

```

Layouts Layouts provide a template for your views:

```

DOCTYPE html>
