RemoveAction.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * Action validator, remove action
  4. *
  5. * Copyright © Magento, Inc. All rights reserved.
  6. * See COPYING.txt for license details.
  7. */
  8. namespace Magento\Framework\Model\ActionValidator;
  9. use Magento\Framework\Model\AbstractModel;
  10. /**
  11. * @api
  12. * @since 100.0.2
  13. */
  14. class RemoveAction
  15. {
  16. /**
  17. * @var \Magento\Framework\Registry
  18. */
  19. protected $registry;
  20. /**
  21. * @var array
  22. */
  23. protected $protectedModels;
  24. /**
  25. * @param \Magento\Framework\Registry $registry
  26. * @param array $protectedModels
  27. */
  28. public function __construct(\Magento\Framework\Registry $registry, array $protectedModels = [])
  29. {
  30. $this->registry = $registry;
  31. $this->protectedModels = $protectedModels;
  32. }
  33. /**
  34. * Safeguard function that checks if item can be removed
  35. *
  36. * @param \Magento\Framework\Model\AbstractModel $model
  37. * @return bool
  38. */
  39. public function isAllowed(AbstractModel $model)
  40. {
  41. $isAllowed = true;
  42. if ($this->registry->registry('isSecureArea')) {
  43. $isAllowed = true;
  44. } elseif (in_array($this->getBaseClassName($model), $this->protectedModels)) {
  45. $isAllowed = false;
  46. }
  47. return $isAllowed;
  48. }
  49. /**
  50. * Get clean model name without Interceptor and Proxy part and slashes
  51. * @param object $object
  52. * @return mixed
  53. */
  54. protected function getBaseClassName($object)
  55. {
  56. $className = ltrim(get_class($object), "\\");
  57. $className = str_replace(['\Interceptor', '\Proxy'], [''], $className);
  58. return $className;
  59. }
  60. }