Skip to content

Commit

Permalink
Merge pull request #191 from ConnectThink/sb-scss-php-1.2.1
Browse files Browse the repository at this point in the history
Updating to version 1.2.1 of ScssPhp
  • Loading branch information
shadoath authored May 31, 2021
2 parents e1d4950 + ac1a6c9 commit 442144f
Show file tree
Hide file tree
Showing 31 changed files with 4,253 additions and 1,567 deletions.
49 changes: 21 additions & 28 deletions scssphp/bin/pscss
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#!/usr/bin/env php
<?php

/**
* SCSSPHP
*
* @copyright 2012-2019 Leaf Corcoran
* @copyright 2012-2020 Leaf Corcoran
*
* @license http://opensource.org/licenses/MIT MIT
*
Expand All @@ -24,13 +25,11 @@ use ScssPhp\ScssPhp\Version;

$style = null;
$loadPaths = null;
$precision = null;
$dumpTree = false;
$inputFile = null;
$changeDir = false;
$debugInfo = false;
$lineNumbers = false;
$ignoreErrors = false;
$encoding = false;
$sourceMap = false;

Expand Down Expand Up @@ -62,25 +61,25 @@ function parseArgument(&$i, $options) {
}

for ($i = 1; $i < $argc; $i++) {
if ($argv[$i] === '-h' || $argv[$i] === '--help') {
if ($argv[$i] === '-?' || $argv[$i] === '-h' || $argv[$i] === '--help') {
$exe = $argv[0];

$HELP = <<<EOT
Usage: $exe [options] [input-file]
Options include:
-h, --help Show this message
--continue-on-error Continue compilation (as best as possible) when error encountered
--debug-info Annotate selectors with CSS referring to the source file and line number
-f=format Set the output format (compact, compressed, crunched, expanded, or nested)
-i=path Set import path
--iso8859-1 Use iso8859-1 encoding instead of utf-8 (default utf-8)
--line-numbers Annotate selectors with comments referring to the source file and line number
-p=precision Set decimal number precision (default 10)
--help Show this message [-h, -?]
--continue-on-error [deprecated] Ignored
--debug-info Annotate selectors with CSS referring to the source file and line number [-g]
--dump-tree Dump formatted parse tree [-T]
--iso8859-1 Use iso8859-1 encoding instead of default utf-8
--line-numbers Annotate selectors with comments referring to the source file and line number [--line-comments]
--load-path=PATH Set import path [-I]
--precision=N [deprecated] Ignored. (default 10) [-p]
--sourcemap Create source map file
-T Dump formatted parse tree
-v, --version Print the version
--style=FORMAT Set the output format (compact, compressed, crunched, expanded, or nested) [-s, -t]
--version Print the version [-v]
EOT;
exit($HELP);
Expand All @@ -90,12 +89,13 @@ EOT;
exit(Version::VERSION . "\n");
}

// Keep parsing --continue-on-error to avoid BC breaks for scripts using it
if ($argv[$i] === '--continue-on-error') {
$ignoreErrors = true;
// TODO report it as a warning ?
continue;
}

if ($argv[$i] === '--debug-info') {
if ($argv[$i] === '-g' || $argv[$i] === '--debug-info') {
$debugInfo = true;
continue;
}
Expand All @@ -115,29 +115,30 @@ EOT;
continue;
}

if ($argv[$i] === '-T') {
if ($argv[$i] === '-T' || $argv[$i] === '--dump-tree') {
$dumpTree = true;
continue;
}

$value = parseArgument($i, array('-f', '--style'));
$value = parseArgument($i, array('-t', '-s', '--style'));

if (isset($value)) {
$style = $value;
continue;
}

$value = parseArgument($i, array('-i', '--load_paths'));
$value = parseArgument($i, array('-I', '--load-path'));

if (isset($value)) {
$loadPaths = $value;
continue;
}

// Keep parsing --precision to avoid BC breaks for scripts using it
$value = parseArgument($i, array('-p', '--precision'));

if (isset($value)) {
$precision = $value;
// TODO report it as a warning ?
continue;
}

Expand Down Expand Up @@ -184,18 +185,10 @@ if ($lineNumbers) {
$scss->setLineNumberStyle(Compiler::LINE_COMMENTS);
}

if ($ignoreErrors) {
$scss->setIgnoreErrors($ignoreErrors);
}

if ($loadPaths) {
$scss->setImportPaths(explode(PATH_SEPARATOR, $loadPaths));
}

if ($precision) {
$scss->setNumberPrecision($precision);
}

if ($style) {
$scss->setFormatter('ScssPhp\\ScssPhp\\Formatter\\' . ucfirst($style));
}
Expand Down
58 changes: 30 additions & 28 deletions scssphp/scss.inc.php
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,34 +1,36 @@
<?php

if (version_compare(PHP_VERSION, '5.6') < 0) {
throw new \Exception('scssphp requires PHP 5.6 or above');
throw new \Exception('scssphp requires PHP 5.6 or above');
}

if (! class_exists('ScssPhp\ScssPhp\Version', false)) {
include_once __DIR__ . '/src/Base/Range.php';
include_once __DIR__ . '/src/Block.php';
include_once __DIR__ . '/src/Cache.php';
include_once __DIR__ . '/src/Colors.php';
include_once __DIR__ . '/src/Compiler.php';
include_once __DIR__ . '/src/Compiler/Environment.php';
include_once __DIR__ . '/src/Exception/CompilerException.php';
include_once __DIR__ . '/src/Exception/ParserException.php';
include_once __DIR__ . '/src/Exception/RangeException.php';
include_once __DIR__ . '/src/Exception/ServerException.php';
include_once __DIR__ . '/src/Formatter.php';
include_once __DIR__ . '/src/Formatter/Compact.php';
include_once __DIR__ . '/src/Formatter/Compressed.php';
include_once __DIR__ . '/src/Formatter/Crunched.php';
include_once __DIR__ . '/src/Formatter/Debug.php';
include_once __DIR__ . '/src/Formatter/Expanded.php';
include_once __DIR__ . '/src/Formatter/Nested.php';
include_once __DIR__ . '/src/Formatter/OutputBlock.php';
include_once __DIR__ . '/src/Node.php';
include_once __DIR__ . '/src/Node/Number.php';
include_once __DIR__ . '/src/Parser.php';
include_once __DIR__ . '/src/SourceMap/Base64.php';
include_once __DIR__ . '/src/SourceMap/Base64VLQ.php';
include_once __DIR__ . '/src/SourceMap/SourceMapGenerator.php';
include_once __DIR__ . '/src/Type.php';
include_once __DIR__ . '/src/Util.php';
include_once __DIR__ . '/src/Version.php';
include_once __DIR__ . '/src/Base/Range.php';
include_once __DIR__ . '/src/Block.php';
include_once __DIR__ . '/src/Cache.php';
include_once __DIR__ . '/src/Colors.php';
include_once __DIR__ . '/src/Compiler.php';
include_once __DIR__ . '/src/Compiler/Environment.php';
include_once __DIR__ . '/src/Exception/SassException.php';
include_once __DIR__ . '/src/Exception/CompilerException.php';
include_once __DIR__ . '/src/Exception/ParserException.php';
include_once __DIR__ . '/src/Exception/RangeException.php';
include_once __DIR__ . '/src/Exception/ServerException.php';
include_once __DIR__ . '/src/Formatter.php';
include_once __DIR__ . '/src/Formatter/Compact.php';
include_once __DIR__ . '/src/Formatter/Compressed.php';
include_once __DIR__ . '/src/Formatter/Crunched.php';
include_once __DIR__ . '/src/Formatter/Debug.php';
include_once __DIR__ . '/src/Formatter/Expanded.php';
include_once __DIR__ . '/src/Formatter/Nested.php';
include_once __DIR__ . '/src/Formatter/OutputBlock.php';
include_once __DIR__ . '/src/Node.php';
include_once __DIR__ . '/src/Node/Number.php';
include_once __DIR__ . '/src/Parser.php';
include_once __DIR__ . '/src/SourceMap/Base64.php';
include_once __DIR__ . '/src/SourceMap/Base64VLQ.php';
include_once __DIR__ . '/src/SourceMap/SourceMapGenerator.php';
include_once __DIR__ . '/src/Type.php';
include_once __DIR__ . '/src/Util.php';
include_once __DIR__ . '/src/Version.php';
}
3 changes: 2 additions & 1 deletion scssphp/src/Base/Range.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php

/**
* SCSSPHP
*
* @copyright 2015-2019 Leaf Corcoran
* @copyright 2015-2020 Leaf Corcoran
*
* @license http://opensource.org/licenses/MIT MIT
*
Expand Down
3 changes: 2 additions & 1 deletion scssphp/src/Block.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php

/**
* SCSSPHP
*
* @copyright 2012-2019 Leaf Corcoran
* @copyright 2012-2020 Leaf Corcoran
*
* @license http://opensource.org/licenses/MIT MIT
*
Expand Down
33 changes: 17 additions & 16 deletions scssphp/src/Cache.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php

/**
* SCSSPHP
*
* @copyright 2012-2019 Leaf Corcoran
* @copyright 2012-2020 Leaf Corcoran
*
* @license http://opensource.org/licenses/MIT MIT
*
Expand All @@ -22,13 +23,12 @@
* taking in account options that affects the result
*
* The cache manager is agnostic about data format and only the operation is expected to be described by string
*
*/

