PHPackages                             madmikeyb/neutron - 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. madmikeyb/neutron

ActiveProject[Framework](/categories/framework)

madmikeyb/neutron
=================

Neutron PHP Framework

0.0.3(2mo ago)19BSD-2-ClausePHP

Since Sep 23Pushed 2mo ago1 watchersCompare

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

READMEChangelogDependencies (12)Versions (4)Used By (0)

Neutron Framework
=================

[](#neutron-framework)

**Neutron** is a lightweight PHP micro-framework built with a focus on simplicity, modularity, and flexibility. It leverages modern PHP libraries for routing, templating, and logging to create a clean and efficient development experience.

---

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

[](#table-of-contents)

- [Features](#features)
- [Requirements](#requirements)
- [Installation](#installation)
- [Directory Structure](#directory-structure)
- [Usage](#usage)
    - [Running the Application](#running-the-application)
    - [Routes](#routes)
    - [Controllers](#controllers)
    - [Handling Request Methods and Parameters](#handling-request-methods-and-parameters)
        - [GET Parameters](#get-parameters)
        - [POST Parameters](#post-parameters)
        - [PUT and PATCH Requests](#put-and-patch-requests)
        - [DELETE Requests](#delete-requests)
    - [Templates](#templates)
    - [Logging](#logging)
- [Working with Console Commands](#working-with-console-commands)
    - [Setting Up Console Commands](#setting-up-console-commands)
    - [Auto-Loading Commands](#auto-loading-commands)
    - [Registering a Command](#registering-a-command)
    - [Running Commands](#running-commands)
    - [Using Input Arguments and Options](#using-input-arguments-and-options)
- [Generating Migrations](#generating-migrations)
    - [Example](#example)
- [Running Migrations](#running-migrations)
- [Using the ORM](#using-the-orm)
    - [Retrieving All Records](#retrieving-all-records)
    - [Retrieving a Single Record](#retrieving-a-single-record)
    - [Filtering Records with `where()`](#filtering-records-with-where)
    - [Ordering Records with `orderBy()`](#ordering-records-with-orderby)
    - [Limiting Results with `limit()` and `offset()`](#limiting-results-with-limit-and-offset)
    - [Checking if a Record Exists with `exists()`](#checking-if-a-record-exists-with-exists)
    - [Inserting a New Record](#inserting-a-new-record)
    - [Updating an Existing Record](#updating-an-existing-record)
    - [Deleting a Record](#deleting-a-record)
    - [Building Queries without Executing Them (with `toSql()`)](#building-queries-without-executing-them-with-tosql)
- [Debugging](#debugging)
- [Environment Variables](#environment-variables)
- [Contributing](#contributing)
- [License](#license)
- [Future Improvements](#future-improvements)

---

Features
--------

[](#features)

- **Routing**: Configurable routing using `league/route`.
- **Templating**: Render templates using `twig/twig`.
- **Logging**: Powerful logging using `monolog/monolog`.
- **Environment Variables**: Manage environment configuration using `vlucas/phpdotenv`.
- **Error Handling**: Improved error pages with `filp/whoops`.
- **Dumping**: Integrated debugging with Symfony’s `var-dumper`.
- **Console**: Application Console using Symfony’s `console`.
- **Models/Migrations/ORM**: Simple Model/Migration/ORM system using PDO and basic SQL files.

---

Requirements
------------

[](#requirements)

- **PHP 8.4+**
- **Composer** (for dependency management)

---

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

[](#installation)

1. Clone the repository:

    ```
    git clone https://github.com/madmikeyb/neutron.git
    ```
2. Navigate into the project directory:

    ```
    cd neutron
    ```
3. Install dependencies using Composer:

    ```
    composer install
    ```
4. Set up your environment variables:

    Copy the example `.env` file to set up environment variables:

    ```
    cp .env.example .env
    ```
5. Update your `.env` file with the necessary configuration:

    ```
    APP_ENV=development
    APP_DEBUG=true
    LOG_CHANNEL=app
    ```

---

Directory Structure
-------------------

[](#directory-structure)

```
/neutron
├── composer.json       # Composer dependencies
├── .env                # Environment configuration
├── neutron             # Console Application entry-point
├── database            # Database storage (SQLite, contents gitignored)
├── logs                # Log files (ignored by Git, but directory tracked)
├── migrations          # Database migrations
├── public              # Publicly accessible files (index.php)
├── src                 # Application source code (controllers, core framework, routes)
│   ├── Command         # Commands for handling console requests
│   ├── Console         # Console core application classes
│   ├── Controller      # Controllers for handling requests
│   ├── Database        # Database ORM classes
│   ├── Models          # Models for interacting with the ORM
│   ├── Neutron.php     # Core framework class
│   ├── console.php     # Console Router
│   └── routes.php      # HTTP Router
└── views               # Twig templates

```

---

Usage
-----

[](#usage)

### Running the Application

[](#running-the-application)

To run the application locally, use PHP's built-in server:

```
php -S localhost:8000 -t public
```

Visit  in your browser to see the application running.

---

### Routes

[](#routes)

Routes are defined in `src/routes.php`. Here is an example of how a route can be defined:

```
$router->map('GET', '/home', [HomeController::class, 'index']);
```

---

### Controllers

[](#controllers)

Controllers are located in the `src/Controller` directory. A typical controller extends the `BaseController` and uses dependency injection for services like logging and rendering.

Example:

```
