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

Matthias Noback:
Introducing the SymfonyConsoleForm package
Jan 20, 2017 @ 11:12:51

In a new post to his site Matthias Noback introduces you to a package that can help you in your Symfony-based console application, combining the Form and Console components, to make it easier to create "forms" on the CLI.

About 2 years ago I created a package that combines the power of two famous Symfony components: the Form component and the Console component. In short: this package allows you to interactively fill in a form by typing in the answers at the CLI. When I started working on it, this seemed like a pretty far-fetched idea. However, it made a lot of sense to me in terms of a the package in use, building a "form" that just asks the user to input a name. An image of the result is included as well. He ends the post with some of his other general findings during the process of creating the package and suggests a few common use cases including installation wizards that can be used in both the CLI and web interfaces.

tagged: symfonyconsoleform package tutorial console form component symfony

Link: https://php-and-symfony.matthiasnoback.nl/2017/01/introducing-symfony-console-form/

Master Zend Framework:
How To Generate Class Factories The Easy Way with FactoryCreator
Jan 20, 2017 @ 10:07:57

The Master Zend Framework site has a new tutorial posted guiding you through the process of generating class factories the easy way with the help of the "FactoryCreator" tool in the Zend ServiceManager component.

If there’s one thing that’s always frustrated me when working with Zend Framework, it’s having to create factories for classes. Sure, it’s gotten easier as Zend ServiceManager’s continued to ever improve. And PhpStorm and Zend ServiceManager Grand Master, Gary Hockin, has given me a number of great tips and suggestions.

But it’s always been something I’ve felt frustrated by. Perhaps you feel the same. [...] But, what I’ve felt for some time is that they could also make it easier for us to follow these best practices too, such as with some tooling support. In the latest release of Zend ServiceManager, version 3.2.0, they have.

He goes on to talk about two tools that are included in this latest release: the ConfigDumper and FactoryCreator. He helps you get the FactoryCreator tool installed and provides a simple example of it in use, generating the factory for a "JournalService" class. He includes the results of the generation of the simple example before moving on to a more complicated example: a TableGateway object. The final example shows the generation of the factory for an "Actions" class, handling the controller processing for a simple MVC application. If you're a bit shorter on time, he's also created a screencast version of the tutorial you can view in-page or over on Vimeo.

tagged: zendframework generate class factory factorycreator tutorial screencast

Link: http://www.masterzendframework.com/simple-factory-generation-with-factorycreator/

SitePoint PHP Blog:
Laravel and Braintree, Sitting in a Tree…
Jan 19, 2017 @ 11:55:51

The SitePoint PHP blog has a new post from author Christopher Vundi that shows the use of Laravel Cashier to create a custom site connecting to Braintree for subscription handling.

Subscriptions to services online are something extremely common – from subscribing to music streaming services to tutorial sites to access premium content.

With Laravel 5, we saw the introduction of Laravel Cashier, an official Laravel package to help developers manage Stripe’s and Braintree’s subscription billing services without writing most of the boilerplate subscription billing code. [...] In this tutorial, we will be building a dummy Courses site with Braintree subscriptions. In the process, we will learn how to use the various methods offered by Cashier.

This part of the series will help you with some of the setup steps you'll need to create the environment for your application. It also shows you how the custom code would look to allow a user of your system to subscribe to a custom plan. They walk you through all of the setup steps to follow and the code you'll need to make the subscription process work. Some screenshots are included so you can ensure you're setting things up in the correct places.

tagged: laravel braintree tutorial subscription plan cashier

Link: https://www.sitepoint.com/laravel-and-braintree-sitting-in-a-tree/

NetTuts.com:
Using Namespaces and Autoloading in WordPress Plugins, Part 4
Jan 19, 2017 @ 10:24:36

The TutsPlus.com site has posted the fourth part of their series covering the use of namespacing and autoloading in WordPress plugins. In this latest tutorial they take everything they've shared (and made) previously and put it all together into a cohesive whole plugin.

At this point, we've laid the foundation for our plugin, written the plugin, and defined and explored namespaces and autoloaders. All that's left is to apply what we've learned.

