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

Tomáš Votruba:
The Bulletproof Event Naming For Symfony Event Dispatcher
Jul 21, 2017 @ 12:39:28

In a recent post to his site Tomáš Votruba shares what he sees as a "bulletproof" event naming scheme for use with the Symfony event dispatcher component.

I wrote intro to SymfonyEventDispatcher and how to use it with simple event.

But when it comes to dispatching events, you can choose from 4 different ways. Which one to choose and why? Today I will show you pros and cons of them to make it easier for you.

He then breaks up the remainder of the post into the four suggestions, each with code examples and brief descriptions:

    1. Start with Stringly
    1. Group File with Events Names as Constants
    1. ...Constant Names in Particular Event Classes
    1. Class-based Event Naming

For each he also includes some "pros" and "cons" to help you select which one might work best for your usage. He ends by taking things "a step further" and sharing integrating a suggestion to remove an argument and simplify the code.

tagged: naming symfony event dispatcher event tutorial

Link: https://pehapkari.cz/blog/2017/07/12/the-bulletproof-event-naming-for-symfony-event-dispatcher/

Sammy Kaye Powers:
Writing tests for PHP source (Series)
Jul 21, 2017 @ 11:21:48

Sammy Kaye Powers has a series of posts over on his site introducing you to testing the PHP language with .phpt tests. So far he's introduced the topic, shown how to run the tests and debugging failing tests.

If you've ever wanted to get involved with PHP internals, writing tests is a great way to get your foot into the door. The tests are written in PHP so you don't even need to know C to get started.

Each of the posts also comes with a screencast, narrated by Sammy, showing the information presented in the tutorial:

There's more to come in the series as he still plans to teach about how to fix current tests and how to eventually create your own. Stay tuned to his site for more tutorials in the series.

tagged: test unittest phpt language source series part1 part2 part3 part4

Link: https://www.sammyk.me/compiling-php-from-source-writing-tests-for-php-source

Jakub Zalas:
Static analysis tools for PHP in a single docker image
Jul 21, 2017 @ 10:56:07

Jakub Zalas has a new post to his site sharing a Docker image he's created to help make static analysis for your PHP code simpler: the phpqa image.

As part of my job I often perform application reviews and code quality analysis for clients who wish to have their code base looked at by an independent company. Running static analysis tools is usually a starting point to the review as it gives a general overview of a state of the project. I also like to run those tools as part of an introduction to an inherited code base.

For an easy access to the most popular static analysis tools for PHP I recently created a docker image - phpqa.

He lists out the tools that are included with the current version (a quite lengthy list) including:

  • analyze
  • box
  • deptrac
  • php-code-fixer
  • phpDocumentor
  • phpa
  • phploc
  • phpmd
  • phpstan
  • psalm

...and many more. Check out the full post for more of the tools in the list and links to more information about each one.

tagged: docker image static analysis tool image phpqa

Link: http://zalas.eu/phpqa-static-analysis-tools-for-php-docker-image/

Laravel News:
Two Best Laravel Packages to Manage Roles/Permissions
Jul 21, 2017 @ 09:48:46

The Laravel News site has posted an in-depth look at two packages Laravel users can implement to add in role/permission management: Bouncer and Laravel-permission.

Roles and permissions are an important part of many web applications. Laravel historically had a lot of packages for them, and improved the core code as well. So what is the situation on this market today? What packages are the best to use? I’ve picked two.

The post starts off by sharing a few reasons why you might even need these packages with the functionality that Laravel already includes. Most of the reasoning comes from the fact that the framework allows for checks but doesn't provide role/permission management. It then gets into what each of the package provide, how to install them and some example code to put them to use. It also looks at the database structure behind them and how they use that to store the authorization data.

tagged: laravel role permission package bouncer laravelpermission introduction tutorial

Link: https://laravel-news.com/two-best-roles-permissions-packages


TutsPlus.com:
How to Register & Use Laravel Service Providers
Jul 20, 2017 @ 14:08:19

On the TutsPlus.com site they've posted a new tutorial showing you how to register and use service providers in Laravel and how it relates to the service container functionality.

