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

Medium.com:
Using Guzzle 6 Middleware in a Laravel Application
May 03, 2017 @ 11:10:36

In this recent post on Medium.com author Paul Redmond shows how to use Guzzle 6 middleware in a Laravel application instead of the framework's own functionality.

The most significant change between Guzzle 5 and 6 is moving away from the event system I grew so accustomed to in Version 5 to middleware in version 6. Needless to say, it was a big adjustment for me at first and it felt like a downgrade. After my initial grumbling, the upgrade guide explains the reasoning for the change.

[...] I prefer to keep my dependencies as up-to-date as possible so I decided to learn Guzzle 6 and become more familiar with the middleware. The concepts are pretty straightforward and I have a few patterns that I like to use when building out middleware within my Laravel applications.

He then shares some code he's used to generate an authorization header and how to add it into the Laravel application as a service using the "tagged" middleware functionality. Finally he shows it in use making a simple request to the endpoint and showing the response results, including the authorization header.

tagged: guzzle middleware laravel application tutorial tagged integration

Link: https://medium.com/@paulredmond/using-guzzle-6-middleware-in-a-laravel-application-7fbd6d966235

Fabien Potencier:
Symfony 4: Automate your Workflow
Apr 13, 2017 @ 10:33:24

Fabien Potencier has continued his series looking at Symfony 4 with a new post to his site today. This time he focuses on workflow automation and removing some of the daily application management tasks.

Symfony 4's most "innovative" feature is the way it drives the day-to-day application management. No more tedious copy/paste from README files. No more boilerplate code. Automation to the max. On a curated list of Composer packages.

He starts the post talking about Symfony Flex (the main engine behind Symfony 4) and how it can help with package management and installation/integration. He uses the sensiolabs/security-checker package as an example, showing how Flex understands the package and knows to run the checks on future composer install commands. He then digs into other areas Flex helps with:

  • bundles
  • configuration
  • environment variables
  • makefile tasks
  • Composer scripts

...and a few others. Examples are provided for each of the sections in the composer.json configuration and the post finishes with an example of the full configuration file, putting everything together.

tagged: symfony4 automation workflow integration installation symfonyflex framework

Link: http://fabien.potencier.org/symfony4-workflow-automation.html

Kevin Schroeder:
(Almost) Stupid Easy PHP Integration with Active Directory on Azure
Apr 12, 2017 @ 12:31:04

Kevin Schroeder has a new post to his site showing an (almost) stupid easy Active Directory integration method on the Windows Azure service via PHP.

There is something nice about simply having to go to one company and say “I need X” and, lo, you have it. Clearly that’s an over-simplification and, to some degree, a lie, but for the Microsoft developers I’ve talked to who have had to make the switch to PHP that is one of the things that they have said the liked better about Microsoft.

This is a simple library that uses the league/oauth2-client to provide OAuth2 based integration with Active Directory. Out of the box it is configured to work with Active Directory on Azure but, though I haven’t tested it, you can provide a different configuration object to the primary adapter and you should be able to authenticate against any Active Directory implementation as long as it has OAuth2 connectivity.

If you haven't worked with Azure's Active Directory before, he includes an instructional video of how to get it set up first. With that in place he shows an example of using the library to make the authentication request to the AD server and how to log back out. He also includes the code you'll need to configure the library via the Magium Configuration Manager or, for those without Magento experience, with some alternate methods: PHP arrays, JSON, YAML or INI files.

tagged: integration activedirectory azure package example tutorial

Link: http://www.eschrade.com/page/almost-stupid-easy-php-integration-with-active-directory-on-azure

Rob Allen:
Using CircleCI for a PHP project
Apr 03, 2017 @ 09:56:20

In a post to his site Rob Allen shares a basic setup for using Circle CI with a PHP project for continuous integration. Circle CI provides the resources to build your project and perform tasks such as run unit tests or even deploy the resulting code to the production environment.

For a new client project, I've decided to use CircleCI to run my tests every time I push to GitHub. This turned out to be quite easy; this is how I did it.

He shares the contents of his .circleci/config.yml configuration file creating a Docker environment each time the build is executed, installing the required software, executing Composer install and running PHPCS and PHPUnit tests. He shares an example of the output from a build and how he hooked in Slack to receive notifications when the builds were complete (and pass/fail status).

tagged: circleci service continuous integration project tutorial configuration docker

Link: https://akrabat.com/using-circleci-for-a-php-project/

Raphael Stolt:
Keeping your CLI integration tests green on Windows
Mar 27, 2017 @ 10:55:08

Raphael Stolt has a new post to his site for the PHP on Windows users out there helping you to keep your integration tests green when little things (like line ending differences) can cause issues between the Windows and unix-based platforms.

Lately on a Windows system, some failing integration tests for CLI commands utilising the Symfony Console component caused me some blip headaches by PHPUnit insisting that two strings are not identical due to different line endings. The following post documents the small steps I took to overcome these headaches.

He starts with the error message that the failing test was giving, a slightly unhelpful response with the "actual" and "expected" values looking basically the same. He suspected it to be something different with the encoding or line endings (a common issue between Windows and Linux platforms). To confirm his suspicions he looked deeper into the Symfony Console code and, on locating the difference, extended the "CommandTester" class to automatically disable the "decorated" setting across all tests.

tagged: phpunit testing integration green windows platform decorate tutorial

Link: http://raphaelstolt.blogspot.com/2017/03/keeping-your-cli-integration-tests.html

Stefano Alletti:
Symfony and Monolog, how use Processor in your project: a practical example
Mar 17, 2017 @ 12:23:44

Stefano Alletti has written up a post to his site showing how to combine Symfony and Monolog along with a custom "processor" to modify the message and content being logged.

