Skip to content

Fix issue where scssphp/Server ALWAYS sets default timezone to UTC #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 24 additions & 12 deletions src/Server.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

/**
* SCSSPHP
*
Expand Down Expand Up @@ -166,11 +165,11 @@ protected function needsCompile($out, &$etag)
/**
* Get If-Modified-Since header from client request
*
* @return string
* @return string|null
*/
protected function getIfModifiedSinceHeader()
{
$modifiedSince = '';
$modifiedSince = null;

if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
$modifiedSince = $_SERVER['HTTP_IF_MODIFIED_SINCE'];
Expand All @@ -186,11 +185,11 @@ protected function getIfModifiedSinceHeader()
/**
* Get If-None-Match header from client request
*
* @return string
* @return string|null
*/
protected function getIfNoneMatchHeader()
{
$noneMatch = '';
$noneMatch = null;

if (isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
$noneMatch = $_SERVER['HTTP_IF_NONE_MATCH'];
Expand All @@ -213,7 +212,6 @@ protected function compile($in, $out)
$result = $this->scss->compileString(file_get_contents($in), $in);

$css = $result->getCss();

$elapsed = round((microtime(true) - $start), 4);

$v = Version::VERSION;
Expand All @@ -234,7 +232,6 @@ protected function compile($in, $out)
return [$css, $etag];
}


/**
* Adds to list of parsed files
*
Expand All @@ -257,7 +254,6 @@ protected function makeParsedFilesFromIncludeFiles($paths)
return $parsedFiles;
}


/**
* Format error as a pseudo-element in CSS
*
Expand Down Expand Up @@ -321,7 +317,11 @@ public function compileFile($in, $out = null)
$compiled = $result->getCss();

if (is_null($out)) {
return array('compiled' => $compiled, 'files' => $this->makeParsedFilesFromIncludeFiles(array_merge([$in], $result->getIncludedFiles())),);
return array(
'compiled' => $compiled,
'files' => $this->makeParsedFilesFromIncludeFiles(array_merge([$in], $result->getIncludedFiles())),
'map' => $result->getSourceMap()
);
}

return file_put_contents($out, $compiled);
Expand All @@ -334,6 +334,8 @@ public function compileFile($in, $out = null)
* @param string $out Output file (.css)
*
* @return bool
*
* @throws \ScssPhp\Server\ServerException
*/
public function checkedCompile($in, $out)
{
Expand Down Expand Up @@ -431,7 +433,7 @@ public function serve($salt = '')
*
* @return string Compiled CSS results
*
* @throws \ScssPhp\ScssPhp\Exception\ServerException
* @throws \ScssPhp\Server\ServerException
*/
public function checkedCachedCompile($in, $out, $force = false)
{
Expand Down Expand Up @@ -472,6 +474,8 @@ public function checkedCachedCompile($in, $out, $force = false)
* @param boolean $force Force rebuild?
*
* @return array scssphp cache structure
*
* @throws \ScssPhp\Server\ServerException
*/
public function cachedCompile($in, $force = false)
{
Expand All @@ -495,10 +499,14 @@ public function cachedCompile($in, $force = false)
break;
}
}
// if (!file_exists($in['root']) or filemtime($in['root']) > $in['updated']) {
// // The main file has changed so we should compile.
// $root = $in['root'];
// }
}
} else {
// TODO: Throw an exception? We got neither a string nor something
// that looks like a compatible lessphp cache structure.
// that looks like a compatible scssphp cache structure.
return null;
}

Expand All @@ -522,6 +530,8 @@ public function cachedCompile($in, $force = false)
* @param string $dir Root directory to .scss files
* @param string $cacheDir Cache directory
* @param \ScssPhp\ScssPhp\Compiler|null $scss SCSS compiler instance
*
* @throws \ScssPhp\Server\ServerException
*/
public function __construct($dir, $cacheDir = null, $scss = null)
{
Expand All @@ -545,6 +555,8 @@ public function __construct($dir, $cacheDir = null, $scss = null)
$this->scss = $scss;
$this->showErrorsAsCSS = false;

date_default_timezone_set('UTC');
if (!ini_get('date.timezone') && function_exists('date_default_timezone_set')) { // PHP >= 5.1.0
date_default_timezone_set('UTC');
}
}
}