private function loadStoredRoutines(): void
  {
    // Log an empty line.
    $this->io->writeln('');

    // Sort the sources by routine name.
    usort($this->sources, function ($a, $b) {
      return strcmp($a['routine_name'], $b['routine_name']);
    });

    // Process all sources.
    foreach ($this->sources as $filename)
    {
      $routineName = $filename['routine_name'];

      $helper = new RoutineLoaderHelper($this->io,
                                        $filename['path_name'],
                                        $this->phpStratumMetadata[$routineName] ?? null,
                                        $this->replacePairs,
                                        $this->rdbmsOldMetadata[$routineName] ?? null,
                                        $this->sqlMode,
                                        $this->characterSet,
                                        $this->collate);

      try
      {
        $this->phpStratumMetadata[$routineName] = $helper->loadStoredRoutine();
      }
      catch (RoutineLoaderException $e)
      {
        $messages = [$e->getMessage(),
                     sprintf("Failed to load file '%s'", $filename['path_name'])];
        $this->io->error($messages);

        $this->errorFilenames[] = $filename['path_name'];
        unset($this->phpStratumMetadata[$routineName]);
      }
      catch (DataLayerException $e)
      {
        if ($e->isQueryError())
        {
          // Exception is caused by a SQL error. Log the message and the SQL statement with highlighting the error.
          $this->io->error($e->getShortMessage());
          $this->io->text($e->getMarkedQuery());
        }
        else
        {
          $this->io->error($e->getMessage());
        }
      }
    }
  }