You are here

private function HamlParser::getFilter in Sassy 7

* Gets a filter. * Filters are loaded on first use. *

Parameters

string filter name: * @throws HamlException if the filter does not exist or does not extend HamlBaseFilter

1 call to HamlParser::getFilter()
HamlParser::parseFilter in phamlp/haml/HamlParser.php
* Parse a filter. *

File

phamlp/haml/HamlParser.php, line 798

Class

HamlParser
HamlParser class. Parses {@link http://haml-lang.com/ Haml} view files. @package PHamlP @subpackage Haml

Code

private function getFilter($filter) {
  static $firstRun = true;
  $imported = false;
  if (empty($this->filters[$filter])) {
    if ($firstRun) {
      require_once 'filters/HamlBaseFilter.php';
      $firstRun = false;
    }
    $filterclass = 'Haml' . ucfirst($filter) . 'Filter';
    if (isset($this->filterDir)) {
      $this->filterDir = substr($this->filterDir, -1) == DIRECTORY_SEPARATOR ? substr($this->filterDir, 0, -1) : $this->filterDir;
      if (file_exists($this->filterDir . DIRECTORY_SEPARATOR . "{$filterclass}.php")) {
        require_once $this->filterDir . DIRECTORY_SEPARATOR . "{$filterclass}.php";
        $imported = true;
      }
    }
    if (!$imported && file_exists(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'filters' . DIRECTORY_SEPARATOR . "{$filterclass}.php")) {
      require_once "filters/{$filterclass}.php";
      $imported = true;
    }
    if (!$imported) {
      throw new HamlException('Unable to find {what}: {filename}', array(
        '{what}' => $filter . ' filter',
        '{filename}' => $filterclass . '.php',
      ), $this);
    }
    $this->filters[$filter] = new $filterclass();
    if (!$this->filters[$filter] instanceof HamlBaseFilter) {
      throw new HamlException('{what} must extend {base} class', array(
        '{what}' => $filter,
        '{base}' => 'HamlBaseFilter',
      ), $this);
    }
    $this->filters[$filter]
      ->init();
  }
  return $this->filters[$filter];
}