Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Zend Framework Blog:
REST Representations for Expressive
Aug 09, 2017 @ 10:12:18

On the Zend Framework blog there's a new post from project lead Matthew Weier O'Phinney covering REST representations in Expressive and the release of two new components to help with their implementation.

We've been working towards our various Apigility on Expressive goals, and have recently published two new components: zend-problem-details and zend-expressive-hal.

These components provide response representations for APIs built with PSR-7 middleware. Specifically, they provide: Problem Details for HTTP APIs (RFC 7807) and Hypertext Application Language (HAL).

These two formats provide both JSON and XML representation options (the latter through a secondary proposal).

The post then goes on to talk about the idea of "representations" and how it relates back to the structure of the data returned and how the user knows what operations they can take on it. He also talks about the differences between normal responses and errors and gives example output helping to illustrate his points. The remainder of the post gets into the details of the two new components, their use and how to implement them in Expressive.

tagged: zendexpressive rest representation data structure response api component tutorial

Link: https://framework.zend.com/blog/2017-08-08-expressive-rest-representations.html

Master Zend Framework:
How to Create a Zend Expressive Module
Jul 26, 2017 @ 11:14:52

On the Master Zend Framework site Matthew Setter has written up a tutorial showing you how to create a Zend Expressive module to help organize your application and keep related files all in one place.

I've been reflecting recently on the things that I commonly have to do when I begin building Zend Expressive applications. Of the list that I created, I found that one of the most common — and uninteresting — of them is setting up the rendering of static page content. [...] To solve this, I've usually manually created modules to handle the rendering of static page content. These module's usually had little more than a PageAction class that returned an HtmlResponse object, whose body was a rendered template file.

[...] If you're in a similar position to where I was and want to collate the logic into a reusable module, then follow along with me in this tutorial I'm going to step you through how to create a module which you can reuse across any Zend Expressive project.

He starts by briefly describing a "module" in the context of a Zend Expressive application and how they relate (or don't) to the modules in Zend Framework v2. He then starts in on the module creation, showing how to set up the environment, change the Composer configuration to autoload correctly and describes what the end result should look like. From there the tutorial starts on the code required for the classes covering the basics of the class, exception handling, configuration and the creation of a factory to make a module instance.

tagged: zendexpressive tutorial module static content zendframework

Link: http://www.masterzendframework.com/create-a-zend-expressive-module/

Master Zend Framework:
How to Migrate from Zend Expressive Version 1 to 2 with Command-Line Tooling
Jun 27, 2017 @ 10:43:30

On the Master Zend Framework site Matthew Setter has written up a new tutorial showing you how to migrate from Zend Expressive v1 to v2 with the help of some command line tooling support provided as a part of recent updates to the project.

In part one of this series, we started learning about the tooling support available for Zend Expressive, provided by Zend Expressive Tooling There, we learned how we can use the package to create, register, and deregister middleware, and scaffold new modules. But that's only half of what the package can do.

Here, in part two, let's learn about the other half, which removes some of the heavy lifting required when migrating Zend Expressive applications from version one to two.

He first defines some of the main differences between the two versions, a checklist of things the tooling will help you more automagically update. He talks more specifically about migration support, moving to "programatic pipelines" in Expressive v2 and scanning for deprecated error middleware. There's also information about locating the legacy request and response handling and how they're refactored to the newer format.

tagged: tutorial zendexpressive zendframework migrate version update tooling commandline

Link: http://www.masterzendframework.com/tooling/migrating-to-version-2/

Master Zend Framework:
Create Modules and Middleware with Command-Line Tooling Support
Jun 12, 2017 @ 10:44:05

The Master Zend Framework site has posted a new tutorial covering an aspect of the Zend Expressive project that doesn't seem to get enough coverage: the tooling included with the skeleton application.

For the longest time, Zend Framework hasn't had the strongest command-line tooling and scaffolding support. In stark contrast, other frameworks — especially Laravel, and its excellent Artisan command — have had far stronger tooling support and as a result have been far easier to build projects with. However, that's all changed!

Since the release of Zend Expressive Skeleton 2.0.2, Zend Expressive's command-line tooling support has been rapidly developing. It's provided through a package called, aptly, Zend Expressive Tooling.

The post briefly describes what features the tooling brings and then gets right into the installation process (via Composer). The tutorial then walks you through the commands it provides to create middleware, modules and handle migration to latest versions of the framework. The module and middleware topics are then covered more in-depth, showing code and commands required.

tagged: zendexpressive tooling middleware module commandline tutorial

Link: http://www.masterzendframework.com/tooling/create-modules-and-middleware/

Alejandro Celaya:
How to customize "not found" and "method not allowed" response prototypes in Zend
May 31, 2017 @ 10:10:23

Alejandro Celaya has posted a new tutorial on his site showing how you can customized the "not found" and "not allowed" responses in a Zend Expressive v2 application based on the needs of your application.

Sometimes the nature of an application requires you to change the default framework's way to structure error responses (like 404 and 405).

On this article I'm going to explain how to customize those responses when working with Zend Expressive 2. [...] In Expressive 1, error handling was different. [...] In expressive 2, the error handler is gone, replaced by a middleware which catches exceptions and lets you generate error responses.

He notes that this new middleware approach (moving away from the error handler) doesn't deal with 404 and 405 errors anymore, they've been split out into other functionality. As these other middleware options allow for a custom PSR-7 response object to be injected, he sets up two "delegates" that will more correctly handle the response. He includes the examples code for these and shows how to hook them into the current Expressive execution flow.

tagged: zendexpressive tutorial customize notfound methodnotallowed response custom psr7

Link: https://blog.alejandrocelaya.com/2017/05/28/how-to-customize-not-found-and-method-not-allowed-response-prototypes-in-zend-expressive-2/

Zend Framework Blog:
Leverage Zend Component Plugin Managers in Expressive
May 19, 2017 @ 09:58:15

The Zend Framework blog has a new post from project lead Matthew Weier O'Phinney showing how you can use plugin managers in Expressive and how it can be used to integrate other components.

With the release of Expressive 2, one of the key stories was the ability to require ZF components within Expressive, and have their dependencies auto-wired into your application courtesy of the component installer.

However, we recently had a user in our Slack channel (need an invite?) indicating they were having issues with usage of custom validators, filters, and input filters. After a <a href=https://discourse.zendframework.com/t/validatormanager-not-calling-custom-validator-factory/109">more thorough writeup on our forums, I realized we'd missed something important when making these integrations, and set out to solve it.

The article then starts with the problem that they're trying to solve, mostly around configuration handling. The solution involved some work done on various packages (like zend-log, zend-filter and zend-form) to make the configuration loading a bit more automated (and with fallback handling).

tagged: zendexpressive module component manager update package

Link: https://framework.zend.com/blog/2017-05-18-plugin-managers.html

Master Zend Framework:
Announcing the new Zend Expressive Essentials Book & Course
May 16, 2017 @ 09:45:18

If you've ever wanted to get into the world of Zend Expressive and haven't known where to start, Matthew Setter is offering something that might just fit the bill. He's announced a new course and book that introduces you to the framework and the essentials to get up and running quickly.

Perhaps you've not seen the news on Twitter, Facebook, or the mailing list. If so, you may not know that I'm actively working on a new book and course about Zend Expressive.

It's called: Zend Expressive Essentials.

Ever since ZendCon 2016, I've been thinking about turning my Zend Expressive talk into a book and course. I had a load of reasons both for and against. But I just couldn't shake the excitement around doing so. And have decided to do it!

His post talks about some of what the course and book will cover, providing a solid foundation for getting up to speed with Zend Expressive. The course/book is coming soon so you can subscribe for more information as updates are released.

tagged: announcement zendexpressive book course essentials matthewsetter

Link: http://www.masterzendframework.com/announcing-zend-expressive-essentials/

Zend Framework Blog:
Manage permissions with zend-permissions-acl
May 10, 2017 @ 13:19:23

The Zend Framework blog is back with their latest installment in their authentication and authorization series with the Zend Expressive framework. In this latest post they show the use of the zend-permissions-acl component to provide another kind of access control evaluation (as opposed to the role-based access control shown in a previous article).

The last couple posts have been around authorization, the act of determining if a given identity has access to a resource. We covered usage of role based access controls, as well as middleware that uses an RBAC.

In this post, we'll explore another option provided by Zend Framework, zend-permissions-acl, which implements Access Control Lists (ACL).

This post will follow the same basic format as the one covering zend-permissions-rbac, using the same basic examples.

They start off the post as they've done with the others, showing how to install the component and defining some basic vocabulary so everyone's on the same page. It then starts on creating an access control list instance, defining some roles in that ACL and some example isAllowed checks for evaluating those permissions. With that in place, the tutorial moves on to resources, role inheritance and resource inheritance. Finally, they talk about ACLs in general, what they should contain and how to add in custom assertions if the need should arise.

tagged: zendframework zendexpressive permissions zendpermissionsacl tutorial component

Link: https://framework.zend.com/blog/2017-05-09-zend-permissions-acl.html

Zend Framework Blog:
Authorize users using Middleware
May 04, 2017 @ 09:40:56

Previously the Zend Framework blog posted a tutorial showed you how to authenticate a user with middleware in a Zend Expressive application. In this latest post in the series they move on to the next step: authorization.

In a previous post, we demonstrated how to authenticate a middleware application in PHP. In this post we will continue the discussion, showing how to manage authorizations.

We will start from an authenticated user and demonstrate how to allow or disable actions for specific users. We will collect users by groups and we will use a Role-Based Access Control (RBAC) system to manage the authorizations.

To implement RBAC, we will consume zendframework/zend-permissions-rbac.

They start by pulling in the Zend Expressive tooling support and creating the Permission module. The tutorial then gets into the basics of using a role-based access control system and the roles they're going to define: admin, editor and contributor (as well as what each can do). The roles are then defined in a configuration file and briefly explained. Next is the creation of the middleware to authorize the user and its action in the application, performing a check against the roles of the user on the requirements of the action. There's also an example of setting up role inheritance and how to configure the resulting route to fire off the authorization handling.

tagged: zendexpressive middleware authorization zendrbac rbac rolebased accesscontrol tutorial

Link: https://framework.zend.com/blog/2017-05-04-authorization-middleware.html

BitExpert Blog:
Mocking callables in an Expressive app
May 01, 2017 @ 11:18:28

On the BitExpert blog Stephan Hochdörfer shows you how to mock callables in a Zend Expressive application based on a way he found during his own unit testing.

While working with Zend Expressive, a PSR-7 middleware microframework, I wanted to apply some unit testing with a nice coverage to my middlewares. Middlewares are called by the __invoke method if you provide them as an object and not as a closure. [...] Additionally, my middleware implementation does some stuff, but the middleware itself does not return a response, which is fine. Instead, my implementation calls the $next middleware in line.

He finishes the post with a quick example of how to mock out this $next call in his testing using the createPartialMock functionality in PHPUnit. He uses this method to create a mock that covers the __invoke method and returns a ResponseInterface instance of his choosing.

tagged: zendexpressive mocking phpunit unittest invoke callable testing tutorial

Link: https://blog.bitexpert.de/blog/mocking-callables-in-an-expressive-app/