Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/old/app/code/Soon/AjaxScroll/Model/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/old/app/code/Soon/AjaxScroll/Model/AjaxResponseBuilder.php
<?php
/**
 * @license http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 * @author Hervé Guétin <[email protected]> <@herveguetin>
 * @copyright Copyright (c) 2017 Agence Soon (http://www.agence-soon.fr)
 */

namespace Soon\AjaxScroll\Model;

use Magento\Framework\App\Action\Action;
use Magento\Framework\App\Action\Context;
use Magento\Framework\App\ResponseInterface;
use Magento\Framework\Controller\ResultInterface;
use Magento\Framework\Exception\NotFoundException;
use Magento\Framework\HTTP\PhpEnvironment\Response;
use Magento\Framework\View\Result\Page;
use Symfony\Component\DomCrawler\Crawler;

class AjaxResponseBuilder
{
    private $coreControllerFactory;
    /**
     * @var Context
     */
    private $context;
    /**
     * @var ResultInterface|ResponseInterface|Page
     */
    private $result;

    /**
     * AjaxResponseBuilder constructor.
     * @param $coreControllerFactory
     * @param Context $context
     */
    public function __construct(
        $coreControllerFactory,
        Context $context
    ) {
        $this->coreControllerFactory = $coreControllerFactory;
        $this->context = $context;
    }

    /**
     * Dispatch request
     *
     * @return ResultInterface|ResponseInterface
     * @throws NotFoundException
     */
    public function response()
    {
        /** @var Action $action */
        $action = $this->coreControllerFactory->create();
        $this->result = $action->execute();

        if (!$this->context->getRequest()->getParam('isSoonAjaxScroll')) {
            return $this->result;
        }

        return $this->ajaxResponse();
    }

    /**
     * @return Response
     */
    private function ajaxResponse()
    {
        /** @var Response $response */
        $response = $this->context->getResponse();
        if ($this->result !== null) {
            $this->result->renderResult($response);
        }
        $crawler = new Crawler($response->getBody());
        $productList = $crawler->filterXPath('//div[@soon_ajaxscroll]')->html();
        $response->setBody($productList);

        return $response;
    }
}

Spamworldpro Mini