So in this tutorial, we're going to put all of the pieces together. Specifically, we're going to revisit the source code of our plugin, namespace all relevant classes, and write an autoloader so that we can remove all of our include statements.

He starts off talking about namespacing and how it relates to directory structure and the code you'll need for each of the plugin files for put them in the correct namespace. With just these in place, however, errors are thrown. This requires the setup of a custom autoloader and PHP's own spl_autoload_register handling. He includes the code for the autoloader, taking in the class name and splitting it up to locate the correct directory, making it easier to replace the loading of all plugin scripts.

tagged: namespacing tutorial series part4 wordpress plugin autoloading namespace

Link: https://code.tutsplus.com/tutorials/using-namespaces-and-autoloading-in-wordpress-plugins-4--cms-27342

Mohammed Said:
Conditional Validation Rules
Jan 17, 2017 @ 09:46:46

Mohammed Said has a new post to his site sharing how you can add validators conditionally in Laravel based on different requirements using the "sometimes" method.

Laravel's validation library is very powerful and easy to use, using a few keystrokes you can build a strong defence around your application, preventing invalid user input from corrupting the application flow and potentially introducing bugs.

In this post I'd like to highlight a trick related to conditionally adding validation rules, this trick is specially important since I've seen many people on Laravel's GitHub repository opening issues complaining about an un-expected validator behaviour.

He sets up a simple scenario where the "subject" value is required allowing for a custom value but validating the length if custom is selected. He then shows how to modify things to use the "sometimes" method for conditional checks for the same "custom" checking. He also shows how to pass in multiple fields and how to evaluate a "model exists" for a user.

tagged: conditional validation rules laravel tutorial sometimes

Link: http://themsaid.com/laravel-advanced-validation-conditionally-adding-rules-20170110/

SitePoint PHP Blog:
Home-Made Twitter and Gmail Notifications with PHP and Arduino
Jan 16, 2017 @ 10:48:54

On the SitePoint PHP blog Christopher Pitt is back with another tutorial showing you yet another "odd" use of PHP. In this latest post he shows you how to integrate PHP and an Arduino to relay Twitter and Gmail notifications.

I am a little obsessed with Twitter. It’s how I communicate with most of the developers I’m not fortunate to live in the same city as. I’m a little less obsessed with IoT projects, but then it’s harder to find the time to work on them than it is to check Twitter.

Unless I can do both at the same time.

Ever since the IoT week, I’ve been meaning to work on a project that will let me know when someone wants to speak to me. Something that looks cool, and is at the same time non-invasive. This is what I’ve come up with...

He connects the Arduino with a RBG LED and a a proximity sensor to a PHP script that will change the LED color based on the notification type. The sensor would allow some "hand waving" to dismiss the notification as "read". He then starts in on the hardware side of things including some illustrations of the Arduino board and how things connect. With that simple setup in place he moves over to the software side, creating a Notifier service interface and using the "endroid/twitter" package to connect over to Twitter. He then walks through the creation of the Gmail and Twitter applications, grabbing the related OAuth credentials and dropping them into the script's configuration file. He builds out notifier classes for each service and hooks it into the Arduino with the Firmata and Carica libraries. Finally he hooks it all together with a bit of SPLQueue functionality to loop and listen for new alerts to relay to the Ardunio.

tagged: arduino twitter gmail notifications tutorial proximity sensor led

Link: https://www.sitepoint.com/home-made-twitter-and-gmail-notifications-with-php-and-arduino/

Freek Van der Herten:
Easily work with the Twitter Streaming API in PHP
Jan 16, 2017 @ 09:25:26

On his site ** has posted a tutorial showing you how to use the Twitter Streaming API from PHP with some help from the Phirehose package.

Twitter provides a streaming API with which you can do interesting things such as listen for tweets that contain specific strings or actions a user might take (e.g. liking a tweet, following someone,…). In this post you’ll learn an easy way to work with that API.

When researching on how to work with the streaming API in PHP it stumbled upon Phirehose. This package can authenticate and set up a connection with the streaming API.

