File List Generation, Phix and using GitHub as a PEAR channel

My current project at work started in late July, and we have been able to use Jenkins for Continuous Integration and Deployment into our Alpha and Beta environments. We have multiple people committing to the project branch, which is new for us, as historically we had one merge master. Basically this project is a guinea pig for a different approach in our department, which luckily for me, is currently working. The downside to multiple people merging into the project is no overall ownership or gatekeeper to what is on the project branch. This can lead to some issues..

We are doing releases every 3rd week, and getting the code, database configuration and filesystem configuration all rolled onto the production platform is now a doddle since it is automated for Alpha/Beta. Right now we haven’t automated the full roll to production, however we are in the process of making this happen. One part of the deployment we seem to forget however, is removing redundant files. We remove the files from git, great, but we forget to add the files we removed to a bash script which does the file removal for us on the production platform. Not so great really!


As project lead (or a just being conscientious), I really don’t want to be leaving redundant/dead code on the production servers, so I wanted a way of knowing what was in git and what was in production. I therefore came up with “phpflg” which stands for PHP File List Generator. Yes, I know, you can do most, if not all of this using bash commands, however there isn’t much fun in that and I wanted to play with a few things :-)

So, first up, this is how you install it:

$ sudo pear channel-discover benmatselby.github.com/pear
$ sudo pear channel-discover pear.phix-project.org
$ sudo pear channel-discover pear.phpunit.de
$ sudo pear install benmatselby/PHPFLG
downloading PHPFLG-1.0.0.tgz ...
Starting to download PHPFLG-1.0.0.tgz (8,963 bytes)
.....done: 8,963 bytes
install ok: channel://benmatselby.github.com/pear/PHPFLG-1.0.0

Notice the GitHub PEAR Channel!! Once you have installed it, you should be able to run it like:

$ phpflg --help
phpflg 1.0.0

Usage: phpflg [switches]

  --base-path            Folder to generate file list from.
  --prefix-path          The prefix to be added to all files.
  --exclude-path         Path to be excluded from the file list.

  --suffixes             Suffix limiter for the file list.
  --prefixes             Prefix limiter for the file list.

  --transformer          Which printer to use to output the file list.
                         Options include text (Default), json, php.

  --report-file          Report output filename.

  --help                 Outputs help information.
  --version              Outputs version information.

As you can see, it’s fairly flexible in the files to generate the list for (–exclude-path, –suffixes, –prefixes etc) and its fairly flexible in the format of the output (text based, json based or php variable and it’s trivial to add more transformers.)

This mainly wraps File_Iterator from Sebastian Bergmann.

So, now I can run “phpflg” from within my git folder, use –prefix-path to add the filesystem path on our production servers to generate me a list of files that is in git. I do the same on our production platform and then do a diff against the two files. Hopefully I only have files to remove, rather than files that are in git and not on our product servers once the product is live!

Some examples of the output are below.

Basic text based output:

$ phpflg --base-path src/php/
phpflg 1.0.0

src/php/PHPFLG/Generator.php
src/php/PHPFLG/Printer/File.php
src/php/PHPFLG/Printer/Screen.php
src/php/PHPFLG/Printer.php
src/php/PHPFLG/TextUI/Application.php
src/php/PHPFLG/Transformer/Json.php
src/php/PHPFLG/Transformer/Php.php
src/php/PHPFLG/Transformer/Text.php
src/php/PHPFLG/Transformer.php

PHP based output:

$ phpflg --base-path src/php/ --transformer Php
phpflg 1.0.0

$phpflgFileList = array (
  0 => 'src/php/PHPFLG/Generator.php',
  1 => 'src/php/PHPFLG/Printer/File.php',
  2 => 'src/php/PHPFLG/Printer/Screen.php',
  3 => 'src/php/PHPFLG/Printer.php',
  4 => 'src/php/PHPFLG/TextUI/Application.php',
  5 => 'src/php/PHPFLG/Transformer/Json.php',
  6 => 'src/php/PHPFLG/Transformer/Php.php',
  7 => 'src/php/PHPFLG/Transformer/Text.php',
  8 => 'src/php/PHPFLG/Transformer.php',
)

Adding prefix to the files:

$ phpflg --base-path src/php/ --prefix-path /path/to/production/folder/
phpflg 1.0.0

/path/to/production/folder/src/php/PHPFLG/Generator.php
/path/to/production/folder/src/php/PHPFLG/Printer/File.php
/path/to/production/folder/src/php/PHPFLG/Printer/Screen.php
/path/to/production/folder/src/php/PHPFLG/Printer.php
/path/to/production/folder/src/php/PHPFLG/TextUI/Application.php
/path/to/production/folder/src/php/PHPFLG/Transformer/Json.php
/path/to/production/folder/src/php/PHPFLG/Transformer/Php.php
/path/to/production/folder/src/php/PHPFLG/Transformer/Text.php
/path/to/production/folder/src/php/PHPFLG/Transformer.php

So, that gives a basic overview of what the little tool can do, and I imagine I’ll be the only one to ever use it, but it let me learn about:

  • Phix
  • Making your GitHub account a PEAR channel

Phix

So, phix.

Phix makes it extremely easy to create and maintain your own PEAR-installer compatible components for reuse in your PHP applications

All I can say to that is, Yes it does. When I first starting building phpflg, I did not use Phix, mainly as I was ignorant to it, and wanted to just get some functionality working before looking into all of the options out there.

I spoke to Sebastian Marek who had taken Stuart Herbert’s tutorial at the PHPNW11 Conference: “Maintainable Applications in PHP Using Components” who convinced me to look into Phix, so I did. Within about 20-30 minutes of being told to look into it, I had converted phpflg into a Phix based application, with all the magic you get out of the box: “Pear Packaging, Phing Build File, Autoloading, folder structure ready for most use cases and so on”

It's time to ditch dial-up. Get up to 20Mb broadband from PlusNet. Free setup now available - terms apply. PlusNet broadband.

Myself and Seb then spent a while just looking over all the things I wanted to change so we could feed this back to Stuart:

  • Using phpunit.xml.dist file in build file, so I could have phpunit.xml overriding any local requirements I had.
  • I didn’t want the phpunit.xml file to state the logging locations, as when I run the test locally I don’t want all the files it generates, although having the above means I could stop that if I wanted.
  • I didn’t want the build.xml file to restrict the running of PHPUnit to ${project.src.testunitdir} as I had phpt tests to test the command based UI.
  • PHPUnit to run in –strict mode.
  • I wanted to have DocBlox as my Documentation generator.

We past all this information onto Stuart who has been very accommodating with the whole experience.

Excellent stuff, from now on, I’ll be using Phix, and everyone else should at least look into it.

Making your GitHub account a PEAR channel

I saw a tweet that mentioned you could do this, which I saved for later. However, since I had phpflg ready, and was now using Phix, it didn’t seem that arduous to make a pear package and then try and setup a channel on GitHub. So quick search lead me back to the original article I had seen:

How to serve PHP/Pear packages with GitHub

Side note: There are many articles covering this now, I have no idea which was the first, so apologies for not linking to the original!

On this topic, all I can say is follow the instructions and you have yourself a PEAR channel on GitHub. One thing to note here is, I’ve found that the PEAR installation on the machine you want to install a GitHub based PEAR package onto, needs to be running PEAR 1.9.4 (It may be a few dot releases earlier than .4, but certainly .1 doesn’t work)

Lastly, I was building a command line tool, so I had phpflg.php in the bin directory, which I really just wanted to be phpflg when installed on the users machine. Phix, currently as of 3rd November 2011, does not support this in an automated fashion, so you have to make a manual change.

When you have run

$ phing pear-package

In the folder of your Phix based application it will generate you a tarball in the dist folder. You need to edit the package.xml file within it. Right at the bottom of the file just before the closing of the </package> tag, add:

  <phprelease>
    <filelist>
      <install as="phpflg" name="/phpflg.php" />
    </filelist>
  </phprelease>

Obviously you will need to change the names for your application, but what this tells PEAR to do once installed is create phpflg without the .php extension.

It all then works nicely.

So, Go play around with Phix, it’s fantastic. Go create a GitHub PEAR channel, and if you don’t want to figure out the bash command to generate file lists (Yes, Yes, I hear Seb Marek in my head saying it’s easy Ben, it’s easy!!), then install phpflg.

And if you do create a PEAR channel, do not forget to register it with Pyri

Wallsplattr 0.4 out now

After I spent some time working on the 0.3 version in isolation I then started talking to some people at work, mainly Stu, Gary and Dan. They all pointed out various things that actually started to bug me, so 0.4 addresses those issues. There is nothing visually different between the 0.3 and 0.4 releases, however you have much more control over the google map in version 0.4.

The newly created ChangeLog clearly indicates the changes for 0.4, but for those not wanting to venture off to another site, here it is:

  • Fixed GH-1 Moved maxMarkerCount to application.ini
  • Fixed GH-2 Make the location and Zoom of the Google map configurable in application.ini
  • Fixed GH-3 Markers are now removed on a rolling basis rather than all at once
  • Fixed GH-4 Now displays an Info Window rather than going direct to twitter.com
  • Added ChangeLog.markdown
  • Added docs/Map.markdown to help with map settings
  • docs/TweetStructure.markdown to help with understanding the data that is available in a tweet
  • Validation fixes for HTML and JavaScript
  • Moved phpunit.xml.dist file to top level, which was a comment I saw on twitter about checking out an application and running phpunit from root (Makes sense)
  • Allowed the configuration of the type of map to be viewed (application.ini)
  • Other general tidy up fixes

I quite like this version, and I’m starting to learn a lot more about JavaScript, which is really the goal of this project: To Learn. I think docs/Map.markdown is an interesting file to checkout as that talks about how you can configure the map, which is where all the changes for this release are located.

In this release I have tried to be more more verbose with what is going on, so you can see many new .markdown files have been created and I’ve tried to update the Docblocks as and where appropriate

0.4 version can be downloaded from here