public function __construct($user_options = array(), $context = array()) { $config = Crush::$config; Crush::loadAssets(); // Initialize properties. $this->cacheData = array(); $this->mixins = array(); $this->fragments = array(); $this->references = array(); $this->absoluteImports = array(); $this->charset = null; $this->sources = array(); $this->vars = array(); $this->plugins = array(); $this->settings = array(); $this->misc = new \stdClass(); $this->input = new \stdClass(); $this->output = new \stdClass(); $this->tokens = new Tokens(); $this->functions = new Functions(); $this->hooks = new Hooks(); $this->sourceMap = null; $this->selectorAliases = array(); $this->selectorAliasesPatt = null; $this->io = new Crush::$config->io($this); $this->errors = array(); $this->warnings = array(); $this->debugLog = array(); $this->stat = array(); // Copy config values. $this->aliases = $config->aliases; // Options. $this->options = new Options($user_options, $config->options); // Context options. $context += array('type' => 'filter', 'data' => ''); $this->ioContext = $context['type']; // Keep track of global vars to maintain cache integrity. $this->options->global_vars = $config->vars; // Shortcut commonly used options to avoid __get() overhead. $this->docRoot = isset($this->options->doc_root) ? $this->options->doc_root : $config->docRoot; $this->generateMap = $this->ioContext === 'file' && $this->options->__get('source_map'); $this->ruleFormatter = $this->options->__get('formatter'); $this->minifyOutput = $this->options->__get('minify'); $this->newline = $this->options->__get('newlines'); if ($context['type'] === 'file') { $file = $context['data']; $this->input->raw = $file; if (!($inputFile = Util::resolveUserPath($file, null, $this->docRoot))) { throw new \Exception('Input file \'' . basename($file) . '\' not found.'); } $this->resolveContext(dirname($inputFile), $inputFile); } elseif ($context['type'] === 'filter') { if (!empty($this->options->context)) { $this->resolveContext($this->options->context); } else { $this->resolveContext(); } $this->input->string = $context['data']; } }