function Versions::setChannel
File
-
vendor/
composer/ composer/ src/ Composer/ SelfUpdate/ Versions.php, line 65
Class
- Versions
- @author Jordi Boggiano <j.boggiano@seld.be>
Namespace
Composer\SelfUpdateCode
public function setChannel(string $channel, ?IOInterface $io = null) : void {
if (!in_array($channel, self::CHANNELS, true)) {
throw new \InvalidArgumentException('Invalid channel ' . $channel . ', must be one of: ' . implode(', ', self::CHANNELS));
}
$channelFile = $this->config
->get('home') . '/update-channel';
$this->channel = $channel;
// rewrite '2' and '1' channels to stable for future self-updates, but LTS ones like '2.2' remain pinned
$storedChannel = Preg::isMatch('{^\\d+$}D', $channel) ? 'stable' : $channel;
$previouslyStored = file_exists($channelFile) ? trim((string) file_get_contents($channelFile)) : null;
file_put_contents($channelFile, $storedChannel . PHP_EOL);
if ($io !== null && $previouslyStored !== $storedChannel) {
$io->writeError('Storing "<info>' . $storedChannel . '</info>" as default update channel for the next self-update run.');
}
}