Ashan Ghimire
Ashan Ghimire
Introducing Elementary: A modern PHP micro-framework

Introducing Elementary: A modern PHP micro-framework

Hello PHP Devs!


Router::middleware('auth')->prefix('/admin')->group(function () {
	Router::get('/', AdminController::class . '@dashboard')->name('admin.dashboard');
});

class AdminController extends AbstractController {

	public function dashboard(Request $request): Response 
	{
		
		$sales = Order::query()->where('status', '=', 'paid')->get();
		
		return $this->render('admin/dashboard', [
			'sales' => $sales
		]);
	}
}


@extends('layouts/admin')


@section('content')

	<h1> Sales Report </h1>

	@foreach(...)
		@if(...)
		
		@endif
	@endforeach

@endsection

Does this ring a bell? You'll be surprised to know that the Request, Response and everything else does not come from some Symfony or Laravel packages. It's all custom, yet everything follows the same patterns that we have come to love as a PHP community.

Why?

Sometimes, you just want the basic toolset to do small things. Maybe you need a few API endpoints without trading off the familiarity of frameworks like Laravel, Symfony etc. Maybe you just need a page or two of dynamic content and you don't want to burden with countless dependencies, yet you still want to use the framework because you're used to writing code in a particular way.

This is where Elementary comes in. I developed this framework in a way that it uses one production dependency (psr/container which is not even a real package, let's be honest). For dev environment, you have (filp/whoops) in addition with the container interface for pretty error messages. That's it.

Of course this is very early days for elementary and a lot more needs to be done, but before you say no, check out elementary for more information. You might even learn something new.

Till next time, Aashan

Comments

No comments yet. Be the first one to comment.

Leave a comment

Name
Email
Comment