-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Don't rely on inaccessible packages when fetching update info.
Composer wants to use information about all dependencies when reporting the most up-to-date version that meets the project's stability/version constraints and doesn't conflict with any other dependencies. If a dependency is inaccessible (e.g. private repositories or IP-restricted hosting) composer will fail to declare a version candidate, which results in missing information even for some accessible packages. By ommitting inaccessible repositories, we do at least get _some_ version information, even if there is a change of compatability issues.
- Loading branch information
1 parent
ba8bae9
commit 23d7e5f
Showing
3 changed files
with
144 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
|
||
namespace BringYourOwnIdeas\UpdateChecker; | ||
|
||
use Composer\Config; | ||
use Composer\IO\IOInterface; | ||
use Composer\Repository\VcsRepository; | ||
use ReflectionObject; | ||
use RuntimeException; | ||
|
||
class DriverReflection | ||
{ | ||
public static function getDriverWithoutException(VcsRepository $repo, IOInterface $io, Config $config) | ||
{ | ||
$reflectedRepo = new ReflectionObject($repo); | ||
$drivers = static::getRepoField($repo, $reflectedRepo, 'drivers'); | ||
|
||
if (isset($drivers[static::getRepoField($repo, $reflectedRepo, 'type')])) { | ||
$class = $drivers[static::getRepoField($repo, $reflectedRepo, 'type')]; | ||
$driver = new $class($repo->getRepoConfig(), $io, $config); | ||
try { | ||
$driver->initialize(); | ||
} catch (RuntimeException $e) { | ||
// no-op - this is probably caused due to insufficient permissions when trying to create /var/www/.ssh | ||
// but since we're just getting the driver as a shortcut to getting the repository name, we can ignore this for now. | ||
} | ||
return $driver; | ||
} | ||
|
||
foreach ($drivers as $driver) { | ||
if ($driver::supports($io, $config, static::getRepoField($repo, $reflectedRepo, 'url'))) { | ||
$driver = new $driver($repo->getRepoConfig(), $io, $config); | ||
try { | ||
$driver->initialize(); | ||
} catch (RuntimeException $e) { | ||
// no-op - this is probably caused due to insufficient permissions when trying to create /var/www/.ssh | ||
// but since we're just getting the driver as a shortcut to getting the repository name, we can ignore this for now. | ||
} | ||
return $driver; | ||
} | ||
} | ||
|
||
foreach ($drivers as $driver) { | ||
if ($driver::supports($io, $config, static::getRepoField($repo, $reflectedRepo, 'url'), true)) { | ||
$driver = new $driver($repo->getRepoConfig(), $io, $config); | ||
try { | ||
$driver->initialize(); | ||
} catch (RuntimeException $e) { | ||
// no-op - this is probably caused due to insufficient permissions when trying to create /var/www/.ssh | ||
// but since we're just getting the driver as a shortcut to getting the repository name, we can ignore this for now. | ||
} | ||
return $driver; | ||
} | ||
} | ||
} | ||
|
||
public static function getSshUrl($driver) | ||
{ | ||
$reflectedDriver = new ReflectionObject($driver); | ||
if ($reflectedDriver->hasMethod('generateSshUrl')) { | ||
$reflectedMethod = $reflectedDriver->getMethod('generateSshUrl'); | ||
$reflectedMethod->setAccessible(true); | ||
return $reflectedMethod->invoke($driver); | ||
} | ||
return null; | ||
} | ||
|
||
protected static function getRepoField(VcsRepository $repo, ReflectionObject $reflectedRepo, string $field) | ||
{ | ||
$reflectedUrl = $reflectedRepo->getProperty($field); | ||
$reflectedUrl->setAccessible(true); | ||
return $reflectedUrl->getValue($repo); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters