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

Alfred Nutile:
Feature Flags In Laravel
Jan 26, 2016 @ 09:45:02

In a post to his site Alfred Nutile has posted a guide to integrating feature flags (toggles) into your Laravel-based application to show and hide features based on different criteria. He makes use of the Atriedes/feature library to handle some of the logic and decisions for him.

We are working on using FeatureFlags or Toggles in our applications. For one we are aiming to do all our work on mainline branch at all times so this would be a key coding discipline to use FeatureFlags so we can hide a feature in progress knowing it will not interfere with the application.

[...] One key thing, as I use this in Laravel, is I will try and mix this with the existing Authorization workflow that is already present. This gives me some already prepared ways to think about this both at the view layer, model layer and controller layer and where to register these states.

He shows how to get the "feature" library installed and integrates it with the Laravel application via two service providers: one for the core flag handling and the other for defining the policies themselves. He includes the code for each of these providers and makes some simple "can see" and "can add" policies for a Twitter field. He also shows the code for the evaluation methods and how to make use of the functionality in a menu (template). He also includes a screencast showing how it all works in a live application.

tagged: featureflag toggle tutorial laravel atriedes library screencast feature

Link: https://alfrednutile.info/posts/175

Jordi Boggiano:
New Composer Patterns
Dec 21, 2015 @ 11:52:36

Jordi Boggiano, lead developer on the Composer has posted about some of the new Composer patterns that have been introduced into the tool this year, including some you might not even have realized.

Here is a short update on some nice little features that have become available in the last year in Composer.

He includes five of these features in his list (but something tells me these are just some of the more user-facing improvements the project has introduced):

  • Checking dependencies for bad patterns
  • Referencing scripts to avoid duplication
  • Defining your target production environment in composer.json
  • Excluding paths from the optimized classmap
  • Requiring packages easily and safely

For each item he includes the command (and sometimes optional arguments) that make it work and what kind of results you can expect. There's definitely some handy features in here and not just for the "power users" in the crowd.

tagged: composer feature update project patterns duplication environment classmap

Link: http://seld.be/notes/new-composer-patterns

Matt Stauffer:
Implicit route model binding in Laravel 5.2
Dec 18, 2015 @ 09:34:53

Matt Stauffer has continued his series looking at the new features of Laravel v5.2. In this new article he talks about the addition of implicit route model binding. This is a bit more fancy term for the ability to link models to routes and tell Laravel they're related.

If you've never used it, Laravel's route model binding has been around for a while, but Laravel 5.2 is about to make it even easier. [...] In your route service provider, just teach the router: $router->model('shoe', 'AppShoe'); That means, "any time I have a route parameter named shoe, it's an ID representing an instance of AppShoe". [...] In Laravel 5.2, it's even easier to use route model binding. Just typehint a parameter in the route Closure (or your controller method) and name the parameter the same thing as the route parameter.

He includes code examples of the "old way" to do it with model functionality inside the route and the "new way" of linking the model to the route. This allows you to auto-magically have a valid model instance once the route is called. He also shares some of the little known features of this model binding including using closures in bind() calls and changing the "route key" away from the "id" column.

tagged: model route binding laravel feature implicit feature v52

Link: https://mattstauffer.co/blog/implicit-model-binding-in-laravel-5-2

Matt Stauffer:
Implicit route model binding in Laravel 5.2
Dec 18, 2015 @ 09:34:53

Matt Stauffer has continued his series looking at the new features of Laravel v5.2. In this new article he talks about the addition of implicit route model binding. This is a bit more fancy term for the ability to link models to routes and tell Laravel they're related.

If you've never used it, Laravel's route model binding has been around for a while, but Laravel 5.2 is about to make it even easier. [...] In your route service provider, just teach the router: $router->model('shoe', 'AppShoe'); That means, "any time I have a route parameter named shoe, it's an ID representing an instance of AppShoe". [...] In Laravel 5.2, it's even easier to use route model binding. Just typehint a parameter in the route Closure (or your controller method) and name the parameter the same thing as the route parameter.

He includes code examples of the "old way" to do it with model functionality inside the route and the "new way" of linking the model to the route. This allows you to auto-magically have a valid model instance once the route is called. He also shares some of the little known features of this model binding including using closures in bind() calls and changing the "route key" away from the "id" column.

tagged: model route binding laravel feature implicit feature v52

Link: https://mattstauffer.co/blog/implicit-model-binding-in-laravel-5-2

SitePoint PHP Blog:
Feature Toggling Explained with Qandidate’s Toggle
Dec 15, 2015 @ 11:49:57

The SitePoint PHP blog has posted a tutorial showing you how to use the Toggle library from Qandidate to handle the enabling and disabling of features in your application.

A frequently used development workflow in version control systems is feature branching. The idea is that we develop new features in branches other than the master one. After a feature is tested and ready to be released, it is merged back into the master branch or a release branch for deployment. This approach helps us develop new features without disturbing the main code base.

However, developing a feature branch might take much longer than a normal release cycle. [...] One of the techniques widely used as an alternative to feature branching is feature toggling. Feature toggles (or feature flippers) act like on/off switches. [...] We can temporarily hide a partially built or risky feature (release toggles) or limit finished stable features to a certain group of users (business toggles).

They introduce the basics of the Toggle library and it's main components: the Manager, Toggles, Operators, Conditions and Context. These are all combined together to help determine if a feature should be enabled or hidden. Examples of each are included along the way as well as one showing a toggle in action. They also show how to integrate it with a framework, in this case a Laravel project as middleware. The post ends with a look at strategies, giving you even more customization around the conditions of the toggle (example: Affirmative, Majority and Unanimous), statues and creating the conditions from either YAML or array configurations.

