Platformsh\Cli\SelfUpdate\SelfUpdater::update PHP Method

update() public method

Run the update.
public update ( string | null $manifestUrl = null, string | null $currentVersion = null ) : false | string
$manifestUrl string | null
$currentVersion string | null
return false | string The new version number, or false if there was no update.
    public function update($manifestUrl = null, $currentVersion = null)
    {
        $currentVersion = $currentVersion ?: $this->config->get('application.version');
        $manifestUrl = $manifestUrl ?: $this->config->get('application.manifest_url');
        if (!extension_loaded('Phar') || !($localPhar = \Phar::running(false))) {
            $this->stdErr->writeln('This instance of the CLI was not installed as a Phar archive.');
            // Instructions for users who are running a global Composer install.
            if (defined('CLI_ROOT') && file_exists(CLI_ROOT . '/../../autoload.php')) {
                $this->stdErr->writeln("Update using:\n\n  composer global update");
                $this->stdErr->writeln("\nOr you can switch to a Phar install (<options=bold>recommended</>):\n");
                $this->stdErr->writeln("  composer global remove " . $this->config->get('application.package_name'));
                $this->stdErr->writeln("  curl -sS " . $this->config->get('application.installer_url') . " | php\n");
            }
            return false;
        }
        $this->stdErr->writeln(sprintf('Checking for updates (current version: <info>%s</info>)', $currentVersion));
        $updater = new Updater(null, false);
        $strategy = new ManifestStrategy($currentVersion, $manifestUrl, $this->allowMajor, $this->allowUnstable);
        $strategy->setManifestTimeout($this->timeout);
        $updater->setStrategyObject($strategy);
        if (!$updater->hasUpdate()) {
            $this->stdErr->writeln('No updates found');
            return false;
        }
        $newVersionString = $updater->getNewVersion();
        if ($notes = $strategy->getUpdateNotes($updater)) {
            $this->stdErr->writeln('');
            $this->stdErr->writeln(sprintf('Version <info>%s</info> is available. Update notes:', $newVersionString));
            $this->stdErr->writeln(preg_replace('/^/m', '  ', $notes));
            $this->stdErr->writeln('');
        }
        if (!$this->questionHelper->confirm(sprintf('Update to version %s?', $newVersionString))) {
            return false;
        }
        $this->stdErr->writeln(sprintf('Updating to version %s', $newVersionString));
        $updater->update();
        $this->stdErr->writeln("Successfully updated to version <info>{$newVersionString}</info>");
        return $newVersionString;
    }

Usage Example

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $manifestUrl = $input->getOption('manifest') ?: self::$config->get('application.manifest_url');
     $currentVersion = $input->getOption('current-version') ?: self::$config->get('application.version');
     $cliUpdater = new SelfUpdater($input, $output, self::$config, $this->getHelper('question'));
     $cliUpdater->setAllowMajor(!$input->getOption('no-major'));
     $cliUpdater->setAllowUnstable((bool) $input->getOption('unstable'));
     $cliUpdater->setTimeout($input->getOption('timeout'));
     $result = $cliUpdater->update($manifestUrl, $currentVersion);
     if ($result === false) {
         return 1;
     }
     // Phar cannot load more classes after the update has occurred. So to
     // avoid errors from classes loaded after this (e.g.
     // ConsoleTerminateEvent), we exit directly now.
     exit(0);
 }
All Usage Examples Of Platformsh\Cli\SelfUpdate\SelfUpdater::update