public function load(ResourceInterface $resource) { $tokens = $this->twig->tokenize($resource->getContent()); $nodes = $this->twig->parse($tokens); return $this->loadNode($nodes); }
/** * {@inheritdoc} */ public function load(ResourceInterface $resource) { $formulae = array(); $failureTemplates = array(); $successTemplates = array(); foreach ($this->activeTheme->getThemes() as $theme) { $this->activeTheme->setName($theme); try { // determine if the template has any errors $this->twig->tokenize($resource->getContent()); // delegate the formula loading to the parent $formulae += parent::load($resource); $successTemplates[(string) $resource] = true; } catch (\Exception $e) { $failureTemplates[(string) $resource] = $e->getMessage(); } } if ($this->logger) { foreach ($failureTemplates as $failureTemplate => $exceptionMessage) { if (isset($successTemplates[$failureTemplate])) { continue; } $this->logger->error(sprintf('The template "%s" contains an error: "%s"', $resource, $exceptionMessage)); } } return $formulae; }
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; }
public function load(ResourceInterface $resource) { try { $tokens = $this->twig->tokenize($resource->getContent(), (string) $resource); $nodes = $this->twig->parse($tokens); } catch (\Exception $e) { return array(); } return $this->loadNode($nodes); }
public function load(ResourceInterface $resource) { try { $tokens = $this->twig->tokenize($resource->getContent(), (string) $resource); $nodes = $this->twig->parse($tokens); } catch (\Exception $e) { if ($this->logger) { $this->logger->error(sprintf('The template "%s" contains an error: %s', $resource, $e->getMessage())); } return array(); } return $this->loadNode($nodes); }
/** * Loads a cached resource * * @param ResourceInterface $resource * * @return array */ public function load(ResourceInterface $resource) { if (!$resource instanceof CacheResource) { return array(); } if (!$this->cache->has($resource->getName())) { return array(); } $formulas = unserialize($this->cache->get($resource->getName())); foreach ($formulas as $idx => $formula) { $formulas[$idx] = $this->restoreFormulaFilters($formula); } return $formulas; }
/** * {@inheritDoc} */ public function load(ResourceInterface $resource) { $formulae = array(); $filenames = preg_split("/\n+/", $resource->getContent()); foreach ($filenames as $filename) { if (is_file($filename)) { $name = $this->factory->generateAssetName($filename, array()); $output = $this->mapping->getModulePath($filename); if ($output) { // @see \Assetic\Factory\AssetFactory::createAsset() $formulae[$name] = array($filename, array(), array('output' => $output)); } } } return $formulae; }
public function load(ResourceInterface $resource) { $tokens = token_get_all($resource->getContent()); /** * @todo Find and extract asset formulae from calls to the following: * * * $view['assetic']->assets(...) * * $view['assetic']->javascripts(...) * * $view['assetic']->stylesheets(...) * * $view->get('assetic')->assets(...) * * $view->get('assetic')->javascripts(...) * * $view->get('assetic')->stylesheets(...) * * The loader will also need to be aware of debug mode and the default * output strings associated with each method. */ return array(); }
public function load(ResourceInterface $resource) { $formulae = array(); // template source $templateSource = $resource->getContent(); $smarty = $this->engine->getSmarty(); // ask Smarty which delimiters to use $ldelim = $smarty->left_delimiter; $rdelim = $smarty->right_delimiter; $_ldelim = preg_quote($ldelim); $_rdelim = preg_quote($rdelim); // template block tags to look for $tags = implode('|', $this->tags); /** * Thanks Rodney! * * @see https://gist.github.com/483465490f738d1b2b5e */ if (preg_match_all('#' . $_ldelim . '(?<type>' . $tags . ').*?' . $_rdelim . '#s', $templateSource, $matches, PREG_SET_ORDER)) { foreach ($matches as $match) { if (preg_match_all('#(?<key>[a-zA-Z0-9_]+)\\s*=\\s*(["\']?)(?<value>[^\\2]*?)\\2(\\s|' . $_rdelim . ')#s', $match[0], $_matches, PREG_SET_ORDER)) { $t = array('type' => $match['type'], 'attributes' => array()); foreach ($_matches as $_match) { if (empty($_match[2])) { // make eval a little bit safer preg_match('#[^\\w|^\\.]#', $_match['value'], $evalMatches); $_match['value'] = $evalMatches ? null : eval(sprintf('return %s;', $_match['value'])); } $t['attributes'][$_match['key']] = $_match['value']; } $formulae += $this->buildFormula($match['type'], $t['attributes']); } } } return $formulae; }
public function load(ResourceInterface $resource) { return $resource instanceof ConfigurationResource ? $resource->getContent() : array(); }
public function load(ResourceInterface $resource) { return $resource instanceof ThemeResource ? $resource->getContent() : []; }
/** * @inheritdoc */ public function load(ResourceInterface $resource) { return $resource->getContent(); }