DEV Community

Cover image for MightyPHP - Not just another PHP Framework
Desmond Chin
Desmond Chin

Posted on

MightyPHP - Not just another PHP Framework

Introduction

Plenty of times, I had come into projects that uses the typical PHP frameworks, ranging from CodeIgniter, to Symfony, and mostly Laravel. From experiences of using such frameworks, I grew tiresome of having to dive into complexed features; which in my opinion is great for full fledged frameworks, but it takes away the joy.

There were times I wish I could port some nice features or concepts from other frameworks or languages, such as how middlewares were used in ExpressJS, the Include method of Entity Framework Core from .NET Core and many more, while at the same time wishing some features from existing frameworks to be gone.

That is how I had decided to build a solution to my problem; MightyPHP. What started as a tiny hobby project, slowly grew into something I think could go further.

In this article, I will be highlighting briefly on the concepts and features of MightyPHP as of current version, v1.0.0, released just recently. See it, as if it is some sort of a trailer.

Philosophy / Concepts

Designed to Be Bare

A lot of frameworks out there tend to overcomplicate things; not intentionally, but done so to help you achieve more. However, I prefer many things better, bare. MightyPHP aims at not having you to configure a whole lot. Things are there as it is. There will always be only one method for a purpose, and it stays as it is.

Clean & Neat

When we write too much, not only do we introduce bugs, we mess up the readability of the code. What takes up most estate in our editors or IDEs? In my opinion; variables.

An example of class initialization in MightyPHP

class FooController extends Controller
{
    public function bar(Request $request, UserModel $userModel){
        echo $request->query("name");
        $userModel->get();
    }
}
Enter fullscreen mode Exit fullscreen mode

Reduce variable declaration for classes, get it on the get go!

Highlights

ExpressJS-liked Middlewares

I like how middlewares are used in routes in ExpressJS; clean, readable, straight to the point.

$index = new Router('/');
$index->use(["VerifyCsrf", "Foo"]);
Enter fullscreen mode Exit fullscreen mode

Want middlewares only at certain routes? Why not.

$index = new Router('/');
$index->get('/profile', 'UserController@profile')->use('CheckAuth');
Enter fullscreen mode Exit fullscreen mode

Query Builders

Nothing fancy, here just for the sake of being mainstream. A common but crucial feature for any framework!

class UsersModel extends Model
{
    public function get(){
        return $this->select('name', 'age')->get();
    }
}
Enter fullscreen mode Exit fullscreen mode

Want to include child(ren) item(s) into your model objects? Use include!

class UsersModel extends Model
{
    public function get(){
        return $this->select('name', 'age')
               ->include((new UserProfiles()))
               ->get();
    }
}
Enter fullscreen mode Exit fullscreen mode

Console Commands

Like Laravel's artisan? We have mighty. This feature is still under development. Usable, but not pretty.

Example: to scaffold a controller,

php mighty make:controller UserController
Enter fullscreen mode Exit fullscreen mode

Migration & Seeding

Ease of maintaining databases and tables. Example of seeding:

use \Application\Models\UsersModel;             
class seed_user{
    public function plant(){
        $date = date('Y-m-d');
        $password = password_hash('admin', PASSWORD_DEFAULT);

        $user = new UsersModel();
        $user->insert([
            "users_email" => "admin@admin.com",
            "users_password" => $password,
            "users_createdAt" => $date,
            "users_modifiedAt" => $date
        ]);
    }
}
Enter fullscreen mode Exit fullscreen mode

What else? What's to come?

MightyPHP's first version has just been released. Efforts will be going into growing it, and making it better; in hopes that it would grow into an alternative for the bunch of PHP frameworks out there that is offering different sets of solutions.

As of currently, MightyPHP does not support cross-database query builder or ORM, but is indeed in the pipelines of what is to come. Support is currently only for MySQL or MariaDB databases. Even currently, there are already development on-going for Schematics which will be catering for cross-database migrations in the future; which now still heavily relies on raw MySQL queries in that aspect.

Where or how to try out MightyPHP?

Head over to the official site at https://mightyphp.com or go straight to the documentations at https://docs.mightyphp.com (Documentations are still in progress but at least 75% of the required contents are there)

Top comments (4)

Collapse
 
mayowa profile image
mayowa • Edited

I havent used php in a very long while, but this might just tempt me back for certain projects.

Thank you.

Collapse
 
femolacaster profile image
femolacaster

Beautiful.

Collapse
 
blackforestcode profile image
Nils Domin

Great job!

Collapse
 
desmondchoon profile image
Desmond Chin

Thanks!