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

TutsPlus.com:
Understand the Basics of Laravel Middleware
Jul 26, 2017 @ 12:53:38

On the TutsPlus.com site there's a tutorial recently posted sharing the basics of middleware in Laravel applications - reusable pieces of code that operate on the request and response during the execution of your code.

In this article, we'll dive deep into the Laravel framework to understand the concept of middleware. The first half of the article begins with an introduction to middleware and what it's actually used for.

As we move on, we'll cover how to create custom middleware in a Laravel application. After creation of your custom middleware, we'll explore the options available to register it with Laravel so that it could be actually invoked during the request processing flow.

The tutorial starts by explaining what middleware is and how it functions in the flow of the Laravel application (as well as possible uses). It then starts in on the creation of custom middleware designed to redirect mobile users to the "mobile site" for the service. With the test for that in place the post then shows how to apply the middleware to the application on a route.

tagged: laravel middleware introduction custom mobile example

Link: https://code.tutsplus.com/tutorials/understand-the-basics-of-laravel-middleware--cms-29147

Master Zend Framework:
How to Create a Zend Expressive Module
Jul 26, 2017 @ 11:14:52

On the Master Zend Framework site Matthew Setter has written up a tutorial showing you how to create a Zend Expressive module to help organize your application and keep related files all in one place.

I've been reflecting recently on the things that I commonly have to do when I begin building Zend Expressive applications. Of the list that I created, I found that one of the most common — and uninteresting — of them is setting up the rendering of static page content. [...] To solve this, I've usually manually created modules to handle the rendering of static page content. These module's usually had little more than a PageAction class that returned an HtmlResponse object, whose body was a rendered template file.

[...] If you're in a similar position to where I was and want to collate the logic into a reusable module, then follow along with me in this tutorial I'm going to step you through how to create a module which you can reuse across any Zend Expressive project.

He starts by briefly describing a "module" in the context of a Zend Expressive application and how they relate (or don't) to the modules in Zend Framework v2. He then starts in on the module creation, showing how to set up the environment, change the Composer configuration to autoload correctly and describes what the end result should look like. From there the tutorial starts on the code required for the classes covering the basics of the class, exception handling, configuration and the creation of a factory to make a module instance.

tagged: zendexpressive tutorial module static content zendframework

Link: http://www.masterzendframework.com/create-a-zend-expressive-module/

BitExpert Blog:
Why using code as DI config is a win!
Jul 26, 2017 @ 10:58:21

In a post to the bitExpert.de site Stephan Hochdörfer explains why he thinks that using code over configuration in a DI container is a better approach than static configuration definitions.

In my recent talk on introducing Disco - the DI container with the damn coolest name(tm) - I talk about why I believe that using XML or any other non-code configuration (YAML, JSON, ...) is not a good idea. This stirred some twitter discussion recently which led to this blog post.

Just for the record, for a very long time I was part of the XML camp - just browse my collection of old talks to see for yourself. I praised XML a lot as being the only true DI configuration format.

He then goes through some of the main issues he sees with using something like XML for the dependency container's configuration:

  • An XML editor won't give you code-completion for PHP classes or methods.
  • Refactoring won't work properly in an XML configuration file.
  • An XML editor is not capable of doing proper type checks.
  • XML is just too verbose.

For each item he provides a brief explanation and an example of XML where it helps to illustrate the point.

tagged: xml configuration code disco dependency injection container opinion

Link: https://blog.bitexpert.de/blog/why-using-code-as-di-config-is-a-win/

Laravel News:
Introducing Laravel Horizon
Jul 26, 2017 @ 09:42:19

On the Laravel News site today they have a post announcing a new member of the Laravel family that was announced at the current Laracon conference: Laravel Horizon.

The moment everyone in the Laravel community has been waiting for has finally arrived! Laravel Horizon is software to “supercharge your queues with a beautiful dashboard and code-driven configuration.”

[...] Laravel Horizon is designed to make it easy monitor your queues from a web interface and receive notifications when things go wrong.

They list out some of the key features including auto-balancing, code-driven configuration, queue monitoring and a notification system. They briefly describe each of these features and what they see as the "most awesome part" - that the entire thing is open source and 100% free.

tagged: laravel horizon queue management interface release announcement

Link: https://laravel-news.com/introducing-laravel-horizon

Community News:
Recent posts from PHP Quickfix (07.26.2017)
Jul 26, 2017 @ 08:05:01

Recent posts from the PHP Quickfix site:

tagged:

Link:

Sound of Symfony Podcast:
Episode 18 - Event sourcing
Jul 25, 2017 @ 12:51:49

The Sound of Symfony podcast, with hosts Magnus Nordlander and Tobias Nyholm, recently posted their latest episode - Episode #18: Event Sourcing.

In this episode we talk a little bit about Webpack Encore, and a lot about Event Sourcing, with our guest, Beau Simensen.

Other topics mentioned in this show include:

  • Beau's Domain-driven design book
  • Event sourcing libraries like EventCentric, Broadway and Prooph
  • Conferences like SymfonyLive and SymfonyCon Romania

You can listen to this latest episode either using the in-page audio player or by downloading the mp3 directly. If you enjoy the show you can subscribe to their feed and follow them on Twitter to get updates when new shows are released.

tagged: soundofsymfony podcast ep18 eventsourcing event beausimensen

Link: http://www.soundofsymfony.com/episode/episode-18/

thePHP.cc:
Don't call instance methods statically
Jul 25, 2017 @ 11:16:39

In this new post on thePHP.cc site they talk about calling instance methods statically, more specifically that it should be avoided.

There are quite a few things in PHP 4 that were a bit strange. One example is that PHP 4 allowed static calling of instance methods. [...] To keep backwards compatibility with PHP 4, this code works up to PHP 5, even though [the method in the example[ is not declared static.

[...] Now things will get really weird. When calling an instance method of another class statically, the $this context would carry over from the caller to the called class. In other words, $this suddenly refers to another object instance. While in PHP 5, this used to be an E_STRICT error, PHP 7 will emit an E_DEPRECATED error.

They point out that, while this is definitely odd behavior that shouldn't exist, it hasn't been removed because of PHP's backwards compatibility principles and only removing functionality like this in major versions. So, instead, they recommend calling all non-static methods using an instance of the class injected rather than directly calling them.

tagged: instance method call static object avoid error

Link: https://thephp.cc/news/2017/07/dont-call-instance-methods-statically

Alejandro Celaya:
Reusing factories in Zend ServiceManager
Jul 25, 2017 @ 10:03:33

Alejandro Celaya has a new post to his site showing the Zend Framework users out there how you can reuse factories in Zend/ServiceManager. Factories are heavily utilized by the component to create the objects the service returns. Factories tend to be single-use, however, but Alejandro has shown a way around that.

I like zend-servicemanager because it is explicit, and you are always in control of what's done, without loosing flexibility in the process. Since this container expects you to define factories for every service, you usually end up writing, testing and maintaining a lot of factories that doesn't add value to the application.

That's why it is so important to properly reuse factories when possible, not only because you will have to maintain less classes, but because the ServiceManager will instantiate less objects at runtime when it can reuse a factory.

He then talks about ways you can set up shared factories in your application including the use of an abstract factory class or a concrete factory to return other dependencies required. He also shows how to use the ConfigAbstractFactory that allows for the injection of dependencies based on a configuration (similar to the "wiring" in other dependency injection containers). Finally he shows the use of the ReflectionBasedAbstractFactory that handles the injection in about the same way but instead of basing it on a configuration it uses PHP's own reflection to try to determine the class and autoload it into the current system.

tagged: factory zend servicemanager zendframework configuration reflection abstract tutorial

Link: https://blog.alejandrocelaya.com/2017/07/21/reusing-factories-in-zend-servicemanager/

Sammy Kaye Powers:
Writing tests for PHP source (Part 5 & 6)
Jul 25, 2017 @ 09:56:56

Sammy Kaye Powers has posted the latest parts in his series looking at testing the PHP language with phpt tests. So far he's helped you compile PHP from source, run the test suite, learn about the phpt files and debug failing tests. He continues the series with two new posts:

In the 5th part of his series he shows how to use the PHP gcov site to locate lines of code in the PHP language core that aren't tested yet, how to create a new test to cover it and generating a code coverage report to see how much you've tested. In Part 6 he shows you how to take what you've created and submit it back to the PHP project on GitHub as a Pull Request (no RFC needed) based on changes from your own forked repository.

tagged: series testing language phpt untested gcov source pullrequest

Link: https://www.sammyk.me/finding-untested-code-in-php-source-writing-tests-for-php-source

Community News:
Latest PECL Releases (07.25.2017)
Jul 25, 2017 @ 08:05:02

Latest PECL Releases:

  • ssh2 1.1.2
    - Version 1.1.2 is same as 1.1 except this release contains this changelog

    • Fixed bug #72988 (Libor M.)
    • Fixed bug #73198 (Langemeijer)
    • Fixed php_url_parse issue (Remi Collet)
    • fix Invalid write of size 1 (Remi Collet)
    • Fixed bug #73819 (Mitch Hagstrand)
    • Fixed bug #73410 (Mitch Hagstrand)
    • Travis CI (Mitch Hagstrand)
    • Various other fixes on PHP 7 code and code cleanup (Mitch Hagstrand, Libor M., Anatol Belski)
  • ref 0.4.4
    This release improves PHP 7.2 compatibility support

    Changelist:

    • Restore original referent obj handler when it is no longer tracked
  • ds 1.2.0
    - Vector's minimum and default capacity down from 10 to 8. - Map and Set's minimum and default capacity down from 16 to 8. - Hash function of arrays is now the length of the array, so O(1).
  • rar 4.0.0
    - Merge changes made to unrar up to version 5.5.6. - Support PHP 7.0 and PHP 7.1. - Added functions RarEntry::getRedirType(), RarEntry::isRedirectToDirectory() and RarEntry::getRedirTarget(), as well as the following constants on RarEntry: FSREDIR_UNIXSYMLINK, FSREDIR_WINSYMLINK, FSREDIR_JUNCTION, FSREDIR_HARDLINK and FSREDIR_FILECOPY. - Changed stat handler to return UTC time for creation, modification and access time (does not work reliably on Windows). - Fix cloning of RarArchive being allowed.
  • couchbase 2.3.4
    * PCBC-495: update user management APIs * PCBC-478: add tests for Error Map using CouchbaseMock
  • mustache 0.7.4
    - Mark release as stable - Change minimum version to 5.4.0
  • handlebars 0.8.2RC2
    - Mustache delimiter preprocessing support behind the compat flag - Property lookup now generates a closure from a method if the value of the property is null or does not exist to emulate the behaviour of javascript where functions and properties share a symbol table - only supported for PHP 7 or greater - Changed target handlebars.c version to 0.6.4
  • libsodium 2.0.3
    Requires at least php 7.0 and libsodium 1.0.9.
  • libsodium 2.0.4
    Requires at least php 7.0 and libsodium 1.0.9.
tagged:

Link: