TQ
dev.com

Blog about software development

Subscribe

MintyPHP now on packagist!

26 Oct 2018 - by 'Maurits van der Schee'

I have created MintyPHP (formerly known as MindaPHP) to quickly build web applications on the LAMP stack. After using MintyPHP in production for 5 years (this site is created with it) this web framework is (finally) available on packagist! This means that updates will now go automatic with composer. The project is now divided in 4 packages with "MintyPHP" as the main package and 3 dependencies: "core", "tools" and "debugger".

WARNING!

MintyPHP claims to be "refreshingly different", but for some people this is "a bit quirky" or even "completely wrong". It is a web framework with a different approach than other frameworks (such as Laravel, Symfony or Slim). In this post I will try to explain what it does different and why you may like that it does.

OMG, no OOP!

All functionality is implemented in static functions and classes are merely libraries grouping these functions. This approach avoids OOP and this is a good thing. Yes it really is. Watch Brian Will's "Object-Oriented Programming is Bad" presentation if you are in doubt.

Routing based on filenames and directory structure

There is a router, but it is path and filename based. This means that you don't write regular expressions, but you just create files and directories to create routes. You can only create routes in the "pages" directory. You can add a route prefix by creating a directory. Every file you create will either be a "view" or a "controller". Views are identified by the ".phtml" extension, while controllers have the more common ".php" extension.

No ORM, write SQL?!

There is no ORM and no DBAL. It is simple, you just write (MariaDB) queries. They are quite performant and have virtually unlimited possibilities. You will never move away from MariaDB, because MariaDB is free and used at almost every scale. Models are not used as they are an OOP idea. Repositories are really just classes holding named SQL queries. You are free to create these.

View templates and controller parameters in parentheses

The filename of the view contains the name of the template between parentheses (round brackets). The file "hello(default).phtml" is the view for the "hello" action and it uses the "default" template. The file "hello($name).php" is a controller for the "hello" action and between parentheses you see parameter defined. You may invoke this action by requesting the "/hello/world" path. This will execute the controller with the value "world" set in the "$name" variable. This variable is also available in the view that is executed afterwards as both the controller and view are executed within the same variable scope.

PHP as a template language

Your view files are written in PHP and not in Blade or Twig. This is (very) good for performance. The needed security is achieved by static analysis of the executed source code (both the views and controllers). This is only done when debugging to avoid performance problems. The run-time will complain when you use "echo" or "die". The framework also provides you with "e()" a nice escaping echo function and "d()" for printing variables to the debug toolbar (alternative for "var_dump").

Awesome tools built-in

A debugger is built-in and it is designed to be as powerful as Symfony's debug toolbar. From the debugger toolbar you can access the "conventionist" that gives you advice about your database structure. It also gives you access to a database editor "Adminer" (written by Jakub Vrána), which is much better than PHPMyAdmin. There is also a "generator" to create CRUD views and a "configurator" that detects when you need to configure your application parameters (such as database credentials).

Try it

Are you interested in this project? You can find it on Github:

https://github.com/MintyPHP/MintyPHP

Enjoy!


PS: Liked this article? Please share it on Facebook, Twitter or LinkedIn.