What do you think about middleware approach?

Yes. It’s something that may be very useful.

1 Like

Think it would be very useful. For example Laravel has a middleware EmptyStringsToNull (or something) which automatically sets all empty strings in POST requests to null, removing the need to do things like [‘attribute’, ‘default’, null] in models … would save a lot of time (would be nice to be able to do this in yii2)

I was thinking of putting the complete business logic into the middleware pipeline, making a controller action return a list with middleware objects which are then processed by the framework. The purpose being making all actions pure methods and easier to test.

Interesting but that doesn’t sound like PSR middleware that deals with request-response.

No, it also deals with a pipeline payload and any extra commands returned from each command, like

function ($payload) {
  // Do things
  return [$newPayload, [new commands...]];
}

Related to middleware, maybe a unified approach can be found. :slight_smile: