public function BasePhpFormulaLoader::load

Loads formulae from a resource.

Formulae should be loaded the same regardless of the current debug mode. Debug considerations should happen downstream.

Parameters

ResourceInterface $resource A resource:

Return value

array An array of formulae

Overrides FormulaLoaderInterface::load

File

drupal/core/vendor/kriswallsmith/assetic/src/Assetic/Factory/Loader/BasePhpFormulaLoader.php, line 45

Class

BasePhpFormulaLoader
Loads asset formulae from PHP files.

Namespace

Assetic\Factory\Loader

Code

public function load(ResourceInterface $resource) {
  if (!($nbProtos = count($this->prototypes))) {
    throw new \LogicException('There are no prototypes registered.');
  }
  $buffers = array_fill(0, $nbProtos, '');
  $bufferLevels = array_fill(0, $nbProtos, 0);
  $buffersInWildcard = array();
  $tokens = token_get_all($resource
    ->getContent());
  $calls = array();
  while ($token = array_shift($tokens)) {
    $current = self::tokenToString($token);

    // loop through each prototype (by reference)
    foreach (array_keys($this->prototypes) as $i) {
      $prototype =& $this->prototypes[$i][0];
      $options = $this->prototypes[$i][1];
      $buffer =& $buffers[$i];
      $level =& $bufferLevels[$i];
      if (isset($buffersInWildcard[$i])) {
        switch ($current) {
          case '(':
            ++$level;
            break;
          case ')':
            --$level;
            break;
        }
        $buffer .= $current;
        if (!$level) {
          $calls[] = array(
            $buffer . ';',
            $options,
          );
          $buffer = '';
          unset($buffersInWildcard[$i]);
        }
      }
      elseif ($current == self::tokenToString(current($prototype))) {
        $buffer .= $current;
        if ('*' == self::tokenToString(next($prototype))) {
          $buffersInWildcard[$i] = true;
          ++$level;
        }
      }
      else {
        reset($prototype);
        unset($buffersInWildcard[$i]);
        $buffer = '';
      }
    }
  }
  $formulae = array();
  foreach ($calls as $call) {
    $formulae += call_user_func_array(array(
      $this,
      'processCall',
    ), $call);
  }
  return $formulae;
}