| Current Path : /var/www/magento.test.indacotrentino.com/www/app/code/Webkul/BuyButton/Plugin/ |
| Current File : /var/www/magento.test.indacotrentino.com/www/app/code/Webkul/BuyButton/Plugin/CorsHeadersPlugin.php |
<?php
/**
* Webkul Software.
*
* @category Webkul
* @package Webkul_BuyButton
* @author Webkul
* @copyright Copyright (c) Webkul Software Private Limited (https://webkul.com)
* @license https://store.webkul.com/license.html
*/
namespace Webkul\BuyButton\Plugin;
use Magento\Framework\App\FrontControllerInterface;
use Magento\Framework\App\RequestInterface;
class CorsHeadersPlugin
{
/**
* @var \Magento\Framework\Webapi\Rest\Response
*/
private $response;
/**
* @var \Magento\Framework\App\Config\ScopeConfigInterface
*/
private $scopeConfig;
/**
* Initialize dependencies.
*
* @param \Magento\Framework\Webapi\Rest\Response $response
* @param \Magento\Framework\App\Config\ScopeConfigInterface scopeConfig
*/
public function __construct(
\Magento\Framework\Webapi\Rest\Response $response,
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
) {
$this->response = $response;
$this->scopeConfig = $scopeConfig;
}
/**
* Triggers before original dispatch
* This method triggers before original \Magento\Webapi\Controller\Rest::dispatch and set version
* from request params to VersionManager instance
* @param FrontControllerInterface $subject
* @param RequestInterface $request
* @return void
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function beforeDispatch(
FrontControllerInterface $subject,
RequestInterface $request
) {
$this->response->setHeader('Access-Control-Allow-Origin', '*', true);
$this->response->setHeader('Access-Control-Allow-Methods', 'POST, GET, OPTIONS, DELETE, PUT', true);
$this->response->setHeader('Access-Control-Allow-Headers', 'Accept, Content-Type', true);
}
}