public function compile() { $this->preCompile(); $importer = new Importer($this); $this->string = new StringObject($importer->collate()); // Capture phase 0 hook: Before all variables and settings have resolved. $this->hooks->run('capture_phase0', $this); $this->captureVars(); $this->placeAllVars(); $this->resolveIfDefines(); $this->resolveSettings(); // Capture phase 1 hook: After all variables and settings have resolved. $this->hooks->run('capture_phase1', $this); $this->resolveSelectorAliases(); $this->captureMixins(); $this->resolveFragments(); // Capture phase 2 hook: After most built-in directives have resolved. $this->hooks->run('capture_phase2', $this); $this->captureRules(); $this->resolveInBlocks(); // Calling functions on media query lists. $process = $this; $this->string->pregReplaceCallback('~@media\\s+(?<media_list>[^{]+)\\{~i', function ($m) use(&$process) { return "@media {$process->functions->apply($m['media_list'])}{"; }); $this->aliasAtRules(); $this->processRules(); $this->collate(); $this->postCompile(); return $this->string; }