News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Gonzalo Ayuso's Blog:
Using Monkey Patching to store files in CouchDb using the standard filesystem
September 02, 2010 @ 14:10:12

Gonzalo Ayuso takes his "CouchDb as a filesystem" approach one step further (see the previous post about it here) with this new post talking about monkey patching to store files into the CouchDb server using the normal PHP file handling functions.

Since PHP5.3 a new design pattern is available for us: Monkey Patching. With this pattern we can override PHP's core functions with a home-made functions in a different namespace (another example here). That's means if I have fopen function in the above example, PHP uses the filesystem function "fopen" but if we set a namespace in our example, PHP will search first the function within the current namespace.

By defining the new interface inside of a namespace (with functions to override the default PHP file handlers) you can have the rest of the code call the same functions (fopen, fread, etc) but they'll do different things. In this case it handles them as push and pull to the CouchDb instead of the normal filesystem. You can grab the source for this example here.

0 comments voice your opinion now!
monkeypatching namespace filesystem couchdb tutorial


blog comments powered by Disqus

Similar Posts

Master Zend Framework: Create a Simple File Upload Form in Zend Framework 2

PHPMaster.com: Integrating Open Authentication using Opauth

RoofTopSolutions.nl: Caching in PHP using the filesystem, APC, and Memecached

Vinu Thomas' Blog: Wordpress blogging on a S60 Phone

DevShed: Searching and Replacing Nodes with SimpleXML in PHP 5 (Part 3)


Community Events





Don't see your event here?
Let us know!


developer library bugfix community api tips language framework deployment release laravel voicesoftheelephpant conference zendserver list podcast introduction series interview symfony

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework