Skip to content

Commit

Permalink
Refs #1663 - add pharLocation hack to phpdepend/phpmd tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
mrook committed Apr 18, 2023
1 parent 006aad0 commit 838d793
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/Phing/Task/Ext/Analyzer/Pdepend/PhpDependTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,22 @@ class PhpDependTask extends Task
protected function requireDependencies()
{
if (!empty($this->pharLocation)) {
// nasty but necessary: reorder the autoloaders so the one in the PHAR gets priority
$autoloadFunctions = spl_autoload_functions();
$composerAutoloader = null;
if (get_class($autoloadFunctions[0][0]) === 'Composer\Autoload\ClassLoader') {
$composerAutoloader = $autoloadFunctions[0];
spl_autoload_unregister($composerAutoloader);
}

$GLOBALS['_SERVER']['SCRIPT_NAME'] = '-';
ob_start();
include_once 'phar://' . $this->pharLocation . '/vendor/autoload.php';
ob_end_clean();

if ($composerAutoloader !== null) {
spl_autoload_register($composerAutoloader);
}
}

// check 2.x version (composer/phar)
Expand Down
15 changes: 15 additions & 0 deletions src/Phing/Task/Ext/Analyzer/Phpmd/PHPMDTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,22 @@ public function setCacheFile(File $file)
protected function loadDependencies()
{
if (!empty($this->pharLocation)) {
// nasty but necessary: reorder the autoloaders so the one in the PHAR gets priority
$autoloadFunctions = spl_autoload_functions();
$composerAutoloader = null;
if (get_class($autoloadFunctions[0][0]) === 'Composer\Autoload\ClassLoader') {
$composerAutoloader = $autoloadFunctions[0];
spl_autoload_unregister($composerAutoloader);
}

$GLOBALS['_SERVER']['SCRIPT_NAME'] = '-';
ob_start();
include_once 'phar://' . $this->pharLocation . '/vendor/autoload.php';
ob_end_clean();

if ($composerAutoloader !== null) {
spl_autoload_register($composerAutoloader);
}
}

$className = '\PHPMD\PHPMD';
Expand Down

0 comments on commit 838d793

Please sign in to comment.