2017 © Pedro Peláez
 

library expressive-prg

Middleware to implement the Post/Redirect/Get pattern in Zend Expressive

image

netglue/expressive-prg

Middleware to implement the Post/Redirect/Get pattern in Zend Expressive

  • Tuesday, March 21, 2017
  • by netglue
  • Repository
  • 1 Watchers
  • 1 Stars
  • 37 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Post/Redirect/Get Middleware for Zend Expressive

Intro

This is simple middleware that'll help you implement the PRG pattern in your Zend Expressive app., (*1)

Based on the original Zend Framework PRG controller plugin., (*2)

Uses Zend\Session but performs no configuration of the session itself. I figured this was a sane choice for session management. If you know of a standard session library to typehint against, let me know, but afaik there isn't one…, (*3)

Installation

$ composer require netglue/expressive-prg

Usage

First you'll need to register the middleware with your DI container as an invokable with something like:, (*4)

// use NetglueExpressive\Middleware\PostRedirectGet;

'dependencies' => [
    'invokables' => [
        PostRedirectGet::class => PostRedirectGet::class
    ],
],

Add the middleware to your routes whenever you want to perform a PRG something like this:, (*5)

'routes' => [
    'some-form' => [
        'name' => 'some-form',
        'path' => '/somewhere',
        'allowed_methods' => ['GET', 'POST'],
        'middleware' => [
            PostRedirectGet::class
            // Your middleware to post process, render templates etc…
        ],
    ],
],

Inside your action, the request will have an attribute prg set to either false or the posted data (If any), for example:, (*6)

$post = $request->getAttribute('prg');
if (false === $post) {
    // No POST has occurred, probably render the form template
}

// Otherwise, process POST data, validate, store, whatever…

The request attribute name is defined as a constant in PostRedirectGet::KEY, (*7)

It is possible for the attribute to be null if the request is neither a GET, nor a POST request and your route allows other methods such as PUT, DELETE etc…, (*8)

Tests

$ cd vendor/netglue/expressive-prg
$ composer install
$ phpunit

About

Netglue makes web based stuff in Devon, England. We hope this is useful to you and we’d appreciate feedback either way :), (*9)

The Versions

21/03 2017

dev-master

9999999-dev https://github.com/netglue/Expressive-PRG

Middleware to implement the Post/Redirect/Get pattern in Zend Expressive

  Sources   Download

MIT

The Requires

 

The Development Requires

zend expressive prg netglue

21/03 2017

1.0.1

1.0.1.0 https://github.com/netglue/Expressive-PRG

Middleware to implement the Post/Redirect/Get pattern in Zend Expressive

  Sources   Download

MIT

The Requires

 

The Development Requires

zend expressive prg netglue

27/09 2016

1.0

1.0.0.0 https://github.com/netglue/Expressive-PRG

Middleware to implement the Post/Redirect/Get pattern in Zend Expressive

  Sources   Download

MIT

The Requires

 

The Development Requires

zend expressive prg netglue