You are here

protected function BackendBase::getInput in SCSS Compiler 1.0.x

Retrieve the source code to pass to the compiler.

Parameters

\Drupal\compiler\CompilerContextInterface $context: A compiler context used to define a compilation.

Return value

string The source code to pass to the compiler.

File

src/BackendBase.php, line 130

Class

BackendBase
Provides a base compiler backend implementation.

Namespace

Drupal\compiler_scss

Code

protected function getInput(CompilerContextInterface $context) {
  $source = [];

  // Iterate through each compiler input to construct the compiler source.
  foreach (new \RecursiveIteratorIterator($context
    ->getInputs()) as $input) {
    $result = $input
      ->get();
    if ($input instanceof CompilerInputFile) {
      $result = $this
        ->getAbsoluteFilePath($context, $result);
      $result = file_get_contents($result);
    }
    elseif (!$input instanceof CompilerInputDirect) {
      throw new \RuntimeException('Unsupported input type');
    }
    $source[] = $result;
  }

  // Concatenate the array of source code into a single string.
  return implode("\r\n", $source);
}