JustSteveKing

Consultant CTO, Software Engineer, Community Advocate

2 min read

Slim4 - A lightweight breath of fresh air

JustSteveKing

My first introduction into frameworks in the PHP world started with the Slim Framework and I fell in love instantly, this was nearing the end of Slim version 1. The freedom it gave it defining my application architecture and the possibilities ahead of me were very appealing.

Since then I have spent a lot of time in a lot of different frameworks and languages, most recently Laravel for the past 4-5 years or so. Laravel is a fantastic framework, it allows you to create almost anything in a short space of time. For a developer who has been under pressure in a start up that is racing to the go live date to secure investment so the team can get paid - the appeal was obviously there. Laravel is a fantastic framework, and I often recommend it to developers looking to get started with being "better" at PHP. With that being said, I find that the framework does a lot of the heavy lifting for you and you lose full control - at least easily. Obviously you can override a lot of Laravel, given enough time and inclination - the question becomes should you.

This is why every now and then I like to deviate from the usual Laravel work I tend to do with a lot of my clients. Sometimes I write pure PHP - like when creating a new package. Other times I dive into languages like GoLang or nodeJS, or maybe a framework like feathersJS (which is a fantastic framework). No matter what I do I always circle back to Slim PHP, the sense of freedom I get using it, and the enjoyment of building all the behind the scenes magic.

So, Slim framework version 4. The key concept seems to be create a fantastic HTTP messaging application which fully supports the major PSRs and leave the other decisions to the implementation. A lot of people struggle with this part of it, especially if they come from a framework like Yii, Laravel, Symfony, Cake, etc etc. A lot of developers will instantly reach for the Model View Controller (MVC) design pattern because it is what they know and what they are used to - plus the fact it seems to be the industry standard right now.

When Slim 4 was released it came with a new and updated version of the slim skeleton which had a few people confused, as the new project lead showed the power and flexibility of the framework by opting for a Domain Driven Design example for people to use. In the community and slack channels there were many questions about doing things using this skeleton project, as they weren't completely familiar with some of the concepts or how to extend it into something more useable.

In future articles I will be building up a new Slim application using Slim 4, using something other than MVC - stay tuned for more!

© 2020 Steve McDougall. All rights reserved.