5use InvalidArgumentException;
19 private ?array $matchers = [];
21 private bool $matchersInitialized =
false;
26 foreach ( $this->
getMatchers() as $method => $matcher ) {
27 $cacheData[$method] = $matcher->getCacheData();
35 if ( $cacheData[self::CACHE_CONFIG_HASH_KEY] !== $this->getConfigHash() ) {
39 unset( $cacheData[self::CACHE_CONFIG_HASH_KEY] );
42 foreach ( $cacheData as $method => $data ) {
46 $this->matchersInitialized =
true;
63 if ( !$this->matchersInitialized ) {
65 $this->matchersInitialized =
true;
68 return $this->matchers;
84 $methods = (array)$method;
87 if ( !isset( $info[
'spec'] ) ) {
88 throw new InvalidArgumentException(
'Missing key in $info: "spec"' );
91 $info[
'path'] =
$path;
93 foreach ( $methods as $method ) {
94 $method = strtoupper( $method );
96 if ( !isset( $this->matchers[$method] ) ) {
100 $this->matchers[$method]->
add(
$path, $info );
109 string $requestMethod
111 $requestMethod = strtoupper( $requestMethod );
113 $matchers = $this->getMatchers();
114 $matcher = $matchers[$requestMethod] ??
null;
115 $match = $matcher ? $matcher->match(
$path ) :
null;
121 'methods' => $this->getAllowedMethods(
$path ),
124 $info = $match[
'userData'];
125 $info[
'found'] =
true;
126 $info[
'method'] = $requestMethod;
127 $info[
'params'] = $match[
'params'] ?? [];
142 foreach ( $this->getMatchers() as $allowedMethod => $allowedMatcher ) {
143 if ( $allowedMatcher->match( $relPath ) ) {
144 $allowed[] = $allowedMethod;
149 in_array(
'GET', $allowed ) ? array_merge( [
'HEAD' ], $allowed ) : $allowed
if(!defined('MW_SETUP_CALLBACK'))