PHPackages                             nihad1213/litephp - 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. nihad1213/litephp

ActiveProject[Framework](/categories/framework)

nihad1213/litephp
=================

A lightweight PHP framework for building REST APIS.

v1.2.0(1y ago)05MITPHPPHP &gt;=8.0

Since Apr 21Pushed 10mo ago1 watchersCompare

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

READMEChangelogDependencies (1)Versions (7)Used By (0)

LitePHP Framework
=================

[](#litephp-framework)

[![Downloads](https://camo.githubusercontent.com/1e2eef4dfd151ab4d9ea7bd38455ada4ba65ce03bb5b6364527d710f359a36ad/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6e69686164313231332f6c6974657068702e7376673f6361636865427573743d31)](https://camo.githubusercontent.com/1e2eef4dfd151ab4d9ea7bd38455ada4ba65ce03bb5b6364527d710f359a36ad/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6e69686164313231332f6c6974657068702e7376673f6361636865427573743d31)

LitePHP is a lightweight PHP framework designed for building simple and efficient APIs. It provides a straightforward CLI tool for common development tasks and a minimalist structure for rapid API development.

Installation
------------

[](#installation)

Get started with LitePHP using Composer:

```
composer create-project nihad1213/litephp project_name
```

```
cd project_name
```

```
cp .env.example .env
```

```
php lite generate:key
```

```
php lite start
```

This will install LitePHP, navigate to your new project directory, copy .env.example file to .env, genereate JWT\_SECRET key and start the built-in PHP development server.

CLI Commands
------------

[](#cli-commands)

LitePHP comes with a built-in command-line interface to help you manage your development workflow. Here are the available commands:

### Start Development Server

[](#start-development-server)

```
php lite start
```

Launches the PHP built-in development server at , serving files from the 'api' directory.

### Generate JWT Secret Key

[](#generate-jwt-secret-key)

```
php lite key:generate
```

Creates or updates the JWT\_SECRET in your .env file with a secure random key (32 bytes). This is essential for JWT-based authentication in your API.

### Create a Controller

[](#create-a-controller)

```
php lite create:controller UserController
```

Scaffolds a new controller in the 'controllers' directory with RESTful methods (getAll, getOne, create, update, delete) and basic validation.

### Create a Gateway

[](#create-a-gateway)

```
php lite create:gateway UserGateway
```

Scaffolds a new gateway in the 'gateways' directory. Gateways handle database operations for specific entities, providing a clean separation between controllers and database logic.

### Run Database Migrations

[](#run-database-migrations)

```
php lite db:migrate
```

Executes all SQL files in the 'database' directory in alphabetical order, allowing you to set up and modify your database schema.

Project Structure
-----------------

[](#project-structure)

```
project_name/
├── api/               # API endpoint directory (server root)
│   └── bootstrap.php  # Application initialization file
├── controllers/       # Controller classes for handling API requests
├── gateways/          # Data gateway classes for database operations
├── src/               # Source codes of api
├── database/          # SQL files for database migrations
├── .env               # Environment configuration
└── lite              # CLI tool for development tasks

```

Login Route Integration
-----------------------

[](#login-route-integration)

To add authentication routes to your LitePHP application, you can integrate custom routes in your main `index.php` file. Here's an example of how to add a login route that bypasses normal authentication:

```
// Special case for login route (no authentication needed)
if ($path === "/login") {
    require __DIR__ . '/login.php';
    exit;
}
```

This allows you to create dedicated authentication endpoints that don't require existing authentication, such as login forms or token generation endpoints. Place this code in your main routing logic before other route processing occurs.

Key Components
--------------

[](#key-components)

### Controllers

[](#controllers)

Controllers handle HTTP requests and return appropriate responses. They are responsible for:

- Processing incoming requests
- Validating input data
- Interacting with gateways to perform data operations
- Returning appropriate HTTP responses

Each controller extends the `BaseController` class, which provides common response methods and utilities for handling API requests.

#### Controller Example

[](#controller-example)

```
