Transformer - falling in love with PHP's magic methods all over again

PHP's magic functions have been around for a long time. But there were always good reasons to avoid them. Transformer is a practical and reliable way to make use of the most common operations we program: CRUD operations.

MVC (or at least the idea) is still one of the most relevant patterns

Implementations reach from very strickt to very loose definitions. But some things are always true: You will write reusable models for every available entity type. This always leads to transactions with a persistent storage (aka database) and the old four letters C.R.U.D - Create Read Update Delete will make the majority of your work. And some things have to be custom, right? I mean, every project has its own ruleset of what happens when what kind of data gets updated, how to validate certain inputs, what to trigger on deletion. Well, what if your model was just that,

A ruleset that defines how CRUD works - and nothing else.

neoan3 has automated routing, why would it stop at models? The challenge with abstraction is always the same: how to simplify without taking away any freedom? Removing the index-model from the core, updating the autoloader and providing the transformer-app as well as enhancing the cli-tool did the trick.

All you need to to is to update your neoan3-cli and you are ready to go.

So, what is the typical application flow? In theory, nothing changed. You will likely receive requests via API endpoints you didn't have to write routing for, you will authorize the call and call the model to retrieve, update, delete or create entities and return a result. The only difference is, your complete code for a particular endpoint could look like this:


namespace Neoan3\Components;

use Neoan3\Apps\Stateless;
use Neoan3\Model\TaskModel;

class Task extends Demo

    function getTask(array $body)
        return $this->executeTransformer('find', $body);

    function postTask(array $body)
        return $this->executeTransformer('create', $body);

    function updateTask(array $body)
         return $this->executeTransformer('update', $body);

    private function executeTransformer($function, $body)
        return TaskModel::$function($body);

The good, the bad, the ugly

You will be pleased to hear that this time test-coverage was 100% before publishing a version. But documentation is still a huge problem and will require some additional time. We would be pleased to see volunteers jump at us, but I know you guys aren't sitting around bored at home either. As a start, this video should give you first insight into what the potential is and how this will further enhance your development speed.


neoan 09/20/2019
It should be noted that auto-loading prior to neoan3 v0.0.2 does not load transformer-files. When working with older versions, you need to require the model's transformer in the model-file itself.

neoan @neoan

632 readers
php crud c.r.u.d mysql lamp neoan3 tutorial mvc model handling
On topic

Install PHP 7.4 on Ubuntu

Finally PHP 7.4 is out! You have read about the new features, you have followed externals, you have gathered ideas on how new capabilities will save time. Let's get it running.

Static content pages - still the fastest web-experience

Tutorial: How to utilize to generate static content for your website.

Scaffolding REST APIs with JWT authentication

Ever had the need for your own backend while developing your web-app?

Git: globally change GitHub-remotes from git@ to https

Does your IDE or composer set remote repositories to ssh rather than https? Or are repositories you are using set up that way? You are not alone. Let's fix it once and for all!

VueJS & neoan3: a love story.

Setting up neoan3 to play nice with Vue isn't hard. Here is how the two frameworks are combined to support fast, dynamic and rapid development.

Install PHP 8 on Ubuntu

PHP8 has finally been released and it is FAAAAST! Time to update.

SEO strategies for

How to get your content listed where you want it to.

MySQL: ERROR1364 fix

The painful realization of why people use containers. PHP SDK

Create your own blog.

How to Build an Express App in Node That Reads From a Headless CMS

A headless CMS lets you design your own front-end, sometimes your own back-end. Let's set up a small application to get us started. Beginner friendly. Approx. 20 min. to reproduce / follow along

MySQL in PHP - how to deal with databases

How I handle MYSQL database transactions in PHP

Cross publishing to

How to publish your content to from - hopefully

How to install global npm packages without sudo on Ubuntu

Running npm on a server can be painful. Privileges are there for a reason, and so is sudo. Running npm with sudo is not the solution.

What is composer?

Composer has become PHP's package & dependency manager. Why you should use it.