Skip to content

Commit

Permalink
Refactor code to use plugin instead of preference
Browse files Browse the repository at this point in the history
  • Loading branch information
sinisa-colic committed Jan 25, 2019
1 parent 607f446 commit cea4ecb
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 117 deletions.
47 changes: 47 additions & 0 deletions Plugin/AccountManagementPlugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace Timpack\PwnedValidator\Plugin;

use Magento\Customer\Api\AccountManagementInterface;
use Magento\Customer\Api\Data\CustomerInterface;
use Magento\Framework\Event\ManagerInterface;

class AccountManagementPlugin
{
/**
* @var ManagerInterface
*/
protected $eventManager;

/**
* AccountManagementPlugin constructor.
* @param ManagerInterface $eventManager
*/
public function __construct(
ManagerInterface $eventManager
) {
$this->eventManager = $eventManager;
}

/**
* @param AccountManagementInterface $subject
* @param CustomerInterface $customer
* @param null $password
* @param string $redirectUrl
*/
public function beforeCreateAccount(
AccountManagementInterface $subject,
CustomerInterface $customer,
$password = null,
$redirectUrl = ''
) {
if (!is_null($password)) {
$this->eventManager->dispatch(
'timpack_pwnedvalidator_check_password_strength',
[
'password' => $password,
]
);
}
}
}
115 changes: 0 additions & 115 deletions Rewrite/Model/AccountManagement.php

This file was deleted.

5 changes: 3 additions & 2 deletions etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Timpack\PwnedValidator\Api\ValidatorInterface" type="Timpack\PwnedValidator\Model\Validator"/>
<preference for="Magento\Customer\Model\AccountManagement"
type="Timpack\PwnedValidator\Rewrite\Model\AccountManagement"/>
<type name="Magento\Customer\Api\AccountManagementInterface">
<plugin name="timpack_pwnedvalidator_magento_customer_api_accountmanagementinterface" type="Timpack\PwnedValidator\Plugin\AccountManagementPlugin"/>
</type>
<type name="Timpack\PwnedValidator\Api\ValidatorInterface">
<arguments>
<argument name="httpClient" xsi:type="object">Magento\Framework\HTTP\Client\Curl</argument>
Expand Down

0 comments on commit cea4ecb

Please sign in to comment.