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

Matt Stauffer:
Introducing Mailables in Laravel 5.3
Aug 05, 2016 @ 10:57:32

Matt Stauffer has posted the next in his "what's coming in Laravel 5.3" series today with this look at "mailables" to help make sending mail simpler in Laravel-based applications.

For the longest time, sending mail in Laravel has felt clumsy compared to the relatively light APIs of most other Laravel features. I'm not saying it's awful—it's still so much cleaner than its competitors--but it's often confusing to figure out what goes in the closure and what doesn't, what the parameter order is, etc.

Mailables are PHP classes in Laravel 5.3 that represent a single email: "NewUserWelcome", or "PaymentReceipt". Now, similar to event and job dispatching, there's a simple "send" syntax, to which you'll pass an instance of the class that represents what you're "dispatching"; in this context, it's an email.

He gives an example of the updated syntax for calling these "mailables", how to create them with the artisan command and their structure/usage. He also shows how to pass data into the object and some other included features (like customizing the delivery list, queuing and working with attachments).

tagged: mail sending laravel mailable class interface overview

Link: https://mattstauffer.co/blog/introducing-mailables-in-laravel-5-3

Freek Van der Herten:
Following PHP internals and RFC’s
Jul 21, 2016 @ 10:19:08

Freek Van der Herten has a new post to his site sharing a resource you can use to more easily keep up with PHP internals and RFCs - the externals.io service.

When features get added to PHP there’s a lot of discussion first about the new functionality. This is done on the so-called internals mailing list. You can try to follow the discussions via a rather ugly interface at http://news.php.net. The site looks like a very old school web email client where all conversations are just running through each other.

A couple of days ago Matthieu Napoli launched his new site externals.io. This site makes following internals a lot easier.

The externals.io site provides a clean interface to the discussions happening on the php.internals list, including nested threads and the ability to track unread messages. It definitely makes it simpler to keep track of the line of emails in a thread, but it's definitely read-only with no intent on being a full on mailing list replacement.

tagged: phpinternals mailinglist interface externalsio discussion thread unread

Link: https://murze.be/2016/07/following-php-internals-rfcs/

QaFoo Blog:
Outside-In Testing and the Adapter and Facade Patterns
Jul 05, 2016 @ 10:47:03

The QaFoo blog has a post today about outside-in testing, two design patterns - Adapter and Facade - and how they relate.

As part of our workshops on Test-Driven Development we explain to our customers how testing from the outside-in can help find the right test-mix.

The technique puts a focus on test-driven-development, but instead of the traditional approach starts at the acceptance test level. The first test for a feature is an acceptance test and only then the feature is implemented from the outside classes first. [...] Outside-In testing leads to interfaces that are written from what is useful for the client object using them, in contrast to objects that are composed of collaborators that already exist. Because at some point we have to interact with objects that exist already, we will need three techniques to link those newly created interfaces/roles to existing code in our project

These three techniques are:

  • using the adapter pattern to interface with third party code
  • the facade pattern to "layer" your own code
  • continuous refactoring of interfaces/implementations

In this post they focus mostly on the adapter pattern. They show how to use it in interfacing with remote systems in a Symfony application (for example) based on a remote XML file. They also include the test to verify it's functioning correctly and the PHP code to make the mocks and interfaces you'll need for the test.

tagged: outsidein testing adapter facade designpattern refactor interface

Link: https://qafoo.com/blog/087_outside_in_testing_adapter_pattern.html

Matthew Weier O'Phinney:
On Deprecating ServiceLocatorAware
Apr 27, 2016 @ 11:16:51

In this post to his site Matthew Weier O'Phinney talks about a change in the Zend Framework ZendMVC package to deprecate the ServiceLocatorAware interface and some of the unexpected backlash of it.

A month or two ago, we pushed a new release of zend-mvc that provides a number of forwards-compatibility features to help users prepare their applications for the upcoming v3 release.

One of those was, evidently, quite controversial: in v3, zend-servicemanager no longer defines the ServiceLocatorAwareInterface, and this particular release of zend-mvc raises deprecation notices when you attempt to inject a service locator into application services, or pull a service locator within your controllers.

He shares some of the "constructive" feedback they received when they made the change, most importantly asking for a justification for the change. He then goes through their thinking behind the change, some of its original intent and how it allowed for "dependency hiding" in its use. He gets into some detailed code examples for this last point, some of the errors that could happen as a result and other issues (like no type safety and the brittleness of using a service locator).

tagged: deprecation servicelocatoraware interface zendframework zendframework3

Link: https://mwop.net/blog/2016-04-26-on-locators.html

Adam Wathan:
Preventing API Drift with Contract Tests
Feb 03, 2016 @ 12:11:21

In this post to his site Adam Wathan shares a screencast talking about changing APIs (the structure of your code, not like REST/SOAP APIs) and how "API drift" could cause problems in your testing.

One of the risks of writing your own test doubles is that the API of the double can fall out of sync with the API of the real implementation.

In this screencast I walk through an example that explains: how interfaces can provide a false sense of security, why tests make better contracts than interfaces and how to run multiple implementations against a shared set of contract tests.

You can watch the screencast either through the in-page video player or over on Vimeo directly. It's about 10 minutes long but it covers an interesting topic that could throw you if you're not careful in your testing/code changes.

tagged: screencast contract test unittest api drift interface changes

Link: http://adamwathan.me/2016/02/01/preventing-api-drift-with-contract-tests/

