Last active
August 24, 2018 08:01
-
-
Save segg21/ae1c56af0999be898dee1ec5ced6318c to your computer and use it in GitHub Desktop.
Simple routing php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
\| Route/PHPRouting101 | |
\| @author => LegitSoulja | |
\| @copyright => LegitSoulja | |
\| @license => Apache | |
\| @source => https://gist.github.com/LegitSoulja/ae1c56af0999be898dee1ec5ced6318c | |
\| @source => https://github.com/LegitSoulja/PHPRouting101 | |
*/ | |
/* | |
\| Route/PHPRouting101 | |
\| @author => LegitSoulja | |
\| @copyright => LegitSoulja | |
\| @license => Apache | |
\| @source => https://gist.github.com/LegitSoulja/ae1c56af0999be898dee1ec5ced6318c | |
\| @source => https://github.com/LegitSoulja/PHPRouting101 | |
*/ | |
class Route { | |
static _arrToObj(a, b) { | |
for (var i in b) { | |
var o = b[i].split('='); | |
a[o[0]] = o[1]; | |
} | |
} | |
static get() { | |
// document.location was copied/cloned because I didn't want to manipulate any window changes literally | |
var loc = JSON.parse(JSON.stringify(document.location)); | |
if (loc.pathname) { | |
if (!loc.search) { | |
var _try = loc.pathname.indexOf('&'); | |
if (_try > -1) { | |
loc.search = loc.pathname.slice(_try); | |
loc.pathname = loc.pathname.slice(0, _try); | |
} | |
} | |
if (loc.pathname[loc.pathname.length - 1] === "/") | |
loc.pathname = loc.pathname.slice(0, -1); | |
var args = {}; | |
var path = []; | |
if (loc.search) { | |
this._arrToObj(args, loc.search.slice(1).split('&')); | |
} | |
var res = loc.pathname.slice(1).split('/'); | |
if (res.length > 0 && res[0] !== "") { | |
path = loc.pathname.slice(1).split('/'); | |
} | |
return { | |
path: path, | |
args: args | |
} | |
} | |
return { | |
path: [], | |
args: new Proxy({}, { | |
get: function(target) { | |
return target; | |
} | |
}), | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
PHPRouting101
PHP Routing done with skill, and simplistic perfection.
Compatible URI’s
example.com/some/route/?a=b&c=d
example.com/some/route?a=b&c=d
example.com/some/route&a=b&c=d
Installation
Route.php
Route.php
"Usage
Properties
[Array]
(A path of the uri, as of compatible uri's it would be [some, route])[Array(Associative)
(query/get information at the end of the uri)Tips/Warnings