collection = json_decode($json, true); $this->variables = $this->extractVariables(); } public function getCollection() { return $this->collection; } public function getVariables() { return $this->variables; } private function extractVariables() { $variables = []; if (isset($this->collection['variable'])) { foreach ($this->collection['variable'] as $var) { $variables[$var['key']] = $var['value'] ?? ''; } } return $variables; } public function getAuthConfig() { if (!isset($this->collection['auth'])) { return null; } $auth = $this->collection['auth']; if ($auth['type'] === 'oauth2' && isset($auth['oauth2'])) { $oauth2Config = []; foreach ($auth['oauth2'] as $item) { $oauth2Config[$item['key']] = $item['value']; } return [ 'type' => 'oauth2', 'config' => $oauth2Config ]; } return $auth; } public function getAllRequests() { $requests = []; $this->extractRequestsRecursive($this->collection, $requests); return $requests; } private function extractRequestsRecursive($item, &$requests, $path = '') { if (isset($item['item'])) { foreach ($item['item'] as $subItem) { $currentPath = $path ? $path . ' > ' . $subItem['name'] : $subItem['name']; $this->extractRequestsRecursive($subItem, $requests, $currentPath); } } elseif (isset($item['request'])) { $requests[] = [ 'name' => $item['name'], 'path' => $path, 'request' => $item['request'], 'response' => $item['response'] ?? [] ]; } } public function resolveVariables($url, $customVariables = []) { $allVariables = array_merge($this->variables, $customVariables); foreach ($allVariables as $key => $value) { $url = str_replace('{{' . $key . '}}', $value, $url); } return $url; } public function getRequestById($name) { $requests = $this->getAllRequests(); foreach ($requests as $request) { if ($request['name'] === $name) { return $request; } } return null; } }