PHPDeveloper.orghttp://www.phpdeveloper.org
Up-to-the Minute PHP News, views and communityen-usTue, 03 Mar 2015 14:31:56 -060030http://www.phpdeveloper.org/news/22417http://www.phpdeveloper.org/news/22417
Zend recently introduced their Z-Ray inspection tool that allows you to see inside your application and know what's happening in your code, your database and has support for major PHP projects. In this new post to their blog they show you how to develop a custom extension for the Z-Ray system.

One of the coolest features in Z-Ray is the ability to plug in your own extensions. Meaning, you can customize existing Z-Ray panels or add your own personalized Z-Ray panel for displaying information you think is important for developing your specific application. This short tutorial will describe how to write a basic extension for Z-Ray. More specifically, we'll be writing a Z-Ray extension for WordPress that extracts and displays a list of loaded WordPress plugins.

They give you a list of things you'll need to set up before you can get started including a simple WordPress installation on a Zend Server instance. With these in place they help you create the "zray.php" file to define the extension, how to enable it and setting up a "trace" on a function to hook it into the execution. They then dump the WP plugin information and reformat it a bit to show only the list of names and versions in the output panel. As a last touch, they add a logo to the panel to show in the bottom menubar with the WordPress logo.

Link: http://blog.zend.com/2015/02/25/developing-z-ray-extension]]>Wed, 25 Feb 2015 11:54:41 -0600http://www.phpdeveloper.org/news/22392http://www.phpdeveloper.org/news/22392
The SitePoint PHP blog has posted the third part of their series guiding you through the creation of your first PHP package with a look at mocking API responses in unit tests created via the TDD (test-driven development) process.

In parts one and two, we built some very basic functionality and used TDD with PHPUnit to make sure our classes are well tested. We also learned how to test an abstract class in order to make sure its concrete methods worked. Now, let's continue building our library.

He starts with a bit of catching up to ensure everyone is on the same page in the development process. From there he starts in on the mocking of the API, preventing the need for the (slow) external requests. He shows some updates that are needed to the main DiffBot class, the factories/entities for making objects for requests and examples of putting these to use in a few tests. Finally he shows the creation of the mocks themselves and the result from a sample test.

Link: http://www.sitepoint.com/api-client-tdd-mocked-responses/]]>Thu, 19 Feb 2015 12:57:51 -0600http://www.phpdeveloper.org/news/22298http://www.phpdeveloper.org/news/22298
As a part of his involvement in the PHP-FIG standards group, Matthew Weier O'Phinney has been contributing to the PSR-7 proposal. This proposal defines a standardized structure for HTTP message handling. In his latest post he gets into a bit more detail on what this means for the PHP developer and how it might be implemented.

PSR-7 is shaping up nicely. I pushed some updates earlier this week, and we tagged 0.6.0 of the http-message package last week for implementors and potential users to start coding against. I'm still hearing some grumbles both of "simplify!" and "not far enough!" so I'm writing this posts to demonstrate usage of the currently published interfaces, and to illustrate both the ease of use and the completeness and robustness they offer.

He starts with a base definition of what the proposal, well, proposes around HTTP messaging, both the incoming and outgoing. He describes the basic structure of an HTTP message and what each part represents. He talks about message headers, bodies and how the current library could return that content. He then looks at requests vs responses, server-side requests and some various uses cases and more practical examples:

HTTP Clients

Middleware

Frameworks

With the PSR-7 standard in place, all of these different tools could have interchangeable interfaces for HTTP request/responses, easily swappable with any other implementation.

Link: https://mwop.net/blog/2015-01-26-psr-7-by-example.html]]>Thu, 29 Jan 2015 09:13:20 -0600http://www.phpdeveloper.org/news/22280http://www.phpdeveloper.org/news/22280
The Coder on Code site has posted a new tutorial covering the Adapter design pattern in detail. They talk about what the pattern is, what it can be useful for and include some code to illustrate.

The adapter pattern also referred as the wrapper pattern, I find that wrapper is a more fitting name since it describes clearly what this pattern does; it encapsulates the functionality of a class or object into a class with a common public interfaces. [...] Adapters are one of the easiest patterns to comprehend and at the same time one of the most useful ones.

He starts with some of the basic definitions of terms involved in the pattern: client, adapter and adapteee. His example centers around a notification manager class that lets you switch types between Twitter, Email and SMS messaging. His initial code has all of the message types handled in one class method. He shows how to refactor this out to an interface and a set of child classes, each with the corresponding handling in a "sendNotification" method. These are then used by an adapter in the main class to send the given message. This simplifies the main messenger class and contributes to the overall improvement of architecture and testability of the application.

Link: http://coderoncode.com/2015/01/25/design-patterns-in-php-adapters.html]]>Mon, 26 Jan 2015 10:46:42 -0600http://www.phpdeveloper.org/news/22219http://www.phpdeveloper.org/news/22219
In a new post to his site Dave Hulbert has shared some of his thoughts about the PSR-7 standard, a HTTP proposal for HTTP handling.

PSR-7 contains interfaces for HTTP messages. These are like Symfony Kernel's Request and Response interfaces. Having these new interfaces would be great for the PHP community but there's a couple of issues with their current state that I'm not happy with.

One of PSR-7's goals is "Keep the interfaces as minimal as possible". I think the current interfaces are not minimal enough.

He breaks down his thoughts into a few different sections covering ideas around:

Immutability and PSR-7's enforcement of mutability

Being too strict to the (HTTP) spec

Splitting client and server message interfaces

Writing and reading from StreamableInterface

He sums up his thoughts under each section pretty quickly. If you haven't heard much about the PSR-7 proposal and want more context on what he's referencing, check out this proposal (or otherposts sharing opinions from other developers).

Link: http://createopen.com/design/php/2014/12/15/psr-7.html]]>Mon, 12 Jan 2015 12:51:03 -0600http://www.phpdeveloper.org/news/22212http://www.phpdeveloper.org/news/22212
Matthew Weier O'Phinney has a new post to his site today with a thought about how to make the Zend Framework (both ZF1 & ZF2) easier for developers to get into and use. He suggests that middleware might be the answer.

As I've surveyed the successes and failures of ZF1 and ZF2, I've started considering how we can address usability: how do we make the framework more approachable? One concept I've been researching a ton lately is middleware. Middleware exists in a mature form in Ruby (via Rack), Python (via WSGI), and Node (via Connect / ExpressJS); just about every language has some exemplar. Even PHP has some examples already, in StackPHP and Slim Framework.

[...] The idea is that objects, hashes, or structs representing the HTTP request and HTTP response are passed to a callable, which does something with them. You compose these in a number of ways to build an application.

He gives some examples of current frameworks and libraries that make use of the middleware idea, showing both object and callable methods. He points out that, while middleware is approachable and makes a developer's life easier, it's not something PHP can internally handle. He covers the things a PHP developer would need to access just to get the complete details about a HTTP request and that what's really needed is good HTTP abstraction handling, something the PHP-FIG group has been working on as a part of PSR-7. He includes some examples of how it might be used and where middleware would fit into the picture.

Too often, I feel as PHP developers we focus on the tools we use, and forget that we're working in an HTTP-centric ecosystem. [...] If PSR-7 is ratified, I think we have a strong foot forward towards building framework-agnostic web-focused components that have real re-use capabilities -- not just re-use within our chosen framework fiefdoms.

Link: https://mwop.net/blog/2015-01-08-on-http-middleware-and-psr-7.html]]>Fri, 09 Jan 2015 11:38:17 -0600http://www.phpdeveloper.org/news/21826http://www.phpdeveloper.org/news/21826
Michael Dowling has a new post to his site today talking about the latest release for the Guzzle HTTP library and how it now works with RingPHP to make integration life easier. The RingPHP library, inspired by Clojure's Ring library, provides a low-level structure to work with HTTP clients and servers through a simple interface.

With RingPHP, Guzzle does not require cURL and can be used with any HTTP transport mechanism. I'd love to help anyone who is interested in creating RingPHP adapters to bind Guzzle to another library. For example, WyriHaximus on Github is working on binding Guzzle to ReactPHP. (In fact, Guzzle 4 did not require cURL, though it was much harder to use an alternate transport.)

