diff --git a/setup/src/Magento/Setup/Console/Command/DiCompileCommand.php b/setup/src/Magento/Setup/Console/Command/DiCompileCommand.php index 014d699cb239d..0d3466fb343d1 100644 --- a/setup/src/Magento/Setup/Console/Command/DiCompileCommand.php +++ b/setup/src/Magento/Setup/Console/Command/DiCompileCommand.php @@ -72,6 +72,11 @@ class DiCompileCommand extends Command */ private $componentRegistrar; + /** + * @var \Magento\Framework\Event\ManagerInterface + */ + private $eventManager; + /** * Constructor * @@ -82,6 +87,7 @@ class DiCompileCommand extends Command * @param Filesystem $filesystem * @param DriverInterface $fileDriver * @param \Magento\Framework\Component\ComponentRegistrar $componentRegistrar + * @param \Magento\Framework\Event\ManagerInterface $eventManager */ public function __construct( DeploymentConfig $deploymentConfig, @@ -90,7 +96,8 @@ public function __construct( ObjectManagerProvider $objectManagerProvider, Filesystem $filesystem, DriverInterface $fileDriver, - ComponentRegistrar $componentRegistrar + ComponentRegistrar $componentRegistrar, + \Magento\Framework\Event\ManagerInterface $eventManager = null ) { $this->deploymentConfig = $deploymentConfig; $this->directoryList = $directoryList; @@ -99,6 +106,7 @@ public function __construct( $this->filesystem = $filesystem; $this->fileDriver = $fileDriver; $this->componentRegistrar = $componentRegistrar; + $this->eventManager = $eventManager; parent::__construct(); } @@ -162,6 +170,7 @@ protected function execute(InputInterface $input, OutputInterface $output) 'application' => $this->getExcludedModulePaths($modulePaths), 'framework' => $this->getExcludedLibraryPaths($libraryPaths), 'setup' => $this->getExcludedSetupPaths($setupPath), + 'custom-paths' => $this->getExcludedCustomPaths($modulePaths), ]; $this->configureObjectManager($output); @@ -400,4 +409,22 @@ private function getOperationsConfiguration( return $operations; } + + /** + * Exclude custom directories + * + * @param array $modulePaths + * + * @return array + */ + protected function getExcludedCustomPaths(array $modulePaths) { + $excludedCustomPaths = []; + + /** @var \Magento\Framework\Event\ManagerInterface $eventManager */ + if (!$this->eventManager) { + return $excludedCustomPaths; + } + $this->eventManager->dispatch('setup_di_compile_excluded_patterns', array('modulePaths' => $modulePaths, 'excludedPaths' => &$excludedCustomPaths)); + return $excludedCustomPaths; + } } diff --git a/setup/src/Magento/Setup/Test/Unit/Console/Command/DiCompileCommandTest.php b/setup/src/Magento/Setup/Test/Unit/Console/Command/DiCompileCommandTest.php index ca94a1b6fd559..4fe28c2eb9954 100644 --- a/setup/src/Magento/Setup/Test/Unit/Console/Command/DiCompileCommandTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Console/Command/DiCompileCommandTest.php @@ -42,6 +42,9 @@ class DiCompileCommandTest extends \PHPUnit\Framework\TestCase /** @var \Magento\Framework\Component\ComponentRegistrar|\PHPUnit_Framework_MockObject_MockObject */ private $componentRegistrarMock; + /** @var \Magento\Framework\Event\ManagerInterface|\PHPUnit_Framework_MockObject_MockObject */ + private $eventManageMock; + /** @var \Symfony\Component\Console\Output\OutputInterface|\PHPUnit_Framework_MockObject_MockObject */ private $outputMock; @@ -85,6 +88,15 @@ public function setUp() [ComponentRegistrar::LIBRARY, ['/path/to/library/one', '/path (1)/to/library/two']], ]); + $this->eventManageMock = $this->createMock(\Magento\Framework\Event\ManagerInterface::class); + $this->eventManageMock->expects($this->any())->method('dispatch')->with( + 'setup_di_compile_excluded_patterns', array( + 'modulePaths' => ['/path/to/module/one', '/path (1)/to/module/two'], + 'excludedPaths' => [] + ))->willReturnMap([ + ['#^(?:/custom/path/to)/exclude#'] + ]); + $this->outputFormatterMock = $this->createMock( \Symfony\Component\Console\Formatter\OutputFormatterInterface::class ); @@ -99,7 +111,8 @@ public function setUp() $objectManagerProviderMock, $this->filesystemMock, $this->fileDriverMock, - $this->componentRegistrarMock + $this->componentRegistrarMock, + $this->eventManageMock ); }