CakePHP: Interview with Larry E. Masters

Interesting interview with one of the core members of CakePHP community – Larry E. Masters.

Throughout the interview Larry covers CakePHP Framework history, as well as covering major milestones of CakePHP 3.x version. If you’re still into 2.x – it’s time to upgrade, as it brings some nice perks, more flexible code, and massive performance boost.

 

Work fuel: what really motivates us

Seth Godin published once again a great article on work/life motivation.

  • Becoming a better version of yourself
  • Catastrophe (or the world as we know it will end)
  • Connection (because others will join in)
  • Creative itch (the voice inside of you wants to be expressed)
  • Dissatisfaction (because it’s not good enough as it is)
  • Engineer (because there’s a problem to be solved)
  • Generosity (because it’s a chance to contribute)
  • Possibility (because we can, and it’ll be neat to see how it works in the world)
  • Selection (to get in, win the prize, be chosen)

IIO Sensor proxy: screen rotation

One of the things I don’t get is why this thing is enabled by default on Linux distros.

With a GNOME 3.18 (or newer) based system, orientation changes will automatically be applied when rotating the panel, ambient light will be used to change the screen brightness, and Geoclue will be able to read the compass data to show the direction in Maps.

It’s really annoying on the laptops, if you accidentally rotate your monitor.

sudo systemctl stop iio-sensor-proxy.service
sudo systemctl disable iio-sensor-proxy.service

Enough with screen rotations!

PHP: Testing protected methods in CakePHP3

One of the things I recently had to deal with – unit testing protected methods of the class. Few seconds of checking StackOverflow brought a nice and elegant way of checking protected methods using ReflectionClasses. Sebastian Bergmann has a complete guide on how to check non-public functionality of the classes in his archieves.

Here’s a short sample of the code using CakePHP3:

<?php

 use Search\Model\Table\SaveSearchTable;
 use Cake\TestSuite\TestCase;
 
 class SaveSearchTableTest extends TestCase
 {
    public function setUp()
    {
        $this->SavedSearches = \Cake\ORM\TableRegistry::get('SavedSearches');
    }
    
    public function testProtectedMethod()
    {
        $methodName = 'protectedMethod';
        
        $reflectionClass =  new \ReflectionClass('\Search\Model\Table\SaveSearchesTable');
        
        $method = $reflectionClass->getMethod($methodName);
        
        $methodResult = $method->invokeArgs( $this->SavedSearches, [
            'arg1',
            ['arg2']
        ]);
        
        $this->assertNotEmpty($methodResult);
    }
 }

 

WP-CLI moves to make.wordpress.org

Great news to the WordPress community and those who spend most of their time in the console. WP-CLI after reaching 1.x stable moves to make.wordpress.org. No more weird sftpd/vsftpd installations, wp-cli gets officially recognized as a community tool for upgrades that might come handy with composer bundle as we do it in Qobo for WordPress project templates.

Silver Searcher: ack but faster

As a frequent user of grep/ack for the codebase, ag seems to be a silver bullet, especially for the projects with large codebase. Available in rpm repositories.

What’s so great about Ag?

  • It is an order of magnitude faster than ack.
  • It ignores file patterns from your .gitignore and .hgignore.
  • If there are files in your source repo you don’t want to search, just add their patterns to a .ignore file. (*cough* *.min.js *cough*)
  • The command name is 33% shorter than ack, and all keys are on the home row!

CakeDC upgrades users plugin with Google Authenticator

Few days of work, and almost a month of waiting, but it was totally worth it. Yesterday noon, CakeDC community upgraded one of its major plugins, with our Qobo patch, that allows users to enable Google Authenticator functionality I wrote about previously. There’s no need anymore to use ‘dev-develop’ branches in composer.

 

Google Authenticator in CakePHP3.x

Google Authenticator gets a new wave of interest from the web community, trying to put an extra layer on top of user authentication process. There’s a plethora of plugins and components that let you authenticate with Google, but most of them aim to OAuth and Google+ integration. Two-step auth gets aside.

I took few hours on research for the simple 2FA library available on the net and found TwoFactorAuth that already support Google URI QR-codes, that can be easily embedded into any framework/application running on PHP.

CakePHP3.x Integration

With few minor modifications it nicely got integrated into CakePHP 3.x framework. If you’re using CakePHP 3.x, you can install ‘develop’ branch, of CakeDC/Users plugin, and enable two-factor authentication with few minor modifications.

 <?php
 //config/app.php or any other config file that suites your app
 Configure::write('GoogleAuthenticator.login', true);
 /*
 some other custom configs you might need
 'GoogleAuthenticator' => [
            //enable Google Authenticator
            'login' => false,
            'issuer' => null,
            // The number of digits the resulting codes will be
            'digits' => 6,
            // The number of seconds a code will be valid
            'period' => 30,
            // The algorithm used
            'algorithm' => 'sha1',
            // QR-code provider (more on this later)
            'qrcodeprovider' => null,
            // Random Number Generator provider (more on this later)
            'rngprovider' => null,
            // Key used for encrypting the user credentials, leave this false to use Security.salt
            'encryptionKey' => false
        ],
*/
?>

When you enable it the CakeDC/Users Google Authenticator feature, upon ‘/login’ you will ll be redirected to ‘/verify’, where you should insert your verification code from the mobile app (Google Authenticator for Android).

If you’re already sharing a secret key with the website/app, you won’t have to synchronize an app with it. Otherwise, you’ll have to scan it first, as it’s described in the documentation. QR-code will appear on the ‘/verify’ action of the app.

UPD: CakeDC/Users has upgraded the plugin to 4.x version, which enables Google Authenticator in the master repo.

Vim: statusline and git customizations

Working with lots of projects at the same time in qobo.biz, I started to get confused on which branch I’m currently working.

Going back to the terminal, to check the diffs and commits, became a time waste in my daily routine, so I took a break during lunch, to get my vim plugins an upgrade. The catch of the day is the following:

Vim-Airline

Vim-Airline is a powerful status/tabline facelift of a default statusline with lots of customizations, and useful information on the files you work with. It nicely fits solarized theme, has color shift on different modes:

vim-airline demo
vim-airline with solarized theme enabled
Vim-gitgutter

Vim-gitgutter – is currently my favorite. The plugin identifies on-the-fly differences in the files you’re working in.

gitgutter diff
gitgutter diff with numbers on
Vim-fugitive

And last, but not the least for today – git wrapper for vim – vim-fugitive. It comes very useful with its set of git commands that you can access directly from vim, for example:

* :Gblame - now you can blame yourself in all the bugs
* :Gstatus - what's the status?
* :Gbrowse - redirects you to repositories file in github/bitbucket
* :Gcommit - let the fun begin

And just to complete the list of cools stuff, I must mention tagbar, that I’ve been using for long time, and its phpctags addon, that can make your life easier with better PHP support.

To summarize it all, a bit of editors fun from Twitter: