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

Zend Framework Blog:
Async Expressive? Try Swoole!
Mar 22, 2018 @ 09:28:22

On the Zend Framework blog there's a new tutorial posted that wants to help you use Expressive for asynchronous request handling with the help of the Swoole extension.

When we were finalizing features for Expressive 3, we had a number of users testing using asynchronous PHP web servers. As a result, we made a number of changes in the last few iterations to ensure that Expressive will work well under these paradigms.

Specifically, we made changes to how response prototypes are injected into services.

The article starts by talking about the issue with the previous response prototype handling, mostly that, in an async world, all responses would be sharing the same instance rather than rebuilding a new one for each request. It then explains their reasoning behind even worrying about async support in the framework's response handling noting that the major reason had to do with the performance gain. The post mentions the Swoole extension and shows how to install it via PECL but you'll need to check out the project's documentation to see how to create a server that makes use of it.

tagged: asynchronous swoole extension zendframework zendexpressive v3

Link: https://framework.zend.com/blog/2018-03-21-expressive-swoole.html

Zend Framework Blog:
Expressive 3!
Mar 19, 2018 @ 12:14:54

The Zend Framework blog has posted their official announcement of the release of Expressive version 3, the latest major release for the Zend Framework-based microframework based around PSR-15 middleware.

Expressive 3 embraces modern PHP, and requires PHP 7.1 or higher. Strong type-hinting, including return type hints, make both our job and your job easier and more predictable. The ability to use all modern PHP features helps us deliver a solid base for your application.

Expressive 3 provides full support for the PSR-15 (Middleware and Request Handlers) standard. [...] Expressive 3 massively refactors its internals as well. [...] Expressive 3 provides more command line tooling and tooling improvements in order to make developing your application easier.

[...] Finally, we recognize that Expressive has changed massively between versions 1 and 3, while simultaneously keeping its primary API stable and unchanged. However, to help users find the information they need for the version they run, we have rolled out versioned documentation, with each version providing only information specific to its release cycle.

The post also lists out some of the new components including zend-expressive-session, zend-expressive-csrf and zend-expressive-hal. There's also links to more information about upgrading, community resources and a "thank you" section to several people that helped get the project to this version 3 release.

tagged: zendframework zendexpressive release v3 major features upgrade thanks

Link: https://framework.zend.com/blog/2018-03-16-expressive-3.html

Zend Framework Blog:
Expressive 3.0.0RC2 released
Mar 08, 2018 @ 09:36:20

On the Zend Framework blog they've posted the announcement of the release of the latest Release Candidate for their Zend Expressive framework: Expressive 3.0.0 RC2.

This week, we've worked on backports from Expressive 3 to Expressive 2, and, in the process, identified a few issues with how the routing package handles implicit HEAD and OPTIONS requests. As a result, we've just released 3.0.0rc2.

The post starts by explaining the "implicit" nature of the OPTIONS and HEAD requests and how the framework essentially defines them without the developer having to. It then shows how to get started with this new version and how to update your v3.0.0rc1 application to this latest release. The post finishes up with a look ahead at the project's roadmap including documentation updates, deprecations and a target release date of March 15th, 2018.

tagged: zendframework zendexpressive releasecandidate release v3rc2

Link: https://framework.zend.com/blog/2018-03-07-expressive-3-rc2.html

Zend Framework Blog:
Expressive 3.0.0RC1 is now ready!
Feb 28, 2018 @ 12:58:19

The Zend Framework blog has posted an announcement about the release of the latest Release Candidate for the next major step for their Expressive framework: Version 3.0.0RC1.

We've been working diligently the past three weeks to finalize API changes and new features for the Expressive 3.0 release, and are pleased to announce immediate availability of our first release candidate, 3.0.0rc1!

Why RC and not beta? [...] We feel at this point that we've identified and implemented all desired changes both in terms of API as well as features, and announced a feature freeze yesterday. This puts us in a status more analogous to release candidates than beta (where features could still be added).

The post then walks you through this new version and shows you how to get a new Expressive v3.0.0RC1 application set up or migrate an existing application to the new version. It then talks about some of the differences in the code and the ecosystem around the framrwork and finishes up with the roadmap and a look ahead.

tagged: expressive v3rc1 release zendframework zendexpressive tutorial

Link: https://framework.zend.com/blog/2018-02-27-expressive-3-rc1.html

Zend Framework Blog:
Expressive 3 Alpha 3
Feb 09, 2018 @ 09:39:48

On the Zend Framework blog today project lead Matthew Weier O'Phinney has posted an announcement about the latest (alpha) release of the Zend Expressive framework: Zend Expressive 3 Alpha 3.

Today, we pushed the final changes and fixes that culminated in the Expressive Installer and Skeleton 3.0.0alpha3 release!

The alpha releases have a ton of great features; keep reading to find out more!

