So Curl is awesome! But due to my goldfish-esc memory working with it is always a lesson in searching the docs. The great thing with working with a framework is that such tasks can easily be adapted to your own way of working. The great(est?) thing about Kohana is that it is just so damn adaptable, it provides you with a shed load of functionality right out the box, but it’s true power (to me) is that it is easy to adapt to my way of thinking and my way of developing. Add to that the fact that adding extra stuff is laughably easy (if it hasn’t been done allready) and you have a mighty powerful weapon.
I needed a bit of twitter integration for something I was doing, which required some use of Curl. I could of bundled this in with the Twitter library but like a good modular, OO programmer I seperated the logic out into its own library: the Kohana Curl library was born.
OK, after all that great white hype the lib is VERY basic, and as stated before works around my way of thinking so may not suit everybody, but if you have any requests / suggestions then I’d love to hear them!
Usage Examples
<?php
echo Curl::get('http://www.google.co.uk');
?>
<?php
echo Curl::post('http://page-that-takes-post.com', array('drink' => 'beer', 'eat' => 'meat'));
?>
/Matt
Welcome to ninjapenguin. Personal blog of Matthew Wells. I'm a web developer from the North West and enjoy working with Kohana, Mootools and Git
Comments
Nice!
I also like Kohana, but did not need (yet) to extend it through libraries. Looks simple.
Nice!
Clean and easy
Thanks for this. I just used it on an old 2.3 project.
If anyone is wondering where to place it, just drop it into `application/libraries/Curl.php`.
After using this in the wild for a while, I’d like to make a quick suggestion.
I think the post static method shouldn’t assume the POST will be an array, especially as it is passed straight to cURL (which accepts a string or an array).
I came across a payment gateway that wanted the POST to be a string only. I just removed the array type in the method arguments signature to get this library to play ball.
Other than that, thanks again for this. I’m glad Kohana 3 has an in built wrapper for cURL.
Hi Alex,
Thanks for your suggestion, I think you’re absolutely right and so will remove the type requirement on the method
Thanks
/Matt
Post a comment