As I anticipated in the section that you just read, the next step I'm going to take to enhance the previous URL helper class will consist of declaring its implemented methods static, which makes it easy to call them without having to spawn an instance of the class in question. That being said, please take a look at the modified version of the URL helper class, which has been included below. Here it is: class URLHelper { // constructor not implemented public function __construct(){}
// get web server root public static function get_document_root() { return $_SERVER['DOCUMENT_ROOT']; }
// get script URL public static function get_script_url() { return $_SERVER['PHP_SELF']; }
// get script query string public static function get_query_string() { return $_SERVER['QUERY_STRING']; }
// get request URI public static function get_request_uri() { return $_SERVER['REQUEST_URI']; }
// get script file name public static function get_script_filename() { return $_SERVER['SCRIPT_FILENAME']; }
// get request method public static function get_request_method() { return strtolower($_SERVER['REQUEST_METHOD']); }
} Naturally, if you're anything like me, then it's possible that you didn't notice any big differences in the way that the above helper class has been defined. However, in this case the class's methods now have been declared static, in this way introducing the aforementioned benefits. Since the modification of the signature of the helper class should be pretty easy for you to follow, it's time to develop a few illustrative examples to demonstrate how to take advantage of its functionality by calling its methods out of the object scope. Want to see how these examples will be created? Then read the following segment. We're almost finished!
blog comments powered by Disqus |
|
|
|
|
|
|
|