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

TutsPlus.com:
Pagination in CodeIgniter: The Complete Guide
Aug 15, 2017 @ 12:07:18

In this new tutorial posted to the TutsPlus.com site author Sajal Soni shares "the complete guide" to handling pagination in a CodeIgniter framework application using built-in tooling included with the framework.

The benefit of using any full-stack web application framework is that you don't have to worry about the common tasks like input handling, form validation and the like, as the framework already provides wrappers for those features. Thus, it allows you to concentrate on the business logic of the application rather than reinventing the wheel over and over again.

Today, we're going to explore an important library in the CodeIgniter framework—the pagination library.

The tutorial walks you through three main things: the basics of the pagination functionality, options you can use to customize it and the configuration options available for the component. Each section comes with code and configuration examples showing how to use the component.

tagged: pagination codeigniter tutorial options configuration example

Link: https://code.tutsplus.com/tutorials/pagination-in-codeigniter-the-complete-guide--cms-29030`

Derick Rethans:
New Date/Time Support in MongoDB
Aug 15, 2017 @ 09:46:11

In a new post to his site Derick Rethans talks about the new DateTime support in MongoDB and includes some PHP examples showing the changes in action.

In the past few months I have been working on adding time zone support to MongoDB's Aggregation Framework. This support brings in the timelib library that is also used in PHP and HHVM to do time zone calculations.

He then splits the rest of the post up into parts for the changes that this integration brings:

  • Time Zone Support for Date Extraction Operators
  • The $dateToParts Operator
  • The $dateFromParts Operator
  • Changes to the $dateToString Operator
  • The $dateFromString Operator
  • Using Date Expressions in $match

The post ends with a few notes about these changes, noting that it's currently only in the development release and "should be considered experimental" and subject to change. He then points out a few issues that will probably require updates to these features.

tagged: datetime support mongodb example tutorial list

Link: https://derickrethans.nl/mongo-date-time.html

Marco Bunge:
Application logic done right
Aug 14, 2017 @ 12:13:13

In a recent post to his site Marco Bunge offers some suggestions on how to write good application logic in a "clean, testable and reusable" way.

Web based enterprise applications are often accessible via different user interfaces through protocols like HTTP, Sockets, RPC, CLI. The Model-View-Controller is still present as a user-interface pattern. But requests and responses needs to be handled in the way of their interface requirements.

We don’t want to write the same logic for each required interfaces. Furthermore we don’t want to test and maintain code for each required interfaces. We want to write, test and maintain reusable source code at a central point of the application eco-system.

He then talks about the ideas behind the "three-teir architecture" and how this structure can be used to split logic into layers: presentation, logic and data. He mentions domain driven design as a development method to help achieve this structure and his meaning of the word "clean". He then gets into the implementation of this structure, defining the major pieces of functionality for each tier (with code for each included). He ends the post with some suggestions of points for additional reading about things like presenters, the ADR pattern and the "Inversion of Control" principle.

tagged: application logic opinion threetier clean tutorial example code

Link: http://www.marco-bunge.com/2017/08/05/application-logic-done-right/

SitePoint PHP Blog:
What Are the New Features in Laravel 5.5?
Aug 14, 2017 @ 11:22:03

On the SitePoint PHP blog there's a recent article posted by Christopher Vundi looking at the new features coming in Laravel 5.5, the next major release of the popular PHP framework.

Laravel 5.5 will require PHP 7.0+. For the features this modern PHP version brings, please see our recap.

Laravel 5.5 will also be the next LTS (Long Term Support) release. This means bugfixes for two years and three years of security updates. That was also the case with Laravel 5.1, but its two-year window of bug fixes is coming to an end this year. Without further ado, let’s see what this new version has to offer.

Instead of just describing the new features, the article opts to walk you through the installation of v5.5 and showing examples of each. Topics covered include:

  • Rendering Mailables to the Browser
  • Exception Helper Functions
  • Introducing the migrate:fresh Command
  • Automatic Package Discovery
  • Whoops is Back!
  • Custom Exception Report Method
  • Validation Data Return
  • Custom Blade::if() Directives
  • Autoregistering of New Artisan Commands in the Kernel

...among many others. There's a long list of new features coming in this release and the tutorial covers each nicely and provides the code examples it would take to make it all work.

tagged: laravel new feature v55 framework example code

Link: https://www.sitepoint.com/new-features-laravel-5-5/

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

Stovepipe Systems:
Immutability of Data
Jul 13, 2017 @ 10:51:22

On the Stovepipe Systems blog today Yannick de Lange has written up a post looking at data immutability and how using this concept can help improve your development and simplify data handling in your applications.

When dealing with enterprise software, your data is often the most valuable part. It contains all your customer information, contracts, invoices and much more. So what are you going to do to make sure the data is being dealt with correctly? A bug in your code can have a high impact on the integrity of your data. If the bug is causing unwanted changes in your data, fixing the damage might prove to be quite a big challenge.

