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/Kaliop/Styleguide/Observer/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/old/app/code/Kaliop/Styleguide/Observer/RestrictCmsPage.php
<?php
/**
 * Copyright (c) 2019 Kaliop Digital Commerce (https://digitalcommerce.kaliop.com) All Rights Reserved.
 * https://opensource.org/licenses/OSL-3.0  Open Software License (OSL 3.0)
 * kaliop_styleguide_m2
 * Julien TRAJMAN <[email protected]> <[email protected]>
 */

namespace Kaliop\Styleguide\Observer;

use Kaliop\Styleguide\Model\Config;

use Magento\Developer\Helper\Data;
use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;

/**
 * Class RestrictCmsPage
 * @package Kaliop\Styleguide\Observer
 */
class RestrictCmsPage implements ObserverInterface
{
    /**
     * @var Data
     */
    private $developerHelper;
    /**
     * @var \Magento\Framework\App\ResponseFactory
     */
    private $responseFactory;
    /**
     * @var \Magento\Framework\UrlInterface
     */
    private $url;

    /**
     * RestrictCmsPage constructor.
     * @param Data $developerHelper
     * @param \Magento\Framework\App\ResponseFactory $responseFactory
     * @param \Magento\Framework\UrlInterface $url
     */
    public function __construct(
        Data $developerHelper,
        \Magento\Framework\App\ResponseFactory $responseFactory,
        \Magento\Framework\UrlInterface $url
    ) {
        $this->developerHelper = $developerHelper;
        $this->responseFactory = $responseFactory;
        $this->url = $url;
    }

    /**
     * @param Observer $observer
     * @return $this
     */
    public function execute(Observer $observer)
    {
        /** @var \Magento\Cms\Model\Page $page */
        $page = $observer->getEvent()->getPage();

        if ($page->getIdentifier() !== Config::KALIOP_STYLEGUIDE_IDENTIFIER) {
            return $this;
        }

        if (!$this->developerHelper->isDevAllowed()) {
            $redirectionUrl = $this->url->getBaseUrl();
            $this->responseFactory->create()->setRedirect($redirectionUrl)->sendResponse();

            return $this;
        }

        return $this;
    }
}

Spamworldpro Mini