Skip to content

Instantly share code, notes, and snippets.

@deviationist
Created December 23, 2016 14:33
Show Gist options
  • Save deviationist/76a077ff4addef3c6ebbe842fe9e0cc3 to your computer and use it in GitHub Desktop.
Save deviationist/76a077ff4addef3c6ebbe842fe9e0cc3 to your computer and use it in GitHub Desktop.
<?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