If you've ever come across the Laravel framework, it's highly unlikely that you haven't heard of service containers and service providers. In fact, they're the backbone of the Laravel framework and do all the heavy lifting when you launch an instance of any Laravel application.

In this article, we're going to have a glimpse of what the service container is all about, and following that we'll discuss the service provider in detail. In the course of this article, I'll also demonstrate how to create a custom service provider in Laravel.

The article starts with an overview of the service container and service providers, describing what they are and providing some example code/configuration to clarify the concepts. It then gets into the creation of your own custom service provider. In their case they create a provider that doesn't really do anything but it does help to show how to make it, register it and put it to use in a controller.

tagged: tutorial register use laravel service provider serviceprovider container

Link: https://code.tutsplus.com/tutorials/how-to-register-use-laravel-service-providers--cms-28966

SitePoint PHP Blog:
How to Write JavaScript-Style Test Watchers in PHP
Jul 20, 2017 @ 13:18:43

On the SitePoint PHP blog there's a new tutorial that talks about creating "watchers" in your PHP code similar to the ones that the Javascript world has used to detect changes in files and automatically perform actions.

In the land of JavaScript, it’s not uncommon to preprocess source code. In the land of JavaScript, developers write in syntax not widely supported, and the code is transformed into syntax that is widely supported, usually using a tool called Babel.

In order to reduce the burden of invoking the transformation scripts, boilerplate projects have started to include scripts to automatically watch for file changes; and thereafter invoke these scripts.

These projects I’ve worked on have used a similar approach to re-run unit tests. When I change the JavaScript files, these files are transformed and the unit tests are re-run. This way, I can immediately see if I’ve broken anything.

The author (Christopher Pitt) then shows how to create the project and make use of pre-processing and some sample scripts to run tests against. He shows how to set up the test configuration and provides an example test. Finally he includes a script that's used by the "watcher" to recompile the scripts before the tests are executed. To to the watching, he uses the yosymfony/resource-watcher package and a long running PHP script ("watch-test").

tagged: watcher javascript tutorial unittest phpunit resourcewatcher

Link: https://www.sitepoint.com/write-javascript-style-test-watchers-php/

PHP.net:
PHP 7.2.0 Beta 1 Released
Jul 20, 2017 @ 12:49:13

In an announcement on the main PHP.net site, the PHP development team as officially announced the release of the first beta for PHP 7.2.0 - beta 1.

The PHP development team announces the immediate availability of PHP 7.2.0 Beta 1. This release is the first beta for 7.2.0. All users of PHP are encouraged to test this version carefully, and report any bugs and incompatibilities in the bug tracking system.

[...] PHP 7.2.0 Beta 1 builds on previous releases with: the much anticipated Sodium extension, Opcache improvements, Countable support for DOMNodeList and DOMNamedNodeMap improved handling for invalid UTF8 in json_decode() and many bugfixes...

You can find the complete list of updates in the NEWS entry for this beta and, as always, you can download this preview release from the QA downloads page or from windows.php.net/qa for the Windows binaries.

tagged: language beta release php72beta1

Link: http://php.net/index.php#id2017-07-20-1

Laravel News:
The Road To Laracon Soundtrack
Jul 20, 2017 @ 09:46:12

On the Laravel News site they've posted an article sharing a series of podcasts dubbed the "Road to Laracon" where hosts Jacob Bennett and Michael Dyrynda talked with Laracon US 2017 speakers and asked them to suggest one song to use in the playlist.

Next week is Laracon US, and Jacob Bennett and Michael Dyrynda have been interviewing many of the speakers on the podcast. As part of the interview, they’ve asked the speakers to pick a few of their favorite songs and put it together in a Spotify playlist.

It features twenty-three songs and is an hour and forty-three minutes of listening pleasure and I enjoy trying to match the song to the speaker.

If you'd like to hear the interviews with some of the speakers, they've linked to a few at the end of the post including Freek Van der Herten, Jack McDade and Laura Elizabeth.

tagged: laravelnews roadtolaracon soundtrack podcast song playlist

Link: https://laravel-news.com/the-road-to-laracon-soundtrack