Combining phing and Closure Compiler

Posted: May 23rd, 2010 | Author: Jan Gorman | Filed under: Code, Hint | Tags: , , , , , , , , | No Comments »

I have been relatively late to the exciting world of build automation. This has mainly to do with the sys-admin at my old job who insisted on deploying everything himself. By hand. Which left us developers with the task of writing job descriptions for each deploy. And they would typically consist of a list similar to this:

  • Move the packed tar.gz to the server
  • Unpack the tar.gz
  • Copy the contents to the web root
  • Chmod files xyz to 777

Oh the madness. Seeing this it should of course be immediately clear that doing this by hand is extremely error prone and slow and plain stupid. Time to automate!

What can my build-file do for me?

There are plenty of flavours to choose from. After some evaluation I settled on phing since the project I’m currently using this for is PHP based, the build files are easy to read (based on Apache Ant) and it’s extensible. phing comes shipped with plenty of tasks for you to choose from and if there’s ever anything missing you want to get done quick and dirty you can run an Exec Task and have PHP run something on the console for you – neat!

Closure

Phing also comes with a JSMin task but this being 2010 I wanted to use Closure compiler because it’s a much sweeter deal and because I wanted to write this blog post. The files produced are smaller and you can do all kinds of cool things like merging files into one (fewer requests!) or removing dead code. It’s pretty cool. I put the whole thing up on Github so feel free to download it from there and fork me. I’ve included a sample task as well so that should get you up and running pretty quickly.  And did I mention Github?


WP_Registry

Posted: December 6th, 2009 | Author: Jan Gorman | Filed under: Code | Tags: , , , , , , | No Comments »

Just to let everyone know: I just released my first public WordPress plugin into the wild. Hope it comes in handy to someone.


Zend Framework Classloading Performance

Posted: August 25th, 2009 | Author: Jan Gorman | Filed under: Code, Hint | Tags: , , , , , , , , , , , , , , , , | No Comments »

As outlined in the Zend Framework Documentation it’s possible to speed things up a little by removing (almost) all require_once calls from the Framework and relying solely on the autoloading mechanism. I haven’t benchmarked this and I’m fairly certain that it’s a case of micro-optimization but I thought I’d give it a try anyway. The snipped posted there has some minor problems on OS X however. For one the -wholename parameter for find isn’t implemented (can be replaced with -path) and although sed does work, you need to use gsed if you want to pass the arguments as described in the documentation. So here’s the OS X version of the snippet:

find . -name '*.php' -not -path '*/Loader/Autoloader.php' \
  -not -path '*/Application.php' -print0 | \
  xargs -0 gsed --regexp-extended --in-place 's/(require_once)/\/\/ \1/g'

Update: As part of my new job we’re currently working on a merchandise management system which is hosted somewhere in the Amazon S3 Cloud. The performance impact of removing all the require_once calls was very dramatic on that system. So looks like this hint can come in handy after all in certain situations. What I now did is add the snippet to the phing deployment task that takes care of updating Zend Framework. Since it’s hardly any effort at all there really isn’t any reason not to do this.


Typing The Letters A-E-S Into Your Code? You’re Doing It Wrong!

Posted: June 7th, 2009 | Author: Jan Gorman | Filed under: Code, Hint, Link | Tags: , , , | No Comments »

Really interesting article about encryption by Matasano Chargen, well worth a read.


Zend_Form_Element_Exception

Posted: May 28th, 2009 | Author: Jan Gorman | Filed under: Code, Hint | Tags: , , , , | 1 Comment »

After upgrading to Zend Framework 1.8 earlier this week we’ve had a few more minor glitches that have surfaced since. The one which took me some time to figure out was 'Zend_Form_Element_Exception' with message 'No file decorator found... unable to render file element' To ease the generation of forms and get them all to look the same we use a class named Form_Static_Render that the Zend_Form gets pushed into and which takes care of styling, decorators, preview pages and display of form errors. It’s quite a clever little thing. To achieve the proper styling our extension to Zend_Form calls

$element->clearDecorators();

and then either adds the default ViewHelper or whatever gets passed to the method and that was the root of the problem. When clearing the decorators, Zend_Form_Element_File now explicitly requires you to add the File Decorator again before rendering. After discovering that, it turned out being a quick fix…


Replacing Zend_Loader with Zend_Loader_Autoloader

Posted: May 25th, 2009 | Author: Jan Gorman | Filed under: Code, Hint | Tags: , , , , , | No Comments »

It’s been a while since my last post but I’ve been very busy the last couple of weeks. That’s what also kept me from updating to Zend Framework 1.8 (or 1.8.1 by now already) in our production environment. It has been very smooth so far, the only change that required some work was the deprecation of the old

Zend_Loader::registerAutoload( '...' );

However, upgrading everything to the new Zend_Loader_Autoloader_Interface actually worked quite a lot easier than expected:

class Webwerk_Autoloader implements Zend_Loader_Autoloader_Interface
{
  /**
   * Autoloader
   */
  public function autoload ( $class )
  {
    // Custom autoloading of different classes
    // Each one has a return value
 
    // Fallback
    try {
      Zend_Loader::loadClass( $class );
      return $class;
    } catch ( Exception $e ) {
      return false; // Nothing there
    }
 
  }
}

And in the bootstrapper we have:

$autoloader = Zend_Loader_Autoloader::getInstance();
$autoloader->setFallbackAutoloader( true );
$autoloader->pushAutoloader( new Webwerk_Autoloader( ) );

So the only change was making Webwerk_Autoloader match the Zend_Loader_Autoloader_Interface as well as changing the bootstrap to use the default autoloader as fallback and registering the custom autoloader.


PHP Quick Profiler

Posted: April 23rd, 2009 | Author: Jan Gorman | Filed under: Code, Hint | Tags: , , , , | No Comments »

Wow, this is really cool. Ryan Campbell of Particle Tree just put up a post about a tool they developed and now released called PQP to help with profiling PHP code. We developed and use something similar on top of Zend Framework (just not as cool looking) and ours doesn’t come with the memory logging and timing features that PQP provides. Definitely going to give this a try and spruce up the own tool..


Getting up to speed with Pylons

Posted: April 22nd, 2009 | Author: Jan Gorman | Filed under: Code | Tags: , , , , , | No Comments »

True to the Pragmatic Programmer manifest “Invest Regularly in Your Knowledge Portfolio” I’ve recently been reading up on Python again. I’ve made several attempts but due to time constraints never managed to make anything of the knowledge.

I quite enjoy the Python syntax and some of the string manipulation functions are super awesome compared to what PHP has to offer. I had a look at the different web frameworks available, Pylons was the one that appealed to me the most and having spent some time with it today I must say that it doesn’t disappoint. They also have a very cool ebook available called The Pylons Book. I’ll keep you posted on how the adventure continues.


Zend Framework 1.8 Preview Release

Posted: April 8th, 2009 | Author: Jan Gorman | Filed under: Code, Link | Tags: , , , , | No Comments »

The Zend Framework 1.8 Preview Release is now available for testing! This latest release includes a new CLI for creating your initial project structure, adding resources to your project so no more rails envy:

$ zf create project theNewProject

This will create the initial project layout with directories, controllers and all. Brilliant.

The new Zend_Application has been added to handle the task of bootstrapping your application and other cool stuff, one of the most important features is the new way that modules are treated in Zend_Application which should help keep your application DRYer than ever.


Zend_Form decorator

Posted: April 6th, 2009 | Author: Jan Gorman | Filed under: Code, Hint | Tags: , , , , , | No Comments »

Since Matthew Weier O’Phinney can explain this a lot better than I ever could, I’ll simply refer you to his excellent post about Zend_Form decorators, well worth a read.