The post then walks you through the installation process (slightly different since it's an alpha) and shows the creation of a sample middleware via the command line tooling. The tutorial then shows the creation of a request handler and how to configure it in the router. The post ends with a look ahead it what's next for the framework on its roadmap including several features that need completion before v3 of Zend Expressive can be called complete.

tagged: zendexpressive zendframework v3alpha3 tutorial install middleware handler

Link: https://framework.zend.com/blog/2018-02-08-expressive-3-alpha3.html

Zend Framework Blog:
Expressive 3 Preview
Dec 18, 2017 @ 11:14:27

The Zend Framework blog has posted a preview of Expressive v3, the next major release of their lightweight framework based on its larger sibling, Zend Framework.

Last week, the PSR-15 working group voted to start its review phase. PSR-15 seeks to standardize server-side request handlers and middleware, and both Stratigility and Expressive have been implementing draft specifications since their version 2 releases. Entering the review phase is an important moment: it means that the working group feels the specification is stable and ready for adoption. If, after the review period is over, no major changes are required, the specification can be presented to the PHP-FIG core committed for a final acceptance vote, at which point it will be frozen and ready for mass adoption.

Our plan is to have Stratigility and Expressive follow the new specification in its final form. To that end, we have been executing on a plan to prepare all our projects that work with PSR-15 to adopt the latest round of changes.

That work is ready today!

The post starts by talking about what changes come along with the PSR-15 specification including changes in namespacing, interfaces being renamed and a package split. It then talks about what changes they've made based on the PSR-15 updates and how you can test your own project to ensure it will be compatible with the updates. This includes changes that will be required to upgrade as the PSR-15 changes are not backwards compatible.

tagged: zendframework zendexpressive version preview update psr15

Link: https://framework.zend.com/blog/2017-12-14-expressive-3-dev.html

Master Zend Framework:
What Does It Take To Start Using Zend Expressive?
Nov 20, 2017 @ 11:23:17

On the Master Zend Framework site Matthew Setter has posted a new tutorial showing you what it takes to get started using Zend Expressive. The article is more about the environment the framework would live in (well, the application written with it) than the actual framework itself.

Ever thought that it's hard to get started with Zend Expressive? Ever think you need to know Vagrant, Ansible, Docker, Puppet, Linux, and more? Nope, you don't! In this post, I'm going to show you that, while these tools can help, if you’re just getting started with the framework (such as learning about it), you don't need them.

I want to be clear, before we go any further, that I’m not talking about doing fully-fledged development. [...] So what I’m talking about here is when you’re just starting out and getting a feel for Zend Expressive, right up to building a test application. I’m not talking about a fully-fledged, deployed application that requires copious tests, one backed by a CI/CD pipeline.

He then talks a bit about the history of Zend Framework and how one of Expressive's goals it to help take some of the sting out of using it. Following this he covers some of the possible tooling you could use including two environment tools: Docker (useful but not required) and Vagrant (handy but also not a must). Finally he gets to the actual requirement - a version of PHP 7 installed on the system. He shows how it, along with its included web server, can be used in development to host an Expressive site by itself.

tagged: zendexpressive zendframework tool environment tutorial docker vagrant

Link: https://www.masterzendframework.com/what-does-it-take-to-get-started-with-zend-expressive/

Rob Allen:
Implementing CORS in Zend Expressive
Nov 15, 2017 @ 09:20:13

In a new post to his site Rob Allen shows you how to implement CORS in a Zend Expressive application through the use of a simple middleware wrapper that sends the appropriate headers.

On a recent project, I needed to implement CORS support for my Expressive API. The easiest way to do this is to use Mike Tuupola's PSR-7 CORS Middleware.

As this is a standard Slim-Style PSR-7 middleware implementation, we need to wrap it for Expressive, so we make a factory. [...] We then register this in our AppConfigProvider::getDependencies() by adding to the factories key.

He includes the code and configuration changes required to make it all work and includes example output of a request (with headers) from a curl call to the API. He also includes a section on working with JSON error responses and ProblemDetails for when there are issues related to the current CORS policy definition.

tagged: cors tutorial zendexpressive middleware json error problemdetails

Link: https://akrabat.com/implementing-tuupola-cors-in-expressive/

Rob Allen:
Customising Whoops in Expressive
Nov 08, 2017 @ 09:53:40

Rob Allen has a new post to his site showing how you can customize the Whoops output in a Zend Expressive application. Whoops is a package that provides more well-structured and more attractive error output when an issue comes up.

I find the Whoops error handler page in Expressive quite hard to read and particularly dislike that the error message displayed in the top left is hidden if it's more than a few words long.

To fix this, I discovered that you can provide a custom CSS file to the PrettyPrintHandler and then override to your heart's content! One way to do this is to add a delegator factory to add the additional functionality, so let's do that.

He then includes the configuration changes you'll need to make in the Expressive setup to have it recognize the factory and be able to use it as a dependency. He then includes the code to create the factory itself, adding a path to the local CSS files and pushing the custom whoops.css file into the page handler. Example CSS is included showing an update to the display of the main message, removing the need for a mouseover to view it.

tagged: zendexpressive zendframework whoops error handler css configuration factory tutorial

Link: https://akrabat.com/customising-whoops-in-expressive/

Rob Allen:
OuputBuffer Middleware for Expressive
Oct 25, 2017 @ 09:56:14

In a quick post to his site Rob Allen shares code for an OutputBuffer middleware for use with the Zend Expressive framework. Zend Expressive is a middleware-driven framework that makes use of several Zend Framework components to get the job done.

When developing an Expressive application, if you use var_dump(), echo, print_r(), etc when you get [an] error.

This occurs after your data has been displayed and makes perfect sense as Expressive is unable to send headers as you've already started sending the body. To solve this, you need some middleware.

He includes the code for the middleware that grabs the current output being pushed to the user and, using PHP's own output buffering, takes all output and pushes it into the body, preventing any messages about output before the rendering takes place.

tagged: zendexpressive outputbuffer output middleware example

Link: https://akrabat.com/ouputbuffer-middleware-for-expressive/