Zend Framework components as separate zips from the main distro? Sure!

October 6, 2008 – 3:42 pm Tags:

Did you ever want to use just a single component from Zend Framework, but couldn’t figure out which files you needed?

Well, here’s a solution: Zend Framework packageizer script! Just pick the class you want, and you’ll get it and all its dependencies in a nice zip file for you to consume.

Wanna know how this works? Hit the link for more


The packageizer started as an exercise on the PHP tokenizer functions. I wanted to try it out, and I also wanted to do something useful with it.

I had often thought about using just one or a few components from ZF in some projects, but it was difficult to include only the files I needed, as some components depend on many others and there was no easy way to get them, other than to inspect each code file manually and look at the require statements.

So behind the scenes, there’s a class which uses PHP’s tokenizer to find class names, extends, requires and implements from code. Another class parses this information and generates a mapping of dependencies – which file requires what other files for the code in it to work and so on. Finally, all this is converted into an XML file which is used as a cache so we won’t have to go through all the files again (which takes a while!).

The zip file stuff is quite simple. The application simply grabs the dependencies and wraps them in a zip and pushes it to the browser. The zip file is also cached, so we won’t have to compress it again for future requests.

Feel free to use this service. The current Zend Framework version in it is the latest stable release, ZF 1.6. I’ve also been thinking about allowing the user to choose which version they wish to use, and there were some requests for a nightly SVN snapshot one as well… we’ll see about all that =)

Share this:
  1. 21 Responses to “Zend Framework components as separate zips from the main distro? Sure!”

  2. Awesome!

    โ€” Provide list as checkboxes to select two or more components.

    By Sam on Oct 6, 2008

  3. Nice :)

    By Vincent on Oct 6, 2008

  4. please add http://www.php.net/manual/ru/book.phar.php file format.

    By Vkadimir on Oct 6, 2008

  5. Sam, good idea, that’ll be on top of the improvement list.

    Vkadimir, I might, but right now I’m limited by my hosting provider and they don’t support phar. Perhaps sometime in the future.

    By Jani Hartikainen on Oct 6, 2008

  6. Excellent idea.

    By Tom on Oct 6, 2008

  7. “So behind the scenes, thereโ€™s a class which uses PHPโ€™s tokenizer to find class names, extends, requires and implements from code.” – please, post source code! ๐Ÿ˜‰

    By Alexey Shockov on Oct 7, 2008

  8. Bug: http://codeutopia.net/pack/index/dependencies/class/Zend_Cache

    By Sam on Oct 7, 2008

  9. Sam, thanks – looks like it’s getting stumbled on the dynamic require in Zend_Cache. The zip works ok though, so for now if you see that error, just ignore it ๐Ÿ˜‰

    Alexey Shockov,
    tokenizer http://paste.codeutopia.net/59
    filemapper http://paste.codeutopia.net/60

    The tokenizer parses the files, and the filemapper takes the tokenizer’s output to generate some nicer data from it.

    The filemapper has an echo in one of the methods which you will probably want to remove…

    I actually intended to improve the code a bit before publishing any of it, but I never got around to, so it may have some small issues… =)

    By Jani Hartikainen on Oct 7, 2008

  10. Awesome!

    I’ve always wondered how to take advantage of ZF:s modularity without ending up with a potentilly not working version – this seems like a perfect solution!

    By Pelle on Oct 7, 2008

  11. Had the same thing in development Jani ๐Ÿ˜‰ ^^

    One feature i am missing in your version is that the checkbox of dependendent classes will not be auto-checked if i select a component.
    So if i select Zend_Auth the checkbox for Zend_Auth_Storage_Interface should automaticly be checked too.

    By Tobias Petry on Nov 17, 2008

  12. awesome idea!
    a couple of ideas/feature requests:
    – command line interface
    – an option to get rid of any calls to include/require (if one wants to depend on autoload completely)
    – an option to put all the code to one big .php file
    – a BSD styled license with the access to repository for others (code.google.com or sourceforge.net) so you wouldn’t have to do it all alone

    By Jan on Nov 17, 2008

  13. Tobias, Jan, good ideas there.

    I might implement some of those, but I’m not so sure about the CLI and sharing the source, not yet at least. The older parts of the code are still kinda messy, since it was initially just something experimental, though I’ve improved them with the new version =)

    By Jani Hartikainen on Nov 18, 2008

  14. Another approach would be to generate svn:externals settings to only import the necessary files. Note that only in svn 1.6 will it be possible to set an external on a file, currently only directories are supported. However I think its possible to pull in a directory but selectively ignore certain files ..

    By Lukas on Nov 18, 2008

  15. great! I used to do this on my own! thanks a lot!

    By lala on Nov 20, 2008

  16. 404 Not Found…

    By Anti on Jul 12, 2009

  17. Hi, are you ready to deploy the source now?
    What about to make an open source project for this, so that other people can help you?


    By Patrick on Jan 12, 2010

  18. The code is available here:

    Open source project? Hm perhaps, but it would probably need overseeing by someone and I don’t really have the time.

    By Jani Hartikainen on Jan 14, 2010

  19. @Jani: Just publish it on GitHub and make it clear that you don’t have the time to currently maintain it and let others fork away on it so that it perhaps gets a life of it’s own. You don’t have to maintain it just because you’re releasing it as open source – at least as long as you’re being honest about it :)

    By Pelle on Jan 14, 2010

  1. 3 Trackback(s)

  2. Nov 14, 2008: Improved Zend Framework package maker | CodeUtopia
  3. Nov 17, 2008: Zend Framework components as separate zips from the main distro? Sure! | Deconstructing the Web with Larry Root
  4. Jul 26, 2013: Use Zend Framework components without the actual framework? - PHP Solutions - Developers Q & A

Post a Comment

You can use some HTML (a, em, strong, etc.). If you want to post code, use <pre lang="PHP">code here</pre> (you can replace PHP with the language you are posting)