Zend Developer Zone:
Introspecting your Code with Z-Ray for Azure
Jan 13, 2016 @ 12:38:38

On the Zend Developer Zone blog Daniel Berman has posted a guide showing how to use their Z-Ray plugin to inspect code running on Azure for statistics around performance, queries and errors thrown by the code.

Quick experimentation, easy collaboration, automated infrastructure and scalability, together with advanced diagnostic and analytical tools – all provide PHP developers with good reasons to develop in the cloud.

[...] The combination of Z-Ray and the Azure cloud means PHP developers building apps on the Azure web app service get the best of both worlds – Z-Ray’s powerful introspection capabilities and Azure’s rich cloud infrastructure.

The post walks you through the steps to create a new Azure-based web application, how to upload your code and enable the Z-Ray feature directly from the Azure "Tools" menu. The Z-Ray toolbar is then automatically injected into your application for your immediate profiling needs.

tagged: azure microsoft hosting zray profiling tool interface tutorial

Link: http://devzone.zend.com/7093/introspecting-code-with-z-ray-for-azure/

Sarfraz Ahmed:
Coding to Interface
Dec 29, 2015 @ 09:27:48

On his Code in PHP site *Sarfraz Ahmed * has a post talking about coding to interfaces, how its done and why he thinks it's an essential part of any application.

One of the nicest things you can add to your programming skills is coding to interface.

One of the nicest things you can add to your programming skills is coding to interface. One of the five principles of S.O.L.I.D is Dependency inversion principle which states: [...] High-level modules should not depend on low-level modules. Both should depend on abstractions [and] abstractions should not depend on details. Details should depend on abstractions.

He elaborates on this "pretty formal definition" with an example MySQL wrapper class used in a User class, making them tightly coupled to each other. He also points out the same with a `UserController. As a solution to this tight coupling problem, he suggests using dependency injection (inversion of control) to pass in instances of the classes rather than creating them internally. This still couples them, though a bit more loosely, so he suggests using an interface for the dependency instead of a concrete class. This way any number of potential classes could be passed in and the class internally knows how to use them.

tagged: code interface dependency injection ioc solid principles objectoriented coupling

Link: http://codeinphp.github.io/post/coding-to-interface/

Matthieu Napoli:
Approaching coding style rationally
Nov 13, 2015 @ 11:51:07

In a post to his site Matthieu Napoli shares some of his thoughts about "code style rationality" including code formatting in general and some suggestions on one of the harder things in development - naming things.

Habits are sometimes making us blind. We think X looks prettier than Y but that’s just the habit speaking. In this article I’ll try to take a rational approach at coding style. That means leaving the “it looks ugly/better” at the door.

If at any point you feel like something “just doesn’t look good”, breath in, breath out, and try it! Nothing beats hands-on experience, not even some random article on the internet.

He looks at a few subjects specifically (there's way too many to cover them all in detail):

  • the use of trailing commas
  • alignment of values in docblock comments
  • keeping docblock comments minimal
  • using the "Interface" suffix
  • using the "Exception" suffix

He ends the post by reminding readers that the point is to think about code style logically and that no rules are written in stone.

tagged: code style formatting rational approach opinion comma docblock interface exception

Link: http://mnapoli.fr/approaching-coding-style-rationally/

Developer Drive:
How to build an auto-ranking Twitter list with WordPress
Oct 23, 2015 @ 13:55:36

On the Developer Drive site there's a tutorial posted showing how to create a dynamic auto-ranking Twitter list in a WordPress-based application.

My team and I recently built an awesome list template on WordPress that ranks a set of Twitter users based on follower count. It allows a content writer to easily add a list of Twitter handles, and generate a well designed post.

They start with a list of requirements the end result needs to meet including the Twitter information, features it should offer and the resulting output. The rest of the post walks you through every step of the process to get the system set up including:

  • installing the Advanced Custom Fields Pro WordPress plugin
  • Showing an "infinite list" in WordPress
  • Code to loop through the Twitter data
  • using the TwitterAPIExchange PHP library to get Twitter data

All code and steps you'll need to make the system work are included and they've posted a demo so you can see the result first hand.

tagged: autorank wordpress list twitter follower count api interface tutorial

Link: http://www.developerdrive.com/2015/10/how-to-build-an-auto-ranking-twitter-list-with-wordpress/

Symfony Blog:
Paving the way for Symfony 3 with the "Deprecation Detector" tool
Oct 22, 2015 @ 10:48:31

On the Symfony blog there's a post talking about a tool they've introduced that is helping to "pave the way" for the upcoming version 3 release of the Symfony framework - the Deprecation Detector tool.

Symfony 3 will be released at the end of November 2015. Learning from our own history, the transition from Symfony 2 to 3 will be much more pleasant than the transition from symfony 1 to 2 that happened in July 2011.

Technically speaking, Symfony 3 includes no new features comparing it with Symfony 2.8, which will be released at the same time. [...] This means that your Symfony applications won't work on Symfony 3 unless you remove all their deprecations. In order to simplify the task of finding which deprecations affect your applications, a new tool called Deprecation Detector has just been released.

The tool runs static analysis against your codebase and finds locations where you're using deprecated methods/classes/interfaces/etc and reports them back for fixing. The post includes the commands you'll need to get the tool installed and how to run it against your code. You can find out more about the project and get details on command line options on its GitHub repository.

tagged: deprecation detector symfony2 symfony3 method interface class service tool tutorial

Link: http://symfony.com/blog/paving-the-way-for-symfony-3-with-the-deprecation-detector-tool