@@ -31,11 +31,6 @@ class ResourceTemplateReference extends ElementReference
3131 */
3232 private array $ variableNames ;
3333
34- /**
35- * @var array<string, string>
36- */
37- private array $ uriVariables ;
38-
3934 private string $ uriTemplateRegex ;
4035
4136 /**
@@ -53,22 +48,6 @@ public function __construct(
5348 $ this ->compileTemplate ();
5449 }
5550
56- /**
57- * @deprecated
58- * Gets the resource template
59- *
60- * @return array<int, ResourceContents> array of ResourceContents objects
61- */
62- public function read (ContainerInterface $ container , string $ uri ): array
63- {
64- $ arguments = array_merge ($ this ->uriVariables , ['uri ' => $ uri ]);
65-
66- $ referenceHandler = new ReferenceHandler ($ container );
67- $ result = $ referenceHandler ->handle ($ this , $ arguments );
68-
69- return $ this ->formatResult ($ result , $ uri , $ this ->resourceTemplate ->mimeType );
70- }
71-
7251 /**
7352 * @return array<int, string>
7453 */
@@ -87,34 +66,12 @@ public function matches(string $uri): bool
8766 }
8867 }
8968
90- $ this ->uriVariables = $ variables ;
91-
9269 return true ;
9370 }
9471
9572 return false ;
9673 }
9774
98- private function compileTemplate (): void
99- {
100- $ this ->variableNames = [];
101- $ regexParts = [];
102-
103- $ segments = preg_split ('/(\{\w+\})/ ' , $ this ->resourceTemplate ->uriTemplate , -1 , \PREG_SPLIT_DELIM_CAPTURE | \PREG_SPLIT_NO_EMPTY );
104-
105- foreach ($ segments as $ segment ) {
106- if (preg_match ('/^\{(\w+)\}$/ ' , $ segment , $ matches )) {
107- $ varName = $ matches [1 ];
108- $ this ->variableNames [] = $ varName ;
109- $ regexParts [] = '(?P< ' .$ varName .'>[^/]+) ' ;
110- } else {
111- $ regexParts [] = preg_quote ($ segment , '# ' );
112- }
113- }
114-
115- $ this ->uriTemplateRegex = '#^ ' .implode ('' , $ regexParts ).'$# ' ;
116- }
117-
11875 /**
11976 * Formats the raw result of a resource read operation into MCP ResourceContent items.
12077 *
@@ -256,6 +213,26 @@ public function formatResult(mixed $readResult, string $uri, ?string $mimeType =
256213 throw new RuntimeException ("Cannot format resource read result for URI ' {$ uri }'. Handler method returned unhandled type: " .\gettype ($ readResult ));
257214 }
258215
216+ private function compileTemplate (): void
217+ {
218+ $ this ->variableNames = [];
219+ $ regexParts = [];
220+
221+ $ segments = preg_split ('/(\{\w+\})/ ' , $ this ->resourceTemplate ->uriTemplate , -1 , \PREG_SPLIT_DELIM_CAPTURE | \PREG_SPLIT_NO_EMPTY );
222+
223+ foreach ($ segments as $ segment ) {
224+ if (preg_match ('/^\{(\w+)\}$/ ' , $ segment , $ matches )) {
225+ $ varName = $ matches [1 ];
226+ $ this ->variableNames [] = $ varName ;
227+ $ regexParts [] = '(?P< ' .$ varName .'>[^/]+) ' ;
228+ } else {
229+ $ regexParts [] = preg_quote ($ segment , '# ' );
230+ }
231+ }
232+
233+ $ this ->uriTemplateRegex = '#^ ' .implode ('' , $ regexParts ).'$# ' ;
234+ }
235+
259236 /** Guesses MIME type from string content (very basic) */
260237 private function guessMimeTypeFromString (string $ content ): string
261238 {
0 commit comments