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

Master Zend Framework:
How To Simplify Zend Expressive Configuration with ConfigProviders
Aug 15, 2016 @ 12:42:19

The Master Zend Framework site has a new tutorial posted helping you simplify the configuration on your Zend Expressive application with the help of ConfigProviders, a handy feature that lets you split up the configuration into logical "chunks" as PHP classes.

Given Zend Framework’s design (and accompanying flexible nature), this [configuration complexity] can easily be the case if we’re not careful. [...] Specifically, we’ll likely end up with a config/autoload directory polluted with a plethora of configuration, including for dependencies, routing, and middleware.

[...] As it turns out, this was something which was already identified by other developers, including the Zend Framework contributors. [...] In there, he mentioned ConfigProvider classes as a simple way of enabling ZendForm ViewHelpers, which aren’t enabled by default in Zend Expressive. As I looked at the composition of the file, I realized that this was the answer I needed to solve the configuration issue I created for myself.

A screencast is included in the post showing off the solution but the code an explanation are below that as well for those more interested in reading than watching a video. He walks you through the creation of the configuration provider including setting up the dependency configuration, updating the route handling and, finally, actually using the provider in your global configuration.

tagged: zendexpressive configuration provider configprovider tutorial screencast example

Link: http://www.masterzendframework.com/configproviders-classes/

Christoph Rumpel:
Build a PHP chatbot in 10 minutes
Aug 15, 2016 @ 09:45:23

Christoph Rumpel has written up a tutorial showing you how to build a PHP chatbot in 10 minutes by hooking a PHP 7 based script in, via webhooks, to a Facebook Messenger application.

The chatbot topic is huge right now. Finally there is something quite new again and nobody knows what's happening next. This is the perfect time to start experimenting with chatbots and to build your own one right now. Give me 10 minutes of your time and I will give you your first chatbot!

He then walks you through the full process if setting up the Facebook Messenger application, a page to host it from and using the Chatbot boilerplate code to connect the application back to the Facebook platform. This includes both the code needed and screenshots along the way of what you can expect to see during setup. The result is a bot that can respond with, at first, a static string then is modified to show simple exchange rate data.

tagged: chatbot facebook tutorial boilerplate code example application webhook

Link: http://christoph-rumpel.com/2016/08/build-a-php-chatbot-in-10-minutes/

ShippingDocker.com:
Testing in Docker (Using Different PHP Versions)
Aug 12, 2016 @ 12:23:58

On the ShippingDocker.com site there's a video (and matching tutorial) posted showing you how to use Docker to test with multiple PHP versions with relatively little difficulty. In this case they're not testing the frontend of the application, they're running its unit tests.

[This is a] quick video on running PHP unit tests against different versions of PHP using Docker. [We'll] cover unit testing with PHP.

They start with an example of using the pywatch tool to do the testing without Docker, automatically executing the tests when something changes. This has the limitation of only being able to use your current, local version of PHP. They then shift over to the Docker side of things and show how to run the same pywatch command inside a container of your choosing, tagging it with the PHP version and making it easy to switch between them in the future.

tagged: docker version unittest different example video screencast tutorial

Link: https://shippingdocker.com/blog/docker-testing/

In2it:
Decouple Your Framework for Easy Replacement
Aug 12, 2016 @ 11:14:12

In this recent post to the In2it blog Michelangelo van Dam makes a recommendation to decouple your logic from your framework to make it easier in the future if you need to replace it.

Decouple your framework or library from your business logic for future upgrades or replacements through usage of interfaces. By separating your business logic completely from the tool used to glue all things together, you can replace your framework or upgrade to a newer version without much problems.

He talks about how it's common for applications to quickly become "good application turns into a cluster of code on top of a cluster of code". While the title suggests completely swapping out the underlying framework, he shifts it to talk more about updates to the current framework, especially ones that would break non-decoupled functionality. He then covers the ideals of "interoperability" between PHP packages based on common interfaces (like the PSRs) and how following a similar idea can help decouple your code to prevent hard work for future potentially breaking changes.

tagged: framework replacement changes interoperability dependencyinjection example

Link: https://www.in2it.be/2016/08/decouple-framework-library-easy-replacement/

SitePoint PHP Blog:
A Pokemon Crash Course on CouchDB
Aug 12, 2016 @ 10:02:56

The SitePoint PHP blog has a new tutorial posted giving you a "Pokemon Crash Course" on CouchDB, the popular NoSQL database. The "Pokemon" part comes in related to the data the tutorial uses to show you common operations and the use of a PHP interface to perform them.

In this tutorial, we’ll walk through working with CouchDB, a NoSQL database from Apache. This tutorial will focus more on the practical side, so we won’t cover what CouchDB is good for, how to install it, why use it, etc. We’ll focus on how to perform database operations through CouchDB’s HTTP API and how to work with it in PHP, laying the foundation for future, more complex posts.

The article is then broken up into different sections by operation, starting with the use of the CouchDB database via a console then via PHP:

  • Creating a Database
  • Talking to the HTTP API
  • Creating New Documents
  • Bulk Insert
  • Retrieving Documents
  • Updating Documents
  • Working with PHP

Each section includes code snippets and (where relevant) screenshots of the results to help you ensure you're on the right track.

tagged: tutorial couchdb pokemon data introduction crud library example

Link: https://www.sitepoint.com/a-pokemon-crash-course-on-couchdb/

Adam Wathan:
Stubbing Eloquent Relations for Faster Tests
Aug 08, 2016 @ 11:52:53

Adam Wathan has a recent post to his site showing you how to stub out your Eloquent relations in a Laravel application for use in your testing (rather than hitting the database directly).

When you’re trying to test methods on an Eloquent model, you often need to hit the database to really test your code.

But sometimes the functionality you’re testing doesn’t really depend on database features. Is there any way to test that stuff without hitting the database?

He starts with a look at the more traditional method, using the models normally and testing with the database. He includes a simple test and class showing a basic "song duration" integer response. He gets into a bit more detail on how the Eloquent code grabs the data it needs when a relation is accessed (hint: not a separate query) and how to update the test to mimic the eager loading of the duration information. He ends the post by pointing out that "nothing is free" however as, if the underlying database implementation changes, the test would start to fail regardless of it not using the database.

tagged: tutorial screencast example relation eloquent unittest stub

Link: https://adamwathan.me/2016/08/04/stubbing-eloquent-relations-for-faster-tests/

SitePoint PHP Blog:
8 Must-Have Grav Plugins to round-off Your Blog’s Installation
Aug 08, 2016 @ 10:22:52

On the SitePoint PHP blog there's a new post from editor Bruno Skvorc sharing his list of top 8 plugins for Grav he sees as "must haves". Grav is a flat-file based content management system that uses modern PHP practices such as Composer packages, Makdown for content and YAML for configuration.

I recently switched my blog over from Blogger to Grav, and while quite a nifty platform on its own, Grav really shines once you prop it up with some custom themes and plugins.

This post will list the plugins I believe to be essential for a developer’s personal blog, and the reasons behind each suggestion.

Among the plugins on his list are options like:

He includes examples of what the output of each looks like when integrated into the site and how to get them installed and configured. Check out the remainder of the post for more in his list of suggestions.

tagged: grav plugin blog installation example top8 list

Link: https://www.sitepoint.com/8-must-have-grav-plugins-to-round-off-your-blogs-installation/

Freek Van der Herten:
Validating SSL certificates with PHP
Jul 28, 2016 @ 10:45:56

In a new post to his site Freek Van der Herten shares some code he's worked up to validate SSL certificates in PHP to ensure they're correct when accessing a remote site.

With vanilla PHP it’s possible to check of if the SSL certificate of a given site is valid. But it’s kinda madness to do it.

He starts with the code required to do it including:

..then on to parsing the certificate and its "valid time" timestamps. He stops it with the above steps, however, and advocates that you instead try out this package (one developed by him) to make the validation a two-line process. He also describes some of the other methods the package includes to get things like the issuer, domain and any additional domains it covers. Be aware that if you're planning on using it you'll need OpenSSL support in your PHP installation as it's required for the connection and validation.

tagged: package certificate ssl validate openssl example

Link: https://murze.be/2016/07/validating-ssl-certificates-php/

Joseph Silber:
The new Closure::fromCallable() in PHP 7.1
Jul 26, 2016 @ 10:20:47

In a new post to his site Joseph Silber looks at a new feature that will be coming with the next release in the PHP 7.x series - PHP 7.1 - the ability to convert a callable type into an actual Closure instance.

With PHP 5.5 going EOL earlier this week and the PHP 7.1 beta expected later this month, now sounds like a good time to look into a neat little feature coming in 7.1: easily converting any callable into a proper Closure using the new Closure::fromCallable() method.

He starts with a quick refresher on what closures/callables are in PHP (or an introduction for those not already familiar) including a simple example with the reject handling on a Laravel collection. He then modifies the example to try to pass in a base PHP function. This doesn't work directly (as it's not technically "callable" how it's expecting) so he wraps the is_float in a closure instead. This is a bit of a hassle and not as reusable so he updates it for PHP 7.1 and uses the Closure::fromCallable handling to make it automatically. He follows this with another example use case: calling a private method with the array of object/method name from inside the class.

tagged: closure callable fromcallable php7 example introduction

Link: https://josephsilber.com/posts/2016/07/13/closure-from-callable-in-php-7-1

SitePoint PHP Blog:
Can We Use Laravel to Build a Custom Google Drive UI?
Jul 25, 2016 @ 13:57:52

The SitePoint PHP blog has posted a new tutorial that asks the question "Can We Use Laravel to Build a Custom Google Drive UI??" In this case it's a simplified version of the current Google Drive functionality, but it's more of a proof-of-concept than anything.

In this tutorial, we’re going to build an app that talks to the Google Drive API. It will have file search, upload, download and delete features. If you want to follow along, you can clone the repo from Github.

They walk you through the full process of getting the application set up, including creating the project on the Google side and grabbing the API credentials for use in your code. They then switch back over to the code side and create a basic Laravel project and configure it with the Google API credentials you just created. Next up is the creation of all of the routes for the list, upload and delete handling in the Laravel app as well as the controllers/views to make them all work. They also include search functionality, letting you easily query the API for files with names matching a certain string.

tagged: laravel google drive ui tutorial api example

Link: https://www.sitepoint.com/is-laravel-good-enough-to-power-a-custom-google-drive-ui/