/**
* SCSS cache
*
* @author Cedric Morin
* @author Cedric Morin <[email protected]>
*/
class Cache
{
Expand Down Expand Up @@ -57,12 +57,12 @@ class Cache
public function __construct($options)
{
// check $cacheDir
if (isset($options['cache_dir'])) {
self::$cacheDir = $options['cache_dir'];
if (isset($options['cacheDir'])) {
self::$cacheDir = $options['cacheDir'];
}

if (empty(self::$cacheDir)) {
throw new Exception('cache_dir not set');
throw new Exception('cacheDir not set');
}

if (isset($options['prefix'])) {
Expand All @@ -74,7 +74,7 @@ public function __construct($options)
}

if (isset($options['forceRefresh'])) {
self::$forceRefresh = $options['force_refresh'];
self::$forceRefresh = $options['forceRefresh'];
}

self::checkCacheDir();
Expand All @@ -97,18 +97,20 @@ public function getCache($operation, $what, $options = [], $lastModified = null)
{
$fileCache = self::$cacheDir . self::cacheName($operation, $what, $options);

if ((! self::$forceRefresh || (self::$forceRefresh === 'once' &&
if (
((self::$forceRefresh === false) || (self::$forceRefresh === 'once' &&
isset(self::$refreshed[$fileCache]))) && file_exists($fileCache)
) {
$cacheTime = filemtime($fileCache);

if ((is_null($lastModified) || $cacheTime > $lastModified) &&
if (
(\is_null($lastModified) || $cacheTime > $lastModified) &&
$cacheTime + self::$gcLifetime > time()
) {
$c = file_get_contents($fileCache);
$c = unserialize($c);

if (is_array($c) && isset($c['value'])) {
if (\is_array($c) && isset($c['value'])) {
return $c['value'];
}
}
Expand All @@ -132,6 +134,7 @@ public function setCache($operation, $what, $value, $options = [])

$c = ['value' => $value];
$c = serialize($c);

file_put_contents($fileCache, $c);

if (self::$forceRefresh === 'once') {
Expand Down Expand Up @@ -176,13 +179,11 @@ public static function checkCacheDir()
self::$cacheDir = str_replace('\\', '/', self::$cacheDir);
self::$cacheDir = rtrim(self::$cacheDir, '/') . '/';

if (! file_exists(self::$cacheDir)) {
if (! mkdir(self::$cacheDir)) {
throw new Exception('Cache directory couldn\'t be created: ' . self::$cacheDir);
}
} elseif (! is_dir(self::$cacheDir)) {
if (! is_dir(self::$cacheDir)) {
throw new Exception('Cache directory doesn\'t exist: ' . self::$cacheDir);
} elseif (! is_writable(self::$cacheDir)) {
}

if (! is_writable(self::$cacheDir)) {
throw new Exception('Cache directory isn\'t writable: ' . self::$cacheDir);
}
}
Expand Down
Loading

0 comments on commit 442144f

Please sign in to comment.