Skip to content

Commit

Permalink
Merge branch 'MDL-70301' of https://github.com/Chocolate-lightning/mo…
Browse files Browse the repository at this point in the history
  • Loading branch information
junpataleta committed Jan 21, 2021
2 parents dc77f45 + 6d25306 commit a61fbcd
Show file tree
Hide file tree
Showing 32 changed files with 4,705 additions and 1,626 deletions.
3 changes: 2 additions & 1 deletion lib/scssphp/Base/Range.php
@@ -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
5 changes: 3 additions & 2 deletions lib/scssphp/Block.php
@@ -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 Expand Up @@ -49,7 +50,7 @@ class Block
public $sourceColumn;

/**
* @var array
* @var array|null
*/
public $selectors;

Expand Down
21 changes: 12 additions & 9 deletions lib/scssphp/Cache.php
@@ -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 @@ -12,6 +13,7 @@
namespace ScssPhp\ScssPhp;

use Exception;
use ScssPhp\ScssPhp\Version;

/**
* The scss cache manager.
Expand All @@ -22,13 +24,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 <cedric@yterium.com>
*/
class Cache
{
Expand Down Expand Up @@ -97,18 +98,20 @@ public function getCache($operation, $what, $options = [], $lastModified = null)
{
$fileCache = self::$cacheDir . self::cacheName($operation, $what, $options);

if (((self::$forceRefresh === false) || (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 +135,7 @@ public function setCache($operation, $what, $value, $options = [])

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

file_put_contents($fileCache, $c);

if (self::$forceRefresh === 'once') {
Expand All @@ -153,6 +157,7 @@ private static function cacheName($operation, $what, $options = [])
{
$t = [
'version' => self::CACHE_VERSION,
'scssphpVersion' => Version::VERSION,
'operation' => $operation,
'what' => $what,
'options' => $options
Expand All @@ -177,9 +182,7 @@ public static function checkCacheDir()
self::$cacheDir = rtrim(self::$cacheDir, '/') . '/';

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

if (! is_writable(self::$cacheDir)) {
Expand Down
37 changes: 18 additions & 19 deletions lib/scssphp/Colors.php
@@ -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 @@ -28,6 +29,7 @@ class Colors
protected static $cssColors = [
'aliceblue' => '240,248,255',
'antiquewhite' => '250,235,215',
'cyan' => '0,255,255',
'aqua' => '0,255,255',
'aquamarine' => '127,255,212',
'azure' => '240,255,255',
Expand All @@ -46,13 +48,12 @@ class Colors
'cornflowerblue' => '100,149,237',
'cornsilk' => '255,248,220',
'crimson' => '220,20,60',
'cyan' => '0,255,255',
'darkblue' => '0,0,139',
'darkcyan' => '0,139,139',
'darkgoldenrod' => '184,134,11',
'darkgray' => '169,169,169',
'darkgreen' => '0,100,0',
'darkgrey' => '169,169,169',
'darkgreen' => '0,100,0',
'darkkhaki' => '189,183,107',
'darkmagenta' => '139,0,139',
'darkolivegreen' => '85,107,47',
Expand All @@ -74,15 +75,16 @@ class Colors
'firebrick' => '178,34,34',
'floralwhite' => '255,250,240',
'forestgreen' => '34,139,34',
'magenta' => '255,0,255',
'fuchsia' => '255,0,255',
'gainsboro' => '220,220,220',
'ghostwhite' => '248,248,255',
'gold' => '255,215,0',
'goldenrod' => '218,165,32',
'gray' => '128,128,128',
'grey' => '128,128,128',
'green' => '0,128,0',
'greenyellow' => '173,255,47',
'grey' => '128,128,128',
'honeydew' => '240,255,240',
'hotpink' => '255,105,180',
'indianred' => '205,92,92',
Expand All @@ -98,8 +100,8 @@ class Colors
'lightcyan' => '224,255,255',
'lightgoldenrodyellow' => '250,250,210',
'lightgray' => '211,211,211',
'lightgreen' => '144,238,144',
'lightgrey' => '211,211,211',
'lightgreen' => '144,238,144',
'lightpink' => '255,182,193',
'lightsalmon' => '255,160,122',
'lightseagreen' => '32,178,170',
Expand All @@ -111,7 +113,6 @@ class Colors
'lime' => '0,255,0',
'limegreen' => '50,205,50',
'linen' => '250,240,230',
'magenta' => '255,0,255',
'maroon' => '128,0,0',
'mediumaquamarine' => '102,205,170',
'mediumblue' => '0,0,205',
Expand Down Expand Up @@ -145,7 +146,6 @@ class Colors
'plum' => '221,160,221',
'powderblue' => '176,224,230',
'purple' => '128,0,128',
'rebeccapurple' => '102,51,153',
'red' => '255,0,0',
'rosybrown' => '188,143,143',
'royalblue' => '65,105,225',
Expand All @@ -167,14 +167,15 @@ class Colors
'teal' => '0,128,128',
'thistle' => '216,191,216',
'tomato' => '255,99,71',
'transparent' => '0,0,0,0',
'turquoise' => '64,224,208',
'violet' => '238,130,238',
'wheat' => '245,222,179',
'white' => '255,255,255',
'whitesmoke' => '245,245,245',
'yellow' => '255,255,0',
'yellowgreen' => '154,205,50',
'rebeccapurple' => '102,51,153',
'transparent' => '0,0,0,0',
];

/**
Expand All @@ -186,7 +187,7 @@ class Colors
*/
public static function colorNameToRGBa($colorName)
{
if (is_string($colorName) && isset(static::$cssColors[$colorName])) {
if (\is_string($colorName) && isset(static::$cssColors[$colorName])) {
$rgba = explode(',', static::$cssColors[$colorName]);

// only case with opacity is transparent, with opacity=0, so we can intval on opacity also
Expand Down Expand Up @@ -217,28 +218,26 @@ public static function RGBaToColorName($r, $g, $b, $a = 1)
}

if ($a < 1) {
# specific case we dont' revert according to spec
#if (! $a && ! $r && ! $g && ! $b) {
# return 'transparent';
#}

return null;
}

if (is_null($reverseColorTable)) {
if (\is_null($reverseColorTable)) {
$reverseColorTable = [];

foreach (static::$cssColors as $name => $rgb_str) {
$rgb_str = explode(',', $rgb_str);

if (count($rgb_str) == 3) {
$reverseColorTable[intval($rgb_str[0])][intval($rgb_str[1])][intval($rgb_str[2])] = $name;
if (
\count($rgb_str) == 3 &&
! isset($reverseColorTable[\intval($rgb_str[0])][\intval($rgb_str[1])][\intval($rgb_str[2])])
) {
$reverseColorTable[\intval($rgb_str[0])][\intval($rgb_str[1])][\intval($rgb_str[2])] = $name;
}
}
}

if (isset($reverseColorTable[intval($r)][intval($g)][intval($b)])) {
return $reverseColorTable[intval($r)][intval($g)][intval($b)];
if (isset($reverseColorTable[\intval($r)][\intval($g)][\intval($b)])) {
return $reverseColorTable[\intval($r)][\intval($g)][\intval($b)];
}

return null;
Expand Down

0 comments on commit a61fbcd

Please sign in to comment.