Automattic\WooCommerce\Blocks\Domain\Services

Hydration::match_route_to_handler()privateWC 1.0

Inspired from WP core's match_request_to_handler, this matches a given path from available route regexes. However, unlike WP core, this does not check against query params, request method etc.

Method of the class: Hydration{}

No Hooks.

Return

String|null.

Usage

// private - for code of main (parent) class only
$result = $this->match_route_to_handler( $path, $available_routes );
$path(string) (required)
The path to match.
$available_routes(array) (required)
Available routes in { $regex1 => $contoller_class1, ... } format.

Hydration::match_route_to_handler() code WC 9.2.3

private function match_route_to_handler( $path, $available_routes ) {
	$matched_route = null;
	foreach ( $available_routes as $route_path => $controller ) {
		$match = preg_match( '@^' . $route_path . '$@i', $path );
		if ( $match ) {
			$matched_route = $controller;
			break;
		}
	}
	return $matched_route;
}