Zend Framework components as separate zips from the main distro? Sure!
October 6, 2008 – 3:42 pm Tags: Zend FrameworkDid 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
Tokenizer
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 =)
Subscribe!












16 Responses to “Zend Framework components as separate zips from the main distro? Sure!”
Awesome!
Idea:
— Provide list as checkboxes to select two or more components.
By Sam on Oct 6, 2008
Nice
By Vincent on Oct 6, 2008
please add http://www.php.net/manual/ru/book.phar.php file format.
By Vkadimir on Oct 6, 2008
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
Excellent idea.
By Tom on Oct 6, 2008
“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
Bug: http://codeutopia.net/pack/index/dependencies/class/Zend_Cache
By Sam on Oct 7, 2008
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
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
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
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
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
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
great! I used to do this on my own! thanks a lot!
By lala on Nov 20, 2008