He goes on to talk more about the changes in the Guzzle 5 release including more detail on the RingPHP integration, the use of promises/futures and iterable and callable streams. There's also several new events included in the release as well. He finishes out the post with an upgrade guide to help make the transition easier.

Link: http://mtdowling.com/blog/2014/10/13/guzzle-5/]]>Tue, 14 Oct 2014 10:52:25 -0500http://www.phpdeveloper.org/news/21765http://www.phpdeveloper.org/news/21765
Michael Dowling has a new post to his site today talking about the work that's being done on the upcoming release of the Guzzle HTTP client. In the post he talks about a major change in how it allows for asynchronous requests and the work on Guzzle-Ring to make it happen.

Guzzle 4 has been out for a little over six months. It has proven to be leaps and bounds better than Guzzle 3, and I've been very happy with the design so far. However, after the release of Guzzle 4, I've received feedback from numerous members of the PHP community that can be boiled down to "Guzzle needs async support." While Guzzle has always had the ability to send requests concurrently using a pool of requests, there was not a way to send asynchronous requests.

After a couple months of work and borrowing concepts from Clojure, I've created Guzzle-Ring, an extremely simple adapter and middleware library for PHP (not just Guzzle) that can power both clients and servers for both synchronous and asynchronous requests.

The Guzzle-Ring reduces the need for the previous complexity of creating multiple adapters, which ended up with the adapters knowing too much about the request itself. He introduces the Guzzle-Ring system that will be included in Guzzle v5, heavily influenced by Clojure. The adapter makes the request as simple as passing in an array and makes use of "futures" to handle the request/response cycle. He also talks some about creating middleware piece that helps integrate it into your application, wrapping functionality inside of another method. He illustrates all of this with code examples and includes others such as fetching of future responses, sending requests concurrently and the Guzzle-Ring server adapters.

Link: http://mtdowling.com/blog/2014/09/28/guzzle-ring/]]>Tue, 30 Sep 2014 09:36:32 -0500http://www.phpdeveloper.org/news/21507http://www.phpdeveloper.org/news/21507
Continuing on with his series about using the Guzzle PHP HTTP library, Miguel Ibarra Romero is back with this new post showing how to connect your PHP application, via Guzzle, to the Twitter OAuth protected service.

In a previous article, we found out about Guzzle and how it can aid us in the task of establishing communication with third party APIs over HTTP. We used it to get the output of a random number generator and for basic interaction with Github's API. [...] While interacting with Github's API we discovered that it supports basic authentication (sending plain username/password). But what if the API we want to use just offers OAUTH authentication?

He shows how to use Guzzle's own OAuth subscriber to make a basic connection to the API. He walks you through the installation of the subscriber (via Composer) and an example of its use. He explains each part of the code, giving a little background on where it fits into the OAuth request and where to put your API secret and key to make the connection work. Finally, he includes the code to handle the callback once the OAuth request is successful, grabbing the token data and adding it to the user session.

Link: http://www.sitepoint.com/using-guzzle-twitter-via-oauth/]]>Thu, 31 Jul 2014 10:54:01 -0500http://www.phpdeveloper.org/news/21437http://www.phpdeveloper.org/news/21437
In his latest post Michael Dowling looks at a recently proposed PSR standard (the HTTP message one, created by him) and some of his thoughts around it and what it could do for the community.

There's been a lot of talk lately about the PSR HTTP message proposal, PSR-7. The purpose of the proposal is to create a shared interface that can be used by projects to interact with HTTP messages for both clients and servers. When I created the proposal, I envisioned the purpose is not to say projects that utilize HTTP messages need to make breaking changes to use the proposed interfaces, but rather give projects an interface for which they can create an adapter.

He points out that the major part of the proposal that's being debated is the message body methods and structure. He gives a quick overview of this API and how streams could fit in with it, providing a flexible abstraction layer over the actual data. He includes a few ideas for some functionality that could make streams work relatively easily with the proposal (using a StreamInterface):

No Auto-registering of stream protocols and filters

Exceptions cause warnings in stream wrappers and filters

Functionality is spread over many functions

He also shares an example (based around the Guzzle HTTP library) showing how this interface could be put to work. He also talks some about one of the major concerns voiced right now, getting the actual stream itself to work with, and shows how the "detach" method matches this goal.