You are here

public function SassParser::__construct in Sassy 7

Same name and namespace in other branches
  1. 7.3 phpsass/SassParser.php \SassParser::__construct()

* Constructor. * Sets parser options *

Parameters

array $options: * @return SassParser

File

phamlp/sass/SassParser.php, line 288

Class

SassParser
SassParser class. Parses {@link http://sass-lang.com/ .sass and .sccs} files. @package PHamlP @subpackage Sass

Code

public function __construct($options = array()) {
  if (!is_array($options)) {
    throw new SassException('{what} must be a {type}', array(
      '{what}' => 'options',
      '{type}' => 'array',
    ));
  }
  if (!empty($options['language'])) {
    Phamlp::$language = $options['language'];
  }
  if (!empty($options['extensions'])) {
    foreach ($options['extensions'] as $extension => $extOptions) {
      include_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR . $extension . DIRECTORY_SEPARATOR . 'config.php';
      $configClass = 'SassExtentions' . $extension . 'Config';
      $config = new $configClass();
      $config
        ->config($extOptions);
      $lp = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR . $extension . DIRECTORY_SEPARATOR . 'frameworks';
      $fp = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR . $extension . DIRECTORY_SEPARATOR . 'functions';
      $options['load_paths'] = empty($options['load_paths']) ? array(
        $lp,
      ) : array_merge($options['load_paths'], $lp);
      $options['function_paths'] = empty($options['function_paths']) ? array(
        $fp,
      ) : array_merge($options['function_paths'], $fp);
    }
  }
  if (!empty($options['vendor_properties'])) {
    if ($options['vendor_properties'] === true) {
      $this->vendor_properties = $this->_vendorProperties;
    }
    elseif (is_array($options['vendor_properties'])) {
      $this->vendor_properties = array_merge($this->_vendorProperties, $options['vendor_properties']);
    }
  }
  unset($options['language'], $options['vendor_properties']);
  $defaultOptions = array(
    'cache' => self::CACHE,
    'cache_location' => dirname(__FILE__) . DIRECTORY_SEPARATOR . self::CACHE_LOCATION,
    'css_location' => dirname(__FILE__) . DIRECTORY_SEPARATOR . self::CSS_LOCATION,
    'debug_info' => false,
    'filename' => array(
      'dirname' => '',
      'basename' => '',
    ),
    'function_paths' => array(),
    'load_paths' => array(
      dirname(__FILE__) . DIRECTORY_SEPARATOR . self::TEMPLATE_LOCATION,
    ),
    'line' => 1,
    'line_numbers' => false,
    'style' => SassRenderer::STYLE_NESTED,
    'syntax' => SassFile::SASS,
  );
  foreach (array_merge($defaultOptions, $options) as $name => $value) {
    if (property_exists($this, $name)) {
      $this->{$name} = $value;
    }
  }
}