Since the Phirehose API is a bit difficult to work with, he created a package (Laravel version) to help make it a bit easier. He then walks you through the integration of this service with a Laravel-based application, including showing you how to set up the app on the Twitter side and get the API key/secret for the connection. He shows how to add the Laravel package version's provider to the configuration and create a first stream type: listening for certain hashtags. He shows how the stream reacts to a simple tweet of his with the "#laravel" hashtag in a console application. He also includes another example showing a stream that listens for people performing actions on the current user's stream (like favoriting a tweet). You can find out more about the powerful Stream API in the official Twitter documentation for the service.

tagged: twitter streaming api tutorial package phirehose laravel

Link: https://murze.be/2017/01/easily-work-with-the-twitter-streaming-api-in-php/

James Cowie:
All hail Xdebug and lets let var dump die
Jan 12, 2017 @ 12:58:23

In a recent post to his site James Cowie sings the praises of Xdebug for debugging and says that "var_dump must die" as a method for debugging in your application development flow.

How many times have you been working in Magento or any other php application and hit an error, exception or something not quite right? For me a lot. I’ve been that developer that debugs by fire and throws echo var_dumps and dies around like a western gunslinger. It’s easy, provides quick feedback cycles but lets be honest its lazy, in efficient, rarely provides all of the data you need to solve the problem on the first try and its not something you want to boast about by the coffee machine.

[...] So whats the “better” way of debugging a application? Well welcome Xdebug + PHPStorm. Imagine inside of the IDE we can set a breakpoint, a fancy die and reload our web page. Magically the IDE has stopped execution and we can see the state of the application at that exact path. We can see the variables and we can step through the code and see exactly what class and method is called next and so on and so forth.

While his instructions are specific to PHPStorm, most major IDEs will have a similar setup process with their own tweaks. In his case, though, he has one more layer of complexity - the PHP is executing inside a Docker container. He walks you through the process he followed to get the flow from container to local IDE set up. He wraps up the post with an example of debugging a script and what the results look like inside of PHPStorm (including a screencast).

tagged: xdebug vardump phpstorm docker container tutorial

Link: http://jamescowie.me/blog/2016/12/all-hail-xdebug-and-lets-let-var-dump-die/

SitePoint PHP Blog:
Voyager – Can an Admin UI Make Laravel Even More Approachable?
Jan 12, 2017 @ 09:23:37

On the SitePoint PHP blog they've posted an article from Claudio Ribero highlighting an administration UI specifically designed for Laravel applications: Voyager.

Voyager is a Laravel package that provides a full administration system for the framework in its “skeleton app” form. Voyager has 4 main features: Media Manager, Menu Builder, Database Manager and Bread/CRUD builder.

He first walks you through the process of getting a new Laravel application up and running then pulling in the tcp/voyager package. He shows how to update your app configuration to integrate it then install it. Once you've performed these steps you'll have a /admin portion of your site up and ready to go with the default login. With that all set up Claudio gets into the specifics for use of each of the components (listed above) in the package, including screenshots and code where helpful.

tagged: voyager administration interface laravel opensource tutorial

Link: https://www.sitepoint.com/voyager-can-an-admin-interface-make-laravel-even-more-approachable/

Zend Framework Blog:
Implement JSON-RPC with zend-json-server
Jan 11, 2017 @ 12:47:01

On the Zend Framework blog there's a new post showing you how to implement a JSON-RPC interface with zend-json-server, a package from the Zend Framework 2 set of components.

zend-json-server provides a JSON-RPC implementation. JSON-RPC is similar to XML-RPC or SOAP in that it implements a Remote Procedure Call server at a single URI using a predictable calling semantic. Like each of these other protocols, it provides the ability to introspect the server in order to determine what calls are available, what arguments each call expects, and the expected return value(s); JSON-RPC implements this via a Service Mapping Description (SMD), which is usually available via an HTTP GET request to the server.

The article provides a basic example of the creation of a service that handles GET requests and gives back a service mapping description. Building on this, they show how to integrate it into an application that makes use of the zend-mvc structure. They implement a "JsonRpcController" using the same methods as before. Finally they show an example of performing JSON-RPC handling in middleware, outputting the same output as before based on the data in the $response variable.

tagged: zendframework jsonrpc zendjsonserver example controller middleware tutorial

Link: https://framework.zend.com/blog/2017-01-10-zend-json-server.html