Created
December 23, 2016 14:33
-
-
Save deviationist/76a077ff4addef3c6ebbe842fe9e0cc3 to your computer and use it in GitHub Desktop.
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 | |
// Check if API request route contains a given segment | |
function route_contains($segment, $request) { | |
// Check if segment to check is array | |
if( ! is_array($segment) ) { | |
// If not create an array | |
$segment = array($segment); | |
} | |
// Get route from request-object | |
$route = $request->get_route(); | |
// Remove any leading/trailing slashes | |
$route = trim($route, '/'); | |
// Split route into segments | |
$route_segments = explode('/', $route); | |
// Check if segments is in route segments | |
$intersect = array_intersect($segment, $route_segments); | |
return ! empty($intersect); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment