Inflected – a port of ActiveSupport’s inflector to Node.js and the browser

For the last few years I have been heavily involved in building web applications with the CakePHP framework.  Apart from all the usual MVC, ORM, and so on, and so forth, features, I am a big fan of the CakePHP utilities.  And among all of them, my long time favorite is the Inflector class.

The Inflector class makes makes word transformations a breeze – camel-casing, snake-casing, plural, singular, and so on – work like a charm at least for the English language.  It’s also possible to use the same functionality for other languages, but that would require quite a bit of the linguistic expertise.

I’ve got so used to the inflections that I miss them every single time I have to step out of the CakePHP framework.  This doesn’t happen very often for me in the PHP domain, but JavaScript is a totally different story.

The other day I came across the inflected library, which brings most of the CakePHP’s Inflector to JavaScript, via either a Node.JS NPM package, or a simple inclusion of the JavaScript file to the page source and laying off all the hard work on to the browser.

I’m a lot happier with my universe now.

forget-db – a simple GDPR inspired tool to anonymise confidential database data

forget-db:

A simple(ish) command line tool written in PHP 7.1 using Laravel Zero and Faker to help you anonymise/pseudonymise data within your database to support protecting either sensitive information, or peoples right to be forgotten with GDPR compliance.

The tool allows you to connect to either mysql, postgres, sqlite or sqlserver and replace defined information with random data to allow you to keep statistics/relationships/audit of actions etc.

It uses a simple yaml configuration file to define the conditions for overwriting, which fields you want to overwrite, and what to overwrite them with.

Top 100 PHP functions

Top 100 PHP functions” is a list of the top 100 most frequently used PHP functions, from the analysis of the 1,900 open source projects.   If you are still learning PHP, this list is a good overview of what you’ll see the most in real life projects.

Weird operators in PHP

Weird operators in PHP” covers a variety of awkward and weird operators in PHP.  I don’t think I’ll ever write any code using any of these.  But in case I come across any code in the future, that utilizes them, I should be sure to search back in the archives of this blog.  Here’s an example to get you started:

X-fighters

In case you want to add some firepower to the previous fleet, you can summon X-fighters to the PHP source : +-0-+. The following code adds 3 to $a.

$a = $a +-0-+ 3;

When and where to determine the ID of an entity

It always amazes me when I randomly come across an article or a blog post precisely on the subject that I’m mulling over in my head – all without searching specifically for the solution or even researching the problem domain.  It’s almost like the universe knows what I’m thinking and sends help my way.

When and where to determine the ID of an entity” is an example of exactly that.  Lately, I’ve been working with events in CakePHP a lot.  And for one particular scenario, I was considering the beforeSave() event in the model layer, which would trigger some functionality that modifies data in other models.  So, having a reference of the current ID would be useful for debugging and logging purposes.  But since the current entity hasn’t been saved it, the ID is not there.   And that’s where I started thinking about this whole thing and considering where is the right place to generate the ID.

One thing that kind of bothered me on top of the theoretical discussion, was the practical implementation, especially in different frameworks.  If I remember correctly, the earlier version of CakePHP framwork, used the presence or absense of the ID in the entity to differentiate between insert and update operations.  It might still be true now, but at least there is a way to work around it, as CakePHP now has isNew() method to check if the entity needs to be inserted or updated.