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

Zend Framework Blog:
Handling OPTIONS and HEAD Requests with Expressive
Mar 29, 2017 @ 10:39:46

The Zend Framework blog has continued its series of posts focusing on the use of the Zend Expressive framework with a new tutorial covering handling OPTIONS and HEAD requests in an Expressive-based API.

In v1 releases of Expressive, if you did not define routes that included the OPTIONS or HEAD HTTP request methods, routing would result in 404 Not Found statuses, even if a specified route matched the given URI. RFC 7231, however, states that both of these request methods SHOULD work for a given resource URI, so long as it exists on the server. This left users in a bit of a bind.

[...] In the case of a HEAD request, the specification indicates that the resulting response should be identical to that of a GET request to the same URI, only with no body content. This would mean having the same response headers. In the case of an OPTIONS request, typically you would respond with a 200 OK response status, and at least an Allow header indicating what HTTP request methods the resource allows. Sounds like these could be automated, doesn't it? In Expressive 2, we did!

The tutorial then shows you the code you'll need to add to your Expressive v2 application for handling each kind of request. It involves some custom middleware using the route handling on the HEAD request type for one and the other for OPTIONS. The HEAD requests return an empty response while the OPTIONS requests return the data from a manually defined array (no automatic generation from routes or anything).

tagged: zendframework zendexpressive options head request handling

Link: https://framework.zend.com/blog/2017-03-28-expressive-options-head.html

Zend Framework Blog:
Create ZPKs the Easy Way
Mar 22, 2017 @ 09:05:17

On the Zend Framework blog Enrico Zimuel has posted a tutorial showing you how to easily create ZPKs and package up your application for deployment on Zend Server.

Zend Server provides the ability to deploy applications to a single server or cluster of servers via the ZPK package format. We have offered zf-deploy for creating these packages from Zend Framework and Apigility applications, but how can you create these for Expressive, or, really, any PHP application?

They start by listing out some of the requirements you'll need to get started (the zip binary, Composer, etc). The tutorial then walks you through the setup including the contents of the .htaccess and deployment.xmlconfiguration files. It then walks through the installation of dependencies and actually creating the ZFK (via the zip binary). It wraps up with a simple example of the creation of a ZPK containing a single index.php file.

tagged: zendframework zendserver zpk zip package deployment tutorial

Link: https://framework.zend.com/blog/2017-03-21-create-zpks-the-easy-way.html

Zend Framework Blog:
Migrating to Expressive 2.0
Mar 14, 2017 @ 12:36:17

The Zend Framework blog has a tutorial they've posted showing you how to migrate up to Zend Expressive v2.0 from a v1.x application and some of the things that could break along the way.

Last week, we released Expressive 2. A new major version implies breaking changes, which often poses a problem when migrating. That said, we did a lot of work behind the scenes to try and ensure that migrations can happen without too much effort, including providing migration tools to ease the transition.

In this tutorial, we will detail migrating an existing Expressive application from version 1 to version 2.

Using this repository for a testbed, they walk through the steps for the update:

  • Creating a migration branch
  • Updating dependencies
  • using the zendframework/zend-expressive-tooling to aid in the migration
  • scanning your code to find possible breaking locations
  • moving over to the programmatic pipeline structure

They also include some bonus information covering self-invoking functions, the zend-config-aggregator and development mode. The post ends with the updates you'll need to make to middleware to implement the http-interop/http-middleware MiddlewareInterface.

tagged: zendframework zendexpressive v2 migration guide tool

Link: https://framework.zend.com/blog/2017-03-13-expressive-2-migration.html

Zend Framework Blog:
Announcing Expressive 2.0
Mar 07, 2017 @ 11:43:29

On the Zend Framework blog today Matthew Weier O'Phinney has posted the official announcement of the release of Zend Expressive v2.0, the latest major release with several large changes.

Today we're excited to announce Expressive 2.0! What has changed since 1.0 was released last year? The short version: we've been providing changes that standardize, simplify, and streamline application development in Expressive.

Updates in this latest version include:

  • PSR-11 (ContainerInterface) support
  • Programmatic pipelines
  • An emphasis on modularized applications
  • Extensible routing and dispatch middleware

The post gets into details on each of the above topics and several others. It also shows how to install this latest version via Composer (or install the skeleton application to get up and running quickly).

tagged: zendframework zendexpressive v2 release announcement major version

Link: https://framework.zend.com/blog/2017-03-07-expressive-2.html

Zend Framework Blog:
Scrape Screens with zend-dom
Feb 28, 2017 @ 16:46:27

The Zend Framework blog has posted another tutorial focusing on the use of one of the components that makes up the framework. In this latest tutorial Matthew Weier O'Phinney focuses on the zend-dom component and how to use it for scraping content from remote sources.

Even in this day-and-age of readily available APIs and RSS/Atom feeds, many sites offer none of them. How do you get at the data in those cases? Through the ancient internet art of screen scraping.

The problem then becomes: how do you get at the data you need in a pile of HTML soup? You could use regular expressions or any of the various string functions in PHP. All of these are easily subject to error, though, and often require some convoluted code to get at the data of interest.

[...] zend-dom provides CSS selector capabilities for PHP, via the ZendDomQuery class. [...] While it does not implement the full spectrum of CSS selectors, it does provide enough to generally allow you to get at the information you need within a page.

He gives an example of it in use, showing how to grab a navigation list from the Zend Framework documentation site (a list of items in a <ul> tag). He also suggests some other uses of the tool including use in testing of your application, checking content in the page without having to hard-code specific strings.

tagged: zendframework zenddom scrape content html dom xml tutorial

Link: https://framework.zend.com/blog/2017-02-28-zend-dom.html

Zend Framework Blog:
zend-config For All Your Configuration Needs
Feb 23, 2017 @ 10:25:13

The Zend Framework blog has a new post from Matthew Weier O'Phinney focusing on another useful component of the framework, the zend-config component. This component, already in wide use across the framework, allows for flexible configurations to be defined and easily consumed for your use.

Different applications and frameworks have different opinions about how configuration should be created. Some prefer XML, others YAML, some like JSON, others like INI, and some even stick to the JavaProperties format; in Zend Framework, we tend to prefer PHP arrays, as each of the other formats essentially get compiled to PHP arrays eventually anyways.

At heart, though, we like to support developer needs, whatever they may be, and, as such, our zend-config component provides ways of working with a variety of configuration formats.

He walks you through the installation of the component (via Composer) and the dependencies it requires. The post then moves on to the use of the component to get configuration values from a single or multiple files (.php, .ini, .json, etc). It also covers the optional return of the values as objects, making them read-only, including your own configurations and using alternative parsers (like Symfony's YAML component). It ends with a look at some of the configuration options you can give the component including the addition of processors to manipulate values once they're read.

tagged: zendframework zendconfig component spotlight tutorial

Link: https://framework.zend.com/blog/2017-02-22-zend-config.html

Rob Allen:
Stand-alone usage of Zend-InputFilter
Feb 15, 2017 @ 09:58:51

Rob Allen has written up a brief tutorial showing you how to use the Zend/Filter component independently from a Zend Framework application. In his example he integrates it into a simple API endpoint.

Any data that you receive needs to be checked and validated. There are number of ways to do this including PHP's filter_var, but I prefer Zend-InputFilter. This is how to use it as a stand-alone component.

He shows you how to get the component installed (along with the Zend ServiceManager) and the creation of a basic validation/filtering on "author" data. He explains the different parts that make up the instance: required, filters and validators. He then shows how to use it in your request and the resulting output if something fails.

tagged: zendframework zendfilter component standalone usage tutorial

Link: https://akrabat.com/standalone-usage-of-zend-inputfilter/

Zend Framework Blog:
Using Laravel Homestead with Zend Framework Projects
Feb 07, 2017 @ 15:13:25

On the Zend Framework blog there's a new tutorial posted showing you how you can get Laravel Homestead and Zend Framework playing nicely together. Fortunately it's relatively easy to get set up with these two technologies, it "just works".

Laravel Homestead is an interesting project by the Laravel community that provides a Vagrant box for PHP developers. It includes a full set of services for PHP developers, such as the Nginx web server, PHP 7.1, MySQL, Postgres, Redis, Memcached, Node, and more.

One the most interesting features of this project is the ability to enable it per project. This means you can run a vagrant box for your specific PHP project. In this post, we'll examine using it for Zend Framework MVC, Expressive, and Apigility projects. In each case, installation and usage is exactly the same.

They walk you through the download of the Homestead Vagrant box and the vagrant-hostsupdater package to help with renaming the application's local hostname. An example Homestead configuration is included as well as information on how to test and ensure your setup is working as expected.

tagged: laravel homestead zendframework apigility

Link: https://framework.zend.com/blog/2017-02-07-laravel-homestead.html

Zend Framework Blog:
Paginating data collections with zend-paginator
Feb 02, 2017 @ 10:26:13

The Zend Framework blog has continued with its series of posts highlighting a component of the framework and some of the benefits and functionality it brings to the table. In their latest post they focus on zend-paginator for easy and automatic pagination of results.

zend-paginator is a flexible component for paginating collections of data and presenting that data to users. Pagination is a standard UI solution to manage the visualization of lists of items, like a list of posts in a blog or a list of products in an online store.

zend-paginator is very popular among Zend Framework developers, and it's often used with zend-view, thanks to the pagination control view helper zend-view provides. It can be used also with other template engines. In this article, I will demonstrate how to use it with Plates.

The tutorial starts with the Composer command to get the component pulled into your project and details what all comes with it. It then shows the creation of a custom adapter type (for "Posts"") and how to use the package to paginate through the results with an example of the output here. Then comes the example using the Plates templating framework via a "PaginatorMiddleware" middleware, a simple template using the pagination object directly and inserting the page navigation via a partial (again making use of the object but getting the values needed to build out the links).

tagged: zendframework pagination zendpaginator plates templating tutorial

Link: https://framework.zend.com/blog/2017-01-31-zend-paginator.html

Zend Framework Blog:
Implement a SOAP server with zend-soap
Jan 25, 2017 @ 11:22:58

The Zend Framework blog continues on its series of posts showing how to create various types of web services using various components from the framework itself. In this latest post they show you how to implement a SOAP server with zend-soap, a component specifically designed to "create, serve, and access SOAP applications, and parse and generate WSDL".

zend-soap provides a full-featured SOAP implementation. SOAP is an XML-based web protocol designed to allow describing messages, and, optionally, operations to perform. It's similar to XML-RPC, but with a few key differences: arbitrary data structures may be described [and] multiple operations may be described in a message as well.

The post goes on to talk about why they're show how to use these other service types when they primarily use REST in Apigility. It also covers some of the benefits using the module has over PHP's own SOAP handling. From there it's all about the code: first just creating the server and then populating it with the classes and functions it allows. The remainder of the post is split between two other methods for setting up the server: using it in a MVC application and as middleware in something like Zend Expressive.

tagged: zendframework soap server zendsoap tutorial api wsdl mvc middleware

Link: https://framework.zend.com/blog/2017-01-24-zend-soap-server.html