With this post I would like to show how data immutability can help design a more robust system. One that is less susceptible to bugs that might make unwanted changes to your data.

He starts by talking about how immutability and data handling might seem like "a contradiction" but that it can, instead, be thought of as "versioning your data". He gives an example of an end date on a contract and how changing it directly leads to data loss. He then gets into an actual code example showing how to implement this data versioning. He starts by creating the basic "Contract" object but then refactors it into "versioned" types and how the changes would be tracked internally, updating with each change to the data instead of overwriting.

tagged: data immutability example tutorial version dataloss

Link: https://stovepipe.systems/post/immutability-of-data

Sam Greenwood:
Event Sourcing for the Rest of Us
Jun 27, 2017 @ 12:15:20

In this recent post to his site Sam Greenwood gives a high level overview of functionality that's becoming more popular and widely used - event sourcing. His post is a guide to event sourcing "for the rest of us" that aren't familiar with it but want to get an understanding of what it's all about.

Event sourcing can be described as storing the events that happened in your system in the order they happened, in some kind of store. These events are then replayed to recreate state in your system, rather than just having a single row in a table, using event sourcing, you have a full history of actions that happened in your system, and how your state got to the given point that it is in.

He uses a single entity in his illustration, showing how the changes would be put into an EventStore repository (possibly stored in something like this). He then sets up his event system for "members" and shows how to apply the different associated events. This is then sent to the repository for handling and saving to whatever data source you have defined.

tagged: eventsourcing introduction tutorial member event example

Link: https://www.samgreenwood.me/event-sourcing-for-the-rest-of-us/

SitePoint PHP Blog:
There’s a Gender Extension for PHP
Jun 26, 2017 @ 13:58:25

On the SitePoint PHP blog there's a new post from editor Bruno Skvorc sharing information about a "gender" extension for PHP that tries to guess the gender of a first name.

Recently, I ventured into a section of the PHP manual which lists extensions that are used to help with Human Language and Character Encoding. I had never looked at them as a whole – while dealing with gettext, for example, I always kind of landed directly on it and ignored the rest. Well, of those others, there’s one that caught my eye – especially in this day and age given the various controversies – the Gender extension.

This extension, in short, tries to guess the gender of first names. As its introduction says: "Gender PHP extension is a port of the gender.c program originally written by Joerg Michael. The main purpose is to find out the gender of firstnames. The current database contains >40000 firstnames from 54 countries."

This is interesting beyond the fact that the author is kinda called George Michael. In fact, there are many aspects of this extension that are quite baffling.

He then walks through some examples of putting the extension to use, evaluating various names in different languages and gauging the results. The extension allows for definite answers (is male/female), relative results, unisex, a "couple" or, when all else fails, erroring or giving a "not found" result. It also can check for "nicknames" for common names. He walks you through getting it installed and shows other functionality for getting similar names and checking for nicknames, showing code examples and the resulting output.

tagged: gender extension language tutorial introduction install example

Link: https://www.sitepoint.com/theres-a-gender-extension-for-php/

Stefan Koopmanschap:
The idempotent command
May 31, 2017 @ 13:33:05

In a new post to his site Stefan Koopmanschap covers the creation of idempotent commands, that is, commands that can only run one at a time without having to worry about possible overlap.

One of the things you may run into these days (and that I had to solve this week) is that these days we provision all servers similarly (or according to their role). This may also mean that you provision several of your servers to run the same cronjobs at the same time. However, some tasks may not be run multiple times, and especially not at the same time. In a symfony project I'm working on, I was tasked with making sure some of the cronjobs would only be run once, even if started on several servers at the same time.

He then goes through the process he followed for adding in the locking making use of the console.command and console.terminate hooks in the Symfony Command component. He then made use of the arvenil/ninja-mutex package to do the actual locking. He works through his decision process on when to lock and how to detect which commands needed to be locked. He ends the post with the code for the listener to create and release the lock automagically when the command has finished.

tagged: idempotent command symfony example locking

Link: https://leftontheweb.com/blog/2017/05/30/The-idempotent-command/

Rob Allen:
Slim's route cache file
May 31, 2017 @ 09:35:15

In a new post to his site Rob Allen talks about how you can speed up the routing in your Slim framework based application using the route cache file.

When you have a lot of routes, that have parameters, consider using the router's cache file to speed up performance.

To do this, you set the routerCacheFile setting to a valid file name. The next time the app is run, then the file is created which contains an associative array with data that means that the router doesn't need to recompile the regular expressions that it uses.

He gives an example of how to enable the setting and makes the recommendation that it's only used in production. He includes a simple example that defines "25 groups, each with 4000 routes, each of which has a placeholder parameter with a constraint." The first run on a route responds in 2.7 seconds but, once the cache file is created, it drops down to just 263 milliseconds - a major improvement.

tagged: slim route cache file tutorial example performance

Link: https://akrabat.com/slims-route-cache-file/