Cache bridge file response

@param MethodInvocation $invocation
@return \KickAss\Commerce\Product\Map\Product

@Around("execution(public KickAss\Commerce\Product\Repository\Product->loadByAttribute(*))")
347558
public function afterMethodExecution(MethodInvocation $invocation)
    {
        $filesystemAdapter = new Local(APP_BASE_DIR . 'storage/cache/api/');
        $filesystem        = new Filesystem($filesystemAdapter);

        $pool = new FilesystemCachePool($filesystem);

        $cacheKey = "products_" . md5(implode('_', $invocation->getArguments()));

        $item = $pool->getItem($cacheKey);
        $normalizer = new ObjectNormalizer();

        if ($item->isHit()) { // found the item in cache
            /** @var MapProduct $cacheItem */
            $cacheItem = $normalizer->denormalize($item->get(), MapProduct::class);
            return $cacheItem;
        }

        // execute the API call
        /** @var \KickAss\Commerce\Product\Map\Product $returnValue */
        $returnValue = $invocation->proceed();

        $item->set($normalizer->normalize($returnValue, 'array'))
            ->setTags(['products']);
        $item->expiresAfter(3600);

        $pool->save($item);

        // return value as expected
        return $returnValue;
    }
850799
public function alterTextarea(MethodInvocation $invocation)
    {
        $helper = $invocation->getThis();
        list($fieldName, $options) = array_pad($invocation->getArguments(), 2, null);

        if (!empty($options['class']) &&
            strpos($options['class'], 'ckeditor') !== false &&
            $helper instanceof FormHelper
        ) {
            static::$_counter++;
            $editorId = 'ck-editor-' . static::$_counter;
            $options['class'] .= ' ' . $editorId;
            $view = $this->getProperty($helper, '_View');

            if (!static::$_scriptsLoaded) {
                static::$_scriptsLoaded = true;
                $filebrowserBrowseUrl = $view->Url->build(['plugin' => 'Wysiwyg', 'controller' => 'finder']);
                $view->Html->script('Wysiwyg./ckeditor/ckeditor.js', ['block' => true]);
                $view->Html->script('Wysiwyg./ckeditor/adapters/jquery.js', ['block' => true]);
                $view->Html->scriptBlock('$(document).ready(function () {
                    CKEDITOR.editorConfig = function(config) {
                        config.filebrowserBrowseUrl = "' . $filebrowserBrowseUrl . '";
                    };
                });', ['block' => true]);
                $this->_includeLinksToContents($view);
            }
        }

        $this->setProperty($invocation, 'arguments', [$fieldName, $options]);

        return $invocation->proceed();
    }
331918
private function fetchContext(int $invocationTID, int $argumentsTID): array
    {
        $class = $operator = '';
        $name = trim($this->getSource($invocationTID, $argumentsTID), '( ');

        //Let's try to fetch all information we need
        if (strpos($name, '->') !== false) {
            $operator = '->';
        } elseif (strpos($name, '::') !== false) {
            $operator = '::';
        }

        if (!empty($operator)) {
            list($class, $name) = explode($operator, $name);

            //We now have to clarify class name
            if (in_array($class, ['self', 'static', '$this'])) {
                $class = $this->activeDeclaration($invocationTID);
            }
        }

        return [$class, $operator, $name];
    }
106758
public function aroundArrayFunctions(FunctionInvocation $invocation)
    {
        echo 'Calling Around Interceptor for ',
            $invocation,
            ' with arguments: ',
            json_encode($invocation->getArguments()),
            PHP_EOL;

        return $invocation->proceed();
    }
475432
public function hasResultFor(string $method, int $invocationCount): bool
    {
        if (!array_key_exists($method, $this->callMap)) {
            return false;
        }

        if ($this->callMap[$method] instanceof InvocationResults) {
            return $this->callMap[$method]->hasResultForInvocation($invocationCount - 1);
        }

        return true;
    }
597988
public function alterCreate(MethodInvocation $invocation)
    {
        $helper = $invocation->getThis();
        list($model, $options) = array_pad($invocation->getArguments(), 2, null);
        $options = (array)$options;
        $bootstrap = isset($options['bootstrap']) ? (bool)$options['bootstrap'] : true;

        if ($bootstrap) {
            $this->_addTemplates($helper);
        }

        if (isset($options['bootstrap'])) {
            unset($options['bootstrap']);
        }

        $this->setProperty($invocation, 'arguments', [$model, $options]);

        return $invocation->proceed();
    }
