/** * @param InterceptionInterface $interception * @param CacheAnnotationInterface $annotation * * @return string * @throws \Phpro\AnnotatedCache\Exception\UnsupportedKeyParameterException */ public function generateKey(InterceptionInterface $interception, CacheAnnotationInterface $annotation) : string { $format = property_exists($annotation, 'key') ? $annotation->key : ''; $parameters = array_merge($interception->getParams(), ['interception' => $interception]); if ($format && ($result = $this->language->evaluate($format, $parameters))) { return sha1(serialize($result)); } return $this->keyGenerator->generateKey($interception, $annotation); }
/** * @param InterceptionInterface $interception * @param CacheAnnotationInterface $annotation * * @return string * @throws UnsupportedKeyParameterException */ public function generateKey(InterceptionInterface $interception, CacheAnnotationInterface $annotation) : string { $hash = get_class($interception->getInstance()) . '::' . $interception->getMethod() . ';'; foreach ($interception->getParams() as $key => $value) { if (null === $value) { $paramHash = 'null'; } elseif (is_scalar($value)) { $paramHash = sha1($value); } elseif (is_array($value) || is_object($value)) { $paramHash = sha1(serialize($value)); } else { throw new UnsupportedKeyParameterException(sprintf('Not supported parameter type "%s"', gettype($value))); } $hash .= $key . '=' . $paramHash . ';'; } return sha1($hash); }