tagged: feature toggle flag qandidate library tutorial introduction functionality

Link: http://www.sitepoint.com/feature-toggling-explained-with-qandidates-toggle/

PHP Roundtable:
035: Immutable PHP
Nov 25, 2015 @ 09:53:44

The PHP Roundtable podcast has posted their latest episode, recorded live with host Sammy Kaye Powers and guests Larry Garfield, Matthew Weier O'Phinney and Glen Hickle talking about immutability in PHP.

Immutability plays a huge role in functional programming and many languages support immutability directly; like the readonly keyword in C#. It is possible to create immutable objects in PHP, but the language lacks inherent immutable features for scalar variables and class properties. We discuss how to bring functional programming concepts to PHP and brainstorm some features that could possibly be added to future versions of PHP to offer better immutability support.

You can watch the live recording of this latest episode either through the in-page video player or directly over on YouTube. If you enjoy the show, be sure to also subscribe to their feed and follow them on Twitter for information on the latest episodes (and when future live recordings are happening).

tagged: phproundtable ep32 immutability programming feature functional support

Link: https://www.phproundtable.com/episode/immutability-and-functional-concepts-in-php

Laravel News:
Laravel 5.2 - A Look at what’s coming
Nov 02, 2015 @ 11:06:05

The Laravel News site has posted a look ahead at Laravel 5.2, the next minor version release of the popular framework.

ravel 5.2 development is underway and so far a few nice additions have been announced. Let’s take a look at everything we know is coming to the release.

Among the things mentioned are improvements/features like:

  • Implicit model binding
  • Form Array Validation
  • Collections Wildcards
  • Database Session Driver updates

This version isn't released yet (as of the time of this post) but it's coming soon. Keep an eye on the main Laravel site for more information.

tagged: laravel minor version update enhancement feature framework

Link: https://laravel-news.com/2015/11/laravel-5-2-a-look-at-whats-coming/

Paragon Initiative:
How to Safely Implement Cryptography Features in Any Application
Oct 07, 2015 @ 11:51:41

The Paragon Initiative blog has posted a new article showing you how to safely implement cryptography in any PHP-based application (or really just about any application) with the help of libsodium.

Why not {Mcrypt, OpenSSL, Bouncy Castle, KeyCzar, etc.}? These cryptography libraries are really building blocks that by and large must be used, with expert care, to build the interfaces you want developers to use. In most cases, libsodium is the interface you want developers to use. [...] By default, these libraries don't provide [authenticated encryption](https://tonyarcieri.com/all-the-crypto-code-youve-ever-written-is-probably-broken). Most of them force developers to use RSA (or ECDSA but certainly not EdDSA), which is [hard to get right](http://www.daemonology.net/blog/2009-06-11-cryptographic-right-answers.html) and for which [index calculus attacks are improving each year](https://events.ccc.de/congress/2014/Fahrplan/system/attachments/2501/original/20141227.pdf).

He goes on to talk about NaCI as a possible option (libsodium is from a fork of it) but points out that NaCI isn't as easily available as libsodium to non-C/Python developers. He shares a few reasons why he thinks "libsodium is so great" and a few reasons not to use it (mostly dealing with outside limitations, not technical ones). Finally he points you in the right direction to help you get started using libsodium for PHP as a PECL extension.

tagged: cryptography feature safe guide tutorial introduction pecl extension

Link: https://paragonie.com/blog/2015/09/how-to-safely-implement-cryptography-in-any-application

Knp University:
Fun with Symfony's Console Component
Oct 06, 2015 @ 10:26:41

In a post to the Knp University blog they show you some of the fun you can have with the Symfony Console component in a single file including a few lesser known (and lesser used) features.

One of the best parts of using Symfony's Console component is all the output control you have to the CLI: colors, tables, progress bars etc. Usually, you create a command to do this. But what you may not know is that you can get to all this goodness in a single, flat PHP file.

They walk you through the creation of a ConsoleOutput object with a simple writeln output of a formatted method. They briefly mention the handling for changing up the output (OutputFormatter and OutputFormatterStyle) before getting into something a bit more complex - table layouts. They end the post with an interesting "hidden" feature inside the component, the Symfony track progress bar (animated gif included to show the end result).

tagged: symfony console component feature pretty output table track progressbar

Link: http://knpuniversity.com/blog/fun-with-symfonys-console

Lorna Mitchell:
New in PHP 7: null coalesce operator
Sep 30, 2015 @ 10:51:52

Lorna Mitchell has a post to her site talking about a new addition to PHP in the upcoming major release of PHP 7 - the null coalesce operator. Despite its slightly confusing name, the operator is very handy for certain use cases with the ternary syntax.

Not the catchiest name for an operator, but PHP 7 brings in the rather handy null coalesce so I thought I'd share an example. In PHP 5, we already have a ternary operator, which tests a value, and then returns the second element if that returns true and the third if it doesn't. [...] There is also a shorthand for that which allows you to skip the second element if it's the same as the first one.

[...] In PHP 7 we additionally get the ?? operator which rather than indicating extreme confusion which is how I would usually use two question marks together instead allows us to chain together a string of values.

She includes an example of this new operator in use, chaining together a simple expression and showing the resulting output. It's a little confusing at first, but then if you remember it reads left to right it clears it up a bit.

tagged: null coalesce operator php7 feature example

Link: http://www.lornajane.net/posts/2015/new-in-php-7-null-coalesce-operator