This looks to be a very well done class, but you have slightly re-invented the wheel when it comes to sending http requests. Perhaps a separate class as an abstraction layer for sending these? That way when curl (god forbid) changes it's methods, or someone wants to use something other than curl, they can plug in their own class to send the http request.
Perhaps just defining an interface, say HTTPRequest, which requires certain methods, and then just check that the user supplied class implements the interface.
Thanks for sharing.
interface HTTPRequest {
public static function send($request);
...
}
class MyHTTPRequester implements HTTPRequest {
...
}
define('REQUEST_CLASS', 'MyHTTPRequester');
class swd_SMS {
...
if (defined('REQUEST_CLASS') === false) die('No HTTPRequest class');
if (in_array('HTTPRequest', class_implements(REQUEST_CLASS)) === false) die('Bad Request class');
...
}
Hi, thanks for your input. The reason I did it this way is because cURL and fsockopen() are the only methods known to me to send HTTP requests via PHP, so I don't see a need for a separate class. And I highly doubt that cURL will change it's methods, but in either case, it could simply be modified in the main class. Anyway, thanks for the input, I appreciate it. And I'll keep the point with abstraction layers in mind in the future.
http://www.morad.info/
Perhaps just defining an interface, say HTTPRequest, which requires certain methods, and then just check that the user supplied class implements the interface.
Thanks for sharing.
i run this code but it doesn't work.
can somebody help me