PHPackages                             hiyan/phpenalva - 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. hiyan/phpenalva

ActiveProject[Framework](/categories/framework)

hiyan/phpenalva
===============

PHPenalva is a micro php framework for building web applications and simple APIs.

v2.0.0(1y ago)26MITPHPPHP &gt;=8.0.0

Since Nov 29Pushed 11mo ago1 watchersCompare

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

READMEChangelog (3)Dependencies (1)Versions (5)Used By (0)

PHPenalva 𓅓
===========

[](#phpenalva-𓅓)

[![logomarca](public/assets/images/logomarca.png)](public/assets/images/logomarca.png)

### Overview

[](#overview)

PHPenalva is a lightweight PHP micro-framework designed on the Model-View-Controller (MVC) architecture.
Built with simplicity in mind, PHPenalva empowers you to swiftly create APIs and web applications.

**Note**: This project is currently under construction. Please bear with us as we work to make it even better.

### Requirements

[](#requirements)

- **PHP Version**: PHP 7.4 or higher is required.
- **Web Server**: You'll need a web server with URL rewriting enabled.
- **Supported Servers**: PHPenalva plays nicely with Apache, Nginx, and IIS.
- **Database Compatibility**: PHPenalva is compatible with MySQL, MariaDB, PostgreSQL, and SQLite.
- **Platform**: PHPenalva can be used on Linux, Windows, and macOS.

### Installation

[](#installation)

Getting started with PHPenalva is a breeze.
You can install it via Composer with the following command in your project directory:
`composer create-project hiyan/phpenalva your_project_name`

### Development Environment

[](#development-environment)

PHPenalva comes with a pre-configured development environment using Docker, which simplifies the setup and execution of the microframework without the need to install servers and dependencies directly on your machine.

#### How to Use the Development Environment

[](#how-to-use-the-development-environment)

1. **Starting the Environment**: You can start the development environment with the following command. This will launch the necessary Docker containers to run PHPenalva:

    ```
    composer start
    ```

    This command runs `docker compose up -d`, starting the containers with a web server and database ready for use.
2. **Environment Structure**: All Docker environment configurations are located in the `.docker` directory. In this directory, you'll find configuration files like `Dockerfile` and `nginx.conf`, which define how the environment is built and how services (PHP, NGINX, etc.) are configured.
3. **Customization**: If you need to adjust the development environment (e.g., change NGINX settings or add PHP extensions), you can edit the files within the `.docker` directory to customize the environment as needed.
4. **Stopping the Environment**: To stop the development environment, use the following command:

    ```
    composer stop
    ```

    This command runs `docker compose down`, shutting down the running containers.

With this setup, you can focus on developing with PHPenalva without worrying about complex local configurations. Simply run `composer start` to begin and `composer stop` to halt the environment as needed.

These commands make it easy to manage the environment, allowing you to work directly on the project with convenience! 🚀

### Migrations

[](#migrations)

PHPenalva includes a simple migration system that allows you to define and manage your database schema. The migration system is managed through classes and a custom Composer command, making it easy to create tables, modify columns, and keep track of changes over time.

#### How it Works

[](#how-it-works)

1. **Migration Classes**: Each migration is a PHP class stored in the `database/migrations` directory. These classes extend the base class `BaseMigration` and define two methods: `up()` (to apply the migration) and `down()` (to reverse it).
2. **Migration Manager**: The `MigrationManager` class, located in `core`, handles the execution of migrations. It checks for all migration files, applies any new migrations that haven't been executed yet, and logs them in a special table to keep track.
3. **Custom Composer Command**: We’ve added a `composer migrate` command to simplify the execution of migrations. This command looks for all new migrations in the `database/migrations` directory and applies them.

#### Running Migrations

[](#running-migrations)

To apply all pending migrations, simply run:

```
composer migrate
```

This command will create a `migrations` table in the database (if it doesn’t already exist) to keep track of which migrations have been applied. Then, it will execute each migration's `up()` method that hasn't been applied yet.

#### Creating a New Migration

[](#creating-a-new-migration)

1. Create a new file in `database/migrations`, with a name that reflects the purpose of the migration (e.g., `CreateUsersTable.php`).
2. Define a class with the same name as the file and extend `Core\BaseMigration`.

Example of a migration to create a `users` table:

```
