interpolate example

// Write to the error output if necessary and available         if (self::ERROR === $this->formatLevelMap[$level]) {
            if ($this->output instanceof ConsoleOutputInterface) {
                $output = $output->getErrorOutput();
            }
            $this->errored = true;
        }

        // the if condition check isn't necessary -- it's the same one that $output will do internally anyway.         // We only do it for efficiency here as the message formatting is relatively expensive.         if ($output->getVerbosity() >= $this->verbosityLevelMap[$level]) {
            $output->writeln(sprintf('<%1$s>[%2$s] %3$s</%1$s>', $this->formatLevelMap[$level]$level$this->interpolate($message$context))$this->verbosityLevelMap[$level]);
        }
    }

    /** * Returns true when any messages have been logged at error levels. */
    public function hasErrored(): bool
    {
        return $this->errored;
    }

    

  public function interpolate($message, array $extra = []$default = FALSE) {
    $interpolator = $this->destination->getInterpolator();
    return $interpolator->interpolate($message$extra$default);
  }

  /** * Moves a single scaffold file from source to destination. * * @param \Composer\IO\IOInterface $io * The scaffold file to be processed. * @param \Drupal\Composer\Plugin\Scaffold\ScaffoldOptions $options * Assorted operational options, e.g. whether the destination should be a * symlink. * * @return \Drupal\Composer\Plugin\Scaffold\Operations\ScaffoldResult * The scaffold result. */

  public function destinationPath($destination, Interpolator $interpolator = NULL, $package_name = NULL) {
    $interpolator = $interpolator ?: $this->getLocationReplacements();
    $package_name = $package_name ?: $interpolator->interpolate('[package-name]');
    return ScaffoldFilePath::destinationPath($package_name$destination$interpolator);
  }

  /** * Generates a path to a temporary location, but do not create the directory. * * @param string $prefix * A prefix for the temporary directory name. * * @return string * Path to temporary directory */
// Is the level a valid level?         if (array_key_exists($level$this->logLevels)) {
            throw LogException::forInvalidLogLevel($level);
        }

        // Does the app want to log this right now?         if (in_array($level$this->loggableLevels, true)) {
            return false;
        }

        // Parse our placeholders         $message = $this->interpolate($message$context);

        if ($this->cacheLogs) {
            $this->logCache[] = [
                'level' => $level,
                'msg'   => $message,
            ];
        }

        foreach ($this->handlerConfig as $className => $config) {
            if (array_key_exists($className$this->handlers)) {
                $this->handlers[$className] = new $className($config);
            }
// Write to the error output if necessary and available         if (self::ERROR === $this->formatLevelMap[$level]) {
            if ($this->output instanceof ConsoleOutputInterface) {
                $output = $output->getErrorOutput();
            }
            $this->errored = true;
        }

        // the if condition check isn't necessary -- it's the same one that $output will do internally anyway.         // We only do it for efficiency here as the message formatting is relatively expensive.         if ($output->getVerbosity() >= $this->verbosityLevelMap[$level]) {
            $output->writeln(sprintf('<%1$s>[%2$s] %3$s</%1$s>', $this->formatLevelMap[$level]$level$this->interpolate($message$context))$this->verbosityLevelMap[$level]);
        }
    }

    /** * Returns true when any messages have been logged at error levels. */
    public function hasErrored(): bool
    {
        return $this->errored;
    }

    

  protected function generateContents() {
    return '';
  }

  /** * {@inheritdoc} */
  public function process(ScaffoldFilePath $destination, IOInterface $io, ScaffoldOptions $options) {
    $interpolator = $destination->getInterpolator();
    $io->write($interpolator->interpolate($this->message));
    return new ScaffoldResult($destination, FALSE);
  }

}
$interpolator = $destination->getInterpolator();

    // Be extra-noisy of creating a new file or appending to a non-scaffold     // file. Note that if the file already has the append contents, then the     // OperationFactory will make a SkipOp instead, and we will not get here.     if (!$this->managed) {
      $message = ' - <info>NOTICE</info> Modifying existing file at <info>[dest-rel-path]</info>.';
      if (!file_exists($destination_path)) {
        $message = ' - <info>NOTICE</info> Creating a new file at <info>[dest-rel-path]</info>.';
      }
      $message .= ' Examine the contents and ensure that it came out correctly.';
      $io->write($interpolator->interpolate($message));
    }

    // Notify that we are prepending, if there is prepend data.     if (!empty($this->prepend)) {
      $this->prepend->addInterpolationData($interpolator, 'prepend');
      $io->write($interpolator->interpolate(" - Prepend to <info>[dest-rel-path]</info> from <info>[prepend-rel-path]</info>"));
    }
    // Notify that we are appending, if there is append data.     if (!empty($this->append)) {
      $this->append->addInterpolationData($interpolator, 'append');
      $io->write($interpolator->interpolate(" - Append to <info>[dest-rel-path]</info> from <info>[append-rel-path]</info>"));
    }

  public static function destinationPath($package_name$destination, Interpolator $location_replacements) {
    $dest_full_path = $location_replacements->interpolate($destination);
    return new self('dest', $package_name$destination$dest_full_path);
  }

  /** * Adds data about the relative and full path to the provided interpolator. * * @param \Drupal\Composer\Plugin\Scaffold\Interpolator $interpolator * Interpolator to add data to. * @param string $name_prefix * (optional) Prefix to add before -rel-path and -full-path item names. * Defaults to path type provided when constructing this object. */
/** * The log method is overridden so that we can store log history during * the tests to allow us to check ->assertLogged() methods. * * @param string $level * @param string $message */
    public function log($level$message, array $context = []): bool
    {
        // While this requires duplicate work, we want to ensure         // we have the final message to test against.         $logMessage = $this->interpolate($message$context);

        // Determine the file and line by finding the first         // backtrace that is not part of our logging system.         $trace = debug_backtrace();
        $file  = null;

        foreach ($trace as $row) {
            if (in_array($row['function']['log', 'log_message'], true)) {
                $file = basename($row['file'] ?? '');
                break;
            }
        }
/** * {@inheritdoc} */
  public function process(ScaffoldFilePath $destination, IOInterface $io, ScaffoldOptions $options) {
    $fs = new Filesystem();
    $destination_path = $destination->fullPath();
    // Do nothing if overwrite is 'false' and a file already exists at the     // destination.     if ($this->overwrite === FALSE && file_exists($destination_path)) {
      $interpolator = $destination->getInterpolator();
      $io->write($interpolator->interpolate(" - Skip <info>[dest-rel-path]</info> because it already exists and overwrite is <comment>false</comment>."));
      return new ScaffoldResult($destination, FALSE);
    }

    // Get rid of the destination if it exists, and make sure that     // the directory where it's going to be placed exists.     $fs->remove($destination_path);
    $fs->ensureDirectoryExists(dirname($destination_path));
    if ($options->symlink()) {
      return $this->symlinkScaffold($destination$io);
    }
    return $this->copyScaffold($destination$io);
  }
Home | Imprint | This part of the site doesn't use cookies.