We often have to use different micro-services who write in many log files. Use utilities like Kibana is a good thing, but in order to take full advantage of its features we have to try to standardize and normalize the logs.

The company where I work having introduced Kibana recently, he asked me to implement a proper strategy to log all the micro-services.

He starts by outlining the fields that are required to be in the log output (a great place to start) before moving into the code to implement the logging. He briefly talks about Monolog itself and how to implement it in a Symfony application. The remainder of the post includes the code to implement the logger and how to add the custom processor to modify the extra data being included in the logged data. He also goes a step further and creates a custom formatter to modify the output in the message for the customer ID and product line values.

tagged: tutorial symfony monolog processor formatter integration

Link: https://stefanoalletti.wordpress.com/2017/03/09/symfony-and-monolog-how-use-processor-in-your-project/

Playing with RabbitMQ, PHP and node
Feb 20, 2017 @ 11:51:58

In the latest post to his site Gonzalo Ayuso shares some of the results of his "playing with RabbitMQ, PHP and node", creating a queue system that both languages could talk to easily.

I need to use RabbitMQ in one project. I’m a big fan of Gearman, but I must admit Rabbit is much more powerful. In this project I need to handle with PHP code and node, so I want to build a wrapper for those two languages. I don’t want to re-invent the wheel so I will use existing libraries (php-amqplib and amqplib for node).

Basically I need to use three things: First I need to create exchange channels to log different actions. I need to decouple those actions from the main code. I also need to create work queues to ensure those works are executed. It doesn’t matter if work is executed later but it must be executed. And finally RPC commands.

He goes through some of the basics of using RabbitMQ , showing the code for each of the languages - pushing a new value into the queue, registering workers, creating Queue builders and using an exchange and receiver to process the message. The post finishes with the last piece in his requirements: creating the functionality to handle RPC commands to get an answer back from the queue.

tagged: rabbitmq node tutorial integration nodejs queue

Link: https://gonzalo123.com/2017/02/20/playing-with-rabbitmq-php-and-node/

Delicious Brains Blog:
Debugging JavaScript and PHP at the same time with PhpStorm
Feb 16, 2017 @ 11:14:20

The Delicious Brains site has a tutorial posted from author Peter Tasker showing you how to debug Javascript and PHP at the same time directly in your PHPStorm IDE.

Since I started with Delicious Brains last July, I’ve become a big fan of PhpStorm. It really is the bee’s knees. I won’t go over the full list of features, but some of the things I find helpful daily are: Cmd+clicking into method definitions, VCS integration and color highlighting of code changes, code bookmarks, and of course, Xdebug integration

In this post I want to expand on what Iain already covered with PhpStorm and Xdebug and show you how to level up your JavaScript debugging skills with PhpStorm.

The tutorial starts with a section explaining why using the PHPStorm debugger could be more beneficial and provide a more integrated workflow. It then starts in on the setup, showing how to set up the extension for Chrome so that it can talk to the IDE for the Javascript side complete with screenshots (and screencasts). With the two integrated the next step is to add a breakpoint in the code and what the results look like when it's executed and thrown.

The post finishes up covering the integration of the debugger with Xdebug allowing for the complete debugging of your application in one place.

tagged: debug javascript phpstorm integration tutorial xdebug

Link: https://deliciousbrains.com/debugging-php-javascript-phpstorm/

DotDev.co:
Google ReCaptcha integration with Laravel
Jan 10, 2017 @ 09:26:28

On the DotDev.co site they've posted an article from Talevski Igor about integrating Google's ReCaptcha with Laravel for use in verifying forms and protecting them against automated attacks.

Today i have task to create ReCaptcha on contact form with in a Laravel Web page and I like to share the process of making this possible.

He then walks you through the process of getting the configuration you'll need for your domain and using this package to easily integrate it with Laravel and its forms. He adds the routes for both the GET and POST requests along with the matching view and controller. He then uses the env helper function to get the ReCaptcha key from the configuration and places it in the form. He also adds the "g-recaptcha-response" variable to the required values rules and creates a simple Guzzle HTTP client to make the request back to Google to verify the result.

tagged: recaptcha security laravel tutorial form integration package

Link: https://dotdev.co/google-recaptcha-integration-with-laravel-ad0f30b52d7d?gi=ec5b94e26a27#.qdpwauax0

Fabian Schmengler:
Collection Pipelines in PHP
Dec 28, 2016 @ 12:24:24

In a new post to his site Fabian Schmengler has written up an introduction to collection pipelines and how it could be applied to a Magento-based environment.

If you read the book “Refactoring to Collections” or saw screencasts and talks by Adam Wathan about collection pipelines, but do not work with Laravel, you might have asked yourself how to apply these techniques to other PHP applications, for example Magento.

[...] This is very similar to Unix pipes, where the individual commands are the operations, and the lines passed through input and output stream, the collection.

He starts by illustrating the idea in Bash and Ruby, showing the three main types of collection operations: map, filter and reduce. He talks about the advantages these methods have over traditional looping and what kind of value they can provide in both Laravel and plain old PHP. He illustrates the PHP-only versions using the array_filter, array_map and array_reduce functions and some thoughts on when it's good to use them over normal looping (and when it's not). He then gets into the Magento-specific handling and making use of a package to handle collections: Knapsack. He shows how to use the library to work with collections and, as another option, a "home-grown" version that lives in a single class. The post wraps up with the Magento integration of this functionality, a brief mention of functional programming and "the hard part" of issues with debugging.

tagged: collection pipeline package knapsack magento integration tutorial introduction map reduce filter

Link: https://www.schmengler-se.de/en/2016/12/collection-pipelines-in-magento/