A simple php route class and a simple php route class. A simple php routing class, simple php routing class this article examples for you to share with you the php write a simple routing class for your reference, the specific content is as follows: phpnamespacecmhcHcrail; cl is a simple php route class and a simple php route class.
The example in this article shows you how to compile a simple routing class in php for your reference. the specific content is as follows:
<? Phpnamespace cmhc \ Hcrail; class Hcrail {/*** callback function * @ var callable */protected static $ callback; /*** match string or match regexp * @ var string */protected static $ match; protected static $ routeFound = false;/*** deal with get, post, head, put, delete, options, head * @ param $ method * @ param $ arguments * @ return */public static function _ callstatic ($ method, $ arguments) {self :: $ match = Str_replace ("//", "/", dirname ($ _ SERVER ['php _ SELF ']). '/'. $ arguments [0]); self: $ callback = $ arguments [1]; self: dispatch (); return ;} /*** processing ordinary route matches * @ param string $ requestUri * @ return */public static function normalMatch ($ requestUri) {if (self: $ match = $ requestUri) {self: $ routeFound = true; call_user_func (self ::$ callback);} return ;}/ *** processing regul Ar route matches * @ param string $ requestUri * @ return */public static function regexpMatch ($ requestUri) {// process regular expressions $ regexp = self: $ match; preg_match ("# $ regexp #", $ requestUri, $ matches); if (! Empty ($ matches) {self ::$ routeFound = true; call_user_func (self ::$ callback, $ matches);} return ;} /*** dispatch route * @ return */public static function dispatch () {if (self: $ routeFound) {return ;} $ requestUri = parse_url ($ _ SERVER ['request _ URI '], PHP_URL_PATH); $ requestMethod = $ _ SERVER ['request _ method']; if (strpos (self :: $ match, '(') === false) {self: normalMatch ($ requestUri);} else {se Lf: regexpMatch ($ requestUri) ;}/ *** Determining whether the route is found * @ return boolean */public static function isNotFound () {return! Self: $ routeFound ;}}
: Https://github.com/cmhc/Hcrail
I hope this article will help you learn PHP programming.
Examples in this article share with you how to compile a simple routing class in php for your reference. the specific content is as follows: phpnamespace cmhc \ Hcrail; cl...