コード例 #1
0
 /**
  * AbstractResult constructor.
  *
  * @param InterceptionInterface $interception
  * @param string                $key
  * @param array                 $pools
  */
 public function __construct(InterceptionInterface $interception, string $key, array $pools)
 {
     $this->className = get_class($interception->getInstance());
     $this->method = $interception->getMethod();
     $this->key = $key;
     $this->pools = $pools;
 }
コード例 #2
0
 /**
  * @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);
 }
コード例 #3
0
 /**
  * @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);
 }
コード例 #4
0
 protected function setUp()
 {
     $this->interception = $this->getMockWithoutInvokingTheOriginalConstructor(InterceptionInterface::class);
     $this->interception->method('getInstance')->willReturn(new BookService());
     $this->interception->method('getMethod')->willReturn('getBookByIsbn');
 }