Skip to content

Commit

Permalink
DEPRECATED: AbstractAccount for Magento_Customer controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
lbajsarowicz committed Mar 9, 2020
1 parent cac512f commit 007a891
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
4 changes: 2 additions & 2 deletions app/code/Magento/Customer/Controller/AbstractAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
use Magento\Framework\App\Action\Action;

/**
* Class AbstractAccount
* @package Magento\Customer\Controller
* @SuppressWarnings(PHPMD.NumberOfChildren)
* @deprecated 2.4.0
* @see \Magento\Customer\Controller\AccountInterface
*/
abstract class AbstractAccount extends Action implements AccountInterface
{
Expand Down
23 changes: 15 additions & 8 deletions app/code/Magento/Customer/Controller/Plugin/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Customer\Controller\Plugin;

use Magento\Customer\Controller\AccountInterface;
use Magento\Customer\Model\Session;
use Magento\Framework\App\ActionInterface;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\App\ResponseInterface;
use Magento\Framework\App\Action\AbstractAction;
use Magento\Framework\Controller\ResultInterface;

class Account
Expand All @@ -23,29 +25,35 @@ class Account
* @var array
*/
private $allowedActions = [];
/**
* @var RequestInterface
*/
private $request;

/**
* @param RequestInterface $request
* @param Session $customerSession
* @param array $allowedActions List of actions that are allowed for not authorized users
*/
public function __construct(
RequestInterface $request,
Session $customerSession,
array $allowedActions = []
) {
$this->session = $customerSession;
$this->allowedActions = $allowedActions;
$this->request = $request;
}

/**
* Dispatch actions allowed for not authorized users
*
* @param AbstractAction $subject
* @param RequestInterface $request
* @param AccountInterface $subject
* @return void
*/
public function beforeDispatch(AbstractAction $subject, RequestInterface $request)
public function beforeExecute(AccountInterface $subject)
{
$action = strtolower($request->getActionName());
$action = strtolower($this->request->getActionName());
$pattern = '/^(' . implode('|', $this->allowedActions) . ')$/i';

if (!preg_match($pattern, $action)) {
Expand All @@ -60,13 +68,12 @@ public function beforeDispatch(AbstractAction $subject, RequestInterface $reques
/**
* Remove No-referer flag from customer session
*
* @param AbstractAction $subject
* @param AccountInterface $subject
* @param ResponseInterface|ResultInterface $result
* @param RequestInterface $request
* @return ResponseInterface|ResultInterface
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function afterDispatch(AbstractAction $subject, $result, RequestInterface $request)
public function afterExecute(AccountInterface $subject, $result)
{
$this->session->unsNoReferer(false);
return $result;
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Customer/etc/frontend/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
</argument>
</arguments>
</type>
<type name="Magento\Customer\Controller\AbstractAccount">
<type name="Magento\Customer\Controller\AccountInterface">
<plugin name="customer_account" type="Magento\Customer\Controller\Plugin\Account" />
</type>
<type name="Magento\Checkout\Block\Cart\Sidebar">
Expand Down

0 comments on commit 007a891

Please sign in to comment.