Example #1
0
 protected function getBoilerplate()
 {
     $file = false;
     $boilerplateOption = $this->options->boilerplate;
     if ($boilerplateOption === true) {
         $file = Crush::$dir . '/boilerplate.txt';
     } elseif (is_string($boilerplateOption)) {
         if (file_exists($boilerplateOption)) {
             $file = $boilerplateOption;
         }
     }
     // Return an empty string if no file is found.
     if (!$file) {
         return '';
     }
     $boilerplate = file_get_contents($file);
     // Substitute any tags
     if (preg_match_all('~\\{\\{([^}]+)\\}\\}~', $boilerplate, $boilerplateMatches)) {
         // Command line arguments (if any).
         $commandArgs = 'n/a';
         if (isset($_SERVER['argv'])) {
             $argv = $_SERVER['argv'];
             array_shift($argv);
             $commandArgs = 'csscrush ' . implode(' ', $argv);
         }
         $tags = array('datetime' => @date('Y-m-d H:i:s O'), 'year' => @date('Y'), 'command' => $commandArgs, 'plugins' => implode(',', $this->plugins), 'version' => csscrush_version(), 'git_version' => function () {
             return csscrush_version(true);
         }, 'compile_time' => function () {
             $now = microtime(true) - Crush::$process->stat['compile_start_time'];
             return round($now, 4) . ' seconds';
         });
         foreach (array_keys($boilerplateMatches[0]) as $index) {
             $tagName = trim($boilerplateMatches[1][$index]);
             $replacement = '?';
             if (isset($tags[$tagName])) {
                 $replacement = is_callable($tags[$tagName]) ? $tags[$tagName]() : $tags[$tagName];
             }
             $replacements[] = $replacement;
         }
         $boilerplate = str_replace($boilerplateMatches[0], $replacements, $boilerplate);
     }
     // Pretty print.
     $EOL = $this->newline;
     $boilerplate = preg_split('~[\\t]*' . Regex::$classes->newline . '[\\t]*~', trim($boilerplate));
     $boilerplate = array_map('trim', $boilerplate);
     $boilerplate = "{$EOL} * " . implode("{$EOL} * ", $boilerplate);
     return "/*{$boilerplate}{$EOL} */{$EOL}";
 }
Example #2
0
$version = PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION;
$requiredVersion = 5.3;
if ($version < $requiredVersion) {
    stderr(array("PHP version {$requiredVersion} or higher is required to use this tool.", "You are currently running PHP {$version}"));
    exit(STATUS_ERROR);
}
try {
    $args = parse_args();
} catch (Exception $ex) {
    stderr(message($ex->getMessage(), array('type' => 'error')));
    exit($ex->getCode());
}
##################################################################
##  Information options.
if ($args->version) {
    stdout((string) csscrush_version(true));
    exit(STATUS_OK);
} elseif ($args->help) {
    stdout(manpage());
    exit(STATUS_OK);
} elseif ($args->list) {
    foreach (CssCrush\Plugin::info() as $name => $docs) {
        $headline = isset($docs[0]) ? $docs[0] : '';
        stdout(message(array($name => $headline), array('color' => 'g')));
    }
    exit(STATUS_OK);
}
##################################################################
##  Resolve input.
$input = null;
if ($args->input_file) {