ruleset = new Ruleset($ruleset, $partitions); $this->cache = new LruArrayCache(100); } /** * @return Ruleset */ public function getRuleset() { return $this->ruleset; } /** * Given a Ruleset and input parameters, determines the correct endpoint * or an error to be thrown for a given request. * * @return RulesetEndpoint * @throws UnresolvedEndpointException */ public function resolveEndpoint(array $inputParameters) { $hashedParams = $this->hashInputParameters($inputParameters); $match = $this->cache->get($hashedParams); if (!is_null($match)) { return $match; } $endpoint = $this->ruleset->evaluate($inputParameters); if ($endpoint === false) { throw new UnresolvedEndpointException( 'Unable to resolve an endpoint using the provider arguments: ' . json_encode($inputParameters) ); } $this->cache->set($hashedParams, $endpoint); return $endpoint; } private function hashInputParameters($inputParameters) { return md5(serialize($inputParameters)); } }