Skip to content
29 changes: 28 additions & 1 deletion setup/src/Magento/Setup/Console/Command/DiCompileCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ class DiCompileCommand extends Command
*/
private $componentRegistrar;

/**
* @var \Magento\Framework\Event\ManagerInterface
*/
private $eventManager;

/**
* Constructor
*
Expand All @@ -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,
Expand All @@ -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;
Expand All @@ -99,6 +106,7 @@ public function __construct(
$this->filesystem = $filesystem;
$this->fileDriver = $fileDriver;
$this->componentRegistrar = $componentRegistrar;
$this->eventManager = $eventManager;
parent::__construct();
}

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
);
Expand All @@ -99,7 +111,8 @@ public function setUp()
$objectManagerProviderMock,
$this->filesystemMock,
$this->fileDriverMock,
$this->componentRegistrarMock
$this->componentRegistrarMock,
$this->eventManageMock
);
}

Expand Down