forked from opengento/magento2-gdpr
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
opengento#26 add notifiers to actions list
- Loading branch information
1 parent
dd91074
commit 864197e
Showing
32 changed files
with
458 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
/** | ||
* Copyright © OpenGento, All rights reserved. | ||
* See LICENSE bundled with this library for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Opengento\Gdpr\Model\Action\Erase; | ||
|
||
use InvalidArgumentException; | ||
use Magento\Framework\ObjectManagerInterface; | ||
use Opengento\Gdpr\Api\Data\ActionContextInterface; | ||
use Opengento\Gdpr\Api\Data\ActionResultInterface; | ||
use Opengento\Gdpr\Model\Action\AbstractAction; | ||
use Opengento\Gdpr\Model\Action\ArgumentReader as ActionArgumentReader; | ||
use Opengento\Gdpr\Model\Action\ResultBuilder; | ||
use Opengento\Gdpr\Model\Erase\NotifierInterface; | ||
use function sprintf; | ||
|
||
final class NotifierActionBundle extends AbstractAction | ||
{ | ||
/** | ||
* @var string[] | ||
*/ | ||
private $notifiers; | ||
|
||
/** | ||
* @var ObjectManagerInterface | ||
*/ | ||
private $objectManager; | ||
|
||
public function __construct( | ||
ResultBuilder $resultBuilder, | ||
array $notifiers, | ||
ObjectManagerInterface $objectManager | ||
) { | ||
$this->notifiers = $notifiers; | ||
$this->objectManager = $objectManager; | ||
parent::__construct($resultBuilder); | ||
} | ||
|
||
public function execute(ActionContextInterface $actionContext): ActionResultInterface | ||
{ | ||
$this->resolveNotifier($actionContext)->notify(ArgumentReader::getEntity($actionContext)); | ||
|
||
return $this->createActionResult(['is_notify' => true]); | ||
} | ||
|
||
private function resolveNotifier(ActionContextInterface $actionContext): NotifierInterface | ||
{ | ||
$entityType = ActionArgumentReader::getEntityType($actionContext); | ||
|
||
if (!isset($this->notifiers[$entityType])) { | ||
throw new InvalidArgumentException(sprintf('Unknown notifier for entity type "%s".', $entityType)); | ||
} | ||
|
||
return $this->objectManager->get($this->notifiers[$entityType]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
/** | ||
* Copyright © OpenGento, All rights reserved. | ||
* See LICENSE bundled with this library for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Opengento\Gdpr\Model\Action\Export; | ||
|
||
use InvalidArgumentException; | ||
use Magento\Framework\ObjectManagerInterface; | ||
use Opengento\Gdpr\Api\Data\ActionContextInterface; | ||
use Opengento\Gdpr\Api\Data\ActionResultInterface; | ||
use Opengento\Gdpr\Model\Action\AbstractAction; | ||
use Opengento\Gdpr\Model\Action\ArgumentReader as ActionArgumentReader; | ||
use Opengento\Gdpr\Model\Action\ResultBuilder; | ||
use Opengento\Gdpr\Model\Export\NotifierInterface; | ||
use function sprintf; | ||
|
||
final class NotifierActionBundle extends AbstractAction | ||
{ | ||
/** | ||
* @var string[] | ||
*/ | ||
private $notifiers; | ||
|
||
/** | ||
* @var ObjectManagerInterface | ||
*/ | ||
private $objectManager; | ||
|
||
public function __construct( | ||
ResultBuilder $resultBuilder, | ||
array $notifiers, | ||
ObjectManagerInterface $objectManager | ||
) { | ||
$this->notifiers = $notifiers; | ||
$this->objectManager = $objectManager; | ||
parent::__construct($resultBuilder); | ||
} | ||
|
||
public function execute(ActionContextInterface $actionContext): ActionResultInterface | ||
{ | ||
$this->resolveNotifier($actionContext)->notify(ArgumentReader::getEntity($actionContext)); | ||
|
||
return $this->createActionResult(['is_notify' => true]); | ||
} | ||
|
||
private function resolveNotifier(ActionContextInterface $actionContext): NotifierInterface | ||
{ | ||
$entityType = ActionArgumentReader::getEntityType($actionContext); | ||
|
||
if (!isset($this->notifiers[$entityType])) { | ||
throw new InvalidArgumentException(sprintf('Unknown notifier for entity type "%s".', $entityType)); | ||
} | ||
|
||
return $this->objectManager->get($this->notifiers[$entityType]); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
/** | ||
* Copyright © OpenGento, All rights reserved. | ||
* See LICENSE bundled with this library for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Opengento\Gdpr\Model\Action\PerformedBy; | ||
|
||
use Opengento\Gdpr\Model\Action\PerformedByInterface; | ||
|
||
final class NotEmptyStrategy implements PerformedByInterface | ||
{ | ||
private const PERFORMED_BY = 'Unknown'; | ||
|
||
/** | ||
* @var PerformedByInterface[] | ||
*/ | ||
private $performedByList; | ||
|
||
/** | ||
* @param PerformedByInterface[] $performedByList | ||
*/ | ||
public function __construct( | ||
array $performedByList | ||
) { | ||
$this->performedByList = (static function (PerformedByInterface ...$performedByList) { | ||
return $performedByList; | ||
})(...$performedByList); | ||
} | ||
|
||
public function get(): string | ||
{ | ||
foreach ($this->performedByList as $performedBy) { | ||
$performer = $performedBy->get(); | ||
|
||
if (!empty($performer)) { | ||
return $performer; | ||
} | ||
} | ||
|
||
return self::PERFORMED_BY; | ||
} | ||
} |
Oops, something went wrong.