Skip to content

Commit

Permalink
Use Core hook dispatcher in Module manager + refacto
Browse files Browse the repository at this point in the history
  • Loading branch information
mickaelandrieu committed Aug 17, 2018
1 parent 8164557 commit 443963b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 22 deletions.
26 changes: 9 additions & 17 deletions src/Core/Addon/Module/ModuleManager.php
Expand Up @@ -25,7 +25,6 @@
*/
namespace PrestaShop\PrestaShop\Core\Addon\Module;

use Employee;
use Exception;
use PrestaShop\PrestaShop\Adapter\Module\AdminModuleDataProvider;
use PrestaShop\PrestaShop\Adapter\Module\Module;
Expand All @@ -36,7 +35,7 @@
use PrestaShop\PrestaShop\Core\Addon\AddonsCollection;
use PrestaShop\PrestaShop\Core\Addon\Module\Exception\UnconfirmedModuleActionException;
use PrestaShopBundle\Event\ModuleManagementEvent;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use PrestaShop\PrestaShop\Core\Hook\HookDispatcherInterface;
use Symfony\Component\HttpFoundation\ParameterBag;
use Symfony\Component\Translation\TranslatorInterface;

Expand Down Expand Up @@ -77,14 +76,9 @@ class ModuleManager implements AddonManagerInterface
private $translator;

/**
* @var Employee Legacy employee class
* @var HookDispatcherInterface
*/
private $employee;

/**
* @var EventDispatcherInterface
*/
private $dispatcher;
private $hookDispatcher;

/**
* Additionnal data used for module actions
Expand All @@ -94,13 +88,13 @@ class ModuleManager implements AddonManagerInterface
private $actionParams;

/**
* @param AdminModuleDataProvider $adminModulesProvider
* @param AdminModuleDataProvider $adminModuleProvider
* @param ModuleDataProvider $modulesProvider
* @param ModuleDataUpdater $modulesUpdater
* @param ModuleRepository $moduleRepository
* @param ModuleZipManager $moduleZipManager
* @param TranslatorInterface $translator
* @param Employee|null $employee
* @param HookDispatcherInterface $hookDispatcher
*/
public function __construct(
AdminModuleDataProvider $adminModuleProvider,
Expand All @@ -109,8 +103,7 @@ public function __construct(
ModuleRepository $moduleRepository,
ModuleZipManager $moduleZipManager,
TranslatorInterface $translator,
EventDispatcherInterface $dispatcher,
Employee $employee = null
HookDispatcherInterface $hookDispatcher
)
{
$this->adminModuleProvider = $adminModuleProvider;
Expand All @@ -119,8 +112,7 @@ public function __construct(
$this->moduleRepository = $moduleRepository;
$this->moduleZipManager = $moduleZipManager;
$this->translator = $translator;
$this->employee = $employee;
$this->dispatcher = $dispatcher;
$this->hookDispatcher = $hookDispatcher;

$this->actionParams = new ParameterBag();
}
Expand Down Expand Up @@ -624,12 +616,12 @@ public function getError($name)

/**
* This function is a refacto of the event dispatching
* @param strig $event
* @param string $event
* @param \PrestaShop\PrestaShop\Core\Addon\Module\Module $module
*/
private function dispatch($event, $module)
{
$this->dispatcher->dispatch($event, new ModuleManagementEvent($module));
$this->hookDispatcher->dispatchWithParameters($event, new ModuleManagementEvent($module));
}

private function checkIsInstalled($name)
Expand Down
3 changes: 1 addition & 2 deletions src/Core/Addon/Module/ModuleManagerBuilder.php
Expand Up @@ -98,8 +98,7 @@ public function build()
$this->buildRepository(),
self::$moduleZipManager,
self::$translator,
new NullDispatcher(),
Context::getContext()->employee
new NullDispatcher()
);
}
}
Expand Down
Expand Up @@ -47,7 +47,6 @@ services:
- "@prestashop.module.zip.manager"
- "@translator"
- "@event_dispatcher"
- "@=service('prestashop.adapter.legacy.context').getContext().employee"

prestashop.module.zip.manager:
class: PrestaShop\PrestaShop\Adapter\Module\ModuleZipManager
Expand Down
3 changes: 1 addition & 2 deletions tests/Unit/Core/Addon/Module/ModuleManagerTest.php
Expand Up @@ -56,8 +56,7 @@ public function setUp()
$this->moduleRepositoryS,
$this->moduleZipManagerS,
$this->translatorS,
$this->dispatcherS,
$this->employeeS
$this->dispatcherS
);
}

Expand Down

0 comments on commit 443963b

Please sign in to comment.