N°2982 - Speed up SCSS themes compilation during setup : create a php file dedicated to CompileCSSService/FindStylesheetObject

This commit is contained in:
odain
2021-02-15 17:23:58 +01:00
parent c36d650d61
commit e2940150c3
4 changed files with 156 additions and 2 deletions

View File

@@ -0,0 +1,38 @@
<?php
/**
* Copyright (C) 2013-2020 Combodo SARL
*
* This file is part of iTop.
*
* iTop is free software; you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* iTop is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
*/
/**
* Class CompileCSSService : used to ease testing ThemeHander class via mocks
*
* @author Olivier DAIN <olivier.dain@combodo.com>
* @since 3.0.0 N°2982
*/
class CompileCSSService
{
/**
* CompileCSSService constructor.
*/
public function __construct()
{
}
public function CompileCSSFromSASS($sSassContent, $aImportPaths = [], $aVariables = []){
return utils::CompileCSSFromSASS($sSassContent, $aImportPaths, $aVariables);
}
}

View File

@@ -0,0 +1,114 @@
<?php
/**
* Copyright (C) 2013-2020 Combodo SARL
*
* This file is part of iTop.
*
* iTop is free software; you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* iTop is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
*/
/**
* Class FindStylesheetObject: dedicated class to store computations made in method ThemeHandler::FindStylesheetFile.
* @author Olivier DAIN <olivier.dain@combodo.com>
* @since 3.0.0 N°3588
*/
class FindStylesheetObject{
//file URIs
private $aStylesheetFileURIs;
//fill paths
private $aStylesheetImportPaths;
private $aAllStylesheetFilePaths;
private $sLastStyleSheetPath;
private $iLastModified;
/**
* FindStylesheetObject constructor.
*/
public function __construct()
{
$this->aStylesheetFileURIs = [];
$this->aStylesheetImportPaths = [];
$this->aAllStylesheetFilePaths = [];
$this->sLastStyleSheetPath = "";
$this->iLastModified = 0;
}
public function GetLastStylesheetFile(): string
{
return $this->sLastStyleSheetPath;
}
public function GetImportPaths(): array
{
return $this->aStylesheetImportPaths;
}
/**
* @return array : main stylesheets URIs
*/
public function GetStylesheetFileURIs(): array
{
return $this->aStylesheetFileURIs;
}
public function GetLastModified() : int
{
return $this->iLastModified;
}
/**
* @return array : main stylesheets paths + included files paths
*/
public function GetAllStylesheetPaths(): array
{
return $this->aAllStylesheetFilePaths;
}
/**
* @return string : last found stylesheet URI
*/
public function GetLastStyleSheetPath(): string
{
return $this->sLastStyleSheetPath;
}
public function AddStylesheet(string $sStylesheetFileURI, string $sStylesheetFilePath): void
{
$this->aStylesheetFileURIs[] = $sStylesheetFileURI;
$this->aAllStylesheetFilePaths[] = $sStylesheetFilePath;
$this->sLastStyleSheetPath = $sStylesheetFilePath;
}
public function AlreadyFetched(string $sStylesheetFilePath) : bool {
return in_array($sStylesheetFilePath, $this->aAllStylesheetFilePaths);
}
public function AddImport(string $sStylesheetFileURI, string $sStylesheetFilePath): void
{
$this->aStylesheetImportPaths[$sStylesheetFileURI] = $sStylesheetFilePath;
$this->aAllStylesheetFilePaths[] = $sStylesheetFilePath;
}
public function UpdateLastModified(string $sStylesheetFile): void
{
$this->iLastModified = max($this->iLastModified, @filemtime($sStylesheetFile));
}
public function ResetLastStyleSheet(): void
{
$this->sLastStyleSheetPath = "";
}
}

View File

@@ -335,7 +335,7 @@ return array(
'Combodo\\iTop\\Renderer\\FormRenderer' => $baseDir . '/sources/Renderer/FormRenderer.php',
'Combodo\\iTop\\Renderer\\RenderingOutput' => $baseDir . '/sources/Renderer/RenderingOutput.php',
'Combodo\\iTop\\TwigExtension' => $baseDir . '/application/twigextension.class.inc.php',
'CompileCSSService' => $baseDir . '/application/themehandler.class.inc.php',
'CompileCSSService' => $baseDir . '/application/compilecssservice.class.inc.php',
'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php',
'Config' => $baseDir . '/core/config.class.inc.php',
'ConfigException' => $baseDir . '/application/exceptions/ConfigException.php',
@@ -443,6 +443,7 @@ return array(
'FilterDefinition' => $baseDir . '/core/filterdef.class.inc.php',
'FilterFromAttribute' => $baseDir . '/core/filterdef.class.inc.php',
'FilterPrivateKey' => $baseDir . '/core/filterdef.class.inc.php',
'FindStylesheetObject' => $baseDir . '/application/findstylesheetobject.class.inc.php',
'FunctionExpression' => $baseDir . '/core/oql/expression.class.inc.php',
'FunctionOqlExpression' => $baseDir . '/core/oql/oqlquery.class.inc.php',
'GraphEdge' => $baseDir . '/core/simplegraph.class.inc.php',

View File

@@ -565,7 +565,7 @@ class ComposerStaticInit0018331147de7601e7552f7da8e3bb8b
'Combodo\\iTop\\Renderer\\FormRenderer' => __DIR__ . '/../..' . '/sources/Renderer/FormRenderer.php',
'Combodo\\iTop\\Renderer\\RenderingOutput' => __DIR__ . '/../..' . '/sources/Renderer/RenderingOutput.php',
'Combodo\\iTop\\TwigExtension' => __DIR__ . '/../..' . '/application/twigextension.class.inc.php',
'CompileCSSService' => __DIR__ . '/../..' . '/application/themehandler.class.inc.php',
'CompileCSSService' => __DIR__ . '/../..' . '/application/compilecssservice.class.inc.php',
'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php',
'Config' => __DIR__ . '/../..' . '/core/config.class.inc.php',
'ConfigException' => __DIR__ . '/../..' . '/application/exceptions/ConfigException.php',
@@ -673,6 +673,7 @@ class ComposerStaticInit0018331147de7601e7552f7da8e3bb8b
'FilterDefinition' => __DIR__ . '/../..' . '/core/filterdef.class.inc.php',
'FilterFromAttribute' => __DIR__ . '/../..' . '/core/filterdef.class.inc.php',
'FilterPrivateKey' => __DIR__ . '/../..' . '/core/filterdef.class.inc.php',
'FindStylesheetObject' => __DIR__ . '/../..' . '/application/findstylesheetobject.class.inc.php',
'FunctionExpression' => __DIR__ . '/../..' . '/core/oql/expression.class.inc.php',
'FunctionOqlExpression' => __DIR__ . '/../..' . '/core/oql/oqlquery.class.inc.php',
'GraphEdge' => __DIR__ . '/../..' . '/core/simplegraph.class.inc.php',