0

I am creating a module to capture response on controller_front_send_response_before event.

In my observer file, I am getting both request and response object but I am not able to locate below class of response object:

Magento\Framework\App\Response\Http\Interceptor

I am searching in /magento root/vendor/magento/framework/App directory.

Also, When I was trying to log response, I got only headers in log file. How can I get final content that will print on browser?

In onbserver file I have written following code:

Ktpl\Logresponse\Observer\Response\Capture.php

namespace Ktpl\Logresponse\Observer\Response;

use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\Event\Observer;

class Capture implements ObserverInterface
{
    private $logger;

    public function __construct(\Psr\Log\LoggerInterface $logger) {
        $this->logger = $logger;
    }

    public function execute(Observer $observer) {
        try {
            $response = $observer->getEvent()->getData('response');
            $this->logger->debug($response);
            $this->logger->debug(get_class($response));
        } catch(\Exception $e) {
            $this->logger->critical($e);
        }
    }
}

Please share if anyone has any idea about this.

  • Refer useful to you blog.belvg.com/declaring-observers-in-magento-2-0.html – Prashant Valanda Mar 2 '16 at 12:52
  • Thank you for this useful link -- but my observer is working fine. When I call get_class function for response object, it gives me this class: Magento\Framework\App\Response\Http\Interceptor and I'm not able to locate this class. – Shyam Mar 2 '16 at 12:56
  • Also, how can I get final content from response object? – Shyam Mar 2 '16 at 12:57
0

the class Magento\Framework\App\Response\Http\Interceptor is generated by the ObjectManager.

You can find the class on your Server under var/generation/Magento/Framework/App/Response/Http/Interceptor.php

This class is responsible for executing all Plugins defined for Magento\Framework\App\Response\Http

So the Actual Response Object is still Magento\Framework\App\Response\Http, but the Interceptor class is injected as a wrapper for this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.