156200
private function registerInvocations(array $invocations)
    {
        foreach ($invocations as $invocation) {
            if ($invocation->getArgument(0)->getType() != ReflectionArgument::STRING) {
                //We can only index invocations with constant string arguments
                continue;
            }

            $string = $invocation->getArgument(0)->stringValue();
            $string = $this->prepareMessage($string);

            $this->registerMessage($this->invocationDomain($invocation), $string, false);
        }
    }
1298546
private function getNamedArguments(MethodInvocation $invocation)
    {
        $submit = [];
        $params = $invocation->getMethod()->getParameters();
        $args = $invocation->getArguments()->getArrayCopy();
        foreach ($params as $param) {
            $arg = array_shift($args);
            $submit[$param->getName()] = $arg;
        }
        // has token ?
        if (isset($_POST[AntiCsrf::TOKEN_KEY])) {
            $submit[AntiCsrf::TOKEN_KEY] = $_POST[AntiCsrf::TOKEN_KEY];
        }

        return $submit;
    }
102234
public function invoke(MethodInvocation $invocation)
    {
        $object = $invocation->getThis();
        /* @var $formValidation FormValidation */
        $method = $invocation->getMethod();
        $formValidation = $this->reader->getMethodAnnotation($method, AbstractValidation::class);
        $form = $this->getFormProperty($formValidation, $object);
        $data = $form instanceof SubmitInterface ? $form->submit() : $this->getNamedArguments($invocation);
        $isValid = $this->isValid($data, $form);
        if ($isValid === true) {
            // validation   success
            return $invocation->proceed();
        }

        return $this->failureHandler->handle($formValidation, $invocation, $form);
    }
1225175
protected function _getDataFromBucket($in, &$consumed)
    {
        $data = '';
        while ($bucket = stream_bucket_make_writeable($in)) {
            $data .= $bucket->data;
            $consumed += $bucket->datalen;
        }

        return $data;
    }
719132
public static function invocationId()
    {
        return function (callable $handler) {
            return function (
                CommandInterface $command,
                RequestInterface $request
            ) use ($handler){
                return $handler($command, $request->withHeader(
                    'aws-sdk-invocation-id',
                    md5(uniqid(gethostname(), true))
                ));
            };
        };
    }
917494
private function failureException(MethodInvocation $invocation, FailureInterface $failure)
    {
        $class = new \ReflectionClass($invocation->getThis());
        $className = $class->implementsInterface(WeavedInterface::class) ? $class->getParentClass()->name : $class->name;
        $errors = json_encode($failure->getMessages());
        $msg = sprintf('%s::%s() %s', $className, $invocation->getMethod()->name, $errors);

        return new InvalidArgumentException($msg, 400);
    }
346971
public function invoke(\PHPUnit_Framework_MockObject_Invocation $invocation)
    {
        $exception      = null;
        $hasReturnValue = false;

        $returnValue = next::caller();

        foreach ($this->matchers as $match) {
            try {
                if ($match->matches($invocation)) {
                    $value = $match->invoked($invocation);

                    if (!$hasReturnValue) {
                        $returnValue    = $value;
                        $hasReturnValue = true;
                    }
                }
            } catch (\Exception $e) {
                $exception = $e;
            }
        }

        if ($exception !== null) {
            throw $exception;
        }

        return $returnValue;
    }
359258
protected function createInvoker()
    {
        $config = $this->config;

        $interface = Arr::pull($config, 'interface');
        $concrete = Arr::pull($config, 'refer', $interface);

        $invoker = new ConcreteInvoker($this->context, $interface, $concrete, $config);

        return $this->withMiddleware($invoker, $interface, $config);
    }
137634
public RpcRequest getRequest(final Invocation invocation) {
		if (invocation == null) throw new NullPointerException("invocation");

		MethodDescriptor<?, ?> method = invocation.getMethod();
		if (!method.isTerminal()) {
			throw new IllegalArgumentException("Last invocation method must be terminal");
		}

		RpcRequest request = new RpcRequest(method.isPost() ? RpcRequest.POST : RpcRequest.GET);
		for (Invocation invocation1 : invocation.toChain()) {
			writeInvocation(request, invocation1);
		}

		return request;
	}
27879
public final I getInvocation(Object protocolKey)
  {
    I invocation = null;

    // XXX: see if can remove this
    LruCache<Object,I> invocationCache = _invocationCache;

    if (invocationCache != null) {
      invocation = invocationCache.get(protocolKey);
    }

    if (invocation == null) {
      return null;
    }
    else if (invocation.isModified()) {
      return null;
    }
    else {
      return invocation;
    }
  }
1078299
protected function generateCacheName($name, MethodInvocation $invocation): array
    {
        if (is_array($name)) {
            throw new \InvalidArgumentException('Invalid argument');
        }
        if (is_null($name)) {
            $name = $invocation->getMethod()->name;
        }

        return [$name];
    }