From 242963b8781017c4fe05be896d5b3185bbdd18f6 Mon Sep 17 00:00:00 2001 From: gtbu <60353863+g7sim@users.noreply.github.com> Date: Mon, 24 Apr 2023 17:13:37 +0200 Subject: [PATCH] Less update 3.21 Update because of deprecations with php 8.2. 4.1 as reserve --- .../less.php/{____4.0.0/bin => }/API.md | 0 include/thirdparty/less.php/Autoloader.php | 38 +- .../less.php/{____4.0.0/bin => }/CHANGES.md | 9 - .../{____4.0.0/bin => }/CODE_OF_CONDUCT.md | 0 include/thirdparty/less.php/Cache.php | 97 +- include/thirdparty/less.php/Colors.php | 319 +++--- include/thirdparty/less.php/Configurable.php | 12 +- include/thirdparty/less.php/Environment.php | 58 +- .../thirdparty/less.php/Exception/Chunk.php | 36 +- .../less.php/Exception/Compiler.php | 3 - .../thirdparty/less.php/Exception/Parser.php | 43 +- include/thirdparty/less.php/Functions.php | 212 ++-- .../less.php/{____4.0.0/bin => }/LICENSE | 0 include/thirdparty/less.php/Mime.php | 37 +- .../less.php/{____4.0.0/bin => }/NOTICE.txt | 0 include/thirdparty/less.php/Output.php | 14 +- include/thirdparty/less.php/Output/Mapped.php | 18 +- include/thirdparty/less.php/Parser.php | 1018 +++++++++-------- .../less.php/{____4.0.0/bin => }/README.md | 0 .../less.php/{____4.0.0/bin => }/SECURITY.md | 0 .../less.php/SourceMap/Base64VLQ.php | 38 +- .../less.php/SourceMap/Generator.php | 48 +- include/thirdparty/less.php/Tree.php | 23 +- include/thirdparty/less.php/Tree/Alpha.php | 6 +- .../thirdparty/less.php/Tree/Anonymous.php | 12 +- .../thirdparty/less.php/Tree/Assignment.php | 6 +- .../thirdparty/less.php/Tree/Attribute.php | 6 +- include/thirdparty/less.php/Tree/Call.php | 45 +- include/thirdparty/less.php/Tree/Color.php | 58 +- include/thirdparty/less.php/Tree/Comment.php | 12 +- .../thirdparty/less.php/Tree/Condition.php | 22 +- .../thirdparty/less.php/Tree/DefaultFunc.php | 6 +- .../less.php/Tree/DetachedRuleset.php | 6 +- .../thirdparty/less.php/Tree/Dimension.php | 26 +- .../thirdparty/less.php/Tree/Directive.php | 8 +- include/thirdparty/less.php/Tree/Element.php | 41 +- .../thirdparty/less.php/Tree/Expression.php | 15 +- include/thirdparty/less.php/Tree/Extend.php | 24 +- include/thirdparty/less.php/Tree/Import.php | 66 +- .../thirdparty/less.php/Tree/Javascript.php | 12 +- include/thirdparty/less.php/Tree/Keyword.php | 10 +- include/thirdparty/less.php/Tree/Media.php | 62 +- .../thirdparty/less.php/Tree/Mixin/Call.php | 32 +- .../less.php/Tree/Mixin/Definition.php | 41 +- .../thirdparty/less.php/Tree/NameValue.php | 14 +- include/thirdparty/less.php/Tree/Negative.php | 8 +- .../thirdparty/less.php/Tree/Operation.php | 8 +- include/thirdparty/less.php/Tree/Paren.php | 10 +- include/thirdparty/less.php/Tree/Quoted.php | 8 +- include/thirdparty/less.php/Tree/Rule.php | 17 +- include/thirdparty/less.php/Tree/Ruleset.php | 355 ++++-- .../thirdparty/less.php/Tree/RulesetCall.php | 10 +- include/thirdparty/less.php/Tree/Selector.php | 34 +- .../less.php/Tree/UnicodeDescriptor.php | 10 +- include/thirdparty/less.php/Tree/Unit.php | 28 +- .../less.php/Tree/UnitConversions.php | 20 +- include/thirdparty/less.php/Tree/Url.php | 13 +- include/thirdparty/less.php/Tree/Value.php | 11 +- include/thirdparty/less.php/Tree/Variable.php | 17 +- include/thirdparty/less.php/Version.php | 5 +- include/thirdparty/less.php/Visitor.php | 18 +- .../less.php/Visitor/extendFinder.php | 18 +- .../less.php/Visitor/joinSelector.php | 39 +- .../less.php/Visitor/processExtends.php | 46 +- include/thirdparty/less.php/Visitor/toCSS.php | 53 +- .../thirdparty/less.php/VisitorReplacing.php | 12 +- .../____4.0.0/.easymin/ignore_prefixes | 2 - .../{ => ____4.1}/.easymin/ignore_prefixes | 0 include/thirdparty/less.php/____4.1/API.md | 197 ++++ .../{____4.0.0 => ____4.1}/Autoloader.php | 0 .../thirdparty/less.php/____4.1/CHANGES.md | 91 ++ .../less.php/____4.1/CODE_OF_CONDUCT.md | 1 + .../less.php/{____4.0.0 => ____4.1}/Cache.php | 0 .../{____4.0.0 => ____4.1}/Colors.php | 0 .../{____4.0.0 => ____4.1}/Configurable.php | 0 .../{____4.0.0 => ____4.1}/Environment.php | 2 +- .../Exception/Chunk.php | 0 .../Exception/Compiler.php | 0 .../Exception/Parser.php | 0 .../{____4.0.0 => ____4.1}/Functions.php | 0 include/thirdparty/less.php/____4.1/LICENSE | 202 ++++ .../{____4.0.0 => ____4.1}/Less.php.combine | 0 .../less.php/{____4.0.0 => ____4.1}/Mime.php | 0 .../thirdparty/less.php/____4.1/NOTICE.txt | 18 + .../{____4.0.0 => ____4.1}/Output.php | 0 .../{____4.0.0 => ____4.1}/Output/Mapped.php | 0 .../{____4.0.0 => ____4.1}/Parser.php | 29 +- include/thirdparty/less.php/____4.1/README.md | 77 ++ .../thirdparty/less.php/____4.1/SECURITY.md | 5 + .../SourceMap/Base64VLQ.php | 0 .../SourceMap/Generator.php | 0 .../less.php/{____4.0.0 => ____4.1}/Tree.php | 0 .../{____4.0.0 => ____4.1}/Tree/Alpha.php | 0 .../{____4.0.0 => ____4.1}/Tree/Anonymous.php | 0 .../Tree/Assignment.php | 0 .../{____4.0.0 => ____4.1}/Tree/Attribute.php | 0 .../{____4.0.0 => ____4.1}/Tree/Call.php | 0 .../{____4.0.0 => ____4.1}/Tree/Color.php | 0 .../{____4.0.0 => ____4.1}/Tree/Comment.php | 0 .../{____4.0.0 => ____4.1}/Tree/Condition.php | 0 .../Tree/DefaultFunc.php | 0 .../Tree/DetachedRuleset.php | 0 .../{____4.0.0 => ____4.1}/Tree/Dimension.php | 0 .../{____4.0.0 => ____4.1}/Tree/Directive.php | 52 +- .../{____4.0.0 => ____4.1}/Tree/Element.php | 0 .../Tree/Expression.php | 0 .../{____4.0.0 => ____4.1}/Tree/Extend.php | 0 .../{____4.0.0 => ____4.1}/Tree/Import.php | 29 +- .../Tree/Javascript.php | 0 .../{____4.0.0 => ____4.1}/Tree/Keyword.php | 0 .../{____4.0.0 => ____4.1}/Tree/Media.php | 0 .../Tree/Mixin/Call.php | 0 .../Tree/Mixin/Definition.php | 0 .../{____4.0.0 => ____4.1}/Tree/NameValue.php | 0 .../{____4.0.0 => ____4.1}/Tree/Negative.php | 0 .../{____4.0.0 => ____4.1}/Tree/Operation.php | 0 .../{____4.0.0 => ____4.1}/Tree/Paren.php | 0 .../{____4.0.0 => ____4.1}/Tree/Quoted.php | 0 .../{____4.0.0 => ____4.1}/Tree/Rule.php | 0 .../{____4.0.0 => ____4.1}/Tree/Ruleset.php | 0 .../Tree/RulesetCall.php | 0 .../{____4.0.0 => ____4.1}/Tree/Selector.php | 0 .../Tree/UnicodeDescriptor.php | 0 .../{____4.0.0 => ____4.1}/Tree/Unit.php | 0 .../Tree/UnitConversions.php | 0 .../{____4.0.0 => ____4.1}/Tree/Url.php | 0 .../{____4.0.0 => ____4.1}/Tree/Value.php | 0 .../{____4.0.0 => ____4.1}/Tree/Variable.php | 0 .../{____4.0.0 => ____4.1}/Version.php | 2 +- .../{____4.0.0 => ____4.1}/Visitor.php | 0 .../Visitor/extendFinder.php | 0 .../{____4.0.0 => ____4.1}/Visitor/import.php | 0 .../Visitor/joinSelector.php | 8 + .../Visitor/processExtends.php | 0 .../{____4.0.0 => ____4.1}/Visitor/toCSS.php | 0 .../VisitorReplacing.php | 0 .../less.php/{____4.0.0 => ____4.1}/bin/lessc | 0 .../{____4.0.0/bin => ____4.1}/lessc.inc.php | 0 include/thirdparty/less.php/bin/lessc | 191 ++++ include/thirdparty/less.php/lessc.inc.php | 274 +++++ include/tool/Output/Css.php | 2 +- 141 files changed, 2819 insertions(+), 1656 deletions(-) rename include/thirdparty/less.php/{____4.0.0/bin => }/API.md (100%) rename include/thirdparty/less.php/{____4.0.0/bin => }/CHANGES.md (84%) rename include/thirdparty/less.php/{____4.0.0/bin => }/CODE_OF_CONDUCT.md (100%) rename include/thirdparty/less.php/{____4.0.0/bin => }/LICENSE (100%) rename include/thirdparty/less.php/{____4.0.0/bin => }/NOTICE.txt (100%) rename include/thirdparty/less.php/{____4.0.0/bin => }/README.md (100%) rename include/thirdparty/less.php/{____4.0.0/bin => }/SECURITY.md (100%) delete mode 100644 include/thirdparty/less.php/____4.0.0/.easymin/ignore_prefixes rename include/thirdparty/less.php/{ => ____4.1}/.easymin/ignore_prefixes (100%) create mode 100644 include/thirdparty/less.php/____4.1/API.md rename include/thirdparty/less.php/{____4.0.0 => ____4.1}/Autoloader.php (100%) create mode 100644 include/thirdparty/less.php/____4.1/CHANGES.md create mode 100644 include/thirdparty/less.php/____4.1/CODE_OF_CONDUCT.md rename include/thirdparty/less.php/{____4.0.0 => ____4.1}/Cache.php (100%) rename include/thirdparty/less.php/{____4.0.0 => ____4.1}/Colors.php (100%) rename include/thirdparty/less.php/{____4.0.0 => ____4.1}/Configurable.php (100%) rename include/thirdparty/less.php/{____4.0.0 => ____4.1}/Environment.php (98%) rename include/thirdparty/less.php/{____4.0.0 => ____4.1}/Exception/Chunk.php (100%) rename include/thirdparty/less.php/{____4.0.0 => ____4.1}/Exception/Compiler.php (100%) rename include/thirdparty/less.php/{____4.0.0 => ____4.1}/Exception/Parser.php (100%) rename include/thirdparty/less.php/{____4.0.0 => ____4.1}/Functions.php (100%) create mode 100644 include/thirdparty/less.php/____4.1/LICENSE rename include/thirdparty/less.php/{____4.0.0 => ____4.1}/Less.php.combine (100%) rename include/thirdparty/less.php/{____4.0.0 => ____4.1}/Mime.php (100%) create mode 100644 include/thirdparty/less.php/____4.1/NOTICE.txt rename include/thirdparty/less.php/{____4.0.0 => ____4.1}/Output.php (100%) rename include/thirdparty/less.php/{____4.0.0 => ____4.1}/Output/Mapped.php (100%) rename include/thirdparty/less.php/{____4.0.0 => ____4.1}/Parser.php (98%) create mode 100644 include/thirdparty/less.php/____4.1/README.md create mode 100644 include/thirdparty/less.php/____4.1/SECURITY.md rename include/thirdparty/less.php/{____4.0.0 => ____4.1}/SourceMap/Base64VLQ.php (100%) rename include/thirdparty/less.php/{____4.0.0 => ____4.1}/SourceMap/Generator.php (100%) rename include/thirdparty/less.php/{____4.0.0 => ____4.1}/Tree.php (100%) rename include/thirdparty/less.php/{____4.0.0 => ____4.1}/Tree/Alpha.php (100%) rename include/thirdparty/less.php/{____4.0.0 => ____4.1}/Tree/Anonymous.php (100%) rename include/thirdparty/less.php/{____4.0.0 => ____4.1}/Tree/Assignment.php (100%) rename include/thirdparty/less.php/{____4.0.0 => ____4.1}/Tree/Attribute.php (100%) rename include/thirdparty/less.php/{____4.0.0 => ____4.1}/Tree/Call.php (100%) rename include/thirdparty/less.php/{____4.0.0 => ____4.1}/Tree/Color.php (100%) rename include/thirdparty/less.php/{____4.0.0 => ____4.1}/Tree/Comment.php (100%) rename include/thirdparty/less.php/{____4.0.0 => ____4.1}/Tree/Condition.php (100%) rename include/thirdparty/less.php/{____4.0.0 => ____4.1}/Tree/DefaultFunc.php (100%) rename include/thirdparty/less.php/{____4.0.0 => ____4.1}/Tree/DetachedRuleset.php (100%) rename include/thirdparty/less.php/{____4.0.0 => ____4.1}/Tree/Dimension.php (100%) rename include/thirdparty/less.php/{____4.0.0 => ____4.1}/Tree/Directive.php (51%) rename include/thirdparty/less.php/{____4.0.0 => ____4.1}/Tree/Element.php (100%) rename include/thirdparty/less.php/{____4.0.0 => ____4.1}/Tree/Expression.php (100%) rename include/thirdparty/less.php/{____4.0.0 => ____4.1}/Tree/Extend.php (100%) rename include/thirdparty/less.php/{____4.0.0 => ____4.1}/Tree/Import.php (93%) rename include/thirdparty/less.php/{____4.0.0 => ____4.1}/Tree/Javascript.php (100%) rename include/thirdparty/less.php/{____4.0.0 => ____4.1}/Tree/Keyword.php (100%) rename include/thirdparty/less.php/{____4.0.0 => ____4.1}/Tree/Media.php (100%) rename include/thirdparty/less.php/{____4.0.0 => ____4.1}/Tree/Mixin/Call.php (100%) rename include/thirdparty/less.php/{____4.0.0 => ____4.1}/Tree/Mixin/Definition.php (100%) rename include/thirdparty/less.php/{____4.0.0 => ____4.1}/Tree/NameValue.php (100%) rename include/thirdparty/less.php/{____4.0.0 => ____4.1}/Tree/Negative.php (100%) rename include/thirdparty/less.php/{____4.0.0 => ____4.1}/Tree/Operation.php (100%) rename include/thirdparty/less.php/{____4.0.0 => ____4.1}/Tree/Paren.php (100%) rename include/thirdparty/less.php/{____4.0.0 => ____4.1}/Tree/Quoted.php (100%) rename include/thirdparty/less.php/{____4.0.0 => ____4.1}/Tree/Rule.php (100%) rename include/thirdparty/less.php/{____4.0.0 => ____4.1}/Tree/Ruleset.php (100%) rename include/thirdparty/less.php/{____4.0.0 => ____4.1}/Tree/RulesetCall.php (100%) rename include/thirdparty/less.php/{____4.0.0 => ____4.1}/Tree/Selector.php (100%) rename include/thirdparty/less.php/{____4.0.0 => ____4.1}/Tree/UnicodeDescriptor.php (100%) rename include/thirdparty/less.php/{____4.0.0 => ____4.1}/Tree/Unit.php (100%) rename include/thirdparty/less.php/{____4.0.0 => ____4.1}/Tree/UnitConversions.php (100%) rename include/thirdparty/less.php/{____4.0.0 => ____4.1}/Tree/Url.php (100%) rename include/thirdparty/less.php/{____4.0.0 => ____4.1}/Tree/Value.php (100%) rename include/thirdparty/less.php/{____4.0.0 => ____4.1}/Tree/Variable.php (100%) rename include/thirdparty/less.php/{____4.0.0 => ____4.1}/Version.php (89%) rename include/thirdparty/less.php/{____4.0.0 => ____4.1}/Visitor.php (100%) rename include/thirdparty/less.php/{____4.0.0 => ____4.1}/Visitor/extendFinder.php (100%) rename include/thirdparty/less.php/{____4.0.0 => ____4.1}/Visitor/import.php (100%) rename include/thirdparty/less.php/{____4.0.0 => ____4.1}/Visitor/joinSelector.php (85%) rename include/thirdparty/less.php/{____4.0.0 => ____4.1}/Visitor/processExtends.php (100%) rename include/thirdparty/less.php/{____4.0.0 => ____4.1}/Visitor/toCSS.php (100%) rename include/thirdparty/less.php/{____4.0.0 => ____4.1}/VisitorReplacing.php (100%) rename include/thirdparty/less.php/{____4.0.0 => ____4.1}/bin/lessc (100%) rename include/thirdparty/less.php/{____4.0.0/bin => ____4.1}/lessc.inc.php (100%) create mode 100644 include/thirdparty/less.php/bin/lessc create mode 100644 include/thirdparty/less.php/lessc.inc.php diff --git a/include/thirdparty/less.php/____4.0.0/bin/API.md b/include/thirdparty/less.php/API.md similarity index 100% rename from include/thirdparty/less.php/____4.0.0/bin/API.md rename to include/thirdparty/less.php/API.md diff --git a/include/thirdparty/less.php/Autoloader.php b/include/thirdparty/less.php/Autoloader.php index 00116f7..a4f7a4a 100644 --- a/include/thirdparty/less.php/Autoloader.php +++ b/include/thirdparty/less.php/Autoloader.php @@ -2,28 +2,14 @@ /** * Autoloader - * - * @package Less - * @subpackage autoload */ class Less_Autoloader { - /** - * Registered flag - * - * @var boolean - */ + /** @var bool */ protected static $registered = false; /** - * Library directory - * - * @var string - */ - protected static $libDir; - - /** - * Register the autoloader in the spl autoloader + * Register the autoloader in the SPL autoloader * * @return void * @throws Exception If there was an error in registration @@ -33,9 +19,7 @@ class Less_Autoloader { return; } - self::$libDir = dirname( __FILE__ ); - - if ( false === spl_autoload_register( array( 'Less_Autoloader', 'loadClass' ) ) ) { + if ( !spl_autoload_register( [ 'Less_Autoloader', 'loadClass' ] ) ) { throw new Exception( 'Unable to register Less_Autoloader::loadClass as an autoloading method.' ); } @@ -43,17 +27,17 @@ class Less_Autoloader { } /** - * Unregisters the autoloader + * Unregister the autoloader * * @return void */ public static function unregister() { - spl_autoload_unregister( array( 'Less_Autoloader', 'loadClass' ) ); + spl_autoload_unregister( [ 'Less_Autoloader', 'loadClass' ] ); self::$registered = false; } /** - * Loads the class + * Load the class * * @param string $className The class to load */ @@ -64,14 +48,10 @@ class Less_Autoloader { } $className = substr( $className, 5 ); - $fileName = self::$libDir . DIRECTORY_SEPARATOR . str_replace( '_', DIRECTORY_SEPARATOR, $className ) . '.php'; + $fileName = __DIR__ . DIRECTORY_SEPARATOR . str_replace( '_', DIRECTORY_SEPARATOR, $className ) . '.php'; - if ( file_exists( $fileName ) ) { - require $fileName; - return true; - } else { - throw new Exception( 'file not loadable '.$fileName ); - } + require $fileName; + return true; } } diff --git a/include/thirdparty/less.php/____4.0.0/bin/CHANGES.md b/include/thirdparty/less.php/CHANGES.md similarity index 84% rename from include/thirdparty/less.php/____4.0.0/bin/CHANGES.md rename to include/thirdparty/less.php/CHANGES.md index f5670ae..3334aeb 100644 --- a/include/thirdparty/less.php/____4.0.0/bin/CHANGES.md +++ b/include/thirdparty/less.php/CHANGES.md @@ -1,14 +1,5 @@ # Changelog -## 4.0.0 - -* [All changes](https://gerrit.wikimedia.org/g/mediawiki/libs/less.php/+log/v4.0.0) -* Remove support for PHP 7.2 and 7.3. Raise requirement to PHP 7.4+. -* Remove support for `cache_method=php` and `cache_method=var_export`, only the faster and more secure `cache_method=serialize` is now available. The built-in cache remains disabled by default. -* Fix `url(#myid)` to be treated as absolute URL. [T331649](https://phabricator.wikimedia.org/T331688) -* Fix "Undefined property" PHP 8.1 warning when `calc()` is used with CSS `var()`. [T331688](https://phabricator.wikimedia.org/T331688) -* Less_Parser: Improve performance by removing MatchFuncs and NewObj overhead. (Timo Tijhof) - ## 3.2.1 * [All changes](https://gerrit.wikimedia.org/g/mediawiki/libs/less.php/+log/v3.2.1) diff --git a/include/thirdparty/less.php/____4.0.0/bin/CODE_OF_CONDUCT.md b/include/thirdparty/less.php/CODE_OF_CONDUCT.md similarity index 100% rename from include/thirdparty/less.php/____4.0.0/bin/CODE_OF_CONDUCT.md rename to include/thirdparty/less.php/CODE_OF_CONDUCT.md diff --git a/include/thirdparty/less.php/Cache.php b/include/thirdparty/less.php/Cache.php index 7b6df23..c8c4b44 100644 --- a/include/thirdparty/less.php/Cache.php +++ b/include/thirdparty/less.php/Cache.php @@ -1,27 +1,21 @@ '/' ); + $less_files += [ $vars_file => '/' ]; } // generate name for compiled css file $hash = md5( json_encode( $less_files ) ); - $list_file = Less_Cache::$cache_dir . Less_Cache::$prefix . $hash . '.list'; + $list_file = self::$cache_dir . self::$prefix . $hash . '.list'; // check cached content if ( !isset( $parser_options['use_cache'] ) || $parser_options['use_cache'] === true ) { @@ -129,19 +123,13 @@ class Less_Cache { * @param array $modify_vars Array of variables * @return string Name of the css file */ - public static function Regen( $less_files, $parser_options = array(), $modify_vars = array() ) { + public static function Regen( $less_files, $parser_options = [], $modify_vars = [] ) { $parser_options['use_cache'] = false; return self::Get( $less_files, $parser_options, $modify_vars ); } - public static function Cache( &$less_files, $parser_options = array() ) { - // get less.php if it exists - $file = dirname( __FILE__ ) . '/Less.php'; - if ( file_exists( $file ) && !class_exists( 'Less_Parser' ) ) { - require_once $file; - } - - $parser_options['cache_dir'] = Less_Cache::$cache_dir; + public static function Cache( &$less_files, $parser_options = [] ) { + $parser_options['cache_dir'] = self::$cache_dir; $parser = new Less_Parser( $parser_options ); // combine files @@ -172,54 +160,52 @@ class Less_Cache { return $parser_options['output']; } - return Less_Cache::$cache_dir.$parser_options['output']; + return self::$cache_dir . $parser_options['output']; } - return Less_Cache::$cache_dir.$compiled_name; + return self::$cache_dir . $compiled_name; } private static function CompiledName( $files, $extrahash ) { // save the file list - $temp = array( Less_Version::cache_version ); + $temp = [ Less_Version::cache_version ]; foreach ( $files as $file ) { - $temp[] = filemtime( $file )."\t".filesize( $file )."\t".$file; + $temp[] = filemtime( $file ) . "\t" . filesize( $file ) . "\t" . $file; } - return Less_Cache::$prefix.sha1( json_encode( $temp ).$extrahash ).'.css'; + return self::$prefix . sha1( json_encode( $temp ) . $extrahash ) . '.css'; } public static function SetCacheDir( $dir ) { - Less_Cache::$cache_dir = $dir; + self::$cache_dir = $dir; self::CheckCacheDir(); } public static function CheckCacheDir() { - Less_Cache::$cache_dir = str_replace( '\\', '/', Less_Cache::$cache_dir ); - Less_Cache::$cache_dir = rtrim( Less_Cache::$cache_dir, '/' ).'/'; + self::$cache_dir = str_replace( '\\', '/', self::$cache_dir ); + self::$cache_dir = rtrim( self::$cache_dir, '/' ) . '/'; - if ( !file_exists( Less_Cache::$cache_dir ) ) { - if ( !mkdir( Less_Cache::$cache_dir ) ) { - throw new Less_Exception_Parser( 'Less.php cache directory couldn\'t be created: '.Less_Cache::$cache_dir ); + if ( !file_exists( self::$cache_dir ) ) { + if ( !mkdir( self::$cache_dir ) ) { + throw new Less_Exception_Parser( 'Less.php cache directory couldn\'t be created: ' . self::$cache_dir ); } - } elseif ( !is_dir( Less_Cache::$cache_dir ) ) { - throw new Less_Exception_Parser( 'Less.php cache directory doesn\'t exist: '.Less_Cache::$cache_dir ); + } elseif ( !is_dir( self::$cache_dir ) ) { + throw new Less_Exception_Parser( 'Less.php cache directory doesn\'t exist: ' . self::$cache_dir ); - } elseif ( !is_writable( Less_Cache::$cache_dir ) ) { - throw new Less_Exception_Parser( 'Less.php cache directory isn\'t writable: '.Less_Cache::$cache_dir ); + } elseif ( !is_writable( self::$cache_dir ) ) { + throw new Less_Exception_Parser( 'Less.php cache directory isn\'t writable: ' . self::$cache_dir ); } - } /** * Delete unused less.php files - * */ public static function CleanCache() { static $clean = false; - if ( $clean || empty( Less_Cache::$cache_dir ) ) { + if ( $clean || empty( self::$cache_dir ) ) { return; } @@ -227,9 +213,9 @@ class Less_Cache { // only remove files with extensions created by less.php // css files removed based on the list files - $remove_types = array( 'lesscache' => 1,'list' => 1,'less' => 1,'map' => 1 ); + $remove_types = [ 'lesscache' => 1,'list' => 1,'less' => 1,'map' => 1 ]; - $files = scandir( Less_Cache::$cache_dir ); + $files = scandir( self::$cache_dir ); if ( !$files ) { return; } @@ -238,7 +224,7 @@ class Less_Cache { foreach ( $files as $file ) { // don't delete if the file wasn't created with less.php - if ( strpos( $file, Less_Cache::$prefix ) !== 0 ) { + if ( strpos( $file, self::$prefix ) !== 0 ) { continue; } @@ -249,7 +235,7 @@ class Less_Cache { continue; } - $full_path = Less_Cache::$cache_dir . $file; + $full_path = self::$cache_dir . $file; $mtime = filemtime( $full_path ); // don't delete if it's a relatively new file @@ -261,7 +247,7 @@ class Less_Cache { if ( $type === 'list' ) { self::ListFiles( $full_path, $list, $css_file_name ); if ( $css_file_name ) { - $css_file = Less_Cache::$cache_dir . $css_file_name; + $css_file = self::$cache_dir . $css_file_name; if ( file_exists( $css_file ) ) { unlink( $css_file ); } @@ -270,12 +256,10 @@ class Less_Cache { unlink( $full_path ); } - } /** * Get the list of less files and generated css file from a list file - * */ static function ListFiles( $list_file, &$list, &$css_file_name ) { $list = explode( "\n", file_get_contents( $list_file ) ); @@ -283,11 +267,10 @@ class Less_Cache { // pop the cached name that should match $compiled_name $css_file_name = array_pop( $list ); - if ( !preg_match( '/^' . Less_Cache::$prefix . '[a-f0-9]+\.css$/', $css_file_name ) ) { + if ( !preg_match( '/^' . self::$prefix . '[a-f0-9]+\.css$/', $css_file_name ) ) { $list[] = $css_file_name; $css_file_name = false; } - } } diff --git a/include/thirdparty/less.php/Colors.php b/include/thirdparty/less.php/Colors.php index 9be76cb..2f715c2 100644 --- a/include/thirdparty/less.php/Colors.php +++ b/include/thirdparty/less.php/Colors.php @@ -1,169 +1,176 @@ '#f0f8ff', - 'antiquewhite' => '#faebd7', - 'aqua' => '#00ffff', - 'aquamarine' => '#7fffd4', - 'azure' => '#f0ffff', - 'beige' => '#f5f5dc', - 'bisque' => '#ffe4c4', - 'black' => '#000000', - 'blanchedalmond' => '#ffebcd', - 'blue' => '#0000ff', - 'blueviolet' => '#8a2be2', - 'brown' => '#a52a2a', - 'burlywood' => '#deb887', - 'cadetblue' => '#5f9ea0', - 'chartreuse' => '#7fff00', - 'chocolate' => '#d2691e', - 'coral' => '#ff7f50', - 'cornflowerblue' => '#6495ed', - 'cornsilk' => '#fff8dc', - 'crimson' => '#dc143c', - 'cyan' => '#00ffff', - 'darkblue' => '#00008b', - 'darkcyan' => '#008b8b', - 'darkgoldenrod' => '#b8860b', - 'darkgray' => '#a9a9a9', - 'darkgrey' => '#a9a9a9', - 'darkgreen' => '#006400', - 'darkkhaki' => '#bdb76b', - 'darkmagenta' => '#8b008b', - 'darkolivegreen' => '#556b2f', - 'darkorange' => '#ff8c00', - 'darkorchid' => '#9932cc', - 'darkred' => '#8b0000', - 'darksalmon' => '#e9967a', - 'darkseagreen' => '#8fbc8f', - 'darkslateblue' => '#483d8b', - 'darkslategray' => '#2f4f4f', - 'darkslategrey' => '#2f4f4f', - 'darkturquoise' => '#00ced1', - 'darkviolet' => '#9400d3', - 'deeppink' => '#ff1493', - 'deepskyblue' => '#00bfff', - 'dimgray' => '#696969', - 'dimgrey' => '#696969', - 'dodgerblue' => '#1e90ff', - 'firebrick' => '#b22222', - 'floralwhite' => '#fffaf0', - 'forestgreen' => '#228b22', - 'fuchsia' => '#ff00ff', - 'gainsboro' => '#dcdcdc', - 'ghostwhite' => '#f8f8ff', - 'gold' => '#ffd700', - 'goldenrod' => '#daa520', - 'gray' => '#808080', - 'grey' => '#808080', - 'green' => '#008000', - 'greenyellow' => '#adff2f', - 'honeydew' => '#f0fff0', - 'hotpink' => '#ff69b4', - 'indianred' => '#cd5c5c', - 'indigo' => '#4b0082', - 'ivory' => '#fffff0', - 'khaki' => '#f0e68c', - 'lavender' => '#e6e6fa', - 'lavenderblush' => '#fff0f5', - 'lawngreen' => '#7cfc00', - 'lemonchiffon' => '#fffacd', - 'lightblue' => '#add8e6', - 'lightcoral' => '#f08080', - 'lightcyan' => '#e0ffff', - 'lightgoldenrodyellow' => '#fafad2', - 'lightgray' => '#d3d3d3', - 'lightgrey' => '#d3d3d3', - 'lightgreen' => '#90ee90', - 'lightpink' => '#ffb6c1', - 'lightsalmon' => '#ffa07a', - 'lightseagreen' => '#20b2aa', - 'lightskyblue' => '#87cefa', - 'lightslategray' => '#778899', - 'lightslategrey' => '#778899', - 'lightsteelblue' => '#b0c4de', - 'lightyellow' => '#ffffe0', - 'lime' => '#00ff00', - 'limegreen' => '#32cd32', - 'linen' => '#faf0e6', - 'magenta' => '#ff00ff', - 'maroon' => '#800000', - 'mediumaquamarine' => '#66cdaa', - 'mediumblue' => '#0000cd', - 'mediumorchid' => '#ba55d3', - 'mediumpurple' => '#9370d8', - 'mediumseagreen' => '#3cb371', - 'mediumslateblue' => '#7b68ee', - 'mediumspringgreen' => '#00fa9a', - 'mediumturquoise' => '#48d1cc', - 'mediumvioletred' => '#c71585', - 'midnightblue' => '#191970', - 'mintcream' => '#f5fffa', - 'mistyrose' => '#ffe4e1', - 'moccasin' => '#ffe4b5', - 'navajowhite' => '#ffdead', - 'navy' => '#000080', - 'oldlace' => '#fdf5e6', - 'olive' => '#808000', - 'olivedrab' => '#6b8e23', - 'orange' => '#ffa500', - 'orangered' => '#ff4500', - 'orchid' => '#da70d6', - 'palegoldenrod' => '#eee8aa', - 'palegreen' => '#98fb98', - 'paleturquoise' => '#afeeee', - 'palevioletred' => '#d87093', - 'papayawhip' => '#ffefd5', - 'peachpuff' => '#ffdab9', - 'peru' => '#cd853f', - 'pink' => '#ffc0cb', - 'plum' => '#dda0dd', - 'powderblue' => '#b0e0e6', - 'purple' => '#800080', - 'red' => '#ff0000', - 'rosybrown' => '#bc8f8f', - 'royalblue' => '#4169e1', - 'saddlebrown' => '#8b4513', - 'salmon' => '#fa8072', - 'sandybrown' => '#f4a460', - 'seagreen' => '#2e8b57', - 'seashell' => '#fff5ee', - 'sienna' => '#a0522d', - 'silver' => '#c0c0c0', - 'skyblue' => '#87ceeb', - 'slateblue' => '#6a5acd', - 'slategray' => '#708090', - 'slategrey' => '#708090', - 'snow' => '#fffafa', - 'springgreen' => '#00ff7f', - 'steelblue' => '#4682b4', - 'tan' => '#d2b48c', - 'teal' => '#008080', - 'thistle' => '#d8bfd8', - 'tomato' => '#ff6347', - 'turquoise' => '#40e0d0', - 'violet' => '#ee82ee', - 'wheat' => '#f5deb3', - 'white' => '#ffffff', - 'whitesmoke' => '#f5f5f5', - 'yellow' => '#ffff00', - 'yellowgreen' => '#9acd32' - ); + private const COLORS = [ + 'aliceblue' => '#f0f8ff', + 'antiquewhite' => '#faebd7', + 'aqua' => '#00ffff', + 'aquamarine' => '#7fffd4', + 'azure' => '#f0ffff', + 'beige' => '#f5f5dc', + 'bisque' => '#ffe4c4', + 'black' => '#000000', + 'blanchedalmond' => '#ffebcd', + 'blue' => '#0000ff', + 'blueviolet' => '#8a2be2', + 'brown' => '#a52a2a', + 'burlywood' => '#deb887', + 'cadetblue' => '#5f9ea0', + 'chartreuse' => '#7fff00', + 'chocolate' => '#d2691e', + 'coral' => '#ff7f50', + 'cornflowerblue' => '#6495ed', + 'cornsilk' => '#fff8dc', + 'crimson' => '#dc143c', + 'cyan' => '#00ffff', + 'darkblue' => '#00008b', + 'darkcyan' => '#008b8b', + 'darkgoldenrod' => '#b8860b', + 'darkgray' => '#a9a9a9', + 'darkgrey' => '#a9a9a9', + 'darkgreen' => '#006400', + 'darkkhaki' => '#bdb76b', + 'darkmagenta' => '#8b008b', + 'darkolivegreen' => '#556b2f', + 'darkorange' => '#ff8c00', + 'darkorchid' => '#9932cc', + 'darkred' => '#8b0000', + 'darksalmon' => '#e9967a', + 'darkseagreen' => '#8fbc8f', + 'darkslateblue' => '#483d8b', + 'darkslategray' => '#2f4f4f', + 'darkslategrey' => '#2f4f4f', + 'darkturquoise' => '#00ced1', + 'darkviolet' => '#9400d3', + 'deeppink' => '#ff1493', + 'deepskyblue' => '#00bfff', + 'dimgray' => '#696969', + 'dimgrey' => '#696969', + 'dodgerblue' => '#1e90ff', + 'firebrick' => '#b22222', + 'floralwhite' => '#fffaf0', + 'forestgreen' => '#228b22', + 'fuchsia' => '#ff00ff', + 'gainsboro' => '#dcdcdc', + 'ghostwhite' => '#f8f8ff', + 'gold' => '#ffd700', + 'goldenrod' => '#daa520', + 'gray' => '#808080', + 'grey' => '#808080', + 'green' => '#008000', + 'greenyellow' => '#adff2f', + 'honeydew' => '#f0fff0', + 'hotpink' => '#ff69b4', + 'indianred' => '#cd5c5c', + 'indigo' => '#4b0082', + 'ivory' => '#fffff0', + 'khaki' => '#f0e68c', + 'lavender' => '#e6e6fa', + 'lavenderblush' => '#fff0f5', + 'lawngreen' => '#7cfc00', + 'lemonchiffon' => '#fffacd', + 'lightblue' => '#add8e6', + 'lightcoral' => '#f08080', + 'lightcyan' => '#e0ffff', + 'lightgoldenrodyellow' => '#fafad2', + 'lightgray' => '#d3d3d3', + 'lightgrey' => '#d3d3d3', + 'lightgreen' => '#90ee90', + 'lightpink' => '#ffb6c1', + 'lightsalmon' => '#ffa07a', + 'lightseagreen' => '#20b2aa', + 'lightskyblue' => '#87cefa', + 'lightslategray' => '#778899', + 'lightslategrey' => '#778899', + 'lightsteelblue' => '#b0c4de', + 'lightyellow' => '#ffffe0', + 'lime' => '#00ff00', + 'limegreen' => '#32cd32', + 'linen' => '#faf0e6', + 'magenta' => '#ff00ff', + 'maroon' => '#800000', + 'mediumaquamarine' => '#66cdaa', + 'mediumblue' => '#0000cd', + 'mediumorchid' => '#ba55d3', + 'mediumpurple' => '#9370d8', + 'mediumseagreen' => '#3cb371', + 'mediumslateblue' => '#7b68ee', + 'mediumspringgreen' => '#00fa9a', + 'mediumturquoise' => '#48d1cc', + 'mediumvioletred' => '#c71585', + 'midnightblue' => '#191970', + 'mintcream' => '#f5fffa', + 'mistyrose' => '#ffe4e1', + 'moccasin' => '#ffe4b5', + 'navajowhite' => '#ffdead', + 'navy' => '#000080', + 'oldlace' => '#fdf5e6', + 'olive' => '#808000', + 'olivedrab' => '#6b8e23', + 'orange' => '#ffa500', + 'orangered' => '#ff4500', + 'orchid' => '#da70d6', + 'palegoldenrod' => '#eee8aa', + 'palegreen' => '#98fb98', + 'paleturquoise' => '#afeeee', + 'palevioletred' => '#d87093', + 'papayawhip' => '#ffefd5', + 'peachpuff' => '#ffdab9', + 'peru' => '#cd853f', + 'pink' => '#ffc0cb', + 'plum' => '#dda0dd', + 'powderblue' => '#b0e0e6', + 'purple' => '#800080', + 'red' => '#ff0000', + 'rosybrown' => '#bc8f8f', + 'royalblue' => '#4169e1', + 'saddlebrown' => '#8b4513', + 'salmon' => '#fa8072', + 'sandybrown' => '#f4a460', + 'seagreen' => '#2e8b57', + 'seashell' => '#fff5ee', + 'sienna' => '#a0522d', + 'silver' => '#c0c0c0', + 'skyblue' => '#87ceeb', + 'slateblue' => '#6a5acd', + 'slategray' => '#708090', + 'slategrey' => '#708090', + 'snow' => '#fffafa', + 'springgreen' => '#00ff7f', + 'steelblue' => '#4682b4', + 'tan' => '#d2b48c', + 'teal' => '#008080', + 'thistle' => '#d8bfd8', + 'tomato' => '#ff6347', + 'turquoise' => '#40e0d0', + 'violet' => '#ee82ee', + 'wheat' => '#f5deb3', + 'white' => '#ffffff', + 'whitesmoke' => '#f5f5f5', + 'yellow' => '#ffff00', + 'yellowgreen' => '#9acd32', + ]; - public static function hasOwnProperty( $color ) { - return isset( self::$colors[$color] ); + /** + * @param string $color + * @return bool + */ + public static function hasOwnProperty( string $color ): bool { + return isset( self::COLORS[$color] ); } - public static function color( $color ) { - return self::$colors[$color]; + /** + * @param string $color Should be an existing color name, + * checked via hasOwnProperty() + * @return string the corresponding hexadecimal representation + */ + public static function color( string $color ): string { + return self::COLORS[$color]; } } diff --git a/include/thirdparty/less.php/Configurable.php b/include/thirdparty/less.php/Configurable.php index 7f1348b..ec16d80 100644 --- a/include/thirdparty/less.php/Configurable.php +++ b/include/thirdparty/less.php/Configurable.php @@ -1,10 +1,6 @@ defaultOptions ); diff --git a/include/thirdparty/less.php/Environment.php b/include/thirdparty/less.php/Environment.php index 2555d03..bfc3825 100644 --- a/include/thirdparty/less.php/Environment.php +++ b/include/thirdparty/less.php/Environment.php @@ -1,39 +1,35 @@ ',', ': ' => ':', '' => '', @@ -70,11 +66,11 @@ class Less_Environment { '|' => '|', '^' => '^', '^^' => '^^' - ); + ]; } else { - Less_Environment::$_outputMap = array( + self::$_outputMap = [ ',' => ', ', ': ' => ': ', '' => '', @@ -86,19 +82,19 @@ class Less_Environment { '|' => '|', '^' => ' ^ ', '^^' => ' ^^ ' - ); + ]; } } - public function copyEvalEnv( $frames = array() ) { + public function copyEvalEnv( $frames = [] ) { $new_env = new Less_Environment(); $new_env->frames = $frames; return $new_env; } public static function isMathOn() { - return !Less_Parser::$options['strictMath'] || Less_Environment::$parensStack; + return !Less_Parser::$options['strictMath'] || self::$parensStack; } public static function isPathRelative( $path ) { @@ -108,15 +104,14 @@ class Less_Environment { /** * Canonicalize a path by resolving references to '/./', '/../' * Does not remove leading "../" - * @param string path or url + * @param string $path or url * @return string Canonicalized path - * */ public static function normalizePath( $path ) { $segments = explode( '/', $path ); $segments = array_reverse( $segments ); - $path = array(); + $path = []; $path_len = 0; while ( $segments ) { @@ -124,9 +119,10 @@ class Less_Environment { switch ( $segment ) { case '.': - break; + break; case '..': + // @phan-suppress-next-line PhanTypeInvalidDimOffset False positive if ( !$path_len || ( $path[$path_len - 1] === '..' ) ) { $path[] = $segment; $path_len++; @@ -134,12 +130,12 @@ class Less_Environment { array_pop( $path ); $path_len--; } - break; + break; default: $path[] = $segment; $path_len++; - break; + break; } } diff --git a/include/thirdparty/less.php/Exception/Chunk.php b/include/thirdparty/less.php/Exception/Chunk.php index 1f1dddb..8071eb8 100644 --- a/include/thirdparty/less.php/Exception/Chunk.php +++ b/include/thirdparty/less.php/Exception/Chunk.php @@ -1,10 +1,6 @@ message = 'ParseError: Unexpected input'; // default message @@ -40,7 +34,6 @@ class Less_Exception_Chunk extends Less_Exception_Parser { /** * See less.js chunks() * We don't actually need the chunks - * */ protected function Chunks() { $level = 0; @@ -95,7 +88,9 @@ class Less_Exception_Chunk extends Less_Exception_Parser { break; // \ case 92: - if ( $this->parserCurrentIndex < $this->input_len - 1 ) { $this->parserCurrentIndex++; break; + if ( $this->parserCurrentIndex < $this->input_len - 1 ) { + $this->parserCurrentIndex++; + break; } return $this->fail( "unescaped `\\`" ); @@ -105,11 +100,12 @@ class Less_Exception_Chunk extends Less_Exception_Parser { case 96: $matched = 0; $currentChunkStartIndex = $this->parserCurrentIndex; - for ( $this->parserCurrentIndex = $this->parserCurrentIndex + 1; $this->parserCurrentIndex < $this->input_len; $this->parserCurrentIndex++ ) { + for ( $this->parserCurrentIndex += 1; $this->parserCurrentIndex < $this->input_len; $this->parserCurrentIndex++ ) { $cc2 = $this->CharCode( $this->parserCurrentIndex ); if ( $cc2 > 96 ) { continue; } - if ( $cc2 == $cc ) { $matched = 1; break; + if ( $cc2 == $cc ) { $matched = 1; +break; } if ( $cc2 == 92 ) { // \ if ( $this->parserCurrentIndex == $this->input_len - 1 ) { @@ -129,15 +125,15 @@ class Less_Exception_Chunk extends Less_Exception_Parser { $cc2 = $this->CharCode( $this->parserCurrentIndex + 1 ); if ( $cc2 == 47 ) { // //, find lnfeed - for ( $this->parserCurrentIndex = $this->parserCurrentIndex + 2; $this->parserCurrentIndex < $this->input_len; $this->parserCurrentIndex++ ) { + for ( $this->parserCurrentIndex += 2; $this->parserCurrentIndex < $this->input_len; $this->parserCurrentIndex++ ) { $cc2 = $this->CharCode( $this->parserCurrentIndex ); if ( ( $cc2 <= 13 ) && ( ( $cc2 == 10 ) || ( $cc2 == 13 ) ) ) { break; } } - } else if ( $cc2 == 42 ) { + } elseif ( $cc2 == 42 ) { // /*, find */ $lastMultiComment = $currentChunkStartIndex = $this->parserCurrentIndex; - for ( $this->parserCurrentIndex = $this->parserCurrentIndex + 2; $this->parserCurrentIndex < $this->input_len - 1; $this->parserCurrentIndex++ ) { + for ( $this->parserCurrentIndex += 2; $this->parserCurrentIndex < $this->input_len - 1; $this->parserCurrentIndex++ ) { $cc2 = $this->CharCode( $this->parserCurrentIndex ); if ( $cc2 == 125 ) { $lastMultiCommentEndBrace = $this->parserCurrentIndex; } @@ -167,7 +163,7 @@ class Less_Exception_Chunk extends Less_Exception_Parser { } else { return $this->fail( "missing closing `}`", $lastOpening ); } - } else if ( $parenLevel !== 0 ) { + } elseif ( $parenLevel !== 0 ) { return $this->fail( "missing closing `)`", $lastParen ); } @@ -186,7 +182,7 @@ class Less_Exception_Chunk extends Less_Exception_Parser { } else { $this->index = $index; } - $this->message = 'ParseError: '.$msg; + $this->message = 'ParseError: ' . $msg; } /* diff --git a/include/thirdparty/less.php/Exception/Compiler.php b/include/thirdparty/less.php/Exception/Compiler.php index 1c3727a..e963b69 100644 --- a/include/thirdparty/less.php/Exception/Compiler.php +++ b/include/thirdparty/less.php/Exception/Compiler.php @@ -2,9 +2,6 @@ /** * Compiler Exception - * - * @package Less - * @subpackage exception */ class Less_Exception_Compiler extends Less_Exception_Parser { diff --git a/include/thirdparty/less.php/Exception/Parser.php b/include/thirdparty/less.php/Exception/Parser.php index 8bbf25f..22d9d19 100644 --- a/include/thirdparty/less.php/Exception/Parser.php +++ b/include/thirdparty/less.php/Exception/Parser.php @@ -2,46 +2,36 @@ /** * Parser Exception - * - * @package Less - * @subpackage exception */ class Less_Exception_Parser extends Exception { /** * The current file * - * @var Less_ImportedFile + * @var array */ public $currentFile; /** * The current parser index * - * @var integer + * @var int */ public $index; protected $input; - protected $details = array(); + protected $details = []; /** - * Constructor - * - * @param string $message - * @param Exception $previous Previous exception - * @param integer $index The current parser index - * @param Less_FileInfo|string $currentFile The file - * @param integer $code The exception code + * @param string|null $message + * @param Exception|null $previous Previous exception + * @param int|null $index The current parser index + * @param array|null $currentFile The file + * @param int $code The exception code */ public function __construct( $message = null, Exception $previous = null, $index = null, $currentFile = null, $code = 0 ) { - if ( PHP_VERSION_ID < 50300 ) { - $this->previous = $previous; - parent::__construct( $message, $code ); - } else { - parent::__construct( $message, $code, $previous ); - } + parent::__construct( $message, $code, $previous ); $this->currentFile = $currentFile; $this->index = $index; @@ -56,20 +46,18 @@ class Less_Exception_Parser extends Exception { } /** - * Converts the exception to string - * - * @return string + * Set a message based on the exception info */ public function genMessage() { if ( $this->currentFile && $this->currentFile['filename'] ) { - $this->message .= ' in '.basename( $this->currentFile['filename'] ); + $this->message .= ' in ' . basename( $this->currentFile['filename'] ); } if ( $this->index !== null ) { $this->getInput(); if ( $this->input ) { $line = self::getLineNumber(); - $this->message .= ' on line '.$line.', column '.self::getColumn(); + $this->message .= ' on line ' . $line . ', column ' . self::getColumn(); $lines = explode( "\n", $this->input ); @@ -78,17 +66,16 @@ class Less_Exception_Parser extends Exception { $last_line = min( $count, $start_line + 6 ); $num_len = strlen( $last_line ); for ( $i = $start_line; $i < $last_line; $i++ ) { - $this->message .= "\n".str_pad( $i + 1, $num_len, '0', STR_PAD_LEFT ).'| '.$lines[$i]; + $this->message .= "\n" . str_pad( (string)( $i + 1 ), $num_len, '0', STR_PAD_LEFT ) . '| ' . $lines[$i]; } } } - } /** * Returns the line number the error was encountered * - * @return integer + * @return int */ public function getLineNumber() { if ( $this->index ) { @@ -105,7 +92,7 @@ class Less_Exception_Parser extends Exception { /** * Returns the column the error was encountered * - * @return integer + * @return int */ public function getColumn() { $part = substr( $this->input, 0, $this->index ); diff --git a/include/thirdparty/less.php/Functions.php b/include/thirdparty/less.php/Functions.php index c9e97bd..43a964c 100644 --- a/include/thirdparty/less.php/Functions.php +++ b/include/thirdparty/less.php/Functions.php @@ -2,34 +2,33 @@ /** * Builtin functions - * - * @package Less - * @subpackage function - * @see http://lesscss.org/functions/ + * @see https://lesscss.org/functions/ */ class Less_Functions { public $env; public $currentFileInfo; - function __construct( $env, $currentFileInfo = null ) { + function __construct( $env, array $currentFileInfo = null ) { $this->env = $env; $this->currentFileInfo = $currentFileInfo; } /** * @param string $op + * @param float $a + * @param float $b */ public static function operate( $op, $a, $b ) { switch ( $op ) { case '+': -return $a + $b; + return $a + $b; case '-': -return $a - $b; + return $a - $b; case '*': -return $a * $b; + return $a * $b; case '/': -return $a / $b; + return $a / $b; } } @@ -52,7 +51,7 @@ return $a / $b; public static function number( $n ) { if ( $n instanceof Less_Tree_Dimension ) { return floatval( $n->unit->is( '%' ) ? $n->value / 100 : $n->value ); - } else if ( is_numeric( $n ) ) { + } elseif ( is_numeric( $n ) ) { return $n; } else { throw new Less_Exception_Compiler( "color functions take numbers as parameters" ); @@ -63,20 +62,20 @@ return $a / $b; if ( $n instanceof Less_Tree_Dimension && $n->unit->is( '%' ) ) { return (float)$n->value * $size / 100; } else { - return Less_Functions::number( $n ); + return self::number( $n ); } } public function rgb( $r = null, $g = null, $b = null ) { - if ( is_null( $r ) || is_null( $g ) || is_null( $b ) ) { + if ( $r === null || $g === null || $b === null ) { throw new Less_Exception_Compiler( "rgb expects three parameters" ); } return $this->rgba( $r, $g, $b, 1.0 ); } public function rgba( $r = null, $g = null, $b = null, $a = null ) { - $rgb = array( $r, $g, $b ); - $rgb = array_map( array( 'Less_Functions','scaled' ), $rgb ); + $rgb = [ $r, $g, $b ]; + $rgb = array_map( [ 'Less_Functions','scaled' ], $rgb ); $a = self::number( $a ); return new Less_Tree_Color( $rgb, $a ); @@ -96,18 +95,30 @@ return $a / $b; $m1 = $l * 2 - $m2; - return $this->rgba( self::hsla_hue( $h + 1 / 3, $m1, $m2 ) * 255, - self::hsla_hue( $h, $m1, $m2 ) * 255, - self::hsla_hue( $h - 1 / 3, $m1, $m2 ) * 255, - $a ); + return $this->rgba( + self::hsla_hue( $h + 1 / 3, $m1, $m2 ) * 255, + self::hsla_hue( $h, $m1, $m2 ) * 255, + self::hsla_hue( $h - 1 / 3, $m1, $m2 ) * 255, + $a + ); } /** - * @param double $h + * @param float $h + * @param float $m1 + * @param float $m2 */ public function hsla_hue( $h, $m1, $m2 ) { $h = $h < 0 ? $h + 1 : ( $h > 1 ? $h - 1 : $h ); - if ( $h * 6 < 1 ) return $m1 + ( $m2 - $m1 ) * $h * 6; else if ( $h * 2 < 1 ) return $m2; else if ( $h * 3 < 2 ) return $m1 + ( $m2 - $m1 ) * ( 2 / 3 - $h ) * 6; else return $m1; + if ( $h * 6 < 1 ) { + return $m1 + ( $m2 - $m1 ) * $h * 6; + } elseif ( $h * 2 < 1 ) { + return $m2; + } elseif ( $h * 3 < 2 ) { + return $m1 + ( $m2 - $m1 ) * ( 2 / 3 - $h ) * 6; + } else { + return $m1; + } } public function hsv( $h, $s, $v ) { @@ -115,33 +126,42 @@ return $a / $b; } /** - * @param double $a + * @param Less_Tree|float $h + * @param Less_Tree|float $s + * @param Less_Tree|float $v + * @param float $a */ public function hsva( $h, $s, $v, $a ) { - $h = ( ( Less_Functions::number( $h ) % 360 ) / 360 ) * 360; - $s = Less_Functions::number( $s ); - $v = Less_Functions::number( $v ); - $a = Less_Functions::number( $a ); + $h = ( ( self::number( $h ) % 360 ) / 360 ) * 360; + $s = self::number( $s ); + $v = self::number( $v ); + $a = self::number( $a ); - $i = floor( ( $h / 60 ) % 6 ); + $i = floor( (int)( $h / 60 ) % 6 ); $f = ( $h / 60 ) - $i; - $vs = array( $v, - $v * ( 1 - $s ), - $v * ( 1 - $f * $s ), - $v * ( 1 - ( 1 - $f ) * $s ) ); + $vs = [ + $v, + $v * ( 1 - $s ), + $v * ( 1 - $f * $s ), + $v * ( 1 - ( 1 - $f ) * $s ) + ]; - $perm = array( array( 0, 3, 1 ), - array( 2, 0, 1 ), - array( 1, 0, 3 ), - array( 1, 2, 0 ), - array( 3, 1, 0 ), - array( 0, 1, 2 ) ); + $perm = [ + [ 0, 3, 1 ], + [ 2, 0, 1 ], + [ 1, 0, 3 ], + [ 1, 2, 0 ], + [ 3, 1, 0 ], + [ 0, 1, 2 ] + ]; - return $this->rgba( $vs[$perm[$i][0]] * 255, - $vs[$perm[$i][1]] * 255, - $vs[$perm[$i][2]] * 255, - $a ); + return $this->rgba( + $vs[$perm[$i][0]] * 255, + $vs[$perm[$i][1]] * 255, + $vs[$perm[$i][2]] * 255, + $a + ); } public function hue( $color = null ) { @@ -275,7 +295,8 @@ return $a / $b; } /** - * @param Less_Tree_Dimension $amount + * @param Less_Tree_Color|null $color + * @param Less_Tree_Dimension|null $amount */ public function desaturate( $color = null, $amount = null ) { if ( !$color instanceof Less_Tree_Color ) { @@ -286,7 +307,6 @@ return $a / $b; } $hsl = $color->toHSL(); - $hsl['s'] -= $amount->value / 100; $hsl['s'] = self::clamp( $hsl['s'] ); @@ -385,11 +405,13 @@ return $a / $b; // // Copyright (c) 2006-2009 Hampton Catlin, Nathan Weizenbaum, and Chris Eppstein - // http://sass-lang.com + // https://sass-lang.com/ // /** - * @param Less_Tree_Color $color1 + * @param Less_Tree|null $color1 + * @param Less_Tree|null $color2 + * @param Less_Tree|null $weight */ public function mix( $color1 = null, $color2 = null, $weight = null ) { if ( !$color1 instanceof Less_Tree_Color ) { @@ -414,9 +436,11 @@ return $a / $b; $w1 = ( ( ( ( $w * $a ) == -1 ) ? $w : ( $w + $a ) / ( 1 + $w * $a ) ) + 1 ) / 2; $w2 = 1 - $w1; - $rgb = array( $color1->rgb[0] * $w1 + $color2->rgb[0] * $w2, - $color1->rgb[1] * $w1 + $color2->rgb[1] * $w2, - $color1->rgb[2] * $w1 + $color2->rgb[2] * $w2 ); + $rgb = [ + $color1->rgb[0] * $w1 + $color2->rgb[0] * $w2, + $color1->rgb[1] * $w1 + $color2->rgb[1] * $w2, + $color1->rgb[2] * $w1 + $color2->rgb[2] * $w2 + ]; $alpha = $color1->alpha * $p + $color2->alpha * ( 1 - $p ); @@ -456,7 +480,7 @@ return $a / $b; if ( !$threshold ) { $threshold = 0.43; } else { - $threshold = Less_Functions::number( $threshold ); + $threshold = self::number( $threshold ); } if ( $color->luma() < $threshold ) { @@ -474,7 +498,7 @@ return $a / $b; } public function escape( $str ) { - $revert = array( '%21' => '!', '%2A' => '*', '%27' => "'",'%3F' => '?','%26' => '&','%2C' => ',','%2F' => '/','%40' => '@','%2B' => '+','%24' => '$' ); + $revert = [ '%21' => '!', '%2A' => '*', '%27' => "'",'%3F' => '?','%26' => '&','%2C' => ',','%2F' => '/','%40' => '@','%2B' => '+','%24' => '$' ]; return new Less_Tree_Anonymous( strtr( rawurlencode( $str->value ), $revert ) ); } @@ -486,7 +510,7 @@ return $a / $b; public function replace( $string, $pattern, $replacement, $flags = null ) { $result = $string->value; - $expr = '/'.str_replace( '/', '\\/', $pattern->value ).'/'; + $expr = '/' . str_replace( '/', '\\/', $pattern->value ) . '/'; if ( $flags && $flags->value ) { $expr .= self::replace_flags( $flags->value ); } @@ -507,11 +531,11 @@ return $a / $b; switch ( $flag ) { case 'e': case 'g': - break; + break; default: $new_flags .= $flag; - break; + break; } } @@ -642,7 +666,7 @@ return $a / $b; } $args[0] = (float)$args[0]->value; return new Less_Tree_Dimension( call_user_func_array( $fn, $args ), $unit ); - } else if ( is_numeric( $args[0] ) ) { + } elseif ( is_numeric( $args[0] ) ) { return call_user_func_array( $fn, $args ); } else { throw new Less_Exception_Compiler( "math functions take numbers as parameters" ); @@ -650,7 +674,8 @@ return $a / $b; } /** - * @param boolean $isMin + * @param bool $isMin + * @param array $args */ private function _minmax( $isMin, $args ) { $arg_count = count( $args ); @@ -663,18 +688,24 @@ return $a / $b; $unitClone = null; $unitStatic = null; - $order = array(); // elems only contains original argument values. - $values = array(); // key is the unit.toString() for unified tree.Dimension values, - // value is the index into the order array. + // elems only contains original argument values. + $order = []; + // key is the unit.toString() for unified tree.Dimension values, + // value is the index into the order array. + $values = []; for ( $i = 0; $i < $arg_count; $i++ ) { $current = $args[$i]; if ( !( $current instanceof Less_Tree_Dimension ) ) { - if ( is_array( $args[$i]->value ) ) { + // @phan-suppress-next-line PhanUndeclaredProperty Checked Less_Tree->value + if ( property_exists( $args[$i], 'value' ) && is_array( $args[$i]->value ) ) { + // @phan-suppress-next-line PhanUndeclaredProperty Checked Less_Tree->value $args[] = $args[$i]->value; } continue; } + // PhanTypeInvalidDimOffset -- False positive, safe after continue or non-first iterations + '@phan-var non-empty-list $order'; if ( $current->unit->toString() === '' && !$unitClone ) { $temp = new Less_Tree_Dimension( $current->value, $unitClone ); @@ -725,11 +756,11 @@ return $a / $b; if ( count( $order ) == 1 ) { return $order[0]; } - $args = array(); + $args = []; foreach ( $order as $a ) { - $args[] = $a->toCSS( $this->env ); + $args[] = $a->toCSS(); } - return new Less_Tree_Anonymous( ( $isMin ? 'min(' : 'max(' ) . implode( Less_Environment::$_outputMap[','], $args ).')' ); + return new Less_Tree_Anonymous( ( $isMin ? 'min(' : 'max(' ) . implode( Less_Environment::$_outputMap[','], $args ) . ')' ); } public function min() { @@ -807,10 +838,12 @@ return $a / $b; } /** - * @param string $unit + * @param Less_Tree $n + * @param Less_Tree|string $unit */ public function isunit( $n, $unit ) { if ( is_object( $unit ) && property_exists( $unit, 'value' ) ) { + // @phan-suppress-next-line PhanUndeclaredProperty Checked Less_Tree->value $unit = $unit->value; } @@ -818,6 +851,7 @@ return $a / $b; } /** + * @param Less_Tree $n * @param string $type */ private function _isa( $n, $type ) { @@ -866,15 +900,16 @@ return $a / $b; $filePath = str_replace( '\\', '/', $filePath ); if ( Less_Environment::isPathRelative( $filePath ) ) { - + $currentFileInfo = $this->currentFileInfo; + '@phan-var array $currentFileInfo'; if ( Less_Parser::$options['relativeUrls'] ) { - $temp = $this->currentFileInfo['currentDirectory']; + $temp = $currentFileInfo['currentDirectory']; } else { - $temp = $this->currentFileInfo['entryPath']; + $temp = $currentFileInfo['entryPath']; } if ( !empty( $temp ) ) { - $filePath = Less_Environment::normalizePath( rtrim( $temp, '/' ).'/'.$filePath ); + $filePath = Less_Environment::normalizePath( rtrim( $temp, '/' ) . '/' . $filePath ); } } @@ -895,7 +930,7 @@ return $a / $b; $mimetype = Less_Mime::lookup( $filePath ); $charset = Less_Mime::charsets_lookup( $mimetype ); - $useBase64 = !in_array( $charset, array( 'US-ASCII', 'UTF-8' ) ); + $useBase64 = !in_array( $charset, [ 'US-ASCII', 'UTF-8' ] ); if ( $useBase64 ) { $mimetype .= ';base64'; } @@ -914,8 +949,8 @@ return $a / $b; $DATA_URI_MAX_KB = 32; $fileSizeInKB = round( strlen( $buf ) / 1024 ); if ( $fileSizeInKB >= $DATA_URI_MAX_KB ) { - $url = new Less_Tree_Url( ( $filePathNode ? $filePathNode : $mimetypeNode ), $this->currentFileInfo ); - return $url->compile( $this ); + $url = new Less_Tree_Url( ( $filePathNode ?: $mimetypeNode ), $this->currentFileInfo ); + return $url->compile( $this->env ); } if ( $buf ) { @@ -994,9 +1029,9 @@ return $a / $b; $returner .= ''; if ( $useBase64 ) { - $returner = "'data:image/svg+xml;base64,".base64_encode( $returner )."'"; + $returner = "'data:image/svg+xml;base64," . base64_encode( $returner ) . "'"; } else { - $returner = "'data:image/svg+xml,".$returner."'"; + $returner = "'data:image/svg+xml," . $returner . "'"; } return new Less_Tree_URL( new Less_Tree_Anonymous( $returner ) ); @@ -1009,17 +1044,18 @@ return $a / $b; * @return string The encoded string */ public static function encodeURIComponent( $string ) { - $revert = array( '%21' => '!', '%2A' => '*', '%27' => "'", '%28' => '(', '%29' => ')' ); + $revert = [ '%21' => '!', '%2A' => '*', '%27' => "'", '%28' => '(', '%29' => ')' ]; return strtr( rawurlencode( $string ), $revert ); } // Color Blending - // ref: http://www.w3.org/TR/compositing-1 - + // ref: https://www.w3.org/TR/compositing-1/ public function colorBlend( $mode, $color1, $color2 ) { - $ab = $color1->alpha; // backdrop - $as = $color2->alpha; // source - $r = array(); // result + // backdrop + $ab = $color1->alpha; + // source + $as = $color2->alpha; + $result = []; $ar = $as + $ab * ( 1 - $as ); for ( $i = 0; $i < 3; $i++ ) { @@ -1029,10 +1065,10 @@ return $a / $b; if ( $ar ) { $cr = ( $as * $cs + $ab * ( $cb - $as * ( $cb + $cs - $cr ) ) ) / $ar; } - $r[$i] = $cr * 255; + $result[$i] = $cr * 255; } - return new Less_Tree_Color( $r, $ar ); + return new Less_Tree_Color( $result, $ar ); } public function multiply( $color1 = null, $color2 = null ) { @@ -1043,7 +1079,7 @@ return $a / $b; throw new Less_Exception_Compiler( 'The second argument to multiply must be a color' . ( $color2 instanceof Less_Tree_Expression ? ' (did you forgot commas?)' : '' ) ); } - return $this->colorBlend( array( $this,'colorBlendMultiply' ), $color1, $color2 ); + return $this->colorBlend( [ $this,'colorBlendMultiply' ], $color1, $color2 ); } private function colorBlendMultiply( $cb, $cs ) { @@ -1058,7 +1094,7 @@ return $a / $b; throw new Less_Exception_Compiler( 'The second argument to screen must be a color' . ( $color2 instanceof Less_Tree_Expression ? ' (did you forgot commas?)' : '' ) ); } - return $this->colorBlend( array( $this,'colorBlendScreen' ), $color1, $color2 ); + return $this->colorBlend( [ $this,'colorBlendScreen' ], $color1, $color2 ); } private function colorBlendScreen( $cb, $cs ) { @@ -1073,7 +1109,7 @@ return $a / $b; throw new Less_Exception_Compiler( 'The second argument to overlay must be a color' . ( $color2 instanceof Less_Tree_Expression ? ' (did you forgot commas?)' : '' ) ); } - return $this->colorBlend( array( $this,'colorBlendOverlay' ), $color1, $color2 ); + return $this->colorBlend( [ $this,'colorBlendOverlay' ], $color1, $color2 ); } private function colorBlendOverlay( $cb, $cs ) { @@ -1091,7 +1127,7 @@ return $a / $b; throw new Less_Exception_Compiler( 'The second argument to softlight must be a color' . ( $color2 instanceof Less_Tree_Expression ? ' (did you forgot commas?)' : '' ) ); } - return $this->colorBlend( array( $this,'colorBlendSoftlight' ), $color1, $color2 ); + return $this->colorBlend( [ $this,'colorBlendSoftlight' ], $color1, $color2 ); } private function colorBlendSoftlight( $cb, $cs ) { @@ -1113,7 +1149,7 @@ return $a / $b; throw new Less_Exception_Compiler( 'The second argument to hardlight must be a color' . ( $color2 instanceof Less_Tree_Expression ? ' (did you forgot commas?)' : '' ) ); } - return $this->colorBlend( array( $this,'colorBlendHardlight' ), $color1, $color2 ); + return $this->colorBlend( [ $this,'colorBlendHardlight' ], $color1, $color2 ); } private function colorBlendHardlight( $cb, $cs ) { @@ -1128,7 +1164,7 @@ return $a / $b; throw new Less_Exception_Compiler( 'The second argument to difference must be a color' . ( $color2 instanceof Less_Tree_Expression ? ' (did you forgot commas?)' : '' ) ); } - return $this->colorBlend( array( $this,'colorBlendDifference' ), $color1, $color2 ); + return $this->colorBlend( [ $this,'colorBlendDifference' ], $color1, $color2 ); } private function colorBlendDifference( $cb, $cs ) { @@ -1143,7 +1179,7 @@ return $a / $b; throw new Less_Exception_Compiler( 'The second argument to exclusion must be a color' . ( $color2 instanceof Less_Tree_Expression ? ' (did you forgot commas?)' : '' ) ); } - return $this->colorBlend( array( $this,'colorBlendExclusion' ), $color1, $color2 ); + return $this->colorBlend( [ $this,'colorBlendExclusion' ], $color1, $color2 ); } private function colorBlendExclusion( $cb, $cs ) { @@ -1158,7 +1194,7 @@ return $a / $b; throw new Less_Exception_Compiler( 'The second argument to average must be a color' . ( $color2 instanceof Less_Tree_Expression ? ' (did you forgot commas?)' : '' ) ); } - return $this->colorBlend( array( $this,'colorBlendAverage' ), $color1, $color2 ); + return $this->colorBlend( [ $this,'colorBlendAverage' ], $color1, $color2 ); } // non-w3c functions: @@ -1174,7 +1210,7 @@ return $a / $b; throw new Less_Exception_Compiler( 'The second argument to negation must be a color' . ( $color2 instanceof Less_Tree_Expression ? ' (did you forgot commas?)' : '' ) ); } - return $this->colorBlend( array( $this,'colorBlendNegation' ), $color1, $color2 ); + return $this->colorBlend( [ $this,'colorBlendNegation' ], $color1, $color2 ); } public function colorBlendNegation( $cb, $cs ) { diff --git a/include/thirdparty/less.php/____4.0.0/bin/LICENSE b/include/thirdparty/less.php/LICENSE similarity index 100% rename from include/thirdparty/less.php/____4.0.0/bin/LICENSE rename to include/thirdparty/less.php/LICENSE diff --git a/include/thirdparty/less.php/Mime.php b/include/thirdparty/less.php/Mime.php index b4723f9..45a7bf3 100644 --- a/include/thirdparty/less.php/Mime.php +++ b/include/thirdparty/less.php/Mime.php @@ -1,37 +1,32 @@ 'text/html', - '.html' => 'text/html', - '.gif' => 'image/gif', - '.jpg' => 'image/jpeg', - '.jpeg' => 'image/jpeg', - '.png' => 'image/png', - '.ttf' => 'application/x-font-ttf', - '.otf' => 'application/x-font-otf', - '.eot' => 'application/vnd.ms-fontobject', - '.woff' => 'application/x-font-woff', - '.svg' => 'image/svg+xml', - ); + private static $types = [ + '.htm' => 'text/html', + '.html' => 'text/html', + '.gif' => 'image/gif', + '.jpg' => 'image/jpeg', + '.jpeg' => 'image/jpeg', + '.png' => 'image/png', + '.ttf' => 'application/x-font-ttf', + '.otf' => 'application/x-font-otf', + '.eot' => 'application/vnd.ms-fontobject', + '.woff' => 'application/x-font-woff', + '.svg' => 'image/svg+xml', + ]; public static function lookup( $filepath ) { $parts = explode( '.', $filepath ); - $ext = '.'.strtolower( array_pop( $parts ) ); + $ext = '.' . strtolower( array_pop( $parts ) ); - if ( !isset( self::$_types[$ext] ) ) { - return null; - } - return self::$_types[$ext]; + return self::$types[$ext] ?? null; } public static function charsets_lookup( $type = null ) { diff --git a/include/thirdparty/less.php/____4.0.0/bin/NOTICE.txt b/include/thirdparty/less.php/NOTICE.txt similarity index 100% rename from include/thirdparty/less.php/____4.0.0/bin/NOTICE.txt rename to include/thirdparty/less.php/NOTICE.txt diff --git a/include/thirdparty/less.php/Output.php b/include/thirdparty/less.php/Output.php index 8f7dd61..be6c160 100644 --- a/include/thirdparty/less.php/Output.php +++ b/include/thirdparty/less.php/Output.php @@ -1,26 +1,24 @@ strs ) === 0; diff --git a/include/thirdparty/less.php/Output/Mapped.php b/include/thirdparty/less.php/Output/Mapped.php index e486c98..ece5172 100644 --- a/include/thirdparty/less.php/Output/Mapped.php +++ b/include/thirdparty/less.php/Output/Mapped.php @@ -1,10 +1,8 @@ false, // option - whether to compress 'strictUnits' => false, // whether units need to evaluate correctly 'strictMath' => false, // whether math has to be within parenthesis @@ -22,7 +16,7 @@ class Less_Parser { 'urlArgs' => '', // whether to add args into url tokens 'numPrecision' => 8, - 'import_dirs' => array(), + 'import_dirs' => [], 'import_callback' => null, 'cache_dir' => null, 'cache_method' => 'php', // false, 'serialize', 'php', 'var_export', 'callback'; @@ -36,16 +30,17 @@ class Less_Parser { 'indentation' => ' ', - 'plugins' => array(), + 'plugins' => [], - ); + ]; - public static $options = array(); + /** @var array{compress:bool,strictUnits:bool,strictMath:bool,numPrecision:int,import_dirs:array,import_callback:null|callable,indentation:string} */ + public static $options = []; private $input; // Less input string private $input_len; // input string length private $pos; // current index in `input` - private $saveStack = array(); // holds state for backtracking + private $saveStack = []; // holds state for backtracking private $furthest; private $mb_internal_encoding = ''; // for remember exists value of mbstring.internal_encoding @@ -54,9 +49,9 @@ class Less_Parser { */ private $env; - protected $rules = array(); + protected $rules = []; - private static $imports = array(); + private static $imports = []; public static $has_extends = false; @@ -67,7 +62,7 @@ class Less_Parser { * * @var array */ - public static $contentsMap = array(); + public static $contentsMap = []; /** * @param Less_Environment|array|null $env @@ -78,7 +73,7 @@ class Less_Parser { if ( $env instanceof Less_Environment ) { $this->env = $env; } else { - $this->SetOptions( Less_Parser::$default_options ); + $this->SetOptions( self::$default_options ); $this->Reset( $env ); } @@ -89,25 +84,23 @@ class Less_Parser { $this->mb_internal_encoding = ini_get( 'mbstring.internal_encoding' ); @ini_set( 'mbstring.internal_encoding', 'ascii' ); } - } /** * Reset the parser state completely - * */ public function Reset( $options = null ) { - $this->rules = array(); - self::$imports = array(); + $this->rules = []; + self::$imports = []; self::$has_extends = false; - self::$imports = array(); - self::$contentsMap = array(); + self::$imports = []; + self::$contentsMap = []; - $this->env = new Less_Environment( $options ); + $this->env = new Less_Environment(); // set new options if ( is_array( $options ) ) { - $this->SetOptions( Less_Parser::$default_options ); + $this->SetOptions( self::$default_options ); $this->SetOptions( $options ); } @@ -117,7 +110,6 @@ class Less_Parser { /** * Set one or more compiler options * options: import_dirs, cache_dir, cache_method - * */ public function SetOptions( $options ) { foreach ( $options as $option => $value ) { @@ -127,24 +119,23 @@ class Less_Parser { /** * Set one compiler option - * */ public function SetOption( $option, $value ) { switch ( $option ) { case 'import_dirs': $this->SetImportDirs( $value ); - return; + return; case 'cache_dir': if ( is_string( $value ) ) { Less_Cache::SetCacheDir( $value ); Less_Cache::CheckCacheDir(); } - return; + return; } - Less_Parser::$options[$option] = $value; + self::$options[$option] = $value; } /** @@ -163,8 +154,9 @@ class Less_Parser { * @param string $name function name */ public function unregisterFunction( $name ) { - if ( isset( $this->env->functions[$name] ) ) + if ( isset( $this->env->functions[$name] ) ) { unset( $this->env->functions[$name] ); + } } /** @@ -174,13 +166,12 @@ class Less_Parser { */ public function getCss() { $precision = ini_get( 'precision' ); - @ini_set( 'precision', 16 ); + @ini_set( 'precision', '16' ); $locale = setlocale( LC_NUMERIC, 0 ); setlocale( LC_NUMERIC, "C" ); try { - - $root = new Less_Tree_Ruleset( array(), $this->rules ); + $root = new Less_Tree_Ruleset( null, $this->rules ); $root->root = true; $root->firstRoot = true; @@ -191,8 +182,8 @@ class Less_Parser { $this->PostVisitors( $evaldRoot ); - if ( Less_Parser::$options['sourceMap'] ) { - $generator = new Less_SourceMap_Generator( $evaldRoot, Less_Parser::$contentsMap, Less_Parser::$options ); + if ( self::$options['sourceMap'] ) { + $generator = new Less_SourceMap_Generator( $evaldRoot, self::$contentsMap, self::$options ); // will also save file // FIXME: should happen somewhere else? $css = $generator->generateCSS(); @@ -200,7 +191,7 @@ class Less_Parser { $css = $evaldRoot->toCSS(); } - if ( Less_Parser::$options['compress'] ) { + if ( self::$options['compress'] ) { $css = preg_replace( '/(^(\s)+)|((\s)+$)/', '', $css ); } @@ -237,21 +228,21 @@ class Less_Parser { } /** - * - * this function gets the private rules variable and returns an array of the found variables - * it uses a helper method getVariableValue() that contains the logic ot fetch the value from the rule object + * Gets the private rules variable and returns an array of the found variables + * it uses a helper method getVariableValue() that contains the logic ot fetch the value + * from the rule object * * @return array */ public function getVariables() { - $variables = array(); + $variables = []; - $not_variable_type = array( + $not_variable_type = [ 'Comment', // this include less comments ( // ) and css comments (/* */) 'Import', // do not search variables in included files @import 'Ruleset', // selectors (.someclass, #someid, …) 'Operation', // - ); + ]; // @TODO run compilation if not runned yet foreach ( $this->rules as $key => $rule ) { @@ -283,85 +274,82 @@ class Less_Parser { } /** - * * This method gets the value of the less variable from the rules object. * Since the objects vary here we add the logic for extracting the css/less value. * - * @param $var - * - * @return bool|string + * @param Less_Tree $var + * @return string */ - private function getVariableValue( $var ) { - if ( !is_a( $var, 'Less_Tree' ) ) { - throw new Exception( 'var is not a Less_Tree object' ); - } - - switch ( $var->type ) { - case 'Color': + private function getVariableValue( Less_Tree $var ) { + switch ( get_class( $var ) ) { + case Less_Tree_Color::class: return $this->rgb2html( $var->rgb ); - case 'Unit': - return $var->value. $var->unit->numerator[0]; - case 'Variable': + case Less_Tree_Variable::class: return $this->findVarByName( $var->name ); - case 'Keyword': + case Less_Tree_Keyword::class: return $var->value; - case 'Rule': + case Less_Tree_Url::class: + // Based on Less_Tree_Url::genCSS() + // Recurse to serialize the Less_Tree_Quoted value + return 'url(' . $this->getVariableValue( $var->value ) . ')'; + case Less_Tree_Rule::class: return $this->getVariableValue( $var->value ); - case 'Value': + case Less_Tree_Value::class: $value = ''; foreach ( $var->value as $sub_value ) { - $value .= $this->getVariableValue( $sub_value ).' '; + $value .= $this->getVariableValue( $sub_value ) . ' '; } return $value; - case 'Quoted': - return $var->quote.$var->value.$var->quote; - case 'Dimension': + case Less_Tree_Quoted::class: + return $var->quote . $var->value . $var->quote; + case Less_Tree_Dimension::class: $value = $var->value; if ( $var->unit && $var->unit->numerator ) { $value .= $var->unit->numerator[0]; } return $value; - case 'Expression': - $value = ""; + case Less_Tree_Expression::class: + $value = ''; foreach ( $var->value as $item ) { - $value .= $this->getVariableValue( $item )." "; + $value .= $this->getVariableValue( $item ) . " "; } return $value; - case 'Operation': + case Less_Tree_Operation::class: throw new Exception( 'getVariables() require Less to be compiled. please use $parser->getCss() before calling getVariables()' ); - case 'Comment': - case 'Import': - case 'Ruleset': + case Less_Tree_Unit::class: + case Less_Tree_Comment::class: + case Less_Tree_Import::class: + case Less_Tree_Ruleset::class: default: - throw new Exception( "type missing in switch/case getVariableValue for ".$var->type ); + throw new Exception( "type missing in switch/case getVariableValue for " . $var->type ); } - return false; } private function rgb2html( $r, $g = -1, $b = -1 ) { - if ( is_array( $r ) && sizeof( $r ) == 3 ) + if ( is_array( $r ) && count( $r ) == 3 ) { list( $r, $g, $b ) = $r; + } - $r = intval( $r ); $g = intval( $g ); + $r = intval( $r ); +$g = intval( $g ); $b = intval( $b ); $r = dechex( $r < 0 ? 0 : ( $r > 255 ? 255 : $r ) ); $g = dechex( $g < 0 ? 0 : ( $g > 255 ? 255 : $g ) ); $b = dechex( $b < 0 ? 0 : ( $b > 255 ? 255 : $b ) ); - $color = ( strlen( $r ) < 2 ? '0' : '' ).$r; - $color .= ( strlen( $g ) < 2 ? '0' : '' ).$g; - $color .= ( strlen( $b ) < 2 ? '0' : '' ).$b; - return '#'.$color; + $color = ( strlen( $r ) < 2 ? '0' : '' ) . $r; + $color .= ( strlen( $g ) < 2 ? '0' : '' ) . $g; + $color .= ( strlen( $b ) < 2 ? '0' : '' ) . $b; + return '#' . $color; } /** * Run pre-compile visitors - * */ private function PreVisitors( $root ) { - if ( Less_Parser::$options['plugins'] ) { - foreach ( Less_Parser::$options['plugins'] as $plugin ) { + if ( self::$options['plugins'] ) { + foreach ( self::$options['plugins'] as $plugin ) { if ( !empty( $plugin->isPreEvalVisitor ) ) { $plugin->run( $root ); } @@ -371,18 +359,17 @@ class Less_Parser { /** * Run post-compile visitors - * */ private function PostVisitors( $evaldRoot ) { - $visitors = array(); + $visitors = []; $visitors[] = new Less_Visitor_joinSelector(); if ( self::$has_extends ) { $visitors[] = new Less_Visitor_processExtends(); } $visitors[] = new Less_Visitor_toCSS(); - if ( Less_Parser::$options['plugins'] ) { - foreach ( Less_Parser::$options['plugins'] as $plugin ) { + if ( self::$options['plugins'] ) { + foreach ( self::$options['plugins'] as $plugin ) { if ( property_exists( $plugin, 'isPreEvalVisitor' ) && $plugin->isPreEvalVisitor ) { continue; } @@ -398,20 +385,20 @@ class Less_Parser { for ( $i = 0; $i < count( $visitors ); $i++ ) { $visitors[$i]->run( $evaldRoot ); } - } /** - * Parse a Less string into css + * Parse a Less string * + * @throws Less_Exception_Parser If the compiler encounters invalid syntax * @param string $str The string to convert - * @param string $uri_root The url of the file - * @return Less_Tree_Ruleset|Less_Parser + * @param string|null $file_uri The url of the file + * @return Less_Parser */ public function parse( $str, $file_uri = null ) { if ( !$file_uri ) { $uri_root = ''; - $filename = 'anonymous-file-'.Less_Parser::$next_id++.'.less'; + $filename = 'anonymous-file-' . self::$next_id++ . '.less'; } else { $file_uri = self::WinPath( $file_uri ); $filename = $file_uri; @@ -435,7 +422,7 @@ class Less_Parser { /** * Parse a Less string from a given file * - * @throws Less_Exception_Parser + * @throws Less_Exception_Parser If the compiler encounters invalid syntax * @param string $filename The file to parse * @param string $uri_root The url of the file * @param bool $returnRoot Indicates whether the return value should be a css string a root node @@ -465,7 +452,7 @@ class Less_Parser { if ( $returnRoot ) { $rules = $this->GetRules( $filename ); - $return = new Less_Tree_Ruleset( array(), $rules ); + $return = new Less_Tree_Ruleset( null, $rules ); } else { $this->_parse( $filename ); $return = $this; @@ -484,7 +471,7 @@ class Less_Parser { * @return Less_Parser */ public function ModifyVars( $vars ) { - $this->input = Less_Parser::serializeVars( $vars ); + $this->input = self::serializeVars( $vars ); $this->_parse(); return $this; @@ -492,16 +479,17 @@ class Less_Parser { /** * @param string $filename + * @param string $uri_root */ public function SetFileInfo( $filename, $uri_root = '' ) { $filename = Less_Environment::normalizePath( $filename ); $dirname = preg_replace( '/[^\/\\\\]*$/', '', $filename ); if ( !empty( $uri_root ) ) { - $uri_root = rtrim( $uri_root, '/' ).'/'; + $uri_root = rtrim( $uri_root, '/' ) . '/'; } - $currentFileInfo = array(); + $currentFileInfo = []; // entry info if ( isset( $this->env->currentFileInfo ) ) { @@ -516,7 +504,7 @@ class Less_Parser { } $currentFileInfo['currentDirectory'] = $dirname; - $currentFileInfo['currentUri'] = $uri_root.basename( $filename ); + $currentFileInfo['currentUri'] = $uri_root . basename( $filename ); $currentFileInfo['filename'] = $filename; $currentFileInfo['uri_root'] = $uri_root; @@ -530,24 +518,23 @@ class Less_Parser { /** * @deprecated 1.5.1.2 - * */ public function SetCacheDir( $dir ) { if ( !file_exists( $dir ) ) { if ( mkdir( $dir ) ) { return true; } - throw new Less_Exception_Parser( 'Less.php cache directory couldn\'t be created: '.$dir ); + throw new Less_Exception_Parser( 'Less.php cache directory couldn\'t be created: ' . $dir ); } elseif ( !is_dir( $dir ) ) { - throw new Less_Exception_Parser( 'Less.php cache directory doesn\'t exist: '.$dir ); + throw new Less_Exception_Parser( 'Less.php cache directory doesn\'t exist: ' . $dir ); } elseif ( !is_writable( $dir ) ) { - throw new Less_Exception_Parser( 'Less.php cache directory isn\'t writable: '.$dir ); + throw new Less_Exception_Parser( 'Less.php cache directory isn\'t writable: ' . $dir ); } else { $dir = self::WinPath( $dir ); - Less_Cache::$cache_dir = rtrim( $dir, '/' ).'/'; + Less_Cache::$cache_dir = rtrim( $dir, '/' ) . '/'; return true; } } @@ -558,28 +545,28 @@ class Less_Parser { * @param array $dirs */ public function SetImportDirs( $dirs ) { - Less_Parser::$options['import_dirs'] = array(); + self::$options['import_dirs'] = []; foreach ( $dirs as $path => $uri_root ) { $path = self::WinPath( $path ); if ( !empty( $path ) ) { - $path = rtrim( $path, '/' ).'/'; + $path = rtrim( $path, '/' ) . '/'; } if ( !is_callable( $uri_root ) ) { $uri_root = self::WinPath( $uri_root ); if ( !empty( $uri_root ) ) { - $uri_root = rtrim( $uri_root, '/' ).'/'; + $uri_root = rtrim( $uri_root, '/' ) . '/'; } } - Less_Parser::$options['import_dirs'][$path] = $uri_root; + self::$options['import_dirs'][$path] = $uri_root; } } /** - * @param string $file_path + * @param string|null $file_path */ private function _parse( $file_path = null ) { $this->rules = array_merge( $this->rules, $this->GetRules( $file_path ) ); @@ -596,11 +583,11 @@ class Less_Parser { $cache_file = $this->CacheFile( $file_path ); if ( $cache_file ) { - if ( Less_Parser::$options['cache_method'] == 'callback' ) { - if ( is_callable( Less_Parser::$options['cache_callback_get'] ) ) { + if ( self::$options['cache_method'] == 'callback' ) { + if ( is_callable( self::$options['cache_callback_get'] ) ) { $cache = call_user_func_array( - Less_Parser::$options['cache_callback_get'], - array( $this, $file_path, $cache_file ) + self::$options['cache_callback_get'], + [ $this, $file_path, $cache_file ] ); if ( $cache ) { @@ -610,7 +597,7 @@ class Less_Parser { } } elseif ( file_exists( $cache_file ) ) { - switch ( Less_Parser::$options['cache_method'] ) { + switch ( self::$options['cache_method'] ) { // Using serialize // Faster but uses more memory @@ -642,26 +629,26 @@ class Less_Parser { // save the cache if ( $cache_file ) { - if ( Less_Parser::$options['cache_method'] == 'callback' ) { - if ( is_callable( Less_Parser::$options['cache_callback_set'] ) ) { + if ( self::$options['cache_method'] == 'callback' ) { + if ( is_callable( self::$options['cache_callback_set'] ) ) { call_user_func_array( - Less_Parser::$options['cache_callback_set'], - array( $this, $file_path, $cache_file, $rules ) + self::$options['cache_callback_set'], + [ $this, $file_path, $cache_file, $rules ] ); } } else { - // msg('write cache file'); - switch ( Less_Parser::$options['cache_method'] ) { + switch ( self::$options['cache_method'] ) { case 'serialize': file_put_contents( $cache_file, serialize( $rules ) ); break; case 'php': - file_put_contents( $cache_file, '' ); + // Mask PHP open tag to avoid breaking Doxygen + file_put_contents( $cache_file, '<' . '?php return ' . self::ArgString( $rules ) . '; ?>' ); break; case 'var_export': // Requires __set_state() - file_put_contents( $cache_file, '' ); + file_put_contents( $cache_file, '<' . '?php return ' . var_export( $rules, true ) . '; ?>' ); break; } @@ -674,7 +661,6 @@ class Less_Parser { /** * Set up the input buffer - * */ public function SetInput( $file_path ) { if ( $file_path ) { @@ -687,20 +673,18 @@ class Less_Parser { $this->input = preg_replace( '/\\G\xEF\xBB\xBF/', '', $this->input ); $this->input_len = strlen( $this->input ); - if ( Less_Parser::$options['sourceMap'] && $this->env->currentFileInfo ) { + if ( self::$options['sourceMap'] && $this->env->currentFileInfo ) { $uri = $this->env->currentFileInfo['currentUri']; - Less_Parser::$contentsMap[$uri] = $this->input; + self::$contentsMap[$uri] = $this->input; } - } /** * Free up some memory - * */ public function UnsetInput() { - unset( $this->input, $this->pos, $this->input_len, $this->furthest ); - $this->saveStack = array(); + $this->input = $this->pos = $this->input_len = $this->furthest = null; + $this->saveStack = []; } public function CacheFile( $file_path ) { @@ -709,13 +693,13 @@ class Less_Parser { $env = get_object_vars( $this->env ); unset( $env['frames'] ); - $parts = array(); + $parts = []; $parts[] = $file_path; $parts[] = filesize( $file_path ); $parts[] = filemtime( $file_path ); $parts[] = $env; $parts[] = Less_Version::cache_version; - $parts[] = Less_Parser::$options['cache_method']; + $parts[] = self::$options['cache_method']; return Less_Cache::$cache_dir . Less_Cache::$prefix . base_convert( sha1( json_encode( $parts ) ), 16, 36 ) . '.lesscache'; } } @@ -740,6 +724,9 @@ class Less_Parser { } private function restore() { + if ( $this->pos > $this->furthest ) { + $this->furthest = $this->pos; + } $this->pos = array_pop( $this->saveStack ); } @@ -751,10 +738,10 @@ class Less_Parser { * Determine if the character at the specified offset from the current position is a white space. * * @param int $offset - * * @return bool */ private function isWhitespace( $offset = 0 ) { + // @phan-suppress-next-line PhanParamSuspiciousOrder False positive return strpos( " \t\n\r\v\f", $this->input[$this->pos + $offset] ) !== false; } @@ -762,9 +749,9 @@ class Less_Parser { * Parse from a token, regexp or string, and move forward if match * * @param array $toks - * @return array + * @return null|string|array|Less_Tree */ - private function match( $toks ) { + private function matcher( $toks ) { // The match is confirmed, add the match length to `this::pos`, // and consume any extra white-space characters (' ' || '\n') // which come after that. The reason for this is that LeSS's @@ -799,8 +786,7 @@ class Less_Parser { /** * @param string[] $toks - * - * @return string + * @return null|string|array|Less_Tree */ private function MatchFuncs( $toks ) { if ( $this->pos < $this->input_len ) { @@ -811,10 +797,14 @@ class Less_Parser { } } } - } - // Match a single character in the input, + /** + * Match a single character in the input. + * + * @param string $tok + * @see less-2.5.3.js#parserInput.$char + */ private function MatchChar( $tok ) { if ( ( $this->pos < $this->input_len ) && ( $this->input[$this->pos] === $tok ) ) { $this->skipWhitespace( 1 ); @@ -822,7 +812,11 @@ class Less_Parser { } } - // Match a regexp from the current start point + /** + * Match a regexp from the current start point + * + * @return array|null + */ private function MatchReg( $tok ) { if ( preg_match( $tok, $this->input, $match, 0, $this->pos ) ) { $this->skipWhitespace( strlen( $match[0] ) ); @@ -835,7 +829,7 @@ class Less_Parser { * just return the match. * * @param string $tok - * @return integer + * @return int|false */ public function PeekReg( $tok ) { return preg_match( $tok, $this->input, $match, 0, $this->pos ); @@ -845,12 +839,12 @@ class Less_Parser { * @param string $tok */ public function PeekChar( $tok ) { - // return ($this->input[$this->pos] === $tok ); return ( $this->pos < $this->input_len ) && ( $this->input[$this->pos] === $tok ); } /** - * @param integer $length + * @param int $length + * @see less-2.5.3.js#skipWhitespace */ public function skipWhitespace( $length ) { $this->pos += $length; @@ -868,8 +862,8 @@ class Less_Parser { * @param string $tok * @param string|null $msg */ - public function expect( $tok, $msg = NULL ) { - $result = $this->match( array( $tok ) ); + public function expect( $tok, $msg = null ) { + $result = $this->matcher( [ $tok ] ); if ( !$result ) { $this->Error( $msg ? "Expected '" . $tok . "' got '" . $this->input[$this->pos] . "'" : $msg ); } else { @@ -879,11 +873,12 @@ class Less_Parser { /** * @param string $tok + * @param string|null $msg */ public function expectChar( $tok, $msg = null ) { $result = $this->MatchChar( $tok ); if ( !$result ) { - $msg = $msg ? $msg : "Expected '" . $tok . "' got '" . $this->input[$this->pos] . "'"; + $msg = $msg ?: "Expected '" . $tok . "' got '" . $this->input[$this->pos] . "'"; $this->Error( $msg ); } else { return $result; @@ -935,8 +930,9 @@ class Less_Parser { // Only at one point is the primary rule not called from the // block rule: at the root level. // + // @see less-2.5.3.js#parsers.primary private function parsePrimary() { - $root = array(); + $root = []; while ( true ) { @@ -950,8 +946,16 @@ class Less_Parser { continue; } - // $node = $this->MatchFuncs( array( 'parseMixinDefinition', 'parseRule', 'parseRuleset', 'parseMixinCall', 'parseComment', 'parseDirective')); - $node = $this->MatchFuncs( array( 'parseMixinDefinition', 'parseNameValue', 'parseRule', 'parseRuleset', 'parseMixinCall', 'parseComment', 'parseRulesetCall', 'parseDirective' ) ); + $node = $this->MatchFuncs( [ + 'parseMixinDefinition', + 'parseNameValue', + 'parseRule', + 'parseRuleset', + 'parseMixinCall', + 'parseComment', + 'parseRulesetCall', + 'parseDirective' + ] ); if ( $node ) { $root[] = $node; @@ -977,18 +981,18 @@ class Less_Parser { if ( $this->input[$this->pos + 1] === '/' ) { $match = $this->MatchReg( '/\\G\/\/.*/' ); - return $this->NewObj4( 'Less_Tree_Comment', array( $match[0], true, $this->pos, $this->env->currentFileInfo ) ); + return $this->NewObj( 'Less_Tree_Comment', [ $match[0], true, $this->pos, $this->env->currentFileInfo ] ); } // $comment = $this->MatchReg('/\\G\/\*(?:[^*]|\*+[^\/*])*\*+\/\n?/'); $comment = $this->MatchReg( '/\\G\/\*(?s).*?\*+\/\n?/' );// not the same as less.js to prevent fatal errors if ( $comment ) { - return $this->NewObj4( 'Less_Tree_Comment', array( $comment[0], false, $this->pos, $this->env->currentFileInfo ) ); + return $this->NewObj( 'Less_Tree_Comment', [ $comment[0], false, $this->pos, $this->env->currentFileInfo ] ); } } private function parseComments() { - $comments = array(); + $comments = []; while ( $this->pos < $this->input_len ) { $comment = $this->parseComment(); @@ -1002,11 +1006,13 @@ class Less_Parser { return $comments; } - // - // A string, which supports escaping " and ' - // - // "milky way" 'he\'s the one!' - // + /** + * A string, which supports escaping " and ' + * + * "milky way" 'he\'s the one!' + * + * @return Less_Tree_Quoted|null + */ private function parseEntitiesQuoted() { $j = $this->pos; $e = false; @@ -1031,8 +1037,8 @@ class Less_Parser { return; } - $quoted = $char.$matched.$char; - return $this->NewObj5( 'Less_Tree_Quoted', array( $quoted, $matched, $e, $index, $this->env->currentFileInfo ) ); + $quoted = $char . $matched . $char; + return $this->NewObj( 'Less_Tree_Quoted', [ $quoted, $matched, $e, $index, $this->env->currentFileInfo ] ); } /** @@ -1071,11 +1077,13 @@ class Less_Parser { return false; } - // - // A catch-all word, such as: - // - // black border-collapse - // + /** + * A catch-all word, such as: + * + * black border-collapse + * + * @return Less_Tree_Keyword|Less_Tree_Color|null + */ private function parseEntitiesKeyword() { // $k = $this->MatchReg('/\\G[_A-Za-z-][_A-Za-z0-9-]*/'); $k = $this->MatchReg( '/\\G%|\\G[_A-Za-z-][_A-Za-z0-9-]*/' ); @@ -1085,7 +1093,7 @@ class Less_Parser { if ( $color ) { return $color; } - return $this->NewObj1( 'Less_Tree_Keyword', $k ); + return $this->NewObj( 'Less_Tree_Keyword', [ $k ] ); } } @@ -1095,11 +1103,11 @@ class Less_Parser { if ( Less_Colors::hasOwnProperty( $keyword ) ) { // detect named color - return $this->NewObj1( 'Less_Tree_Color', substr( Less_Colors::color( $keyword ), 1 ) ); + return $this->NewObj( 'Less_Tree_Color', [ substr( Less_Colors::color( $keyword ), 1 ) ] ); } if ( $keyword === 'transparent' ) { - return $this->NewObj3( 'Less_Tree_Color', array( array( 0, 0, 0 ), 0, true ) ); + return $this->NewObj( 'Less_Tree_Color', [ [ 0, 0, 0 ], 0, true ] ); } } @@ -1144,19 +1152,19 @@ class Less_Parser { } if ( $name ) { - return $this->NewObj4( 'Less_Tree_Call', array( $name, $args, $index, $this->env->currentFileInfo ) ); + return $this->NewObj( 'Less_Tree_Call', [ $name, $args, $index, $this->env->currentFileInfo ] ); } } /** * Parse a list of arguments * - * @return array + * @return array */ private function parseEntitiesArguments() { - $args = array(); + $args = []; while ( true ) { - $arg = $this->MatchFuncs( array( 'parseEntitiesAssignment','parseExpression' ) ); + $arg = $this->MatchFuncs( [ 'parseEntitiesAssignment', 'parseExpression' ] ); if ( !$arg ) { break; } @@ -1169,15 +1177,20 @@ class Less_Parser { return $args; } + /** @return Less_Tree_Dimension|Less_Tree_Color|Less_Tree_Quoted|Less_Tree_UnicodeDescriptor|null */ private function parseEntitiesLiteral() { - return $this->MatchFuncs( array( 'parseEntitiesDimension','parseEntitiesColor','parseEntitiesQuoted','parseUnicodeDescriptor' ) ); + return $this->MatchFuncs( [ 'parseEntitiesDimension','parseEntitiesColor','parseEntitiesQuoted','parseUnicodeDescriptor' ] ); } - // Assignments are argument entities for calls. - // They are present in ie filter properties as shown below. - // - // filter: progid:DXImageTransform.Microsoft.Alpha( *opacity=50* ) - // + /** + * Assignments are argument entities for calls. + * + * They are present in IE filter properties as shown below. + * + * filter: progid:DXImageTransform.Microsoft.Alpha( *opacity=50* ) + * + * @return Less_Tree_Assignment|null + */ private function parseEntitiesAssignment() { $key = $this->MatchReg( '/\\G\w+(?=\s?=)/' ); if ( !$key ) { @@ -1190,7 +1203,7 @@ class Less_Parser { $value = $this->parseEntity(); if ( $value ) { - return $this->NewObj2( 'Less_Tree_Assignment', array( $key[0], $value ) ); + return $this->NewObj( 'Less_Tree_Assignment', [ $key[0], $value ] ); } } @@ -1206,62 +1219,73 @@ class Less_Parser { return; } - $value = $this->match( array( 'parseEntitiesQuoted','parseEntitiesVariable','/\\Gdata\:.*?[^\)]+/','/\\G(?:(?:\\\\[\(\)\'"])|[^\(\)\'"])+/' ) ); + $value = $this->matcher( [ 'parseEntitiesQuoted','parseEntitiesVariable','/\\Gdata\:.*?[^\)]+/','/\\G(?:(?:\\\\[\(\)\'"])|[^\(\)\'"])+/' ] ); if ( !$value ) { $value = ''; } $this->expectChar( ')' ); + // @phan-suppress-next-line PhanUndeclaredProperty if ( isset( $value->value ) || $value instanceof Less_Tree_Variable ) { - return $this->NewObj2( 'Less_Tree_Url', array( $value, $this->env->currentFileInfo ) ); + return $this->NewObj( 'Less_Tree_Url', [ $value, $this->env->currentFileInfo ] ); } - return $this->NewObj2( 'Less_Tree_Url', array( $this->NewObj1( 'Less_Tree_Anonymous', $value ), $this->env->currentFileInfo ) ); + return $this->NewObj( 'Less_Tree_Url', [ $this->NewObj( 'Less_Tree_Anonymous', [ $value ] ), $this->env->currentFileInfo ] ); } - // - // A Variable entity, such as `@fink`, in - // - // width: @fink + 2px - // - // We use a different parser for variable definitions, - // see `parsers.variable`. - // + /** + * A Variable entity, such as `@fink`, in + * + * width: @fink + 2px + * + * We use a different parser for variable definitions, + * see `parsers.variable`. + * + * @return Less_Tree_Variable|null + */ private function parseEntitiesVariable() { $index = $this->pos; if ( $this->PeekChar( '@' ) && ( $name = $this->MatchReg( '/\\G@@?[\w-]+/' ) ) ) { - return $this->NewObj3( 'Less_Tree_Variable', array( $name[0], $index, $this->env->currentFileInfo ) ); + return $this->NewObj( 'Less_Tree_Variable', [ $name[0], $index, $this->env->currentFileInfo ] ); } } - // A variable entity using the protective {} e.g. @{var} + /** + * A variable entity using the protective `{}` e.g. `@{var}`. + * + * @return Less_Tree_Variable|null + */ private function parseEntitiesVariableCurly() { $index = $this->pos; if ( $this->input_len > ( $this->pos + 1 ) && $this->input[$this->pos] === '@' && ( $curly = $this->MatchReg( '/\\G@\{([\w-]+)\}/' ) ) ) { - return $this->NewObj3( 'Less_Tree_Variable', array( '@'.$curly[1], $index, $this->env->currentFileInfo ) ); + return $this->NewObj( 'Less_Tree_Variable', [ '@' . $curly[1], $index, $this->env->currentFileInfo ] ); } } - // - // A Hexadecimal color - // - // #4F3C2F - // - // `rgb` and `hsl` colors are parsed through the `entities.call` parser. - // + /** + * A Hexadecimal color + * + * #4F3C2F + * + * `rgb` and `hsl` colors are parsed through the `entities.call` parser. + * + * @return Less_Tree_Color|null + */ private function parseEntitiesColor() { if ( $this->PeekChar( '#' ) && ( $rgb = $this->MatchReg( '/\\G#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})/' ) ) ) { - return $this->NewObj1( 'Less_Tree_Color', $rgb[1] ); + return $this->NewObj( 'Less_Tree_Color', [ $rgb[1] ] ); } } - // - // A Dimension, that is, a number and a unit - // - // 0.5em 95% - // + /** + * A Dimension, that is, a number and a unit + * + * 0.5em 95% + * + * @return Less_Tree_Dimension|null + */ private function parseEntitiesDimension() { $c = @ord( $this->input[$this->pos] ); @@ -1272,23 +1296,24 @@ class Less_Parser { $value = $this->MatchReg( '/\\G([+-]?\d*\.?\d+)(%|[a-z]+)?/' ); if ( $value ) { - if ( isset( $value[2] ) ) { - return $this->NewObj2( 'Less_Tree_Dimension', array( $value[1],$value[2] ) ); + return $this->NewObj( 'Less_Tree_Dimension', [ $value[1],$value[2] ] ); } - return $this->NewObj1( 'Less_Tree_Dimension', $value[1] ); + return $this->NewObj( 'Less_Tree_Dimension', [ $value[1] ] ); } } - // - // A unicode descriptor, as is used in unicode-range - // - // U+0?? or U+00A1-00A9 - // + /** + * A unicode descriptor, as is used in unicode-range + * + * U+0?? or U+00A1-00A9 + * + * @return Less_Tree_UnicodeDescriptor|null + */ function parseUnicodeDescriptor() { $ud = $this->MatchReg( '/\\G(U\+[0-9a-fA-F?]+)(\-[0-9a-fA-F?]+)?/' ); if ( $ud ) { - return $this->NewObj1( 'Less_Tree_UnicodeDescriptor', $ud[0] ); + return $this->NewObj( 'Less_Tree_UnicodeDescriptor', [ $ud[0] ] ); } } @@ -1312,7 +1337,7 @@ class Less_Parser { } $str = $this->MatchReg( '/\\G`([^`]*)`/' ); if ( $str ) { - return $this->NewObj3( 'Less_Tree_Javascript', array( $str[1], $this->pos, $e ) ); + return $this->NewObj( 'Less_Tree_Javascript', [ $str[1], $this->pos, $e ] ); } } @@ -1334,7 +1359,7 @@ class Less_Parser { // private function parseRulesetCall() { if ( $this->input[$this->pos] === '@' && ( $name = $this->MatchReg( '/\\G(@[\w-]+)\s*\(\s*\)\s*;/' ) ) ) { - return $this->NewObj1( 'Less_Tree_RulesetCall', $name[1] ); + return $this->NewObj( 'Less_Tree_RulesetCall', [ $name[1] ] ); } } @@ -1343,20 +1368,22 @@ class Less_Parser { // function parseExtend( $isRule = false ) { $index = $this->pos; - $extendList = array(); + $extendList = []; - if ( !$this->MatchReg( $isRule ? '/\\G&:extend\(/' : '/\\G:extend\(/' ) ) { return; + if ( !$this->MatchReg( $isRule ? '/\\G&:extend\(/' : '/\\G:extend\(/' ) ) { + return; } - do{ + do { $option = null; - $elements = array(); + $elements = []; while ( true ) { $option = $this->MatchReg( '/\\G(all)(?=\s*(\)|,))/' ); if ( $option ) { break; } $e = $this->parseElement(); - if ( !$e ) { break; + if ( !$e ) { + break; } $elements[] = $e; } @@ -1365,9 +1392,9 @@ class Less_Parser { $option = $option[1]; } - $extendList[] = $this->NewObj3( 'Less_Tree_Extend', array( $this->NewObj1( 'Less_Tree_Selector', $elements ), $option, $index ) ); + $extendList[] = $this->NewObj( 'Less_Tree_Extend', [ $this->NewObj( 'Less_Tree_Selector', [ $elements ] ), $option, $index ] ); - }while ( $this->MatchChar( "," ) ); + } while ( $this->MatchChar( "," ) ); $this->expect( '/\\G\)/' ); @@ -1407,14 +1434,14 @@ class Less_Parser { $args = $returned['args']; $this->expectChar( ')' ); } else { - $args = array(); + $args = []; } $important = $this->parseImportant(); if ( $this->parseEnd() ) { $this->forget(); - return $this->NewObj5( 'Less_Tree_Mixin_Call', array( $elements, $args, $index, $this->env->currentFileInfo, $important ) ); + return $this->NewObj( 'Less_Tree_Mixin_Call', [ $elements, $args, $index, $this->env->currentFileInfo, $important ] ); } } @@ -1422,7 +1449,7 @@ class Less_Parser { } private function parseMixinCallElements() { - $elements = array(); + $elements = []; $c = null; while ( true ) { @@ -1431,7 +1458,7 @@ class Less_Parser { if ( !$e ) { break; } - $elements[] = $this->NewObj4( 'Less_Tree_Element', array( $c, $e[0], $elemIndex, $this->env->currentFileInfo ) ); + $elements[] = $this->NewObj( 'Less_Tree_Element', [ $c, $e[0], $elemIndex, $this->env->currentFileInfo ] ); $c = $this->MatchChar( '>' ); } @@ -1439,22 +1466,22 @@ class Less_Parser { } /** - * @param boolean $isCall + * @param bool $isCall */ private function parseMixinArgs( $isCall ) { - $expressions = array(); - $argsSemiColon = array(); + $expressions = []; + $argsSemiColon = []; $isSemiColonSeperated = null; - $argsComma = array(); + $argsComma = []; $expressionContainsNamed = null; $name = null; - $returner = array( 'args' => array(), 'variadic' => false ); + $returner = [ 'args' => [], 'variadic' => false ]; $this->save(); while ( true ) { if ( $isCall ) { - $arg = $this->MatchFuncs( array( 'parseDetachedRuleset','parseExpression' ) ); + $arg = $this->MatchFuncs( [ 'parseDetachedRuleset', 'parseExpression' ] ); } else { $this->parseComments(); if ( $this->input[ $this->pos ] === '.' && $this->MatchReg( '/\\G\.{3}/' ) ) { @@ -1464,14 +1491,15 @@ class Less_Parser { } if ( $isSemiColonSeperated ) { - $argsSemiColon[] = array( 'variadic' => true ); + $argsSemiColon[] = [ 'variadic' => true ]; } else { - $argsComma[] = array( 'variadic' => true ); + $argsComma[] = [ 'variadic' => true ]; } break; } - $arg = $this->MatchFuncs( array( 'parseEntitiesVariable','parseEntitiesLiteral','parseEntitiesKeyword' ) ); + $arg = $this->MatchFuncs( [ 'parseEntitiesVariable', 'parseEntitiesLiteral', 'parseEntitiesKeyword' ] ); } + '@phan-var Less_Tree_DetachedRuleset|Less_Tree_Expression|Less_Tree_Variable|Less_Tree_Dimension|Less_Tree_Color|Less_Tree_Quoted|Less_Tree_UnicodeDescriptor|Less_Tree_Keyword|null $arg'; if ( !$arg ) { break; @@ -1519,7 +1547,7 @@ class Less_Parser { $this->Error( 'could not understand value for named argument' ); } else { $this->restore(); - $returner['args'] = array(); + $returner['args'] = []; return $returner; } } @@ -1531,9 +1559,9 @@ class Less_Parser { $isSemiColonSeperated = true; } if ( $isSemiColonSeperated ) { - $argsSemiColon[] = array( 'name' => $arg->name, 'variadic' => true ); + $argsSemiColon[] = [ 'name' => $arg->name, 'variadic' => true ]; } else { - $argsComma[] = array( 'name' => $arg->name, 'variadic' => true ); + $argsComma[] = [ 'name' => $arg->name, 'variadic' => true ]; } break; } elseif ( !$isCall ) { @@ -1546,7 +1574,7 @@ class Less_Parser { $expressions[] = $value; } - $argsComma[] = array( 'name' => $nameLoop, 'value' => $value ); + $argsComma[] = [ 'name' => $nameLoop, 'value' => $value ]; if ( $this->MatchChar( ',' ) ) { continue; @@ -1561,12 +1589,12 @@ class Less_Parser { $isSemiColonSeperated = true; if ( count( $expressions ) > 1 ) { - $value = $this->NewObj1( 'Less_Tree_Value', $expressions ); + $value = $this->NewObj( 'Less_Tree_Value', [ $expressions ] ); } - $argsSemiColon[] = array( 'name' => $name, 'value' => $value ); + $argsSemiColon[] = [ 'name' => $name, 'value' => $value ]; $name = null; - $expressions = array(); + $expressions = []; $expressionContainsNamed = false; } } @@ -1599,6 +1627,7 @@ class Less_Parser { $cond = null; $char = $this->input[$this->pos]; + // TODO: Less.js doesn't limit this to $char == '{'. if ( ( $char !== '.' && $char !== '#' ) || ( $char === '{' && $this->PeekReg( '/\\G[^{]*\}/' ) ) ) { return; } @@ -1619,7 +1648,6 @@ class Less_Parser { // .mixincall(@a: {rule: set;}); // so we have to be nice and restore if ( !$this->MatchChar( ')' ) ) { - $this->furthest = $this->pos; $this->restore(); return; } @@ -1632,9 +1660,9 @@ class Less_Parser { $ruleset = $this->parseBlock(); - if ( is_array( $ruleset ) ) { + if ( $ruleset !== null ) { $this->forget(); - return $this->NewObj5( 'Less_Tree_Mixin_Definition', array( $name, $params, $ruleset, $cond, $variadic ) ); + return $this->NewObj( 'Less_Tree_Mixin_Definition', [ $name, $params, $ruleset, $cond, $variadic ] ); } $this->restore(); @@ -1648,7 +1676,7 @@ class Less_Parser { // and can be found inside a rule's value. // private function parseEntity() { - return $this->MatchFuncs( array( 'parseEntitiesLiteral','parseEntitiesVariable','parseEntitiesUrl','parseEntitiesCall','parseEntitiesKeyword','parseEntitiesJavascript','parseComment' ) ); + return $this->MatchFuncs( [ 'parseEntitiesLiteral','parseEntitiesVariable','parseEntitiesUrl','parseEntitiesCall','parseEntitiesKeyword','parseEntitiesJavascript','parseComment' ] ); } // @@ -1681,33 +1709,45 @@ class Less_Parser { } $this->expectChar( ')' ); - return $this->NewObj1( 'Less_Tree_Alpha', $value ); + return $this->NewObj( 'Less_Tree_Alpha', [ $value ] ); } - // - // A Selector Element - // - // div - // + h1 - // #socks - // input[type="text"] - // - // Elements are the building blocks for Selectors, - // they are made out of a `Combinator` (see combinator rule), - // and an element name, such as a tag a class, or `*`. - // + /** + * A Selector Element + * + * div + * + h1 + * #socks + * input[type="text"] + * + * Elements are the building blocks for Selectors, + * they are made out of a `Combinator` (see combinator rule), + * and an element name, such as a tag a class, or `*`. + * + * @return Less_Tree_Element|null + * @see less-2.5.3.js#parsers.element + */ private function parseElement() { $c = $this->parseCombinator(); $index = $this->pos; - $e = $this->match( array( '/\\G(?:\d+\.\d+|\d+)%/', '/\\G(?:[.#]?|:*)(?:[\w-]|[^\x00-\x9f]|\\\\(?:[A-Fa-f0-9]{1,6} ?|[^A-Fa-f0-9]))+/', - '#*', '#&', 'parseAttribute', '/\\G\([^()@]+\)/', '/\\G[\.#](?=@)/', 'parseEntitiesVariableCurly' ) ); + // TODO: Speed up by calling MatchChar directly, like less.js does + $e = $this->matcher( [ + '/\\G(?:\d+\.\d+|\d+)%/', + '/\\G(?:[.#]?|:*)(?:[\w-]|[^\x00-\x9f]|\\\\(?:[A-Fa-f0-9]{1,6} ?|[^A-Fa-f0-9]))+/', + '#*', + '#&', + 'parseAttribute', + '/\\G\([^&()@]+\)/', + '/\\G[\.#:](?=@)/', + 'parseEntitiesVariableCurly' + ] ); - if ( is_null( $e ) ) { + if ( $e === null ) { $this->save(); if ( $this->MatchChar( '(' ) ) { if ( ( $v = $this->parseSelector() ) && $this->MatchChar( ')' ) ) { - $e = $this->NewObj1( 'Less_Tree_Paren', $v ); + $e = $this->NewObj( 'Less_Tree_Paren', [ $v ] ); $this->forget(); } else { $this->restore(); @@ -1717,8 +1757,8 @@ class Less_Parser { } } - if ( !is_null( $e ) ) { - return $this->NewObj4( 'Less_Tree_Element', array( $c, $e, $index, $this->env->currentFileInfo ) ); + if ( $e !== null ) { + return $this->NewObj( 'Less_Tree_Element', [ $c, $e, $index, $this->env->currentFileInfo ] ); } } @@ -1730,9 +1770,11 @@ class Less_Parser { // as it's an empty space. We have to check the previous character // in the input, to see if it's a ` ` character. // + // @see less-2.5.3.js#parsers.combinator private function parseCombinator() { if ( $this->pos < $this->input_len ) { $c = $this->input[$this->pos]; + // TODO: Figure out why less.js also handles '/' here, and implement with regression test. if ( $c === '>' || $c === '+' || $c === '~' || $c === '|' || $c === '^' ) { $this->pos++; @@ -1752,25 +1794,31 @@ class Less_Parser { } } - // - // A CSS selector (see selector below) - // with less extensions e.g. the ability to extend and guard - // + /** + * A CSS selector (see selector below) + * with less extensions e.g. the ability to extend and guard + * + * @return Less_Tree_Selector|null + * @see less-2.5.3.js#parsers.lessSelector + */ private function parseLessSelector() { return $this->parseSelector( true ); } - // - // A CSS Selector - // - // .class > div + h1 - // li a:hover - // - // Selectors are made out of one or more Elements, see above. - // + /** + * A CSS Selector + * + * .class > div + h1 + * li a:hover + * + * Selectors are made out of one or more Elements, see ::parseElement. + * + * @return Less_Tree_Selector|null + * @see less-2.5.3.js#parsers.selector + */ private function parseSelector( $isLess = false ) { - $elements = array(); - $extendList = array(); + $elements = []; + $extendList = []; $condition = null; $when = false; $extend = false; @@ -1796,12 +1844,13 @@ class Less_Parser { $e = null; } - if ( $c === '{' || $c === '}' || $c === ';' || $c === ',' || $c === ')' ) { break; + if ( $c === '{' || $c === '}' || $c === ';' || $c === ',' || $c === ')' ) { + break; } } if ( $elements ) { - return $this->NewObj5( 'Less_Tree_Selector', array( $elements, $extendList, $condition, $index, $this->env->currentFileInfo ) ); + return $this->NewObj( 'Less_Tree_Selector', [ $elements, $extendList, $condition, $index, $this->env->currentFileInfo ] ); } if ( $extendList ) { $this->Error( 'Extend must be used to extend a selector, it cannot be used on its own' ); @@ -1826,18 +1875,21 @@ class Less_Parser { $op = $this->MatchReg( '/\\G[|~*$^]?=/' ); if ( $op ) { - $val = $this->match( array( 'parseEntitiesQuoted','/\\G[0-9]+%/','/\\G[\w-]+/','parseEntitiesVariableCurly' ) ); + $val = $this->matcher( [ 'parseEntitiesQuoted','/\\G[0-9]+%/','/\\G[\w-]+/','parseEntitiesVariableCurly' ] ); } $this->expectChar( ']' ); - return $this->NewObj3( 'Less_Tree_Attribute', array( $key, $op === null ? null : $op[0], $val ) ); + return $this->NewObj( 'Less_Tree_Attribute', [ $key, $op === null ? null : $op[0], $val ] ); } - // - // The `block` rule is used by `ruleset` and `mixin.definition`. - // It's a wrapper around the `primary` rule, with added `{}`. - // + /** + * The `block` rule is used by `ruleset` and `mixin.definition`. + * It's a wrapper around the `primary` rule, with added `{}`. + * + * @return array|null + * @see less-2.5.3.js#parsers.block + */ private function parseBlock() { if ( $this->MatchChar( '{' ) ) { $content = $this->parsePrimary(); @@ -1851,24 +1903,31 @@ class Less_Parser { $block = $this->parseBlock(); if ( $block ) { - $block = $this->NewObj2( 'Less_Tree_Ruleset', array( null, $block ) ); + $block = $this->NewObj( 'Less_Tree_Ruleset', [ null, $block ] ); } return $block; } + /** @return Less_Tree_DetachedRuleset|null */ private function parseDetachedRuleset() { $blockRuleset = $this->parseBlockRuleset(); if ( $blockRuleset ) { - return $this->NewObj1( 'Less_Tree_DetachedRuleset', $blockRuleset ); + return $this->NewObj( 'Less_Tree_DetachedRuleset', [ $blockRuleset ] ); } } - // - // div, .class, body > p {...} - // + /** + * Ruleset such as: + * + * div, .class, body > p { + * } + * + * @return Less_Tree_Ruleset|null + * @see less-2.5.3.js#parsers.ruleset + */ private function parseRuleset() { - $selectors = array(); + $selectors = []; $this->save(); @@ -1897,25 +1956,24 @@ class Less_Parser { $rules = $this->parseBlock(); if ( is_array( $rules ) ) { $this->forget(); - return $this->NewObj2( 'Less_Tree_Ruleset', array( $selectors, $rules ) ); // Less_Environment::$strictImports + // TODO: Less_Environment::$strictImports is not yet ported + // It is passed here by less.js + return $this->NewObj( 'Less_Tree_Ruleset', [ $selectors, $rules ] ); } } // Backtrack - $this->furthest = $this->pos; $this->restore(); } /** * Custom less.php parse function for finding simple name-value css pairs * ex: width:100px; - * */ private function parseNameValue() { $index = $this->pos; $this->save(); - // $match = $this->MatchReg('/\\G([a-zA-Z\-]+)\s*:\s*((?:\'")?[a-zA-Z0-9\-% \.,!]+?(?:\'")?)\s*([;}])/'); $match = $this->MatchReg( '/\\G([a-zA-Z\-]+)\s*:\s*([\'"]?[#a-zA-Z0-9\-%\.,]+?[\'"]?) *(! *important)?\s*([;}])/' ); if ( $match ) { @@ -1927,63 +1985,68 @@ class Less_Parser { $match[2] .= ' !important'; } - return $this->NewObj4( 'Less_Tree_NameValue', array( $match[1], $match[2], $index, $this->env->currentFileInfo ) ); + return $this->NewObj( 'Less_Tree_NameValue', [ $match[1], $match[2], $index, $this->env->currentFileInfo ] ); } $this->restore(); } + // @see less-2.5.3.js#parsers.rule private function parseRule( $tryAnonymous = null ) { - $merge = false; + $value = null; $startOfRule = $this->pos; - $c = $this->input[$this->pos]; + $important = null; + $merge = false; + + // TODO: Figure out why less.js also handles ':' here, and implement with regression test. if ( $c === '.' || $c === '#' || $c === '&' ) { return; } $this->save(); - $name = $this->MatchFuncs( array( 'parseVariable','parseRuleProperty' ) ); + $name = $this->MatchFuncs( [ 'parseVariable', 'parseRuleProperty' ] ); if ( $name ) { - $isVariable = is_string( $name ); - $value = null; if ( $isVariable ) { $value = $this->parseDetachedRuleset(); } - $important = null; if ( !$value ) { - - // prefer to try to parse first if its a variable or we are compressing - // but always fallback on the other one - //if( !$tryAnonymous && is_string($name) && $name[0] === '@' ){ - if ( !$tryAnonymous && ( Less_Parser::$options['compress'] || $isVariable ) ) { - $value = $this->MatchFuncs( array( 'parseValue','parseAnonymousValue' ) ); - } else { - $value = $this->MatchFuncs( array( 'parseAnonymousValue','parseValue' ) ); - } - - $important = $this->parseImportant(); - // a name returned by this.ruleProperty() is always an array of the form: // [string-1, ..., string-n, ""] or [string-1, ..., string-n, "+"] // where each item is a tree.Keyword or tree.Variable - if ( !$isVariable && is_array( $name ) ) { - $nm = array_pop( $name ); - if ( $nm->value ) { - $merge = $nm->value; + if ( !$isVariable && count( $name ) > 1 ) { + $merge = array_pop( $name )->value; + } + + // prefer to try to parse first if its a variable or we are compressing + // but always fallback on the other one + $tryValueFirst = ( !$tryAnonymous && ( self::$options['compress'] || $isVariable ) ); + if ( $tryValueFirst ) { + $value = $this->parseValue(); + } + if ( !$value ) { + $value = $this->parseAnonymousValue(); + if ( $value ) { + $this->forget(); + // anonymous values absorb the end ';' which is required for them to work + return $this->NewObj( 'Less_Tree_Rule', [ $name, $value, false, $merge, $startOfRule, $this->env->currentFileInfo ] ); } } + if ( !$tryValueFirst && !$value ) { + $value = $this->parseValue(); + } + + $important = $this->parseImportant(); } if ( $value && $this->parseEnd() ) { $this->forget(); - return $this->NewObj6( 'Less_Tree_Rule', array( $name, $value, $important, $merge, $startOfRule, $this->env->currentFileInfo ) ); + return $this->NewObj( 'Less_Tree_Rule', [ $name, $value, $important, $merge, $startOfRule, $this->env->currentFileInfo ] ); } else { - $this->furthest = $this->pos; $this->restore(); if ( $value && !$tryAnonymous ) { return $this->parseRule( true ); @@ -1995,9 +2058,9 @@ class Less_Parser { } function parseAnonymousValue() { - if ( preg_match( '/\\G([^@+\/\'"*`(;{}-]*);/', $this->input, $match, 0, $this->pos ) ) { - $this->pos += strlen( $match[1] ); - return $this->NewObj1( 'Less_Tree_Anonymous', $match[1] ); + $match = $this->MatchReg( '/\\G([^@+\/\'"*`(;{}-]*);/' ); + if ( $match ) { + return $this->NewObj( 'Less_Tree_Anonymous', [ $match[1] ] ); } } @@ -2018,17 +2081,17 @@ class Less_Parser { if ( $dir ) { $options = $this->parseImportOptions(); - $path = $this->MatchFuncs( array( 'parseEntitiesQuoted','parseEntitiesUrl' ) ); + $path = $this->MatchFuncs( [ 'parseEntitiesQuoted','parseEntitiesUrl' ] ); if ( $path ) { $features = $this->parseMediaFeatures(); if ( $this->MatchChar( ';' ) ) { if ( $features ) { - $features = $this->NewObj1( 'Less_Tree_Value', $features ); + $features = $this->NewObj( 'Less_Tree_Value', [ $features ] ); } $this->forget(); - return $this->NewObj5( 'Less_Tree_Import', array( $path, $features, $options, $this->pos, $this->env->currentFileInfo ) ); + return $this->NewObj( 'Less_Tree_Import', [ $path, $features, $options, $this->pos, $this->env->currentFileInfo ] ); } } } @@ -2037,7 +2100,7 @@ class Less_Parser { } private function parseImportOptions() { - $options = array(); + $options = []; // list of options, surrounded by parens if ( !$this->MatchChar( '(' ) ) { @@ -2074,10 +2137,10 @@ class Less_Parser { } private function parseMediaFeature() { - $nodes = array(); + $nodes = []; do{ - $e = $this->MatchFuncs( array( 'parseEntitiesKeyword','parseEntitiesVariable' ) ); + $e = $this->MatchFuncs( [ 'parseEntitiesKeyword','parseEntitiesVariable' ] ); if ( $e ) { $nodes[] = $e; } elseif ( $this->MatchChar( '(' ) ) { @@ -2085,50 +2148,62 @@ class Less_Parser { $e = $this->parseValue(); if ( $this->MatchChar( ')' ) ) { if ( $p && $e ) { - $r = $this->NewObj7( 'Less_Tree_Rule', array( $p, $e, null, null, $this->pos, $this->env->currentFileInfo, true ) ); - $nodes[] = $this->NewObj1( 'Less_Tree_Paren', $r ); + $r = $this->NewObj( 'Less_Tree_Rule', [ $p, $e, null, null, $this->pos, $this->env->currentFileInfo, true ] ); + $nodes[] = $this->NewObj( 'Less_Tree_Paren', [ $r ] ); } elseif ( $e ) { - $nodes[] = $this->NewObj1( 'Less_Tree_Paren', $e ); + $nodes[] = $this->NewObj( 'Less_Tree_Paren', [ $e ] ); } else { return null; } - } else return null; - } - } while ( $e ); - - if ( $nodes ) { - return $this->NewObj1( 'Less_Tree_Expression', $nodes ); - } - } - - private function parseMediaFeatures() { - $features = array(); - - do{ - $e = $this->parseMediaFeature(); - if ( $e ) { - $features[] = $e; - if ( !$this->MatchChar( ',' ) ) break; - } else { - $e = $this->parseEntitiesVariable(); - if ( $e ) { - $features[] = $e; - if ( !$this->MatchChar( ',' ) ) break; + } else { + return null; } } } while ( $e ); - return $features ? $features : null; + if ( $nodes ) { + return $this->NewObj( 'Less_Tree_Expression', [ $nodes ] ); + } + } + + private function parseMediaFeatures() { + $features = []; + + do { + $e = $this->parseMediaFeature(); + if ( $e ) { + $features[] = $e; + if ( !$this->MatchChar( ',' ) ) { + break; + } + } else { + $e = $this->parseEntitiesVariable(); + if ( $e ) { + $features[] = $e; + if ( !$this->MatchChar( ',' ) ) { + break; + } + } + } + } while ( $e ); + + return $features ?: null; } private function parseMedia() { if ( $this->MatchReg( '/\\G@media/' ) ) { + $this->save(); + $features = $this->parseMediaFeatures(); $rules = $this->parseBlock(); - if ( is_array( $rules ) ) { - return $this->NewObj4( 'Less_Tree_Media', array( $rules, $features, $this->pos, $this->env->currentFileInfo ) ); + if ( $rules === null ) { + $this->restore(); + return; } + + $this->forget(); + return $this->NewObj( 'Less_Tree_Media', [ $rules, $features, $this->pos, $this->env->currentFileInfo ] ); } } @@ -2149,7 +2224,10 @@ class Less_Parser { $hasExpression = false; $hasUnknown = false; - $value = $this->MatchFuncs( array( 'parseImport','parseMedia' ) ); + $value = $this->MatchFuncs( [ + 'parseImport', + 'parseMedia' + ] ); if ( $value ) { return $value; } @@ -2158,7 +2236,9 @@ class Less_Parser { $name = $this->MatchReg( '/\\G@[a-z-]+/' ); - if ( !$name ) return; + if ( !$name ) { + return; + } $name = $name[0]; $nonVendorSpecificName = $name; @@ -2214,16 +2294,16 @@ class Less_Parser { if ( !$value ) { $this->error( "expected " . $name . " identifier" ); } - } else if ( $hasExpression ) { + } elseif ( $hasExpression ) { $value = $this->parseExpression(); if ( !$value ) { - $this->error( "expected " . $name. " expression" ); + $this->error( "expected " . $name . " expression" ); } - } else if ( $hasUnknown ) { + } elseif ( $hasUnknown ) { $value = $this->MatchReg( '/\\G[^{;]+/' ); if ( $value ) { - $value = $this->NewObj1( 'Less_Tree_Anonymous', trim( $value[0] ) ); + $value = $this->NewObj( 'Less_Tree_Anonymous', [ trim( $value[0] ) ] ); } } @@ -2233,7 +2313,7 @@ class Less_Parser { if ( $rules || ( !$hasBlock && $value && $this->MatchChar( ';' ) ) ) { $this->forget(); - return $this->NewObj5( 'Less_Tree_Directive', array( $name, $value, $rules, $index, $this->env->currentFileInfo ) ); + return $this->NewObj( 'Less_Tree_Directive', [ $name, $value, $rules, $index, $this->env->currentFileInfo ] ); } $this->restore(); @@ -2248,7 +2328,7 @@ class Less_Parser { // and before the `;`. // private function parseValue() { - $expressions = array(); + $expressions = []; do{ $e = $this->parseExpression(); @@ -2258,10 +2338,10 @@ class Less_Parser { break; } } - }while ( $e ); + } while ( $e ); if ( $expressions ) { - return $this->NewObj1( 'Less_Tree_Value', $expressions ); + return $this->NewObj( 'Less_Tree_Value', [ $expressions ] ); } } @@ -2276,7 +2356,7 @@ class Less_Parser { $a = $this->parseAddition(); if ( $a ) { $this->expectChar( ')' ); - return $this->NewObj2( 'Less_Tree_Expression', array( array( $a ), true ) ); // instead of $e->parens = true so the value is cached + return $this->NewObj( 'Less_Tree_Expression', [ [ $a ], true ] ); // instead of $e->parens = true so the value is cached } } } @@ -2312,11 +2392,10 @@ class Less_Parser { $m->parensInOp = true; $a->parensInOp = true; - $return = $this->NewObj3( 'Less_Tree_Operation', array( $op, array( $return, $a ), $isSpaced ) ); + $return = $this->NewObj( 'Less_Tree_Operation', [ $op, [ $return, $a ], $isSpaced ] ); } } return $return; - } /** @@ -2336,7 +2415,7 @@ class Less_Parser { $op = $op[0]; } else { if ( !$isSpaced ) { - $op = $this->match( array( '#+','#-' ) ); + $op = $this->matcher( [ '#+','#-' ] ); } if ( !$op ) { break; @@ -2350,7 +2429,7 @@ class Less_Parser { $m->parensInOp = true; $a->parensInOp = true; - $return = $this->NewObj3( 'Less_Tree_Operation', array( $op, array( $return, $a ), $isSpaced ) ); + $return = $this->NewObj( 'Less_Tree_Operation', [ $op, [ $return, $a ], $isSpaced ] ); } } @@ -2375,7 +2454,7 @@ class Less_Parser { break; } - $return = $this->NewObj4( 'Less_Tree_Condition', array( 'or', $return, $b, $index ) ); + $return = $this->NewObj( 'Less_Tree_Condition', [ 'or', $return, $b, $index ] ); } return $return; } @@ -2386,32 +2465,34 @@ class Less_Parser { $negate = false; $c = null; - if ( $this->MatchReg( '/\\Gnot/' ) ) $negate = true; + if ( $this->MatchReg( '/\\Gnot/' ) ) { + $negate = true; + } $this->expectChar( '(' ); - $a = $this->MatchFuncs( array( 'parseAddition','parseEntitiesKeyword','parseEntitiesQuoted' ) ); + $a = $this->MatchFuncs( [ 'parseAddition','parseEntitiesKeyword','parseEntitiesQuoted' ] ); if ( $a ) { $op = $this->MatchReg( '/\\G(?:>=|<=|=<|[<=>])/' ); if ( $op ) { - $b = $this->MatchFuncs( array( 'parseAddition','parseEntitiesKeyword','parseEntitiesQuoted' ) ); + $b = $this->MatchFuncs( [ 'parseAddition','parseEntitiesKeyword','parseEntitiesQuoted' ] ); if ( $b ) { - $c = $this->NewObj5( 'Less_Tree_Condition', array( $op[0], $a, $b, $index, $negate ) ); + $c = $this->NewObj( 'Less_Tree_Condition', [ $op[0], $a, $b, $index, $negate ] ); } else { $this->Error( 'Unexpected expression' ); } } else { - $k = $this->NewObj1( 'Less_Tree_Keyword', 'true' ); - $c = $this->NewObj5( 'Less_Tree_Condition', array( '=', $a, $k, $index, $negate ) ); + $k = $this->NewObj( 'Less_Tree_Keyword', [ 'true' ] ); + $c = $this->NewObj( 'Less_Tree_Condition', [ '=', $a, $k, $index, $negate ] ); } $this->expectChar( ')' ); - return $this->MatchReg( '/\\Gand/' ) ? $this->NewObj3( 'Less_Tree_Condition', array( 'and', $c, $this->parseCondition() ) ) : $c; + // @phan-suppress-next-line PhanPossiblyInfiniteRecursionSameParams + return $this->MatchReg( '/\\Gand/' ) ? $this->NewObj( 'Less_Tree_Condition', [ 'and', $c, $this->parseCondition() ] ) : $c; } } /** * An operand is anything that can be part of an operation, * such as a Color, or a Variable - * */ private function parseOperand() { $negate = false; @@ -2424,11 +2505,11 @@ class Less_Parser { $negate = $this->MatchChar( '-' ); } - $o = $this->MatchFuncs( array( 'parseSub','parseEntitiesDimension','parseEntitiesColor','parseEntitiesVariable','parseEntitiesCall' ) ); + $o = $this->MatchFuncs( [ 'parseSub','parseEntitiesDimension','parseEntitiesColor','parseEntitiesVariable','parseEntitiesCall' ] ); if ( $negate ) { $o->parensInOp = true; - $o = $this->NewObj1( 'Less_Tree_Negative', $o ); + $o = $this->NewObj( 'Less_Tree_Negative', [ $o ] ); } return $o; @@ -2438,30 +2519,27 @@ class Less_Parser { * Expressions either represent mathematical operations, * or white-space delimited Entities. * - * 1px solid black - * @var * 2 - * * @return Less_Tree_Expression|null */ private function parseExpression() { - $entities = array(); + $entities = []; - do{ - $e = $this->MatchFuncs( array( 'parseAddition','parseEntity' ) ); + do { + $e = $this->MatchFuncs( [ 'parseAddition','parseEntity' ] ); if ( $e ) { $entities[] = $e; // operations do not allow keyword "/" dimension (e.g. small/20px) so we support that here if ( !$this->PeekReg( '/\\G\/[\/*]/' ) ) { $delim = $this->MatchChar( '/' ); if ( $delim ) { - $entities[] = $this->NewObj1( 'Less_Tree_Anonymous', $delim ); + $entities[] = $this->NewObj( 'Less_Tree_Anonymous', [ $delim ] ); } } } - }while ( $e ); + } while ( $e ); if ( $entities ) { - return $this->NewObj1( 'Less_Tree_Expression', $entities ); + return $this->NewObj( 'Less_Tree_Expression', [ $entities ] ); } } @@ -2482,45 +2560,55 @@ class Less_Parser { * Parse a rule property * eg: 'color', 'width', 'height', etc * - * @return string + * @return array */ private function parseRuleProperty() { - $offset = $this->pos; - $name = array(); - $index = array(); - $length = 0; + $name = []; + $index = []; - $this->rulePropertyMatch( '/\\G(\*?)/', $offset, $length, $index, $name ); - while ( $this->rulePropertyMatch( '/\\G((?:[\w-]+)|(?:@\{[\w-]+\}))/', $offset, $length, $index, $name ) ); // ! + $this->save(); + + $simpleProperty = $this->MatchReg( '/\\G([_a-zA-Z0-9-]+)\s*:/' ); + if ( $simpleProperty ) { + $name[] = $this->NewObj( 'Less_Tree_Keyword', [ $simpleProperty[1] ] ); + $this->forget(); + return $name; + } + + $this->rulePropertyMatch( '/\\G(\*?)/', $index, $name ); + + // Consume! + // @phan-suppress-next-line PhanPluginEmptyStatementWhileLoop + while ( $this->rulePropertyMatch( '/\\G((?:[\w-]+)|(?:@\{[\w-]+\}))/', $index, $name ) ); + + if ( ( count( $name ) > 1 ) && $this->rulePropertyMatch( '/\\G\s*((?:\+_|\+)?)\s*:/', $index, $name ) ) { + $this->forget(); - if ( ( count( $name ) > 1 ) && $this->rulePropertyMatch( '/\\G\s*((?:\+_|\+)?)\s*:/', $offset, $length, $index, $name ) ) { // at last, we have the complete match now. move forward, // convert name particles to tree objects and return: - $this->skipWhitespace( $length ); - if ( $name[0] === '' ) { array_shift( $name ); array_shift( $index ); } foreach ( $name as $k => $s ) { if ( !$s || $s[0] !== '@' ) { - $name[$k] = $this->NewObj1( 'Less_Tree_Keyword', $s ); + $name[$k] = $this->NewObj( 'Less_Tree_Keyword', [ $s ] ); } else { - $name[$k] = $this->NewObj3( 'Less_Tree_Variable', array( '@' . substr( $s, 2, -1 ), $index[$k], $this->env->currentFileInfo ) ); + $name[$k] = $this->NewObj( 'Less_Tree_Variable', [ '@' . substr( $s, 2, -1 ), $index[$k], $this->env->currentFileInfo ] ); } } return $name; + } else { + $this->restore(); } - } - private function rulePropertyMatch( $re, &$offset, &$length, &$index, &$name ) { - preg_match( $re, $this->input, $a, 0, $offset ); - if ( $a ) { - $index[] = $this->pos + $length; - $length += strlen( $a[0] ); - $offset += strlen( $a[0] ); - $name[] = $a[1]; + private function rulePropertyMatch( $re, &$index, &$name ) { + $i = $this->pos; + $chunk = $this->MatchReg( $re ); + if ( $chunk ) { + $index[] = $i; + $name[] = $chunk[1]; return true; } } @@ -2529,15 +2617,16 @@ class Less_Parser { $s = ''; foreach ( $vars as $name => $value ) { - $s .= ( ( $name[0] === '@' ) ? '' : '@' ) . $name .': '. $value . ( ( substr( $value, -1 ) === ';' ) ? '' : ';' ); + $s .= ( ( $name[0] === '@' ) ? '' : '@' ) . $name . ': ' . $value . ( ( substr( $value, -1 ) === ';' ) ? '' : ';' ); } return $s; } /** - * Some versions of php have trouble with method_exists($a,$b) if $a is not an object + * Some versions of PHP have trouble with method_exists($a,$b) if $a is not an object * + * @param mixed $a * @param string $b */ public static function is_method( $a, $b ) { @@ -2547,11 +2636,10 @@ class Less_Parser { /** * Round numbers similarly to javascript * eg: 1.499999 to 1 instead of 2 - * */ - public static function round( $i, $precision = 0 ) { + public static function round( $input, $precision = 0 ) { $precision = pow( 10, $precision ); - $i = $i * $precision; + $i = $input * $precision; $ceil = ceil( $i ); $floor = floor( $i ); @@ -2563,83 +2651,32 @@ class Less_Parser { } /** - * Create Less_Tree_* objects and optionally generate a cache string + * Create a new instance of $class with args $args, and optionally generates a cache string. + * $class should be a Less_Tree_* class. * - * @return mixed + * @phan-template TClassName + * @phan-param class-string $class + * @phan-param array $args + * @phan-return TClassName + * + * @param string $class + * @param mixed[] $args + * @return Less_Tree Instance of $class subclass created with $args */ - public function NewObj0( $class ) { - $obj = new $class(); + public function NewObj( $class, $args = [] ) { + $obj = new $class( ...$args ); if ( $this->CacheEnabled() ) { - $obj->cache_string = ' new '.$class.'()'; + $argStrings = array_map( + [ __CLASS__, 'ArgString' ], + $args + ); + $argCache = implode( ',', $argStrings ); + // @phan-suppress-next-line PhanTypeExpectedObjectPropAccess False positive + $obj->cache_string = " new $class($argCache)"; } return $obj; } - public function NewObj1( $class, $arg ) { - $obj = new $class( $arg ); - if ( $this->CacheEnabled() ) { - $obj->cache_string = ' new '.$class.'('.Less_Parser::ArgString( $arg ).')'; - } - return $obj; - } - - public function NewObj2( $class, $args ) { - $obj = new $class( $args[0], $args[1] ); - if ( $this->CacheEnabled() ) { - $this->ObjCache( $obj, $class, $args ); - } - return $obj; - } - - public function NewObj3( $class, $args ) { - $obj = new $class( $args[0], $args[1], $args[2] ); - if ( $this->CacheEnabled() ) { - $this->ObjCache( $obj, $class, $args ); - } - return $obj; - } - - public function NewObj4( $class, $args ) { - $obj = new $class( $args[0], $args[1], $args[2], $args[3] ); - if ( $this->CacheEnabled() ) { - $this->ObjCache( $obj, $class, $args ); - } - return $obj; - } - - public function NewObj5( $class, $args ) { - $obj = new $class( $args[0], $args[1], $args[2], $args[3], $args[4] ); - if ( $this->CacheEnabled() ) { - $this->ObjCache( $obj, $class, $args ); - } - return $obj; - } - - public function NewObj6( $class, $args ) { - $obj = new $class( $args[0], $args[1], $args[2], $args[3], $args[4], $args[5] ); - if ( $this->CacheEnabled() ) { - $this->ObjCache( $obj, $class, $args ); - } - return $obj; - } - - public function NewObj7( $class, $args ) { - $obj = new $class( $args[0], $args[1], $args[2], $args[3], $args[4], $args[5], $args[6] ); - if ( $this->CacheEnabled() ) { - $this->ObjCache( $obj, $class, $args ); - } - return $obj; - } - - // caching - public function ObjCache( $obj, $class, $args = array() ) { - $obj->cache_string = ' new '.$class.'('. self::ArgCache( $args ).')'; - } - - public function ArgCache( $args ) { - return implode( ',', array_map( array( 'Less_Parser','ArgString' ), $args ) ); - } - /** * Convert an argument to a string for use in the parser cache * @@ -2656,7 +2693,7 @@ class Less_Parser { } elseif ( $type === 'array' ) { $string = ' Array('; foreach ( $arg as $k => $a ) { - $string .= var_export( $k, true ).' => '.self::ArgString( $a ).','; + $string .= var_export( $k, true ) . ' => ' . self::ArgString( $a ) . ','; } return $string . ')'; } @@ -2664,6 +2701,7 @@ class Less_Parser { return var_export( $arg, true ); } + /** @return never */ public function Error( $msg ) { throw new Less_Exception_Parser( $msg, null, $this->furthest, $this->env->currentFileInfo ); } @@ -2673,7 +2711,7 @@ class Less_Parser { } public static function AbsPath( $path, $winPath = false ) { - if ( strpos( $path, '//' ) !== false && preg_match( '_^(https?:)?//\\w+(\\.\\w+)+/\\w+_i', $path ) ) { + if ( strpos( $path, '//' ) !== false && preg_match( '/^(https?:)?\/\//i', $path ) ) { return $winPath ? '' : false; } else { $path = realpath( $path ); @@ -2685,7 +2723,7 @@ class Less_Parser { } public function CacheEnabled() { - return ( Less_Parser::$options['cache_method'] && ( Less_Cache::$cache_dir || ( Less_Parser::$options['cache_method'] == 'callback' ) ) ); + return ( self::$options['cache_method'] && ( Less_Cache::$cache_dir || ( self::$options['cache_method'] == 'callback' ) ) ); } } diff --git a/include/thirdparty/less.php/____4.0.0/bin/README.md b/include/thirdparty/less.php/README.md similarity index 100% rename from include/thirdparty/less.php/____4.0.0/bin/README.md rename to include/thirdparty/less.php/README.md diff --git a/include/thirdparty/less.php/____4.0.0/bin/SECURITY.md b/include/thirdparty/less.php/SECURITY.md similarity index 100% rename from include/thirdparty/less.php/____4.0.0/bin/SECURITY.md rename to include/thirdparty/less.php/SECURITY.md diff --git a/include/thirdparty/less.php/SourceMap/Base64VLQ.php b/include/thirdparty/less.php/SourceMap/Base64VLQ.php index 989a4ce..c27c6ed 100644 --- a/include/thirdparty/less.php/SourceMap/Base64VLQ.php +++ b/include/thirdparty/less.php/SourceMap/Base64VLQ.php @@ -1,31 +1,29 @@ 0, 'B' => 1, 'C' => 2, 'D' => 3, 'E' => 4, 'F' => 5, 'G' => 6, 'H' => 7,'I' => 8, 'J' => 9, 'K' => 10, 'L' => 11, 'M' => 12, 'N' => 13, 'O' => 14, 'P' => 15, 'Q' => 16, 'R' => 17, 'S' => 18, 'T' => 19, 'U' => 20, @@ -44,14 +42,14 @@ class Less_SourceMap_Base64VLQ { 'q' => 42, 'r' => 43, 's' => 44, 't' => 45, 'u' => 46, 'v' => 47, 'w' => 48, 'x' => 49, 'y' => 50, 'z' => 51, 0 => 52, 1 => 53, 2 => 54, 3 => 55, 4 => 56, 5 => 57, 6 => 58, 7 => 59, 8 => 60, 9 => 61, '+' => 62, '/' => 63, - ); + ]; /** * Integer to char map * * @var array */ - private $intToCharMap = array( + private $intToCharMap = [ 0 => 'A', 1 => 'B', 2 => 'C', 3 => 'D', 4 => 'E', 5 => 'F', 6 => 'G', 7 => 'H', 8 => 'I', 9 => 'J', 10 => 'K', 11 => 'L', 12 => 'M', 13 => 'N', 14 => 'O', 15 => 'P', 16 => 'Q', 17 => 'R', 18 => 'S', 19 => 'T', 20 => 'U', @@ -62,7 +60,7 @@ class Less_SourceMap_Base64VLQ { 49 => 'x', 50 => 'y', 51 => 'z', 52 => '0', 53 => '1', 54 => '2', 55 => '3', 56 => '4', 57 => '5', 58 => '6', 59 => '7', 60 => '8', 61 => '9', 62 => '+', 63 => '/', - ); + ]; /** * Constructor @@ -83,7 +81,7 @@ class Less_SourceMap_Base64VLQ { * 2 becomes 4 (100 binary), -2 becomes 5 (101 binary) * We generate the value for 32 bit machines, hence -2147483648 becomes 1, not 4294967297, * even on a 64 bit machine. - * @param string $aValue + * @param int $aValue */ public function toVLQSigned( $aValue ) { return 0xffffffff & ( $aValue < 0 ? ( ( -$aValue ) << 1 ) + 1 : ( $aValue << 1 ) + 0 ); @@ -98,7 +96,7 @@ class Less_SourceMap_Base64VLQ { * Hence * 1 becomes -2147483648 * even on a 64 bit machine. - * @param integer $aValue + * @param int $aValue */ public function fromVLQSigned( $aValue ) { return $aValue & 1 ? $this->zeroFill( ~$aValue + 2, 1 ) | ( -1 - 0x7fffffff ) : $this->zeroFill( $aValue, 1 ); @@ -107,7 +105,7 @@ class Less_SourceMap_Base64VLQ { /** * Return the base 64 VLQ encoded value. * - * @param string $aValue The value to encode + * @param int $aValue The value to encode * @return string The encoded value */ public function encode( $aValue ) { @@ -130,7 +128,7 @@ class Less_SourceMap_Base64VLQ { * Return the value decoded from base 64 VLQ. * * @param string $encoded The encoded value to decode - * @return integer The decoded value + * @return int The decoded value */ public function decode( $encoded ) { $vlq = 0; @@ -148,9 +146,9 @@ class Less_SourceMap_Base64VLQ { /** * Right shift with zero fill. * - * @param integer $a number to shift - * @param integer $b number of bits to shift - * @return integer + * @param int $a number to shift + * @param int $b number of bits to shift + * @return int */ public function zeroFill( $a, $b ) { return ( $a >= 0 ) ? ( $a >> $b ) : ( $a >> $b ) & ( PHP_INT_MAX >> ( $b - 1 ) ); @@ -159,13 +157,13 @@ class Less_SourceMap_Base64VLQ { /** * Encode single 6-bit digit as base64. * - * @param integer $number + * @param int $number * @return string * @throws Exception If the number is invalid */ public function base64Encode( $number ) { if ( $number < 0 || $number > 63 ) { - throw new Exception( sprintf( 'Invalid number "%s" given. Must be between 0 and 63.', $number ) ); + throw new Exception( sprintf( 'Invalid number "%s" given. Must be between 0 and 63.', (string)$number ) ); } return $this->intToCharMap[$number]; } @@ -174,7 +172,7 @@ class Less_SourceMap_Base64VLQ { * Decode single 6-bit digit from base64 * * @param string $char - * @return number + * @return int * @throws Exception If the number is invalid */ public function base64Decode( $char ) { diff --git a/include/thirdparty/less.php/SourceMap/Generator.php b/include/thirdparty/less.php/SourceMap/Generator.php index eded501..7da9609 100644 --- a/include/thirdparty/less.php/SourceMap/Generator.php +++ b/include/thirdparty/less.php/SourceMap/Generator.php @@ -1,10 +1,8 @@ '' - ); + ]; /** * The base64 VLQ encoder @@ -55,7 +53,7 @@ class Less_SourceMap_Generator extends Less_Configurable { * * @var array */ - protected $mappings = array(); + protected $mappings = []; /** * The root node @@ -69,23 +67,24 @@ class Less_SourceMap_Generator extends Less_Configurable { * * @var array */ - protected $contentsMap = array(); + protected $contentsMap = []; /** * File to content map * * @var array */ - protected $sources = array(); - protected $source_keys = array(); + protected $sources = []; + protected $source_keys = []; /** * Constructor * * @param Less_Tree_Ruleset $root The root node + * @param array $contentsMap * @param array $options Array of options */ - public function __construct( Less_Tree_Ruleset $root, $contentsMap, $options = array() ) { + public function __construct( Less_Tree_Ruleset $root, $contentsMap, $options = [] ) { $this->root = $root; $this->contentsMap = $contentsMap; $this->encoder = new Less_SourceMap_Base64VLQ(); @@ -182,20 +181,20 @@ class Less_SourceMap_Generator extends Less_Configurable { /** * Adds a mapping * - * @param integer $generatedLine The line number in generated file - * @param integer $generatedColumn The column number in generated file - * @param integer $originalLine The line number in original file - * @param integer $originalColumn The column number in original file - * @param string $sourceFile The original source file + * @param int $generatedLine The line number in generated file + * @param int $generatedColumn The column number in generated file + * @param int $originalLine The line number in original file + * @param int $originalColumn The column number in original file + * @param array $fileInfo The original source file */ public function addMapping( $generatedLine, $generatedColumn, $originalLine, $originalColumn, $fileInfo ) { - $this->mappings[] = array( + $this->mappings[] = [ 'generated_line' => $generatedLine, 'generated_column' => $generatedColumn, 'original_line' => $originalLine, 'original_column' => $originalColumn, 'source_file' => $fileInfo['currentUri'] - ); + ]; $this->sources[$fileInfo['currentUri']] = $fileInfo['filename']; } @@ -207,7 +206,7 @@ class Less_SourceMap_Generator extends Less_Configurable { * @see https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit# */ protected function generateJson() { - $sourceMap = array(); + $sourceMap = []; $mappings = $this->generateMappings(); // File version (always the first entry in the object) and must be a positive integer. @@ -226,13 +225,13 @@ class Less_SourceMap_Generator extends Less_Configurable { } // A list of original sources used by the 'mappings' entry. - $sourceMap['sources'] = array(); + $sourceMap['sources'] = []; foreach ( $this->sources as $source_uri => $source_filename ) { $sourceMap['sources'][] = $this->normalizeFilename( $source_filename ); } // A list of symbol names used by the 'mappings' entry. - $sourceMap['names'] = array(); + $sourceMap['names'] = []; // A string with the encoded mapping data. $sourceMap['mappings'] = $mappings; @@ -261,7 +260,7 @@ class Less_SourceMap_Generator extends Less_Configurable { if ( empty( $this->sources ) ) { return; } - $content = array(); + $content = []; foreach ( $this->sources as $sourceFile ) { $content[] = file_get_contents( $sourceFile ); } @@ -281,7 +280,7 @@ class Less_SourceMap_Generator extends Less_Configurable { $this->source_keys = array_flip( array_keys( $this->sources ) ); // group mappings by generated line number. - $groupedMap = $groupedMapEncoded = array(); + $groupedMap = $groupedMapEncoded = []; foreach ( $this->mappings as $m ) { $groupedMap[$m['generated_line']][] = $m; } @@ -294,7 +293,7 @@ class Less_SourceMap_Generator extends Less_Configurable { $groupedMapEncoded[] = ';'; } - $lineMapEncoded = array(); + $lineMapEncoded = []; $lastGeneratedColumn = 0; foreach ( $line_map as $m ) { @@ -330,7 +329,7 @@ class Less_SourceMap_Generator extends Less_Configurable { * Finds the index for the filename * * @param string $filename - * @return integer|false + * @return int|false */ protected function findFileIndex( $filename ) { return $this->source_keys[$filename]; @@ -339,6 +338,7 @@ class Less_SourceMap_Generator extends Less_Configurable { /** * fix windows paths * @param string $path + * @param bool $addEndSlash * @return string */ public function fixWindowsPath( $path, $addEndSlash = false ) { diff --git a/include/thirdparty/less.php/Tree.php b/include/thirdparty/less.php/Tree.php index 7b48e9a..f606b58 100644 --- a/include/thirdparty/less.php/Tree.php +++ b/include/thirdparty/less.php/Tree.php @@ -3,12 +3,18 @@ /** * Tree * - * @package Less - * @subpackage tree + * TODO: Callers often use `property_exists(, 'value')` to distinguish + * tree nodes that are considerd value-holding. Refactor this to move + * the 'value' property that most subclasses implement to there, and use + * something else (special value, method, or intermediate class?) to + * signal whether a subclass is considered value-holding. */ class Less_Tree { public $cache_string; + public $parensInOp = false; + public $extendOnEveryPath; + public $allExtends; public function toCSS() { $output = new Less_Output(); @@ -25,7 +31,12 @@ class Less_Tree { public function genCSS( $output ) { } + public function compile( $env ) { + return $this; + } + /** + * @param Less_Output $output * @param Less_Tree_Ruleset[] $rules */ public static function outputRuleset( $output, $rules ) { @@ -45,8 +56,8 @@ class Less_Tree { } // Non-compressed - $tabSetStr = "\n".str_repeat( Less_Parser::$options['indentation'], Less_Environment::$tabLevel - 1 ); - $tabRuleStr = $tabSetStr.Less_Parser::$options['indentation']; + $tabSetStr = "\n" . str_repeat( Less_Parser::$options['indentation'], Less_Environment::$tabLevel - 1 ); + $tabRuleStr = $tabSetStr . Less_Parser::$options['indentation']; $output->add( " {" ); for ( $i = 0; $i < $ruleCnt; $i++ ) { @@ -54,8 +65,7 @@ class Less_Tree { $rules[$i]->genCSS( $output ); } Less_Environment::$tabLevel--; - $output->add( $tabSetStr.'}' ); - + $output->add( $tabSetStr . '}' ); } public function accept( $visitor ) { @@ -64,6 +74,7 @@ class Less_Tree { public static function ReferencedArray( $rules ) { foreach ( $rules as $rule ) { if ( method_exists( $rule, 'markReferenced' ) ) { + // @phan-suppress-next-line PhanUndeclaredMethod $rule->markReferenced(); } } diff --git a/include/thirdparty/less.php/Tree/Alpha.php b/include/thirdparty/less.php/Tree/Alpha.php index cd38c91..bdf5dee 100644 --- a/include/thirdparty/less.php/Tree/Alpha.php +++ b/include/thirdparty/less.php/Tree/Alpha.php @@ -1,10 +1,6 @@ value = $value; @@ -25,7 +21,7 @@ class Less_Tree_Anonymous extends Less_Tree { $this->currentFileInfo = $currentFileInfo; } - public function compile() { + public function compile( $env ) { return new Less_Tree_Anonymous( $this->value, $this->index, $this->currentFileInfo, $this->mapLines ); } diff --git a/include/thirdparty/less.php/Tree/Assignment.php b/include/thirdparty/less.php/Tree/Assignment.php index 69c7a4e..1f939a1 100644 --- a/include/thirdparty/less.php/Tree/Assignment.php +++ b/include/thirdparty/less.php/Tree/Assignment.php @@ -1,10 +1,6 @@ args as $a ) { $args[] = $a->compile( $env ); } @@ -48,41 +44,44 @@ class Less_Tree_Call extends Less_Tree { switch ( $nameLC ) { case '%': $nameLC = '_percent'; - break; + break; case 'get-unit': $nameLC = 'getunit'; - break; + break; case 'data-uri': $nameLC = 'datauri'; - break; + break; case 'svg-gradient': $nameLC = 'svggradient'; - break; + break; } $result = null; if ( $nameLC === 'default' ) { $result = Less_Tree_DefaultFunc::compile(); - } else { - - if ( method_exists( 'Less_Functions', $nameLC ) ) { // 1. - try { - - $func = new Less_Functions( $env, $this->currentFileInfo ); - $result = call_user_func_array( array( $func,$nameLC ), $args ); - - } catch ( Exception $e ) { - throw new Less_Exception_Compiler( 'error evaluating function `' . $this->name . '` '.$e->getMessage().' index: '. $this->index ); - } + $func = null; + if ( method_exists( 'Less_Functions', $nameLC ) ) { + $functions = new Less_Functions( $env, $this->currentFileInfo ); + $func = [ $functions, $nameLC ]; } elseif ( isset( $env->functions[$nameLC] ) && is_callable( $env->functions[$nameLC] ) ) { + $func = $env->functions[$nameLC]; + } + // If the function name isn't known to LESS, output it unchanged as CSS. + if ( $func ) { try { - $result = call_user_func_array( $env->functions[$nameLC], $args ); + $result = call_user_func_array( $func, $args ); } catch ( Exception $e ) { - throw new Less_Exception_Compiler( 'error evaluating function `' . $this->name . '` '.$e->getMessage().' index: '. $this->index ); + // Preserve original trace, especially from custom functions. + // https://github.com/wikimedia/less.php/issues/38 + throw new Less_Exception_Compiler( + 'error evaluating function `' . $this->name . '` ' . $e->getMessage() + . ' index: ' . $this->index, + $e + ); } } } diff --git a/include/thirdparty/less.php/Tree/Color.php b/include/thirdparty/less.php/Tree/Color.php index b0f79db..427f47d 100644 --- a/include/thirdparty/less.php/Tree/Color.php +++ b/include/thirdparty/less.php/Tree/Color.php @@ -1,10 +1,6 @@ rgb = array(); + $this->rgb = []; if ( is_array( $rgb ) ) { $this->rgb = $rgb; - } else if ( strlen( $rgb ) == 6 ) { + } elseif ( strlen( $rgb ) == 6 ) { foreach ( str_split( $rgb, 2 ) as $c ) { $this->rgb[] = hexdec( $c ); } } else { foreach ( str_split( $rgb, 1 ) as $c ) { - $this->rgb[] = hexdec( $c.$c ); + $this->rgb[] = hexdec( $c . $c ); } } $this->alpha = is_numeric( $a ) ? $a : 1; } - public function compile() { - return $this; - } - public function luma() { $r = $this->rgb[0] / 255; $g = $this->rgb[1] / 255; @@ -73,7 +65,7 @@ class Less_Tree_Color extends Less_Tree { return 'transparent'; } - $values = array(); + $values = []; foreach ( $this->rgb as $c ) { $values[] = Less_Functions::clamp( round( $c ), 255 ); } @@ -89,7 +81,7 @@ class Less_Tree_Color extends Less_Tree { // Convert color to short format if ( $color[1] === $color[2] && $color[3] === $color[4] && $color[5] === $color[6] ) { - $color = '#'.$color[1] . $color[3] . $color[5]; + $color = '#' . $color[1] . $color[3] . $color[5]; } } @@ -108,7 +100,7 @@ class Less_Tree_Color extends Less_Tree { * @param string $op */ public function operate( $op, $other ) { - $rgb = array(); + $rgb = []; $alpha = $this->alpha * ( 1 - $other->alpha ) + $other->alpha; for ( $c = 0; $c < 3; $c++ ) { $rgb[$c] = Less_Functions::operate( $op, $this->rgb[$c], $other->rgb[$c] ); @@ -136,16 +128,19 @@ class Less_Tree_Color extends Less_Tree { $s = $l > 0.5 ? $d / ( 2 - $max - $min ) : $d / ( $max + $min ); switch ( $max ) { - case $r: $h = ( $g - $b ) / $d + ( $g < $b ? 6 : 0 ); -break; - case $g: $h = ( $b - $r ) / $d + 2; -break; - case $b: $h = ( $r - $g ) / $d + 4; -break; + case $r: + $h = ( $g - $b ) / $d + ( $g < $b ? 6 : 0 ); + break; + case $g: + $h = ( $b - $r ) / $d + 2; + break; + case $b: + $h = ( $r - $g ) / $d + 4; + break; } $h /= 6; } - return array( 'h' => $h * 360, 's' => $s, 'l' => $l, 'a' => $a ); + return [ 'h' => $h * 360, 's' => $s, 'l' => $l, 'a' => $a ]; } // Adapted from http://mjijackson.com/2008/02/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript @@ -170,16 +165,19 @@ break; $h = 0; if ( $max !== $min ) { switch ( $max ) { - case $r: $h = ( $g - $b ) / $d + ( $g < $b ? 6 : 0 ); -break; - case $g: $h = ( $b - $r ) / $d + 2; -break; - case $b: $h = ( $r - $g ) / $d + 4; -break; + case $r: + $h = ( $g - $b ) / $d + ( $g < $b ? 6 : 0 ); + break; + case $g: + $h = ( $b - $r ) / $d + 2; + break; + case $b: + $h = ( $r - $g ) / $d + 4; + break; } $h /= 6; } - return array( 'h' => $h * 360, 's' => $s, 'v' => $v, 'a' => $a ); + return [ 'h' => $h * 360, 's' => $s, 'v' => $v, 'a' => $a ]; } public function toARGB() { @@ -223,7 +221,7 @@ break; } if ( $keyword === 'transparent' ) { - return new Less_Tree_Color( array( 0, 0, 0 ), 0, true ); + return new Less_Tree_Color( [ 0, 0, 0 ], 0, true ); } } diff --git a/include/thirdparty/less.php/Tree/Comment.php b/include/thirdparty/less.php/Tree/Comment.php index c7e6c0f..b4dd68c 100644 --- a/include/thirdparty/less.php/Tree/Comment.php +++ b/include/thirdparty/less.php/Tree/Comment.php @@ -1,10 +1,6 @@ value = $value; - $this->silent = !!$silent; + $this->silent = (bool)$silent; $this->currentFileInfo = $currentFileInfo; } @@ -40,10 +36,6 @@ class Less_Tree_Comment extends Less_Tree { return $this->silent || $isReference || $isCompressed; } - public function compile() { - return $this; - } - public function markReferenced() { $this->isReferenced = true; } diff --git a/include/thirdparty/less.php/Tree/Condition.php b/include/thirdparty/less.php/Tree/Condition.php index 355de8c..5204e83 100644 --- a/include/thirdparty/less.php/Tree/Condition.php +++ b/include/thirdparty/less.php/Tree/Condition.php @@ -1,10 +1,6 @@ op ) { case 'and': $result = $a && $b; - break; + break; case 'or': $result = $a || $b; - break; + break; default: if ( Less_Parser::is_method( $a, 'compare' ) ) { @@ -53,17 +49,17 @@ class Less_Tree_Condition extends Less_Tree { switch ( $result ) { case -1: $result = $this->op === '<' || $this->op === '=<' || $this->op === '<='; - break; + break; - case 0: + case 0: $result = $this->op === '=' || $this->op === '>=' || $this->op === '=<' || $this->op === '<='; - break; + break; - case 1: + case 1: $result = $this->op === '>' || $this->op === '>='; - break; + break; } - break; + break; } return $this->negate ? !$result : $result; diff --git a/include/thirdparty/less.php/Tree/DefaultFunc.php b/include/thirdparty/less.php/Tree/DefaultFunc.php index 41b78b6..66f0008 100644 --- a/include/thirdparty/less.php/Tree/DefaultFunc.php +++ b/include/thirdparty/less.php/Tree/DefaultFunc.php @@ -1,10 +1,6 @@ unit = $unit; } elseif ( $unit ) { - $this->unit = new Less_Tree_Unit( array( $unit ) ); + $this->unit = new Less_Tree_Unit( [ $unit ] ); } else { $this->unit = new Less_Tree_Unit(); } @@ -28,12 +24,8 @@ class Less_Tree_Dimension extends Less_Tree { $this->unit = $visitor->visitObj( $this->unit ); } - public function compile() { - return $this; - } - public function toColor() { - return new Less_Tree_Color( array( $this->value, $this->value, $this->value ) ); + return new Less_Tree_Color( [ $this->value, $this->value, $this->value ] ); } /** @@ -41,7 +33,7 @@ class Less_Tree_Dimension extends Less_Tree { */ public function genCSS( $output ) { if ( Less_Parser::$options['strictUnits'] && !$this->unit->isSingular() ) { - throw new Less_Exception_Compiler( "Multiple units in dimension. Correct the units or use the unit function. Bad unit: ".$this->unit->toString() ); + throw new Less_Exception_Compiler( "Multiple units in dimension. Correct the units or use the unit function. Bad unit: " . $this->unit->toString() ); } $value = Less_Functions::fround( $this->value ); @@ -49,7 +41,7 @@ class Less_Tree_Dimension extends Less_Tree { if ( $value !== 0 && $value < 0.000001 && $value > -0.000001 ) { // would be output 1e-6 etc. - $strValue = number_format( $strValue, 10 ); + $strValue = number_format( (float)$strValue, 10 ); $strValue = preg_replace( '/\.?0+$/', '', $strValue ); } @@ -57,7 +49,7 @@ class Less_Tree_Dimension extends Less_Tree { // Zero values doesn't need a unit if ( $value === 0 && $this->unit->isLength() ) { $output->add( $strValue ); - return $strValue; + return; } // Float values doesn't need a leading zero @@ -146,7 +138,7 @@ class Less_Tree_Dimension extends Less_Tree { } public function unify() { - return $this->convertTo( array( 'length' => 'px', 'duration' => 's', 'angle' => 'rad' ) ); + return $this->convertTo( [ 'length' => 'px', 'duration' => 's', 'angle' => 'rad' ] ); } public function convertTo( $conversions ) { @@ -154,10 +146,10 @@ class Less_Tree_Dimension extends Less_Tree { $unit = clone $this->unit; if ( is_string( $conversions ) ) { - $derivedConversions = array(); + $derivedConversions = []; foreach ( Less_Tree_UnitConversions::$groups as $i ) { if ( isset( Less_Tree_UnitConversions::${$i}[$conversions] ) ) { - $derivedConversions = array( $i => $conversions ); + $derivedConversions = [ $i => $conversions ]; } } $conversions = $derivedConversions; diff --git a/include/thirdparty/less.php/Tree/Directive.php b/include/thirdparty/less.php/Tree/Directive.php index 6c6a94f..dfada84 100644 --- a/include/thirdparty/less.php/Tree/Directive.php +++ b/include/thirdparty/less.php/Tree/Directive.php @@ -1,10 +1,6 @@ value->genCSS( $output ); } if ( $this->rules ) { - Less_Tree::outputRuleset( $output, array( $this->rules ) ); + Less_Tree::outputRuleset( $output, [ $this->rules ] ); } else { $output->add( ';' ); } diff --git a/include/thirdparty/less.php/Tree/Element.php b/include/thirdparty/less.php/Tree/Element.php index 5e25bc0..11b9ce4 100644 --- a/include/thirdparty/less.php/Tree/Element.php +++ b/include/thirdparty/less.php/Tree/Element.php @@ -1,28 +1,34 @@ value = $value; $this->value_is_object = is_object( $value ); - if ( $combinator ) { - $this->combinator = $combinator; - } + // see less-2.5.3.js#Combinator + $this->combinator = $combinator ?? ''; + $this->combinatorIsEmptyOrWhitespace = ( $combinator === null || trim( $combinator ) === '' ); $this->index = $index; $this->currentFileInfo = $currentFileInfo; @@ -35,15 +41,12 @@ class Less_Tree_Element extends Less_Tree { } public function compile( $env ) { - if ( Less_Environment::$mixin_stack ) { - return new Less_Tree_Element( $this->combinator, ( $this->value_is_object ? $this->value->compile( $env ) : $this->value ), $this->index, $this->currentFileInfo ); - } - - if ( $this->value_is_object ) { - $this->value = $this->value->compile( $env ); - } - - return $this; + return new Less_Tree_Element( + $this->combinator, + ( $this->value_is_object ? $this->value->compile( $env ) : $this->value ), + $this->index, + $this->currentFileInfo + ); } /** diff --git a/include/thirdparty/less.php/Tree/Expression.php b/include/thirdparty/less.php/Tree/Expression.php index cf06315..8324141 100644 --- a/include/thirdparty/less.php/Tree/Expression.php +++ b/include/thirdparty/less.php/Tree/Expression.php @@ -1,16 +1,11 @@ 1 ) { - $ret = array(); + $ret = []; foreach ( $this->value as $e ) { $ret[] = $e->compile( $env ); } @@ -82,7 +77,7 @@ class Less_Tree_Expression extends Less_Tree { public function throwAwayComments() { if ( is_array( $this->value ) ) { - $new_value = array(); + $new_value = []; foreach ( $this->value as $v ) { if ( $v instanceof Less_Tree_Comment ) { continue; diff --git a/include/thirdparty/less.php/Tree/Extend.php b/include/thirdparty/less.php/Tree/Extend.php index 4dd3665..362e284 100644 --- a/include/thirdparty/less.php/Tree/Extend.php +++ b/include/thirdparty/less.php/Tree/Extend.php @@ -1,17 +1,13 @@ allowBefore = true; $this->allowAfter = true; - break; + break; default: $this->allowBefore = false; $this->allowAfter = false; - break; + break; } // This must use a string (instead of int) so that array_merge() // preserves keys on arrays that use IDs in their keys. $this->object_id = 'id_' . $i++; - $this->parent_ids = array( + $this->parent_ids = [ $this->object_id => true - ); + ]; } public function accept( $visitor ) { @@ -62,7 +58,7 @@ class Less_Tree_Extend extends Less_Tree { } public function findSelfSelectors( $selectors ) { - $selfElements = array(); + $selfElements = []; for ( $i = 0, $selectors_len = count( $selectors ); $i < $selectors_len; $i++ ) { $selectorElements = $selectors[$i]->elements; @@ -74,7 +70,7 @@ class Less_Tree_Extend extends Less_Tree { $selfElements = array_merge( $selfElements, $selectors[$i]->elements ); } - $this->selfSelectors = array( new Less_Tree_Selector( $selfElements ) ); + $this->selfSelectors = [ new Less_Tree_Selector( $selfElements ) ]; } } diff --git a/include/thirdparty/less.php/Tree/Import.php b/include/thirdparty/less.php/Tree/Import.php index ffdac64..fc5e81d 100644 --- a/include/thirdparty/less.php/Tree/Import.php +++ b/include/thirdparty/less.php/Tree/Import.php @@ -1,7 +1,6 @@ currentFileInfo = $currentFileInfo; if ( is_array( $options ) ) { - $this->options += array( 'inline' => false ); + $this->options += [ 'inline' => false ]; if ( isset( $this->options['less'] ) || $this->options['inline'] ) { $this->css = !isset( $this->options['less'] ) || !$this->options['less'] || $this->options['inline']; } else { $pathValue = $this->getPath(); - if ( $pathValue && preg_match( '/css([\?;].*)?$/', $pathValue ) ) { + // Leave any ".css" file imports as literals for the browser. + // Also leave any remote HTTP resources as literals regardless of whether + // they contain ".css" in their filename. + if ( $pathValue && preg_match( '/^(https?:)?\/\/|\.css$/i', $pathValue ) ) { $this->css = true; } } @@ -97,13 +98,17 @@ class Less_Tree_Import extends Less_Tree { } /** - * @return string + * @return string|null */ public function getPath() { if ( $this->path instanceof Less_Tree_Quoted ) { $path = $this->path->value; $path = ( isset( $this->css ) || preg_match( '/(\.[a-z]*$)|([\?;].*)$/', $path ) ) ? $path : $path . '.less'; - } else if ( $this->path instanceof Less_Tree_URL ) { + + // During the first pass, Less_Tree_URL may contain a Less_Tree_Variable (not yet expanded), + // and thus has no value property defined yet. Return null until we reach the next phase. + // https://github.com/wikimedia/less.php/issues/29 + } elseif ( $this->path instanceof Less_Tree_URL && !( $this->path->value instanceof Less_Tree_Variable ) ) { $path = $this->path->value->value; } else { return null; @@ -129,7 +134,7 @@ class Less_Tree_Import extends Less_Tree { $pathValue = $path->value; // Add the base path if the import is relative if ( $pathValue && Less_Environment::isPathRelative( $pathValue ) ) { - $path->value = $this->currentFileInfo['uri_root'].$pathValue; + $path->value = $this->currentFileInfo['uri_root'] . $pathValue; } } $path->value = Less_Environment::normalizePath( $path->value ); @@ -159,26 +164,27 @@ class Less_Tree_Import extends Less_Tree { // import once if ( $evald->skip( $full_path, $env ) ) { - return array(); + return []; } + '@phan-var string $full_path'; if ( $this->options['inline'] ) { // todo needs to reference css file not import //$contents = new Less_Tree_Anonymous($this->root, 0, array('filename'=>$this->importedFilename), true ); Less_Parser::AddParsedFile( $full_path ); - $contents = new Less_Tree_Anonymous( file_get_contents( $full_path ), 0, array(), true ); + $contents = new Less_Tree_Anonymous( file_get_contents( $full_path ), 0, [], true ); if ( $this->features ) { - return new Less_Tree_Media( array( $contents ), $this->features->value ); + return new Less_Tree_Media( [ $contents ], $this->features->value ); } - return array( $contents ); + return [ $contents ]; } // optional (need to be before "CSS" to support optional CSS imports. CSS should be checked only if empty($this->currentFileInfo)) if ( isset( $this->options['optional'] ) && $this->options['optional'] && !file_exists( $full_path ) && ( !$evald->css || !empty( $this->currentFileInfo ) ) ) { - return array(); + return []; } // css ? @@ -192,15 +198,13 @@ class Less_Tree_Import extends Less_Tree { /** * Using the import directories, get the full absolute path and uri of the import - * - * @param Less_Tree_Import $evald */ public function PathAndUri() { $evald_path = $this->getPath(); if ( $evald_path ) { - $import_dirs = array(); + $import_dirs = []; if ( Less_Environment::isPathRelative( $evald_path ) ) { // if the path is relative, the file should be in the current directory @@ -226,20 +230,20 @@ class Less_Tree_Import extends Less_Tree { list( $path, $uri ) = call_user_func( $rooturi, $evald_path ); if ( is_string( $path ) ) { $full_path = $path; - return array( $full_path, $uri ); + return [ $full_path, $uri ]; } } elseif ( !empty( $rootpath ) ) { - $path = rtrim( $rootpath, '/\\' ).'/'.ltrim( $evald_path, '/\\' ); + $path = rtrim( $rootpath, '/\\' ) . '/' . ltrim( $evald_path, '/\\' ); if ( file_exists( $path ) ) { $full_path = Less_Environment::normalizePath( $path ); - $uri = Less_Environment::normalizePath( dirname( $rooturi.$evald_path ) ); - return array( $full_path, $uri ); - } elseif ( file_exists( $path.'.less' ) ) { - $full_path = Less_Environment::normalizePath( $path.'.less' ); - $uri = Less_Environment::normalizePath( dirname( $rooturi.$evald_path.'.less' ) ); - return array( $full_path, $uri ); + $uri = Less_Environment::normalizePath( dirname( $rooturi . $evald_path ) ); + return [ $full_path, $uri ]; + } elseif ( file_exists( $path . '.less' ) ) { + $full_path = Less_Environment::normalizePath( $path . '.less' ); + $uri = Less_Environment::normalizePath( dirname( $rooturi . $evald_path . '.less' ) ); + return [ $full_path, $uri ]; } } } @@ -249,6 +253,9 @@ class Less_Tree_Import extends Less_Tree { /** * Parse the import url and return the rules * + * @param string $full_path + * @param string|null $uri + * @param mixed $env * @return Less_Tree_Media|array */ public function ParseImport( $full_path, $uri, $env ) { @@ -264,7 +271,7 @@ class Less_Tree_Import extends Less_Tree { $parser = new Less_Parser( $import_env ); $root = $parser->parseFile( $full_path, $uri, true ); - $ruleset = new Less_Tree_Ruleset( array(), $root->rules ); + $ruleset = new Less_Tree_Ruleset( null, $root->rules ); $ruleset->evalImports( $import_env ); return $this->features ? new Less_Tree_Media( $ruleset->rules, $this->features->value ) : $ruleset->rules; @@ -273,9 +280,11 @@ class Less_Tree_Import extends Less_Tree { /** * Should the import be skipped? * - * @return boolean|null + * @param string|null $path + * @param Less_Environment $env + * @return bool|null */ - private function Skip( $path, $env ) { + private function skip( $path, $env ) { $path = Less_Parser::AbsPath( $path, true ); if ( $path && Less_Parser::FileParsed( $path ) ) { @@ -286,6 +295,5 @@ class Less_Tree_Import extends Less_Tree { return !isset( $this->options['multiple'] ) && !$env->importMultiple; } - } } diff --git a/include/thirdparty/less.php/Tree/Javascript.php b/include/thirdparty/less.php/Tree/Javascript.php index 179781a..218d481 100644 --- a/include/thirdparty/less.php/Tree/Javascript.php +++ b/include/thirdparty/less.php/Tree/Javascript.php @@ -1,10 +1,6 @@ escaped = $escaped; @@ -23,7 +19,7 @@ class Less_Tree_Javascript extends Less_Tree { $this->index = $index; } - public function compile() { + public function compile( $env ) { return new Less_Tree_Anonymous( '/* Sorry, can not do JavaScript evaluation in PHP... :( */' ); } diff --git a/include/thirdparty/less.php/Tree/Keyword.php b/include/thirdparty/less.php/Tree/Keyword.php index ed217cf..60663f0 100644 --- a/include/thirdparty/less.php/Tree/Keyword.php +++ b/include/thirdparty/less.php/Tree/Keyword.php @@ -1,10 +1,6 @@ value = $value; } - public function compile() { - return $this; - } - /** * @see Less_Tree::genCSS */ diff --git a/include/thirdparty/less.php/Tree/Media.php b/include/thirdparty/less.php/Tree/Media.php index ba25a67..3cb1fc4 100644 --- a/include/thirdparty/less.php/Tree/Media.php +++ b/include/thirdparty/less.php/Tree/Media.php @@ -1,10 +1,6 @@ index = $index; $this->currentFileInfo = $currentFileInfo; @@ -23,7 +19,7 @@ class Less_Tree_Media extends Less_Tree { $this->features = new Less_Tree_Value( $features ); - $this->rules = array( new Less_Tree_Ruleset( $selectors, $value ) ); + $this->rules = [ new Less_Tree_Ruleset( $selectors, $value ) ]; $this->rules[0]->allowImports = true; } @@ -39,11 +35,15 @@ class Less_Tree_Media extends Less_Tree { $output->add( '@media ', $this->currentFileInfo, $this->index ); $this->features->genCSS( $output ); Less_Tree::outputRuleset( $output, $this->rules ); - } + /** + * @param Less_Environment $env + * @return Less_Tree_Media|Less_Tree_Ruleset + * @see less-2.5.3.js#Media.prototype.eval + */ public function compile( $env ) { - $media = new Less_Tree_Media( array(), array(), $this->index, $this->currentFileInfo ); + $media = new Less_Tree_Media( [], [], $this->index, $this->currentFileInfo ); $strictMathBypass = false; if ( Less_Parser::$options['strictMath'] === false ) { @@ -61,7 +61,7 @@ class Less_Tree_Media extends Less_Tree { $env->mediaBlocks[] = $media; array_unshift( $env->frames, $this->rules[0] ); - $media->rules = array( $this->rules[0]->compile( $env ) ); + $media->rules = [ $this->rules[0]->compile( $env ) ]; array_shift( $env->frames ); array_pop( $env->mediaPath ); @@ -79,7 +79,7 @@ class Less_Tree_Media extends Less_Tree { public function emptySelectors() { $el = new Less_Tree_Element( '', '&', $this->index, $this->currentFileInfo ); - $sels = array( new Less_Tree_Selector( array( $el ), array(), null, $this->index, $this->currentFileInfo ) ); + $sels = [ new Less_Tree_Selector( [ $el ], [], null, $this->index, $this->currentFileInfo ) ]; $sels[0]->mediaEmpty = true; return $sels; } @@ -100,20 +100,26 @@ class Less_Tree_Media extends Less_Tree { $result->multiMedia = true; } - $env->mediaBlocks = array(); - $env->mediaPath = array(); + $env->mediaBlocks = []; + $env->mediaPath = []; return $result; } + /** + * @param Less_Environment $env + * @return Less_Tree_Ruleset + */ public function compileNested( $env ) { - $path = array_merge( $env->mediaPath, array( $this ) ); + $path = array_merge( $env->mediaPath, [ $this ] ); + '@phan-var array $path'; // Extract the media-query conditions separated with `,` (OR). foreach ( $path as $key => $p ) { $value = $p->features instanceof Less_Tree_Value ? $p->features->value : $p->features; - $path[$key] = is_array( $value ) ? $value : array( $value ); + $path[$key] = is_array( $value ) ? $value : [ $value ]; } + '@phan-var array> $path'; // Trace all permutations to generate the resulting media-query. // @@ -124,7 +130,7 @@ class Less_Tree_Media extends Less_Tree { // b and c and e $permuted = $this->permute( $path ); - $expressions = array(); + $expressions = []; foreach ( $permuted as $path ) { for ( $i = 0, $len = count( $path ); $i < $len; $i++ ) { @@ -132,7 +138,7 @@ class Less_Tree_Media extends Less_Tree { } for ( $i = count( $path ) - 1; $i > 0; $i-- ) { - array_splice( $path, $i, 0, array( new Less_Tree_Anonymous( 'and' ) ) ); + array_splice( $path, $i, 0, [ new Less_Tree_Anonymous( 'and' ) ] ); } $expressions[] = new Less_Tree_Expression( $path ); @@ -140,23 +146,25 @@ class Less_Tree_Media extends Less_Tree { $this->features = new Less_Tree_Value( $expressions ); // Fake a tree-node that doesn't output anything. - return new Less_Tree_Ruleset( array(), array() ); + return new Less_Tree_Ruleset( [], [] ); } public function permute( $arr ) { - if ( !$arr ) - return array(); + if ( !$arr ) { + return []; + } - if ( count( $arr ) == 1 ) + if ( count( $arr ) == 1 ) { return $arr[0]; + } - $result = array(); + $result = []; $rest = $this->permute( array_slice( $arr, 1 ) ); foreach ( $rest as $r ) { foreach ( $arr[0] as $a ) { $result[] = array_merge( - is_array( $a ) ? $a : array( $a ), - is_array( $r ) ? $r : array( $r ) + is_array( $a ) ? $a : [ $a ], + is_array( $r ) ? $r : [ $r ] ); } } @@ -165,9 +173,11 @@ class Less_Tree_Media extends Less_Tree { } public function bubbleSelectors( $selectors ) { - if ( !$selectors ) return; + if ( !$selectors ) { + return; + } - $this->rules = array( new Less_Tree_Ruleset( $selectors, array( $this->rules[0] ) ) ); + $this->rules = [ new Less_Tree_Ruleset( $selectors, [ $this->rules[0] ] ) ]; } } diff --git a/include/thirdparty/less.php/Tree/Mixin/Call.php b/include/thirdparty/less.php/Tree/Mixin/Call.php index 8e1eece..61e10fe 100644 --- a/include/thirdparty/less.php/Tree/Mixin/Call.php +++ b/include/thirdparty/less.php/Tree/Mixin/Call.php @@ -1,5 +1,7 @@ arguments as $a ) { - $args[] = array( 'name' => $a['name'], 'value' => $a['value']->compile( $env ) ); + $args[] = [ 'name' => $a['name'], 'value' => $a['value']->compile( $env ) ]; } foreach ( $env->frames as $frame ) { @@ -68,14 +70,17 @@ class Less_Tree_Mixin_Call extends Less_Tree { if ( $mixin->matchArgs( $args, $env ) ) { - $candidate = array( 'mixin' => $mixin, 'group' => $defNone ); + $candidate = [ 'mixin' => $mixin, 'group' => $defNone ]; if ( $mixin instanceof Less_Tree_Ruleset ) { - for ( $f = 0; $f < 2; $f++ ) { Less_Tree_DefaultFunc::value( $f ); $conditionResult[$f] = $mixin->matchCondition( $args, $env ); } + + // PhanTypeInvalidDimOffset -- False positive + '@phan-var array{0:bool,1:bool} $conditionResult'; + if ( $conditionResult[0] || $conditionResult[1] ) { if ( $conditionResult[0] != $conditionResult[1] ) { $candidate['group'] = $conditionResult[1] ? $defTrue : $defFalse; @@ -93,7 +98,7 @@ class Less_Tree_Mixin_Call extends Less_Tree { Less_Tree_DefaultFunc::reset(); - $count = array( 0, 0, 0 ); + $count = [ 0, 0, 0 ]; for ( $m = 0; $m < count( $candidates ); $m++ ) { $count[ $candidates[$m]['group'] ]++; } @@ -116,7 +121,7 @@ class Less_Tree_Mixin_Call extends Less_Tree { try{ $mixin = $candidates[$m]['mixin']; if ( !( $mixin instanceof Less_Tree_Mixin_Definition ) ) { - $mixin = new Less_Tree_Mixin_Definition( '', array(), $mixin->rules, null, false ); + $mixin = new Less_Tree_Mixin_Definition( '', [], $mixin->rules, null, false ); $mixin->originalRuleset = $mixins[$m]->originalRuleset; } $rules = array_merge( $rules, $mixin->evalCall( $env, $args, $this->important )->rules ); @@ -137,12 +142,11 @@ class Less_Tree_Mixin_Call extends Less_Tree { } if ( $isOneFound ) { - throw new Less_Exception_Compiler( 'No matching definition was found for `'.$this->Format( $args ).'`', null, $this->index, $this->currentFileInfo ); + throw new Less_Exception_Compiler( 'No matching definition was found for `' . $this->Format( $args ) . '`', null, $this->index, $this->currentFileInfo ); } else { - throw new Less_Exception_Compiler( trim( $this->selector->toCSS() ) . " is undefined in ".$this->currentFileInfo['filename'], null, $this->index ); + throw new Less_Exception_Compiler( trim( $this->selector->toCSS() ) . " is undefined in " . $this->currentFileInfo['filename'], null, $this->index ); } - } /** @@ -150,7 +154,7 @@ class Less_Tree_Mixin_Call extends Less_Tree { * */ private function Format( $args ) { - $message = array(); + $message = []; if ( $args ) { foreach ( $args as $a ) { $argValue = ''; diff --git a/include/thirdparty/less.php/Tree/Mixin/Definition.php b/include/thirdparty/less.php/Tree/Mixin/Definition.php index f9f2eb4..08bcd7a 100644 --- a/include/thirdparty/less.php/Tree/Mixin/Definition.php +++ b/include/thirdparty/less.php/Tree/Mixin/Definition.php @@ -1,22 +1,24 @@ name = $name; - $this->selectors = array( new Less_Tree_Selector( array( new Less_Tree_Element( null, $name ) ) ) ); + $this->selectors = [ new Less_Tree_Selector( [ new Less_Tree_Element( null, $name ) ] ) ]; $this->params = $params; $this->condition = $condition; @@ -47,8 +49,8 @@ class Less_Tree_Mixin_Definition extends Less_Tree_Ruleset { } // less.js : /lib/less/tree/mixin.js : tree.mixin.Definition.evalParams - public function compileParams( $env, $mixinFrames, $args = array(), &$evaldArguments = array() ) { - $frame = new Less_Tree_Ruleset( null, array() ); + public function compileParams( $env, $mixinFrames, $args = [], &$evaldArguments = [] ) { + $frame = new Less_Tree_Ruleset( null, [] ); $params = $this->params; $mixinEnv = null; $argsLength = 0; @@ -75,7 +77,7 @@ class Less_Tree_Mixin_Definition extends Less_Tree_Ruleset { $argsLength--; continue; } else { - throw new Less_Exception_Compiler( "Named argument for " . $this->name .' '.$args[$i]['name'] . ' not found' ); + throw new Less_Exception_Compiler( "Named argument for " . $this->name . ' ' . $args[$i]['name'] . ' not found' ); } } } @@ -95,7 +97,7 @@ class Less_Tree_Mixin_Definition extends Less_Tree_Ruleset { if ( isset( $param['name'] ) && $param['name'] ) { if ( isset( $param['variadic'] ) ) { - $varargs = array(); + $varargs = []; for ( $j = $argIndex; $j < $argsLength; $j++ ) { $varargs[] = $args[$j]['value']->compile( $env ); } @@ -106,11 +108,11 @@ class Less_Tree_Mixin_Definition extends Less_Tree_Ruleset { if ( $val ) { $val = $val->compile( $env ); - } else if ( isset( $param['value'] ) ) { + } elseif ( isset( $param['value'] ) ) { if ( !$mixinEnv ) { $mixinEnv = new Less_Environment(); - $mixinEnv->frames = array_merge( array( $frame ), $mixinFrames ); + $mixinEnv->frames = array_merge( [ $frame ], $mixinFrames ); } $val = $param['value']->compile( $mixinEnv ); @@ -145,10 +147,10 @@ class Less_Tree_Mixin_Definition extends Less_Tree_Ruleset { return new Less_Tree_Mixin_Definition( $this->name, $this->params, $this->rules, $this->condition, $this->variadic, $env->frames ); } - public function evalCall( $env, $args = NULL, $important = NULL ) { + public function evalCall( $env, $args = null, $important = null ) { Less_Environment::$mixin_stack++; - $_arguments = array(); + $_arguments = []; if ( $this->frames ) { $mixinFrames = array_merge( $this->frames, $env->frames ); @@ -165,7 +167,7 @@ class Less_Tree_Mixin_Definition extends Less_Tree_Ruleset { $ruleset->originalRuleset = $this->ruleset_id; $ruleSetEnv = new Less_Environment(); - $ruleSetEnv->frames = array_merge( array( $this, $frame ), $mixinFrames ); + $ruleSetEnv->frames = array_merge( [ $this, $frame ], $mixinFrames ); $ruleset = $ruleset->compile( $ruleSetEnv ); if ( $important ) { @@ -177,6 +179,7 @@ class Less_Tree_Mixin_Definition extends Less_Tree_Ruleset { return $ruleset; } + /** @return bool */ public function matchCondition( $args, $env ) { if ( !$this->condition ) { return true; @@ -184,14 +187,14 @@ class Less_Tree_Mixin_Definition extends Less_Tree_Ruleset { // set array to prevent error on array_merge if ( !is_array( $this->frames ) ) { - $this->frames = array(); + $this->frames = []; } $frame = $this->compileParams( $env, array_merge( $this->frames, $env->frames ), $args ); $compile_env = new Less_Environment(); $compile_env->frames = array_merge( - array( $frame ), // the parameter variables + [ $frame ], // the parameter variables $this->frames, // the parent namespace/mixin frames $env->frames // the current environment frames ); @@ -201,7 +204,7 @@ class Less_Tree_Mixin_Definition extends Less_Tree_Ruleset { return (bool)$this->condition->compile( $compile_env ); } - public function matchArgs( $args, $env = NULL ) { + public function matchArgs( $args, $env = null ) { $argsLength = count( $args ); if ( !$this->variadic ) { diff --git a/include/thirdparty/less.php/Tree/NameValue.php b/include/thirdparty/less.php/Tree/NameValue.php index 4f9aa97..88a2296 100644 --- a/include/thirdparty/less.php/Tree/NameValue.php +++ b/include/thirdparty/less.php/Tree/NameValue.php @@ -1,14 +1,14 @@ color:#FF0000; + * In bootstrap, there are about 600-1000 simple name-value pairs (depending on + * how forgiving the match is) -vs- 6,020 dynamic rules (Less_Tree_Rule). * - * @package Less - * @subpackage tree + * Using the name-value object can speed up bootstrap compilation slightly, but + * it breaks color keyword interpretation: `color: red` -> `color: #FF0000`. + * + * @private */ class Less_Tree_NameValue extends Less_Tree { diff --git a/include/thirdparty/less.php/Tree/Negative.php b/include/thirdparty/less.php/Tree/Negative.php index f0f36c8..516f1ee 100644 --- a/include/thirdparty/less.php/Tree/Negative.php +++ b/include/thirdparty/less.php/Tree/Negative.php @@ -1,10 +1,6 @@ value ) ); + $ret = new Less_Tree_Operation( '*', [ new Less_Tree_Dimension( -1 ), $this->value ] ); return $ret->compile( $env ); } return new Less_Tree_Negative( $this->value->compile( $env ) ); diff --git a/include/thirdparty/less.php/Tree/Operation.php b/include/thirdparty/less.php/Tree/Operation.php index d4eb9ac..4d79dc0 100644 --- a/include/thirdparty/less.php/Tree/Operation.php +++ b/include/thirdparty/less.php/Tree/Operation.php @@ -1,10 +1,6 @@ operate( $this->op, $b ); } - return new Less_Tree_Operation( $this->op, array( $a, $b ), $this->isSpaced ); + return new Less_Tree_Operation( $this->op, [ $a, $b ], $this->isSpaced ); } /** diff --git a/include/thirdparty/less.php/Tree/Paren.php b/include/thirdparty/less.php/Tree/Paren.php index 77ee48c..d659b84 100644 --- a/include/thirdparty/less.php/Tree/Paren.php +++ b/include/thirdparty/less.php/Tree/Paren.php @@ -1,16 +1,16 @@ value = $value; } diff --git a/include/thirdparty/less.php/Tree/Quoted.php b/include/thirdparty/less.php/Tree/Quoted.php index d01598b..0c5e190 100644 --- a/include/thirdparty/less.php/Tree/Quoted.php +++ b/include/thirdparty/less.php/Tree/Quoted.php @@ -1,10 +1,6 @@ value, $matches ) ) { foreach ( $matches as $i => $match ) { $js = new Less_Tree_JavaScript( $matches[1], $this->index, true ); - $js = $js->compile()->value; + $js = $js->compile( $env )->value; $value = str_replace( $matches[0][$i], $js, $value ); } } diff --git a/include/thirdparty/less.php/Tree/Rule.php b/include/thirdparty/less.php/Tree/Rule.php index 5f393eb..842ad0c 100644 --- a/include/thirdparty/less.php/Tree/Rule.php +++ b/include/thirdparty/less.php/Tree/Rule.php @@ -1,14 +1,11 @@ name = $name; - $this->value = ( $value instanceof Less_Tree_Value || $value instanceof Less_Tree_Ruleset ) ? $value : new Less_Tree_Value( array( $value ) ); + $this->value = ( $value instanceof Less_Tree ) + ? $value + : new Less_Tree_Value( [ $value ] ); $this->important = $important ? ' ' . trim( $important ) : ''; $this->merge = $merge; $this->index = $index; @@ -52,6 +51,10 @@ class Less_Tree_Rule extends Less_Tree { $output->add( $this->important . ( ( $this->inline || ( Less_Environment::$lastRule && Less_Parser::$options['compress'] ) ) ? "" : ";" ), $this->currentFileInfo, $this->index ); } + /** + * @param Less_Environment $env + * @return Less_Tree_Rule + */ public function compile( $env ) { $name = $this->name; if ( is_array( $name ) ) { @@ -84,7 +87,7 @@ class Less_Tree_Rule extends Less_Tree { $return = $this; } - }catch ( Less_Exception_Parser $e ) { + } catch ( Less_Exception_Parser $e ) { if ( !is_numeric( $e->index ) ) { $e->index = $this->index; $e->currentFile = $this->currentFileInfo; diff --git a/include/thirdparty/less.php/Tree/Ruleset.php b/include/thirdparty/less.php/Tree/Ruleset.php index 9bc8243..7acc6af 100644 --- a/include/thirdparty/less.php/Tree/Ruleset.php +++ b/include/thirdparty/less.php/Tree/Ruleset.php @@ -1,10 +1,6 @@ selectors = $selectors; $this->rules = $rules; - $this->lookups = array(); + $this->lookups = []; $this->strictImports = $strictImports; $this->SetRulesetIndex(); } public function accept( $visitor ) { - if ( $this->paths ) { + if ( $this->paths !== null ) { $paths_len = count( $this->paths ); - for ( $i = 0,$paths_len; $i < $paths_len; $i++ ) { + for ( $i = 0; $i < $paths_len; $i++ ) { $this->paths[$i] = $visitor->visitArray( $this->paths[$i] ); } } elseif ( $this->selectors ) { @@ -65,6 +66,11 @@ class Less_Tree_Ruleset extends Less_Tree { } } + /** + * @param Less_Environment $env + * @return Less_Tree_Ruleset + * @see less-2.5.3.js#Ruleset.prototype.eval + */ public function compile( $env ) { $ruleset = $this->PrepareRuleset( $env ); @@ -72,15 +78,13 @@ class Less_Tree_Ruleset extends Less_Tree { // so they can be evaluated like closures when the time comes. $rsRuleCnt = count( $ruleset->rules ); for ( $i = 0; $i < $rsRuleCnt; $i++ ) { + // These checks are the equivalent of the rule.evalFirst property in less.js if ( $ruleset->rules[$i] instanceof Less_Tree_Mixin_Definition || $ruleset->rules[$i] instanceof Less_Tree_DetachedRuleset ) { $ruleset->rules[$i] = $ruleset->rules[$i]->compile( $env ); } } - $mediaBlockCount = 0; - if ( $env instanceof Less_Environment ) { - $mediaBlockCount = count( $env->mediaBlocks ); - } + $mediaBlockCount = count( $env->mediaBlocks ); // Evaluate mixin calls. $this->EvalMixinCalls( $ruleset, $env, $rsRuleCnt ); @@ -107,7 +111,7 @@ class Less_Tree_Ruleset extends Less_Tree { for ( $j = 0; $j < count( $rule->rules ); $j++ ) { $subRule = $rule->rules[$j]; if ( !( $subRule instanceof Less_Tree_Rule ) || !$subRule->variable ) { - array_splice( $ruleset->rules, ++$i, 0, array( $subRule ) ); + array_splice( $ruleset->rules, ++$i, 0, [ $subRule ] ); $rsRuleCnt++; } } @@ -133,7 +137,7 @@ class Less_Tree_Ruleset extends Less_Tree { * Compile Less_Tree_Mixin_Call objects * * @param Less_Tree_Ruleset $ruleset - * @param integer $rsRuleCnt + * @param int $rsRuleCnt */ private function EvalMixinCalls( $ruleset, $env, &$rsRuleCnt ) { for ( $i = 0; $i < $rsRuleCnt; $i++ ) { @@ -142,7 +146,7 @@ class Less_Tree_Ruleset extends Less_Tree { if ( $rule instanceof Less_Tree_Mixin_Call ) { $rule = $rule->compile( $env ); - $temp = array(); + $temp = []; foreach ( $rule as $r ) { if ( ( $r instanceof Less_Tree_Rule ) && $r->variable ) { // do not pollute the scope if the variable is @@ -164,7 +168,7 @@ class Less_Tree_Ruleset extends Less_Tree { } elseif ( $rule instanceof Less_Tree_RulesetCall ) { $rule = $rule->compile( $env ); - $rules = array(); + $rules = []; foreach ( $rule->rules as $r ) { if ( ( $r instanceof Less_Tree_Rule ) && $r->variable ) { continue; @@ -185,14 +189,21 @@ class Less_Tree_Ruleset extends Less_Tree { /** * Compile the selectors and create a new ruleset object for the compile() method * + * @param Less_Environment $env + * @return Less_Tree_Ruleset */ private function PrepareRuleset( $env ) { + // NOTE: Preserve distinction between null and empty array when compiling + // $this->selectors to $selectors + $thisSelectors = $this->selectors; + $selectors = null; $hasOnePassingSelector = false; - $selectors = array(); - if ( $this->selectors ) { + + if ( $thisSelectors ) { Less_Tree_DefaultFunc::error( "it is currently only allowed in parametric mixin guards," ); - foreach ( $this->selectors as $s ) { + $selectors = []; + foreach ( $thisSelectors as $s ) { $selector = $s->compile( $env ); $selectors[] = $selector; if ( $selector->evaldCondition ) { @@ -206,15 +217,15 @@ class Less_Tree_Ruleset extends Less_Tree { } if ( $this->rules && $hasOnePassingSelector ) { + // Copy the array (no need for slice in PHP) $rules = $this->rules; } else { - $rules = array(); + $rules = []; } $ruleset = new Less_Tree_Ruleset( $selectors, $rules, $this->strictImports ); $ruleset->originalRuleset = $this->ruleset_id; - $ruleset->root = $this->root; $ruleset->firstRoot = $this->firstRoot; $ruleset->allowImports = $this->allowImports; @@ -243,7 +254,7 @@ class Less_Tree_Ruleset extends Less_Tree { $i += $temp_count; $rules_len += $temp_count; } else { - array_splice( $this->rules, $i, 1, array( $rules ) ); + array_splice( $this->rules, $i, 1, [ $rules ] ); } $this->resetCache(); @@ -252,7 +263,7 @@ class Less_Tree_Ruleset extends Less_Tree { } function makeImportant() { - $important_rules = array(); + $important_rules = []; foreach ( $this->rules as $rule ) { if ( $rule instanceof Less_Tree_Rule || $rule instanceof Less_Tree_Ruleset || $rule instanceof Less_Tree_NameValue ) { $important_rules[] = $rule->makeImportant(); @@ -264,7 +275,7 @@ class Less_Tree_Ruleset extends Less_Tree { return new Less_Tree_Ruleset( $this->selectors, $important_rules, $this->strictImports ); } - public function matchArgs( $args ) { + public function matchArgs( $args, $env = null ) { return !$args; } @@ -284,11 +295,11 @@ class Less_Tree_Ruleset extends Less_Tree { function resetCache() { $this->_rulesets = null; $this->_variables = null; - $this->lookups = array(); + $this->lookups = []; } public function variables() { - $this->_variables = array(); + $this->_variables = []; foreach ( $this->rules as $r ) { if ( $r instanceof Less_Tree_Rule && $r->variable === true ) { $this->_variables[$r->name] = $r; @@ -296,11 +307,15 @@ class Less_Tree_Ruleset extends Less_Tree { } } + /** + * @param string $name + * @return Less_Tree_Rule|null + */ public function variable( $name ) { - if ( is_null( $this->_variables ) ) { + if ( $this->_variables === null ) { $this->variables(); } - return isset( $this->_variables[$name] ) ? $this->_variables[$name] : null; + return $this->_variables[$name] ?? null; } public function find( $selector, $self = null ) { @@ -312,7 +327,7 @@ class Less_Tree_Ruleset extends Less_Tree { $self = $this->ruleset_id; } - $this->lookups[$key] = array(); + $this->lookups[$key] = []; $first_oelement = $selector->_oelements[0]; @@ -351,19 +366,24 @@ class Less_Tree_Ruleset extends Less_Tree { $tabRuleStr = $tabSetStr = ''; if ( !Less_Parser::$options['compress'] ) { if ( Less_Environment::$tabLevel ) { - $tabRuleStr = "\n".str_repeat( Less_Parser::$options['indentation'], Less_Environment::$tabLevel ); - $tabSetStr = "\n".str_repeat( Less_Parser::$options['indentation'], Less_Environment::$tabLevel - 1 ); + $tabRuleStr = "\n" . str_repeat( Less_Parser::$options['indentation'], Less_Environment::$tabLevel ); + $tabSetStr = "\n" . str_repeat( Less_Parser::$options['indentation'], Less_Environment::$tabLevel - 1 ); } else { $tabSetStr = $tabRuleStr = "\n"; } } - $ruleNodes = array(); - $rulesetNodes = array(); + $ruleNodes = []; + $rulesetNodes = []; foreach ( $this->rules as $rule ) { $class = get_class( $rule ); - if ( ( $class === 'Less_Tree_Media' ) || ( $class === 'Less_Tree_Directive' ) || ( $this->root && $class === 'Less_Tree_Comment' ) || ( $class === 'Less_Tree_Ruleset' && $rule->rules ) ) { + if ( + ( $class === 'Less_Tree_Media' ) || + ( $class === 'Less_Tree_Directive' ) || + ( $this->root && $class === 'Less_Tree_Comment' ) || + ( $rule instanceof Less_Tree_Ruleset && $rule->rules ) + ) { $rulesetNodes[] = $rule; } else { $ruleNodes[] = $rule; @@ -373,16 +393,6 @@ class Less_Tree_Ruleset extends Less_Tree { // If this is the root node, we don't render // a selector, or {}. if ( !$this->root ) { - - /* - debugInfo = tree.debugInfo(env, this, tabSetStr); - - if (debugInfo) { - output.add(debugInfo); - output.add(tabSetStr); - } - */ - $paths_len = count( $this->paths ); for ( $i = 0; $i < $paths_len; $i++ ) { $path = $this->paths[$i]; @@ -443,7 +453,6 @@ class Less_Tree_Ruleset extends Less_Tree { if ( !Less_Parser::$options['compress'] && $this->firstRoot ) { $output->add( "\n" ); } - } function markReferenced() { @@ -455,9 +464,14 @@ class Less_Tree_Ruleset extends Less_Tree { } } + /** + * @param Less_Tree_Selector[][] $context + * @param Less_Tree_Selector[]|null $selectors + * @return Less_Tree_Selector[][] + */ public function joinSelectors( $context, $selectors ) { - $paths = array(); - if ( is_array( $selectors ) ) { + $paths = []; + if ( $selectors !== null ) { foreach ( $selectors as $selector ) { $this->joinSelector( $paths, $context, $selector ); } @@ -465,26 +479,37 @@ class Less_Tree_Ruleset extends Less_Tree { return $paths; } - public function joinSelector( &$paths, $context, $selector ) { - $hasParentSelector = false; + public function joinSelector( array &$paths, array $context, Less_Tree_Selector $selector ) { + $newPaths = []; + $hadParentSelector = $this->replaceParentSelector( $newPaths, $context, $selector ); - foreach ( $selector->elements as $el ) { - if ( $el->value === '&' ) { - $hasParentSelector = true; - } - } - - if ( !$hasParentSelector ) { + if ( !$hadParentSelector ) { if ( $context ) { - foreach ( $context as $context_el ) { - $paths[] = array_merge( $context_el, array( $selector ) ); + $newPaths = []; + foreach ( $context as $path ) { + $newPaths[] = array_merge( $path, [ $selector ] ); } } else { - $paths[] = array( $selector ); + $newPaths = [ [ $selector ] ]; } - return; } + foreach ( $newPaths as $newPath ) { + $paths[] = $newPath; + } + } + + /** + * Replace all parent selectors inside $inSelector with $context. + * + * @param array &$paths Resulting selectors are appended to $paths. + * @param mixed $context + * @param Less_Tree_Selector $inSelector Inner selector from Less_Tree_Paren + * @return bool True if $inSelector contained at least one parent selector + */ + private function replaceParentSelector( array &$paths, $context, Less_Tree_Selector $inSelector ) { + $hadParentSelector = false; + // The paths are [[Selector]] // The first list is a list of comma separated selectors // The inner list is a list of inheritance separated selectors @@ -497,86 +522,70 @@ class Less_Tree_Ruleset extends Less_Tree { // // the elements from the current selector so far - $currentElements = array(); + $currentElements = []; // the current list of new selectors to add to the path. // We will build it up. We initiate it with one empty selector as we "multiply" the new selectors // by the parents - $newSelectors = array( array() ); + $newSelectors = [ + [] + ]; - foreach ( $selector->elements as $el ) { - - // non parent reference elements just get added + foreach ( $inSelector->elements as $el ) { + // non-parent reference elements just get added if ( $el->value !== '&' ) { - $currentElements[] = $el; + $nestedSelector = $this->findNestedSelector( $el ); + if ( $nestedSelector !== null ) { + $this->mergeElementsOnToSelectors( $currentElements, $newSelectors ); + + $nestedPaths = []; + $replacedNewSelectors = []; + $replaced = $this->replaceParentSelector( $nestedPaths, $context, $nestedSelector ); + $hadParentSelector = $hadParentSelector || $replaced; + // $nestedPaths is populated by replaceParentSelector() + // $nestedPaths should have exactly one TODO, replaceParentSelector does not multiply selectors + foreach ( $nestedPaths as $nestedPath ) { + $replacementSelector = $this->createSelector( $nestedPath, $el ); + + // join selector path from $newSelectors with every selector path in $addPaths array. + // $el contains the element that is being replaced by $addPaths + // + // @see less-2.5.3.js#Ruleset-addAllReplacementsIntoPath + $addPaths = [ $replacementSelector ]; + foreach ( $newSelectors as $newSelector ) { + $replacedNewSelectors[] = $this->addReplacementIntoPath( $newSelector, $addPaths, $el, $inSelector ); + } + } + $newSelectors = $replacedNewSelectors; + $currentElements = []; + } else { + $currentElements[] = $el; + } } else { + $hadParentSelector = true; + // the new list of selectors to add - $selectorsMultiplied = array(); + $selectorsMultiplied = []; // merge the current list of non parent selector elements // on to the current list of selectors to add - if ( $currentElements ) { - $this->mergeElementsOnToSelectors( $currentElements, $newSelectors ); - } + $this->mergeElementsOnToSelectors( $currentElements, $newSelectors ); - // loop through our current selectors foreach ( $newSelectors as $sel ) { - // if we don't have any parent paths, the & might be in a mixin so that it can be used // whether there are parents or not if ( !$context ) { // the combinator used on el should now be applied to the next element instead so that // it is not lost if ( $sel ) { - $sel[0]->elements = array_slice( $sel[0]->elements, 0 ); $sel[0]->elements[] = new Less_Tree_Element( $el->combinator, '', $el->index, $el->currentFileInfo ); } $selectorsMultiplied[] = $sel; } else { - // and the parent selectors foreach ( $context as $parentSel ) { // We need to put the current selectors // then join the last selector's elements on to the parents selectors - - // our new selector path - $newSelectorPath = array(); - // selectors from the parent after the join - $afterParentJoin = array(); - $newJoinedSelectorEmpty = true; - - // construct the joined selector - if & is the first thing this will be empty, - // if not newJoinedSelector will be the last set of elements in the selector - if ( $sel ) { - $newSelectorPath = $sel; - $lastSelector = array_pop( $newSelectorPath ); - $newJoinedSelector = $selector->createDerived( array_slice( $lastSelector->elements, 0 ) ); - $newJoinedSelectorEmpty = false; - } else { - $newJoinedSelector = $selector->createDerived( array() ); - } - - // put together the parent selectors after the join - if ( count( $parentSel ) > 1 ) { - $afterParentJoin = array_merge( $afterParentJoin, array_slice( $parentSel, 1 ) ); - } - - if ( $parentSel ) { - $newJoinedSelectorEmpty = false; - - // join the elements so far with the first part of the parent - $newJoinedSelector->elements[] = new Less_Tree_Element( $el->combinator, $parentSel[0]->elements[0]->value, $el->index, $el->currentFileInfo ); - - $newJoinedSelector->elements = array_merge( $newJoinedSelector->elements, array_slice( $parentSel[0]->elements, 1 ) ); - } - - if ( !$newJoinedSelectorEmpty ) { - // now add the joined selector - $newSelectorPath[] = $newJoinedSelector; - } - - // and the rest of the parent - $newSelectorPath = array_merge( $newSelectorPath, $afterParentJoin ); - + $newSelectorPath = $this->addReplacementIntoPath( $sel, $parentSel, $el, $inSelector ); // add that to our new set of selectors $selectorsMultiplied[] = $newSelectorPath; } @@ -585,30 +594,130 @@ class Less_Tree_Ruleset extends Less_Tree { // our new selectors has been multiplied, so reset the state $newSelectors = $selectorsMultiplied; - $currentElements = array(); + $currentElements = []; } } // if we have any elements left over (e.g. .a& .b == .b) // add them on to all the current selectors - if ( $currentElements ) { - $this->mergeElementsOnToSelectors( $currentElements, $newSelectors ); - } - foreach ( $newSelectors as $new_sel ) { - if ( $new_sel ) { - $paths[] = $new_sel; + $this->mergeElementsOnToSelectors( $currentElements, $newSelectors ); + + foreach ( $newSelectors as &$sel ) { + $length = count( $sel ); + if ( $length ) { + $paths[] = $sel; + $lastSelector = $sel[$length - 1]; + $sel[$length - 1] = $lastSelector->createDerived( $lastSelector->elements, $inSelector->extendList ); } } + + return $hadParentSelector; + } + + /** + * @param array $elementsToPak + * @param Less_Tree_Element $originalElement + * @return Less_Tree_Selector + */ + private function createSelector( array $elementsToPak, $originalElement ) { + if ( !$elementsToPak ) { + // This is an invalid call. Kept to match less.js. Appears unreachable. + // @phan-suppress-next-line PhanTypeMismatchArgumentProbablyReal + $containedElement = new Less_Tree_Paren( null ); + } else { + $insideParent = []; + foreach ( $elementsToPak as $elToPak ) { + $insideParent[] = new Less_Tree_Element( null, $elToPak, $originalElement->index, $originalElement->currentFileInfo ); + } + $containedElement = new Less_Tree_Paren( new Less_Tree_Selector( $insideParent ) ); + } + + $element = new Less_Tree_Element( null, $containedElement, $originalElement->index, $originalElement->currentFileInfo ); + return new Less_Tree_Selector( [ $element ] ); + } + + /** + * @param Less_Tree_Element $element + * @return Less_Tree_Selector|null + */ + private function findNestedSelector( $element ) { + $maybeParen = $element->value; + if ( !( $maybeParen instanceof Less_Tree_Paren ) ) { + return null; + } + $maybeSelector = $maybeParen->value; + if ( !( $maybeSelector instanceof Less_Tree_Selector ) ) { + return null; + } + return $maybeSelector; + } + + /** + * joins selector path from $beginningPath with selector path in $addPath. + * + * $replacedElement contains the element that is being replaced by $addPath + * + * @param Less_Tree_Selector[] $beginningPath + * @param Less_Tree_Selector[] $addPath + * @param Less_Tree_Element $replacedElement + * @param Less_Tree_Selector $originalSelector + * @return Less_Tree_Selector[] Concatenated path + * @see less-2.5.3.js#Ruleset-addReplacementIntoPath + */ + private function addReplacementIntoPath( array $beginningPath, array $addPath, $replacedElement, $originalSelector ) { + // our new selector path + $newSelectorPath = []; + + // construct the joined selector - if `&` is the first thing this will be empty, + // if not newJoinedSelector will be the last set of elements in the selector + if ( $beginningPath ) { + // NOTE: less.js uses Array slice() to copy. In PHP, arrays are naturally copied by value. + $newSelectorPath = $beginningPath; + $lastSelector = array_pop( $newSelectorPath ); + $newJoinedSelector = $originalSelector->createDerived( $lastSelector->elements ); + } else { + $newJoinedSelector = $originalSelector->createDerived( [] ); + } + + if ( $addPath ) { + // if the & does not have a combinator that is "" or " " then + // and there is a combinator on the parent, then grab that. + // this also allows `+ a { & .b { .a & { ...` + $combinator = $replacedElement->combinator; + $parentEl = $addPath[0]->elements[0]; + if ( $replacedElement->combinatorIsEmptyOrWhitespace && !$parentEl->combinatorIsEmptyOrWhitespace ) { + $combinator = $parentEl->combinator; + } + // join the elements so far with the first part of the parent + $newJoinedSelector->elements[] = new Less_Tree_Element( $combinator, $parentEl->value, $replacedElement->index, $replacedElement->currentFileInfo ); + $newJoinedSelector->elements = array_merge( + $newJoinedSelector->elements, + array_slice( $addPath[0]->elements, 1 ) + ); + } + + // now add the joined selector - but only if it is not empty + if ( $newJoinedSelector->elements ) { + $newSelectorPath[] = $newJoinedSelector; + } + + // put together the parent selectors after the join (e.g. the rest of the parent) + if ( count( $addPath ) > 1 ) { + $newSelectorPath = array_merge( $newSelectorPath, array_slice( $addPath, 1 ) ); + } + return $newSelectorPath; } function mergeElementsOnToSelectors( $elements, &$selectors ) { + if ( !$elements ) { + return; + } if ( !$selectors ) { - $selectors[] = array( new Less_Tree_Selector( $elements ) ); + $selectors[] = [ new Less_Tree_Selector( $elements ) ]; return; } foreach ( $selectors as &$sel ) { - // if the previous thing in sel is a parent this needs to join on to it if ( $sel ) { $last = count( $sel ) - 1; diff --git a/include/thirdparty/less.php/Tree/RulesetCall.php b/include/thirdparty/less.php/Tree/RulesetCall.php index 079ff4f..9c162b8 100644 --- a/include/thirdparty/less.php/Tree/RulesetCall.php +++ b/include/thirdparty/less.php/Tree/RulesetCall.php @@ -1,16 +1,15 @@ variable = $variable; } @@ -21,6 +20,7 @@ class Less_Tree_RulesetCall extends Less_Tree { public function compile( $env ) { $variable = new Less_Tree_Variable( $this->variable ); $detachedRuleset = $variable->compile( $env ); + '@phan-var Less_Tree_DetachedRuleset $detachedRuleset'; return $detachedRuleset->callEval( $env ); } } diff --git a/include/thirdparty/less.php/Tree/Selector.php b/include/thirdparty/less.php/Tree/Selector.php index 7ecfc6a..71182da 100644 --- a/include/thirdparty/less.php/Tree/Selector.php +++ b/include/thirdparty/less.php/Tree/Selector.php @@ -1,21 +1,17 @@ elements = $elements; $this->elements_len = count( $elements ); $this->extendList = $extendList; @@ -58,8 +54,16 @@ class Less_Tree_Selector extends Less_Tree { } public function createDerived( $elements, $extendList = null, $evaldCondition = null ) { - $newSelector = new Less_Tree_Selector( $elements, ( $extendList ? $extendList : $this->extendList ), null, $this->index, $this->currentFileInfo, $this->isReferenced ); - $newSelector->evaldCondition = $evaldCondition ? $evaldCondition : $this->evaldCondition; + $newSelector = new Less_Tree_Selector( + $elements, + ( $extendList ?: $this->extendList ), + null, + $this->index, + $this->currentFileInfo, + $this->isReferenced + ); + $newSelector->evaldCondition = $evaldCondition ?: $this->evaldCondition; + $newSelector->mediaEmpty = $this->mediaEmpty; return $newSelector; } @@ -78,8 +82,8 @@ class Less_Tree_Selector extends Less_Tree { } public function CacheElements() { - $this->_oelements = array(); - $this->_oelements_assoc = array(); + $this->_oelements = []; + $this->_oelements_assoc = []; $css = ''; @@ -119,12 +123,12 @@ class Less_Tree_Selector extends Less_Tree { } public function compile( $env ) { - $elements = array(); + $elements = []; foreach ( $this->elements as $el ) { $elements[] = $el->compile( $env ); } - $extendList = array(); + $extendList = []; foreach ( $this->extendList as $el ) { $extendList[] = $el->compile( $el ); } diff --git a/include/thirdparty/less.php/Tree/UnicodeDescriptor.php b/include/thirdparty/less.php/Tree/UnicodeDescriptor.php index 38e0526..304d191 100644 --- a/include/thirdparty/less.php/Tree/UnicodeDescriptor.php +++ b/include/thirdparty/less.php/Tree/UnicodeDescriptor.php @@ -1,10 +1,6 @@ add( $this->value ); } - - public function compile() { - return $this; - } } diff --git a/include/thirdparty/less.php/Tree/Unit.php b/include/thirdparty/less.php/Tree/Unit.php index 29230df..2fd8927 100644 --- a/include/thirdparty/less.php/Tree/Unit.php +++ b/include/thirdparty/less.php/Tree/Unit.php @@ -1,19 +1,15 @@ numerator = $numerator; $this->denominator = $denominator; $this->backupUnit = $backupUnit; @@ -39,7 +35,7 @@ class Less_Tree_Unit extends Less_Tree { public function toString() { $returnStr = implode( '*', $this->numerator ); foreach ( $this->denominator as $d ) { - $returnStr .= '/'.$d; + $returnStr .= '/' . $d; } return $returnStr; } @@ -61,7 +57,7 @@ class Less_Tree_Unit extends Less_Tree { public function isLength() { $css = $this->toCSS(); - return !!preg_match( '/px|em|%|in|cm|mm|pc|pt|ex/', $css ); + return (bool)preg_match( '/px|em|%|in|cm|mm|pc|pt|ex/', $css ); } public function isAngle() { @@ -77,7 +73,7 @@ class Less_Tree_Unit extends Less_Tree { } public function usedUnits() { - $result = array(); + $result = []; foreach ( Less_Tree_UnitConversions::$groups as $groupName ) { $group = Less_Tree_UnitConversions::${$groupName}; @@ -99,25 +95,25 @@ class Less_Tree_Unit extends Less_Tree { } public function cancel() { - $counter = array(); + $counter = []; $backup = null; foreach ( $this->numerator as $atomicUnit ) { if ( !$backup ) { $backup = $atomicUnit; } - $counter[$atomicUnit] = ( isset( $counter[$atomicUnit] ) ? $counter[$atomicUnit] : 0 ) + 1; + $counter[$atomicUnit] = ( $counter[$atomicUnit] ?? 0 ) + 1; } foreach ( $this->denominator as $atomicUnit ) { if ( !$backup ) { $backup = $atomicUnit; } - $counter[$atomicUnit] = ( isset( $counter[$atomicUnit] ) ? $counter[$atomicUnit] : 0 ) - 1; + $counter[$atomicUnit] = ( $counter[$atomicUnit] ?? 0 ) - 1; } - $this->numerator = array(); - $this->denominator = array(); + $this->numerator = []; + $this->denominator = []; foreach ( $counter as $atomicUnit => $count ) { if ( $count > 0 ) { diff --git a/include/thirdparty/less.php/Tree/UnitConversions.php b/include/thirdparty/less.php/Tree/UnitConversions.php index 7f857fb..31efe1c 100644 --- a/include/thirdparty/less.php/Tree/UnitConversions.php +++ b/include/thirdparty/less.php/Tree/UnitConversions.php @@ -1,16 +1,12 @@ 1, 'cm' => 0.01, 'mm' => 0.001, @@ -18,18 +14,18 @@ class Less_Tree_UnitConversions { 'px' => 0.000264583, // 0.0254 / 96, 'pt' => 0.000352778, // 0.0254 / 72, 'pc' => 0.004233333, // 0.0254 / 72 * 12 - ); + ]; - public static $duration = array( + public static $duration = [ 's' => 1, 'ms' => 0.001 - ); + ]; - public static $angle = array( + public static $angle = [ 'rad' => 0.1591549430919, // 1/(2*M_PI), 'deg' => 0.002777778, // 1/360, 'grad' => 0.0025, // 1/400, 'turn' => 1 - ); + ]; } diff --git a/include/thirdparty/less.php/Tree/Url.php b/include/thirdparty/less.php/Tree/Url.php index 4e7f114..6ae3518 100644 --- a/include/thirdparty/less.php/Tree/Url.php +++ b/include/thirdparty/less.php/Tree/Url.php @@ -1,10 +1,6 @@ value = $value; $this->currentFileInfo = $currentFileInfo; @@ -34,7 +35,7 @@ class Less_Tree_Url extends Less_Tree { } /** - * @param Less_Functions $ctx + * @param Less_Environment $ctx */ public function compile( $ctx ) { $val = $this->value->compile( $ctx ); diff --git a/include/thirdparty/less.php/Tree/Value.php b/include/thirdparty/less.php/Tree/Value.php index a4c0d85..bf45caf 100644 --- a/include/thirdparty/less.php/Tree/Value.php +++ b/include/thirdparty/less.php/Tree/Value.php @@ -1,16 +1,15 @@ $value + */ public function __construct( $value ) { $this->value = $value; } @@ -20,7 +19,7 @@ class Less_Tree_Value extends Less_Tree { } public function compile( $env ) { - $ret = array(); + $ret = []; $i = 0; foreach ( $this->value as $i => $v ) { $ret[] = $v->compile( $env ); diff --git a/include/thirdparty/less.php/Tree/Variable.php b/include/thirdparty/less.php/Tree/Variable.php index e36d3d4..dcb1823 100644 --- a/include/thirdparty/less.php/Tree/Variable.php +++ b/include/thirdparty/less.php/Tree/Variable.php @@ -1,10 +1,6 @@ currentFileInfo = $currentFileInfo; } + /** + * @param Less_Environment $env + * @return Less_Tree + * @see less-2.5.3.js#Ruleset.prototype.eval + */ public function compile( $env ) { if ( $this->name[1] === '@' ) { $v = new Less_Tree_Variable( substr( $this->name, 1 ), $this->index + 1, $this->currentFileInfo ); + // While some Less_Tree nodes have no 'value', we know these can't ocurr after a variable + // assignment (would have been a ParseError). + // TODO: Solve better (https://phabricator.wikimedia.org/T327082). + // @phan-suppress-next-line PhanUndeclaredProperty $name = '@' . $v->compile( $env )->value; } else { $name = $this->name; @@ -45,7 +50,7 @@ class Less_Tree_Variable extends Less_Tree { } } - throw new Less_Exception_Compiler( "variable " . $name . " is undefined in file ".$this->currentFileInfo["filename"], null, $this->index, $this->currentFileInfo ); + throw new Less_Exception_Compiler( "variable " . $name . " is undefined in file " . $this->currentFileInfo["filename"], null, $this->index, $this->currentFileInfo ); } } diff --git a/include/thirdparty/less.php/Version.php b/include/thirdparty/less.php/Version.php index 2d05c38..1c96e8e 100644 --- a/include/thirdparty/less.php/Version.php +++ b/include/thirdparty/less.php/Version.php @@ -2,13 +2,10 @@ /** * Release numbers - * - * @package Less - * @subpackage version */ class Less_Version { - public const version = '3.1.0'; // The current build number of less.php + public const version = '3.2.1'; // The current build number of less.php public const less_version = '2.5.3'; // The less.js version that this build should be compatible with public const cache_version = '253'; // The parser cache version diff --git a/include/thirdparty/less.php/Visitor.php b/include/thirdparty/less.php/Visitor.php index 4aed540..582f323 100644 --- a/include/thirdparty/less.php/Visitor.php +++ b/include/thirdparty/less.php/Visitor.php @@ -1,15 +1,11 @@ _visitFnCache = get_class_methods( get_class( $this ) ); @@ -17,7 +13,7 @@ class Less_Visitor { } public function visitObj( $node ) { - $funcName = 'visit'.$node->type; + $funcName = 'visit' . $node->type; if ( isset( $this->_visitFnCache[$funcName] ) ) { $visitDeeper = true; @@ -27,7 +23,7 @@ class Less_Visitor { $node->accept( $this ); } - $funcName = $funcName . "Out"; + $funcName .= "Out"; if ( isset( $this->_visitFnCache[$funcName] ) ) { $this->$funcName( $node ); } @@ -40,7 +36,9 @@ class Less_Visitor { } public function visitArray( $nodes ) { - array_map( array( $this,'visitObj' ), $nodes ); + foreach ( $nodes as $node ) { + $this->visitObj( $node ); + } return $nodes; } } diff --git a/include/thirdparty/less.php/Visitor/extendFinder.php b/include/thirdparty/less.php/Visitor/extendFinder.php index 7d5d3fd..8b3238d 100644 --- a/include/thirdparty/less.php/Visitor/extendFinder.php +++ b/include/thirdparty/less.php/Visitor/extendFinder.php @@ -1,20 +1,16 @@ contexts = array(); - $this->allExtendsStack = array( array() ); + $this->contexts = []; + $this->allExtendsStack = [ [] ]; parent::__construct(); } @@ -40,7 +36,7 @@ class Less_Visitor_extendFinder extends Less_Visitor { return; } - $allSelectorsExtendList = array(); + $allSelectorsExtendList = []; // get &:extend(.a); rules which apply to all selectors in this ruleset if ( $rulesetNode->rules ) { @@ -90,7 +86,7 @@ class Less_Visitor_extendFinder extends Less_Visitor { } public function visitMedia( $mediaNode ) { - $mediaNode->allExtends = array(); + $mediaNode->allExtends = []; $this->allExtendsStack[] =& $mediaNode->allExtends; } @@ -99,7 +95,7 @@ class Less_Visitor_extendFinder extends Less_Visitor { } public function visitDirective( $directiveNode ) { - $directiveNode->allExtends = array(); + $directiveNode->allExtends = []; $this->allExtendsStack[] =& $directiveNode->allExtends; } diff --git a/include/thirdparty/less.php/Visitor/joinSelector.php b/include/thirdparty/less.php/Visitor/joinSelector.php index bb08ece..a106830 100644 --- a/include/thirdparty/less.php/Visitor/joinSelector.php +++ b/include/thirdparty/less.php/Visitor/joinSelector.php @@ -1,14 +1,10 @@ contexts ); + $paths = []; if ( !$rulesetNode->root ) { - $selectors = array(); - - if ( $rulesetNode->selectors && $rulesetNode->selectors ) { - foreach ( $rulesetNode->selectors as $selector ) { + $selectors = $rulesetNode->selectors; + if ( $selectors !== null ) { + $filtered = []; + foreach ( $selectors as $selector ) { if ( $selector->getIsOutput() ) { - $selectors[] = $selector; + $filtered[] = $selector; } } + $selectors = $rulesetNode->selectors = $filtered ?: null; + if ( $selectors ) { + $paths = $rulesetNode->joinSelectors( $context, $selectors ); + } } - if ( !$selectors ) { - $rulesetNode->selectors = null; + if ( $selectors === null ) { $rulesetNode->rules = null; - } else { - $context = end( $this->contexts ); // $context = $this->contexts[ count($this->contexts) - 1]; - $paths = $rulesetNode->joinSelectors( $context, $selectors ); } $rulesetNode->paths = $paths; } - $this->contexts[] = $paths; // different from less.js. Placed after joinSelectors() so that $this->contexts will get correct $paths + // NOTE: Assigned here instead of at the start like less.js, + // because PHP arrays aren't by-ref + $this->contexts[] = $paths; } public function visitRulesetOut() { @@ -58,9 +57,9 @@ class Less_Visitor_joinSelector extends Less_Visitor { } public function visitMedia( $mediaNode ) { - $context = end( $this->contexts ); // $context = $this->contexts[ count($this->contexts) - 1]; + $context = end( $this->contexts ); - if ( !count( $context ) || ( is_object( $context[0] ) && $context[0]->multiMedia ) ) { + if ( count( $context ) === 0 || ( is_object( $context[0] ) && $context[0]->multiMedia ) ) { $mediaNode->rules[0]->root = true; } } diff --git a/include/thirdparty/less.php/Visitor/processExtends.php b/include/thirdparty/less.php/Visitor/processExtends.php index 65082a4..9491f3c 100644 --- a/include/thirdparty/less.php/Visitor/processExtends.php +++ b/include/thirdparty/less.php/Visitor/processExtends.php @@ -1,10 +1,6 @@ allExtends = $this->doExtendChaining( $root->allExtends, $root->allExtends ); - $this->allExtendsStack = array(); + $this->allExtendsStack = []; $this->allExtendsStack[] = &$root->allExtends; return $this->visitObj( $root ); @@ -38,7 +34,7 @@ class Less_Visitor_processExtends extends Less_Visitor { // this is also the most expensive.. and a match on one selector can cause an extension of a selector we had already processed if // we look at each selector at a time, as is done in visitRuleset - $extendsToAdd = array(); + $extendsToAdd = []; // loop through comparing every extend with every target extend. // a target extend is the one on the ruleset we are looking at copy/edit/pasting in place @@ -52,14 +48,14 @@ class Less_Visitor_processExtends extends Less_Visitor { $extend = $extendsList[$extendIndex]; $targetExtend = $extendsListTarget[$targetExtendIndex]; - // Optimisation: Explicit reference,  + // Optimisation: Explicit reference, if ( \array_key_exists( $targetExtend->object_id, $extend->parent_ids ) ) { // ignore circular references continue; } // find a match in the target extends self selector (the bit before :extend) - $selectorPath = array( $targetExtend->selfSelectors[0] ); + $selectorPath = [ $targetExtend->selfSelectors[0] ]; $matches = $this->findMatch( $extend, $selectorPath ); if ( $matches ) { @@ -75,7 +71,7 @@ class Less_Visitor_processExtends extends Less_Visitor { $newExtend->selfSelectors = $newSelector; // add the extend onto the list of extends for that selector - end( $newSelector )->extendList = array( $newExtend ); + end( $newSelector )->extendList = [ $newExtend ]; // $newSelector[ count($newSelector)-1]->extendList = array($newExtend); // record that we need to add it. @@ -171,6 +167,11 @@ class Less_Visitor_processExtends extends Less_Visitor { } } + /** + * @param Less_Tree_Extend $extend + * @param Less_Tree_Selector[] $haystackSelectorPath + * @return false|array + */ private function findMatch( $extend, $haystackSelectorPath ) { if ( !$this->HasMatches( $extend, $haystackSelectorPath ) ) { return false; @@ -181,10 +182,10 @@ class Less_Visitor_processExtends extends Less_Visitor { // returns an array of selector matches that can then be replaced // $needleElements = $extend->selector->elements; - $potentialMatches = array(); + $potentialMatches = []; $potentialMatches_len = 0; $potentialMatch = null; - $matches = array(); + $matches = []; // loop through the haystack elements $haystack_path_len = count( $haystackSelectorPath ); @@ -198,7 +199,7 @@ class Less_Visitor_processExtends extends Less_Visitor { // if we allow elements before our match we can add a potential match every time. otherwise only at the first element. if ( $extend->allowBefore || ( $haystackSelectorIndex === 0 && $hackstackElementIndex === 0 ) ) { - $potentialMatches[] = array( 'pathIndex' => $haystackSelectorIndex, 'index' => $hackstackElementIndex, 'matched' => 0, 'initialCombinator' => $haystackElement->combinator ); + $potentialMatches[] = [ 'pathIndex' => $haystackSelectorIndex, 'index' => $hackstackElementIndex, 'matched' => 0, 'initialCombinator' => $haystackElement->combinator ]; $potentialMatches_len++; } @@ -222,7 +223,7 @@ class Less_Visitor_processExtends extends Less_Visitor { $potentialMatch['length'] = $extend->selector->elements_len; $potentialMatch['endPathIndex'] = $haystackSelectorIndex; $potentialMatch['endPathElementIndex'] = $hackstackElementIndex + 1; // index after end of match - $potentialMatches = array(); // we don't allow matches to overlap, so start matching again + $potentialMatches = []; // we don't allow matches to overlap, so start matching again $potentialMatches_len = 0; $matches[] = $potentialMatch; } @@ -253,7 +254,7 @@ class Less_Visitor_processExtends extends Less_Visitor { return true; } - // Optimisation: Explicit reference,  + // Optimisation: Explicit reference, if ( \array_key_exists( $first_el, $hackstackSelector->_oelements_assoc ) ) { return true; } @@ -263,7 +264,7 @@ class Less_Visitor_processExtends extends Less_Visitor { } /** - * @param integer $hackstackElementIndex + * @param int $hackstackElementIndex */ private function PotentialMatch( $potentialMatch, $needleElements, $haystackElement, $hackstackElementIndex ) { if ( $potentialMatch['matched'] > 0 ) { @@ -292,6 +293,11 @@ class Less_Visitor_processExtends extends Less_Visitor { return $potentialMatch; } + /** + * @param string|Less_Tree_Attribute|Less_Tree_Dimension|Less_Tree_Keyword $elementValue1 + * @param string|Less_Tree_Attribute|Less_Tree_Dimension|Less_Tree_Keyword $elementValue2 + * @return bool + */ private function isElementValuesEqual( $elementValue1, $elementValue2 ) { if ( $elementValue1 === $elementValue2 ) { return true; @@ -353,8 +359,8 @@ class Less_Visitor_processExtends extends Less_Visitor { return true; } - $elementValue1 = ( $elementValue1->value->value ? $elementValue1->value->value : $elementValue1->value ); - $elementValue2 = ( $elementValue2->value->value ? $elementValue2->value->value : $elementValue2->value ); + $elementValue1 = ( $elementValue1->value->value ?: $elementValue1->value ); + $elementValue2 = ( $elementValue2->value->value ?: $elementValue2->value ); return $elementValue1 === $elementValue2; } @@ -364,7 +370,7 @@ class Less_Visitor_processExtends extends Less_Visitor { $currentSelectorPathIndex = 0; $currentSelectorPathElementIndex = 0; - $path = array(); + $path = []; $selectorPath_len = count( $selectorPath ); for ( $matchIndex = 0, $matches_len = count( $matches ); $matchIndex < $matches_len; $matchIndex++ ) { @@ -388,7 +394,7 @@ class Less_Visitor_processExtends extends Less_Visitor { $newElements = array_merge( array_slice( $selector->elements, $currentSelectorPathElementIndex, ( $match['index'] - $currentSelectorPathElementIndex ) ), // last parameter of array_slice is different than the last parameter of javascript's slice - array( $firstElement ), + [ $firstElement ], array_slice( $replacementSelector->elements, 1 ) ); diff --git a/include/thirdparty/less.php/Visitor/toCSS.php b/include/thirdparty/less.php/Visitor/toCSS.php index e90f211..6c476d2 100644 --- a/include/thirdparty/less.php/Visitor/toCSS.php +++ b/include/thirdparty/less.php/Visitor/toCSS.php @@ -1,10 +1,6 @@ variable ) { - return array(); + return []; } return $ruleNode; } @@ -31,17 +27,17 @@ class Less_Visitor_toCSS extends Less_VisitorReplacing { public function visitMixinDefinition( $mixinNode ) { // mixin definitions do not get eval'd - this means they keep state // so we have to clear that state here so it isn't used if toCSS is called twice - $mixinNode->frames = array(); - return array(); + $mixinNode->frames = []; + return []; } public function visitExtend() { - return array(); + return []; } public function visitComment( $commentNode ) { if ( $commentNode->isSilent() ) { - return array(); + return []; } return $commentNode; } @@ -51,14 +47,14 @@ class Less_Visitor_toCSS extends Less_VisitorReplacing { $visitDeeper = false; if ( !$mediaNode->rules ) { - return array(); + return []; } return $mediaNode; } public function visitDirective( $directiveNode ) { if ( isset( $directiveNode->currentFileInfo['reference'] ) && ( !property_exists( $directiveNode, 'isReferenced' ) || !$directiveNode->isReferenced ) ) { - return array(); + return []; } if ( $directiveNode->name === '@charset' ) { // Only output the debug info together with subsequent @charset definitions @@ -72,7 +68,7 @@ class Less_Visitor_toCSS extends Less_VisitorReplacing { // return $this->visit($comment); //} - return array(); + return []; } $this->charset = true; } @@ -86,7 +82,7 @@ class Less_Visitor_toCSS extends Less_VisitorReplacing { foreach ( $rulesetNode->rules as $ruleNode ) { if ( $ruleNode instanceof Less_Tree_Rule && !$ruleNode->variable ) { - $msg = "properties must be inside selector blocks, they cannot be in the root. Index ".$ruleNode->index.( $ruleNode->currentFileInfo ? ( ' Filename: '.$ruleNode->currentFileInfo['filename'] ) : null ); + $msg = "properties must be inside selector blocks, they cannot be in the root. Index " . $ruleNode->index . ( $ruleNode->currentFileInfo ? ( ' Filename: ' . $ruleNode->currentFileInfo['filename'] ) : null ); throw new Less_Exception_Compiler( $msg ); } } @@ -101,7 +97,7 @@ class Less_Visitor_toCSS extends Less_VisitorReplacing { return $this->visitRulesetRoot( $rulesetNode ); } - $rulesets = array(); + $rulesets = []; $rulesetNode->paths = $this->visitRulesetPaths( $rulesetNode ); // Compile rules and rulesets @@ -134,7 +130,7 @@ class Less_Visitor_toCSS extends Less_VisitorReplacing { // now decide whether we keep the ruleset if ( $rulesetNode->paths ) { // array_unshift($rulesets, $rulesetNode); - array_splice( $rulesets, 0, 0, array( $rulesetNode ) ); + array_splice( $rulesets, 0, 0, [ $rulesetNode ] ); } } @@ -156,7 +152,7 @@ class Less_Visitor_toCSS extends Less_VisitorReplacing { if ( $rulesetNode->firstRoot || $rulesetNode->rules ) { return $rulesetNode; } - return array(); + return []; } /** @@ -165,7 +161,7 @@ class Less_Visitor_toCSS extends Less_VisitorReplacing { * @return array */ private function visitRulesetPaths( $rulesetNode ) { - $paths = array(); + $paths = []; foreach ( $rulesetNode->paths as $p ) { if ( $p[0]->elements[0]->combinator === ' ' ) { $p[0]->elements[0]->combinator = ''; @@ -184,7 +180,7 @@ class Less_Visitor_toCSS extends Less_VisitorReplacing { protected function _removeDuplicateRules( &$rules ) { // remove duplicates - $ruleCache = array(); + $ruleCache = []; for ( $i = count( $rules ) - 1; $i >= 0; $i-- ) { $rule = $rules[$i]; if ( $rule instanceof Less_Tree_Rule || $rule instanceof Less_Tree_NameValue ) { @@ -195,7 +191,7 @@ class Less_Visitor_toCSS extends Less_VisitorReplacing { $ruleList =& $ruleCache[$rule->name]; if ( $ruleList instanceof Less_Tree_Rule || $ruleList instanceof Less_Tree_NameValue ) { - $ruleList = $ruleCache[$rule->name] = array( $ruleCache[$rule->name]->toCSS() ); + $ruleList = $ruleCache[$rule->name] = [ $ruleCache[$rule->name]->toCSS() ]; } $ruleCSS = $rule->toCSS(); @@ -210,7 +206,7 @@ class Less_Visitor_toCSS extends Less_VisitorReplacing { } protected function _mergeRules( &$rules ) { - $groups = array(); + $groups = []; // obj($rules); @@ -226,7 +222,7 @@ class Less_Visitor_toCSS extends Less_VisitorReplacing { } if ( !isset( $groups[$key] ) ) { - $groups[$key] = array(); + $groups[$key] = []; } else { array_splice( $rules, $i--, 1 ); $rules_len--; @@ -240,15 +236,15 @@ class Less_Visitor_toCSS extends Less_VisitorReplacing { if ( count( $parts ) > 1 ) { $rule = $parts[0]; - $spacedGroups = array(); - $lastSpacedGroup = array(); - $parts_mapped = array(); + $spacedGroups = []; + $lastSpacedGroup = []; + $parts_mapped = []; foreach ( $parts as $p ) { if ( $p->merge === '+' ) { if ( $lastSpacedGroup ) { $spacedGroups[] = self::toExpression( $lastSpacedGroup ); } - $lastSpacedGroup = array(); + $lastSpacedGroup = []; } $lastSpacedGroup[] = $p; } @@ -257,11 +253,10 @@ class Less_Visitor_toCSS extends Less_VisitorReplacing { $rule->value = self::toValue( $spacedGroups ); } } - } public static function toExpression( $values ) { - $mapped = array(); + $mapped = []; foreach ( $values as $p ) { $mapped[] = $p->value; } @@ -271,7 +266,7 @@ class Less_Visitor_toCSS extends Less_VisitorReplacing { public static function toValue( $values ) { // return new Less_Tree_Value($values); ?? - $mapped = array(); + $mapped = []; foreach ( $values as $p ) { $mapped[] = $p; } diff --git a/include/thirdparty/less.php/VisitorReplacing.php b/include/thirdparty/less.php/VisitorReplacing.php index cd401ad..ae8b82e 100644 --- a/include/thirdparty/less.php/VisitorReplacing.php +++ b/include/thirdparty/less.php/VisitorReplacing.php @@ -1,15 +1,11 @@ type; + $funcName = 'visit' . $node->type; if ( isset( $this->_visitFnCache[$funcName] ) ) { $visitDeeper = true; @@ -20,7 +16,7 @@ class Less_VisitorReplacing extends Less_Visitor { $node->accept( $this ); } - $funcName = $funcName . "Out"; + $funcName .= "Out"; if ( isset( $this->_visitFnCache[$funcName] ) ) { $this->$funcName( $node ); } @@ -34,7 +30,7 @@ class Less_VisitorReplacing extends Less_Visitor { } public function visitArray( $nodes ) { - $newNodes = array(); + $newNodes = []; foreach ( $nodes as $node ) { $evald = $this->visitObj( $node ); if ( $evald ) { diff --git a/include/thirdparty/less.php/____4.0.0/.easymin/ignore_prefixes b/include/thirdparty/less.php/____4.0.0/.easymin/ignore_prefixes deleted file mode 100644 index ca953b2..0000000 --- a/include/thirdparty/less.php/____4.0.0/.easymin/ignore_prefixes +++ /dev/null @@ -1,2 +0,0 @@ -.easymin -Autoloader.php diff --git a/include/thirdparty/less.php/.easymin/ignore_prefixes b/include/thirdparty/less.php/____4.1/.easymin/ignore_prefixes similarity index 100% rename from include/thirdparty/less.php/.easymin/ignore_prefixes rename to include/thirdparty/less.php/____4.1/.easymin/ignore_prefixes diff --git a/include/thirdparty/less.php/____4.1/API.md b/include/thirdparty/less.php/____4.1/API.md new file mode 100644 index 0000000..010c90f --- /dev/null +++ b/include/thirdparty/less.php/____4.1/API.md @@ -0,0 +1,197 @@ +Less.php API +======== + +## Basic use + +#### Parse strings + +```php +$parser = new Less_Parser(); +$parser->parse( '@color: #36c; .link { color: @color; } a { color: @color; }' ); +$css = $parser->getCss(); +``` + +#### Parse files + +The `parseFile()` function takes two parameters: + +* The absolute path to a `.less` file. +* The base URL for any relative image or CSS references in the `.less` file, + typically the same directory that contains the `.less` file or a public equivalent. + +```php +$parser = new Less_Parser(); +$parser->parseFile( '/var/www/mysite/bootstrap.less', 'https://example.org/mysite/' ); +$css = $parser->getCss(); +``` + +#### Handle invalid syntax + +An exception will be thrown if the compiler encounters invalid LESS. + +```php +try{ + $parser = new Less_Parser(); + $parser->parseFile( '/var/www/mysite/bootstrap.less', 'https://example.org/mysite/' ); + $css = $parser->getCss(); +} catch (Exception $e) { + echo $e->getMessage(); +} +``` + +#### Parse multiple inputs + +Less.php can parse multiple input sources (e.g. files and/or strings) and generate a single CSS output. + +```php +$parser = new Less_Parser(); +$parser->parseFile( '/var/www/mysite/bootstrap.less', '/mysite/' ); +$parser->parse( '@color: #36c; .link { color: @color; } a { color: @color; }' ); +$css = $parser->getCss(); +``` + +#### Metadata + +Less.php keeps track of which `.less` files have been parsed, i.e. the input +file(s) and any direct and indirect imports. + +```php +$parser = new Less_Parser(); +$parser->parseFile( '/var/www/mysite/bootstrap.less', '/mysite/' ); +$css = $parser->getCss(); +$files = $parser->AllParsedFiles(); +``` + +#### Compress output + +You can tell Less.php to remove comments and whitespace to generate minified CSS. + +```php +$options = [ 'compress' => true ]; +$parser = new Less_Parser( $options ); +$parser->parseFile( '/var/www/mysite/bootstrap.less', '/mysite/' ); +$css = $parser->getCss(); +``` + +#### Get variables + +You can use the `getVariables()` method to get an all variables defined and +their value in an associative array. Note that the input must be compiled first +by calling `getCss()`. + +```php +$parser = new Less_Parser; +$parser->parseFile( '/var/www/mysite/bootstrap.less'); +$css = $parser->getCss(); +$variables = $parser->getVariables(); + +``` + +#### Set variables + +Use the `ModifyVars()` method to inject additional variables, i.e. custom values +computed or accessed from your PHP code. + +```php +$parser = new Less_Parser(); +$parser->parseFile( '/var/www/mysite/bootstrap.less', '/mysite/' ); +$parser->ModifyVars( [ 'font-size-base' => '16px' ] ); +$css = $parser->getCss(); +``` + +#### Import directories + +By default, Less.php will look for imported files in the directory of the file passed to `parseFile()`. + +If you use `parse()`, or if need to enable additional import directories, you can specify these by +calling `SetImportDirs()`. + +```php +$directories = [ '/var/www/mysite/bootstrap/' => '/mysite/bootstrap/' ]; +$parser = new Less_Parser(); +$parser->SetImportDirs( $directories ); +$parser->parseFile( '/var/www/mysite/theme.less', '/mysite/' ); +$css = $parser->getCss(); +``` + +## Caching + +Compiling LESS code into CSS can be a time-consuming process. It is recommended to cache your results. + +#### Basic cache + +Use the `Less_Cache` class to save and reuse the results of compiling LESS files. +This class will check the modified time and size of each LESS file (including imported files) and +either re-use or re-generate the CSS output accordingly. + +The cache files are determinstically named, based on the full list of referenced LESS files and the metadata (file path, file mtime, file size) of each file. This means that each time a change is made, a different cache filename is used. + +```php +$lessFiles = [ '/var/www/mysite/bootstrap.less' => '/mysite/' ]; +$options = [ 'cache_dir' => '/var/www/writable_folder' ]; +$cssOutputFile = Less_Cache::Get( $lessFiles, $options ); +$css = file_get_contents( '/var/www/writable_folder/' . $cssOutputFile ); +``` + +#### Caching with variables + +Passing custom variables to `Less_Cache::Get()`: + +```php +$lessFiles = [ '/var/www/mysite/bootstrap.less' => '/mysite/' ]; +$options = [ 'cache_dir' => '/var/www/writable_folder' ]; +$variables = [ 'width' => '100px' ]; +$cssOutputFile = Less_Cache::Get( $lessFiles, $options, $variables ); +$css = file_get_contents( '/var/www/writable_folder/' . $cssOutputFile ); +``` + +#### Incremental caching + +In addition to the whole-output caching described above, Less.php also has the ability to keep an internal cache which allows re-parses to be faster by effectively only re-compiling portions that have changed. + +## Source maps + +Less.php supports v3 sourcemaps. + +#### Inline + +The sourcemap will be appended to the generated CSS file. + +```php +$options = [ 'sourceMap' => true ]; +$parser = new Less_Parser($options); +$parser->parseFile( '/var/www/mysite/bootstrap.less', '/mysite/' ); +$css = $parser->getCss(); +``` + +#### Saving to map file + +```php +$options = [ + 'sourceMap' => true, + 'sourceMapWriteTo' => '/var/www/mysite/writable_folder/filename.map', + 'sourceMapURL' => '/mysite/writable_folder/filename.map', +]; +$parser = new Less_Parser($options); +$parser->parseFile( '/var/www/mysite/bootstrap.less', '/mysite/' ); +$css = $parser->getCss(); +``` + +## Command line + +An additional script has been included to use the Less.php compiler from the command line. +In its simplest invocation, you specify an input file and the compiled CSS is written to standard out: + +``` +$ lessc input.less > output.css +``` + +By using the `-w` flag you can watch a specified input file and have it compile as needed to the output file: + +``` +$ lessc -w input.less output.css +``` + +Errors from watch mode are written to standard out. + +For more information, run `lessc --help` diff --git a/include/thirdparty/less.php/____4.0.0/Autoloader.php b/include/thirdparty/less.php/____4.1/Autoloader.php similarity index 100% rename from include/thirdparty/less.php/____4.0.0/Autoloader.php rename to include/thirdparty/less.php/____4.1/Autoloader.php diff --git a/include/thirdparty/less.php/____4.1/CHANGES.md b/include/thirdparty/less.php/____4.1/CHANGES.md new file mode 100644 index 0000000..aa4932f --- /dev/null +++ b/include/thirdparty/less.php/____4.1/CHANGES.md @@ -0,0 +1,91 @@ +# Changelog + +## 4.1.0 + +* Add support for `@supports` blocks. (Anne Tomasevich) [T332923](http://phabricator.wikimedia.org/T332923) +* Less_Parser: Returning a URI from `SetImportDirs()` callbacks is now optional. (Timo Tijhof) + +## 4.0.0 + +* Remove support for PHP 7.2 and 7.3. Raise requirement to PHP 7.4+. +* Remove support for `cache_method=php` and `cache_method=var_export`, only the faster and more secure `cache_method=serialize` is now available. The built-in cache remains disabled by default. +* Fix `url(#myid)` to be treated as absolute URL. [T331649](https://phabricator.wikimedia.org/T331688) +* Fix "Undefined property" PHP 8.1 warning when `calc()` is used with CSS `var()`. [T331688](https://phabricator.wikimedia.org/T331688) +* Less_Parser: Improve performance by removing MatchFuncs and NewObj overhead. (Timo Tijhof) + +## 3.2.1 + +* Tree_Ruleset: Fix support for nested parent selectors (Timo Tijhof) [T204816](https://phabricator.wikimedia.org/T204816) +* Fix ParseError when interpolating variable after colon in selector (Timo Tijhof) [T327163](https://phabricator.wikimedia.org/T327163) +* Functions: Fix "Undefined property" warning on bad minmax arg +* Tree_Call: Include previous exception when catching functions (Robert Frunzke) + +## 3.2.0 + +* Fix "Implicit conversion" PHP 8.1 warnings (Ayokunle Odusan) +* Fix "Creation of dynamic property" PHP 8.2 warnings (Bas Couwenberg) +* Fix "Creation of dynamic property" PHP 8.2 warnings (Rajesh Kumar) +* Tree_Url: Add support for "Url" type to `Parser::getVariables()` (ciroarcadio) [#51](https://github.com/wikimedia/less.php/pull/51) +* Tree_Import: Add support for importing URLs without file extension (Timo Tijhof) [#27](https://github.com/wikimedia/less.php/issues/27) + +## 3.1.0 + +* Add PHP 8.0 support: Drop use of curly braces for sub-string eval (James D. Forrester) +* Make `Directive::__construct` $rules arg optional (fix PHP 7.4 warning) (Sam Reed) +* ProcessExtends: Improve performance by using a map for selectors and parents (Andrey Legayev) + +## 3.0.0 + +* Raise PHP requirement from 7.1 to 7.2.9 (James Forrester) + +## 2.0.0 + +* Relax PHP requirement down to 7.1, from 7.2.9 (Franz Liedke) +* Reflect recent breaking changes properly with the semantic versioning (James Forrester) + +## 1.8.2 + +* Require PHP 7.2.9+, up from 5.3+ (James Forrester) +* release: Update Version.php with the current release ID (COBadger) +* Fix access array offset on value of type null (Michele Locati) +* Fix test suite on PHP 7.4 (Sergei Morozov) + +## 1.8.1 + +* Another PHP 7.3 compatibility tweak + +## 1.8.0 + +Library forked by Wikimedia, from [oyejorge/less.php](https://github.com/oyejorge/less.php). + +* Supports up to PHP 7.3 +* No longer tested against PHP 5, though it's still remains allowed in `composer.json` for HHVM compatibility +* Switched to [semantic versioning](https://semver.org/), hence version numbers now use 3 digits + +## 1.7.0.13 + +* Fix composer.json (PSR-4 was invalid) + +## 1.7.0.12 + +* set bin/lessc bit executable +* Add `gettingVariables` method to `Less_Parser` + +## 1.7.0.11 + +* Fix realpath issue (windows) +* Set Less_Tree_Call property back to public ( Fix 258 266 267 issues from oyejorge/less.php) + +## 1.7.0.10 + +* Add indentation option +* Add `optional` modifier for `@import` +* Fix $color in Exception messages +* take relative-url into account when building the cache filename +* urlArgs should be string no array() +* fix missing on NameValue type [#269](https://github.com/oyejorge/less.php/issues/269) + +## 1.7.0.9 + +* Remove space at beginning of Version.php +* Revert require() paths in test interface diff --git a/include/thirdparty/less.php/____4.1/CODE_OF_CONDUCT.md b/include/thirdparty/less.php/____4.1/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..498acf7 --- /dev/null +++ b/include/thirdparty/less.php/____4.1/CODE_OF_CONDUCT.md @@ -0,0 +1 @@ +The development of this software is covered by a [Code of Conduct](https://www.mediawiki.org/wiki/Special:MyLanguage/Code_of_Conduct). diff --git a/include/thirdparty/less.php/____4.0.0/Cache.php b/include/thirdparty/less.php/____4.1/Cache.php similarity index 100% rename from include/thirdparty/less.php/____4.0.0/Cache.php rename to include/thirdparty/less.php/____4.1/Cache.php diff --git a/include/thirdparty/less.php/____4.0.0/Colors.php b/include/thirdparty/less.php/____4.1/Colors.php similarity index 100% rename from include/thirdparty/less.php/____4.0.0/Colors.php rename to include/thirdparty/less.php/____4.1/Colors.php diff --git a/include/thirdparty/less.php/____4.0.0/Configurable.php b/include/thirdparty/less.php/____4.1/Configurable.php similarity index 100% rename from include/thirdparty/less.php/____4.0.0/Configurable.php rename to include/thirdparty/less.php/____4.1/Configurable.php diff --git a/include/thirdparty/less.php/____4.0.0/Environment.php b/include/thirdparty/less.php/____4.1/Environment.php similarity index 98% rename from include/thirdparty/less.php/____4.0.0/Environment.php rename to include/thirdparty/less.php/____4.1/Environment.php index 54d3f4b..73a32a9 100644 --- a/include/thirdparty/less.php/____4.0.0/Environment.php +++ b/include/thirdparty/less.php/____4.1/Environment.php @@ -9,7 +9,7 @@ class Less_Environment { * * - rootpath: rootpath to append to URLs * - * @var array|null $currentFileInfo; + * @var array|null $currentFileInfo */ public $currentFileInfo; diff --git a/include/thirdparty/less.php/____4.0.0/Exception/Chunk.php b/include/thirdparty/less.php/____4.1/Exception/Chunk.php similarity index 100% rename from include/thirdparty/less.php/____4.0.0/Exception/Chunk.php rename to include/thirdparty/less.php/____4.1/Exception/Chunk.php diff --git a/include/thirdparty/less.php/____4.0.0/Exception/Compiler.php b/include/thirdparty/less.php/____4.1/Exception/Compiler.php similarity index 100% rename from include/thirdparty/less.php/____4.0.0/Exception/Compiler.php rename to include/thirdparty/less.php/____4.1/Exception/Compiler.php diff --git a/include/thirdparty/less.php/____4.0.0/Exception/Parser.php b/include/thirdparty/less.php/____4.1/Exception/Parser.php similarity index 100% rename from include/thirdparty/less.php/____4.0.0/Exception/Parser.php rename to include/thirdparty/less.php/____4.1/Exception/Parser.php diff --git a/include/thirdparty/less.php/____4.0.0/Functions.php b/include/thirdparty/less.php/____4.1/Functions.php similarity index 100% rename from include/thirdparty/less.php/____4.0.0/Functions.php rename to include/thirdparty/less.php/____4.1/Functions.php diff --git a/include/thirdparty/less.php/____4.1/LICENSE b/include/thirdparty/less.php/____4.1/LICENSE new file mode 100644 index 0000000..d645695 --- /dev/null +++ b/include/thirdparty/less.php/____4.1/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/include/thirdparty/less.php/____4.0.0/Less.php.combine b/include/thirdparty/less.php/____4.1/Less.php.combine similarity index 100% rename from include/thirdparty/less.php/____4.0.0/Less.php.combine rename to include/thirdparty/less.php/____4.1/Less.php.combine diff --git a/include/thirdparty/less.php/____4.0.0/Mime.php b/include/thirdparty/less.php/____4.1/Mime.php similarity index 100% rename from include/thirdparty/less.php/____4.0.0/Mime.php rename to include/thirdparty/less.php/____4.1/Mime.php diff --git a/include/thirdparty/less.php/____4.1/NOTICE.txt b/include/thirdparty/less.php/____4.1/NOTICE.txt new file mode 100644 index 0000000..099293c --- /dev/null +++ b/include/thirdparty/less.php/____4.1/NOTICE.txt @@ -0,0 +1,18 @@ +wikimedia/less.php. https://gerrit.wikimedia.org/g/mediawiki/libs/less.php + +Copyright Matt Agar +Copyright Martin Jantošovič +Copyright Josh Schmidt +Copyright Timo Tijhof + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/include/thirdparty/less.php/____4.0.0/Output.php b/include/thirdparty/less.php/____4.1/Output.php similarity index 100% rename from include/thirdparty/less.php/____4.0.0/Output.php rename to include/thirdparty/less.php/____4.1/Output.php diff --git a/include/thirdparty/less.php/____4.0.0/Output/Mapped.php b/include/thirdparty/less.php/____4.1/Output/Mapped.php similarity index 100% rename from include/thirdparty/less.php/____4.0.0/Output/Mapped.php rename to include/thirdparty/less.php/____4.1/Output/Mapped.php diff --git a/include/thirdparty/less.php/____4.0.0/Parser.php b/include/thirdparty/less.php/____4.1/Parser.php similarity index 98% rename from include/thirdparty/less.php/____4.0.0/Parser.php rename to include/thirdparty/less.php/____4.1/Parser.php index cfd933b..35ef79b 100644 --- a/include/thirdparty/less.php/____4.0.0/Parser.php +++ b/include/thirdparty/less.php/____4.1/Parser.php @@ -542,7 +542,27 @@ $g = intval( $g ); /** * Set a list of directories or callbacks the parser should use for determining import paths * - * @param array $dirs + * Import closures are called with a single `$path` argument containing the unquoted `@import` + * string an input LESS file. The string is unchanged, except for a statically appended ".less" + * suffix if the basename does not yet contain a dot. If a dot is present in the filename, you + * are responsible for choosing whether to expand "foo.bar" to "foo.bar.less". If your callback + * can handle this import statement, return an array with an absolute file path and an optional + * URI path, or return void/null to indicate that your callback does not handle this import + * statement. + * + * Example: + * + * function ( $path ) { + * if ( $path === 'virtual/something.less' ) { + * return [ '/srv/elsewhere/thing.less', null ]; + * } + * } + * + * + * @param array $dirs The key should be a server directory from which LESS + * files may be imported. The value is an optional public URL or URL base path that corresponds to + * the same directory (use empty string otherwise). The value may also be a closure, in + * which case the key is ignored. */ public function SetImportDirs( $dirs ) { self::$options['import_dirs'] = []; @@ -2188,6 +2208,7 @@ $g = intval( $g ); $hasIdentifier = false; $hasExpression = false; $hasUnknown = false; + $isRooted = true; $value = $this->parseImport() ?? $this->parseMedia(); if ( $value ) { @@ -2230,6 +2251,7 @@ $g = intval( $g ); case "@right-middle": case "@right-bottom": hasBlock = true; + isRooted = true; break; */ case "@charset": @@ -2245,9 +2267,12 @@ $g = intval( $g ); break; case "@host": case "@page": + $hasUnknown = true; + break; case "@document": case "@supports": $hasUnknown = true; + $isRooted = false; break; } @@ -2275,7 +2300,7 @@ $g = intval( $g ); if ( $rules || ( !$hasBlock && $value && $this->MatchChar( ';' ) ) ) { $this->forget(); - return new Less_Tree_Directive( $name, $value, $rules, $index, $this->env->currentFileInfo ); + return new Less_Tree_Directive( $name, $value, $rules, $index, $isRooted, $this->env->currentFileInfo ); } $this->restore(); diff --git a/include/thirdparty/less.php/____4.1/README.md b/include/thirdparty/less.php/____4.1/README.md new file mode 100644 index 0000000..a89ea6c --- /dev/null +++ b/include/thirdparty/less.php/____4.1/README.md @@ -0,0 +1,77 @@ +[![Packagist](https://img.shields.io/packagist/v/wikimedia/less.php.svg?style=flat)](https://packagist.org/packages/wikimedia/less.php) + +Less.php +======== + +This is a PHP port of the [official LESS processor](https://lesscss.org). + +## About + +The code structure of Less.php mirrors that of upstream Less.js to ensure compatibility and help reduce maintenance. The port is currently compatible with Less.js 2.5.3. Please note that "inline JavaScript expressions" (via eval or backticks) are not supported. + +* [API § Caching](./API.md#caching), Less.php includes a file-based cache. +* [API § Source maps](./API.md#source-maps), Less.php supports v3 sourcemaps. +* [API § Command line](./API.md#command-line), the `lessc` command includes a watch mode. + +## Installation + +You can install the library with Composer or standalone. + +If you have [Composer](https://getcomposer.org/download/) installed: + +1. Run `composer require wikimedia/less.php` +2. Use `Less_Parser` in your code. + +Or standalone: + +1. [Download Less.php](https://gerrit.wikimedia.org/g/mediawiki/libs/less.php/+archive/HEAD.tar.gz) and upload the PHP files to your server. +2. Include the library: + ```php + require_once '[path to]/less.php/lib/Less/Autoloader.php'; + Less_Autoloader::register(); + ``` +3. Use `Less_Parser` in your code. + +## Security + +The LESS processor language is powerful and includes features that may read or embed arbitrary files that the web server has access to, and features that may be computationally exensive if misused. + +In general you should treat LESS files as being in the same trust domain as other server-side executables, such as PHP code. In particular, it is not recommended to allow people that use your web service to provide arbitrary LESS code for server-side processing. + +_See also [SECURITY](./SECURITY.md)._ + +## Who uses Less.php? + +* **[Wikipedia](https://en.wikipedia.org/wiki/MediaWiki)** and the MediaWiki platform ([docs](https://www.mediawiki.org/wiki/ResourceLoader/Architecture#Resource:_Styles)). +* **[Matomo](https://en.wikipedia.org/wiki/Matomo_(software))** ([docs](https://devdocs.magento.com/guides/v2.4/frontend-dev-guide/css-topics/custom_preprocess.html)). +* **[Magento](https://en.wikipedia.org/wiki/Magento)** as part of Adobe Commerce ([docs](https://developer.matomo.org/guides/asset-pipeline#vanilla-javascript-css-and-less-files)). +* **[Icinga](https://en.wikipedia.org/wiki/Icinga)** in Icinga Web ([docs](https://github.com/Icinga/icingaweb2)). +* **[Shopware](https://de.wikipedia.org/wiki/Shopware)** ([docs](https://developers.shopware.com/designers-guide/less/)). + +## Integrations + +Less.php has been integrated with various other projects. + +#### Transitioning from Leafo/lessphp + +If you're looking to transition from the [Leafo/lessphp](https://github.com/leafo/lessphp) library, use the `lessc.inc.php` adapter file that comes with Less.php. + +This allows Less.php to be a drop-in replacement for Leafo/lessphp. + +[Download Less.php](https://gerrit.wikimedia.org/g/mediawiki/libs/less.php/+archive/HEAD.tar.gz), unzip the files into your project, and include its `lessc.inc.php` instead. + +Note: The `setPreserveComments` option is ignored. Less.php already preserves CSS block comments by default, and removes LESS inline comments. + +#### Drupal + +Less.php can be used with [Drupal's less module](https://drupal.org/project/less) via the `lessc.inc.php` adapter. [Download Less.php](https://gerrit.wikimedia.org/g/mediawiki/libs/less.php/+archive/HEAD.tar.gz) and unzip it so that `lessc.inc.php` is located at `sites/all/libraries/lessphp/lessc.inc.php`, then install the Drupal less module as usual. + +#### WordPress + +* [wp_enqueue_less](https://github.com/Ed-ITSolutions/wp_enqueue_less) is a Composer package for use in WordPress themes and plugins. It provides a `wp_enqueue_less()` function to automatically manage caching and compilation on-demand, and loads the compressed CSS on the page. +* [JBST framework](https://github.com/bassjobsen/jamedo-bootstrap-start-theme) bundles a copy of Less.php. +* The [lessphp plugin](https://wordpress.org/plugins/lessphp/) bundles a copy of Less.php for use in other plugins or themes. This dependency can also be combined with the [TGM Library](http://tgmpluginactivation.com/). + +## Credits + +Less.php was originally ported to PHP in 2011 by [Matt Agar](https://github.com/agar) and then updated by [Martin Jantošovič](https://github.com/Mordred) in 2012. From 2013 to 2017, [Josh Schmidt](https://github.com/oyejorge) lead development of the library. Since 2019, the library is maintained by Wikimedia Foundation. diff --git a/include/thirdparty/less.php/____4.1/SECURITY.md b/include/thirdparty/less.php/____4.1/SECURITY.md new file mode 100644 index 0000000..687c735 --- /dev/null +++ b/include/thirdparty/less.php/____4.1/SECURITY.md @@ -0,0 +1,5 @@ +# Security policy + +Wikimedia takes security seriously. If you believe you have found a +security issue, see +for information on how to responsibly report it. diff --git a/include/thirdparty/less.php/____4.0.0/SourceMap/Base64VLQ.php b/include/thirdparty/less.php/____4.1/SourceMap/Base64VLQ.php similarity index 100% rename from include/thirdparty/less.php/____4.0.0/SourceMap/Base64VLQ.php rename to include/thirdparty/less.php/____4.1/SourceMap/Base64VLQ.php diff --git a/include/thirdparty/less.php/____4.0.0/SourceMap/Generator.php b/include/thirdparty/less.php/____4.1/SourceMap/Generator.php similarity index 100% rename from include/thirdparty/less.php/____4.0.0/SourceMap/Generator.php rename to include/thirdparty/less.php/____4.1/SourceMap/Generator.php diff --git a/include/thirdparty/less.php/____4.0.0/Tree.php b/include/thirdparty/less.php/____4.1/Tree.php similarity index 100% rename from include/thirdparty/less.php/____4.0.0/Tree.php rename to include/thirdparty/less.php/____4.1/Tree.php diff --git a/include/thirdparty/less.php/____4.0.0/Tree/Alpha.php b/include/thirdparty/less.php/____4.1/Tree/Alpha.php similarity index 100% rename from include/thirdparty/less.php/____4.0.0/Tree/Alpha.php rename to include/thirdparty/less.php/____4.1/Tree/Alpha.php diff --git a/include/thirdparty/less.php/____4.0.0/Tree/Anonymous.php b/include/thirdparty/less.php/____4.1/Tree/Anonymous.php similarity index 100% rename from include/thirdparty/less.php/____4.0.0/Tree/Anonymous.php rename to include/thirdparty/less.php/____4.1/Tree/Anonymous.php diff --git a/include/thirdparty/less.php/____4.0.0/Tree/Assignment.php b/include/thirdparty/less.php/____4.1/Tree/Assignment.php similarity index 100% rename from include/thirdparty/less.php/____4.0.0/Tree/Assignment.php rename to include/thirdparty/less.php/____4.1/Tree/Assignment.php diff --git a/include/thirdparty/less.php/____4.0.0/Tree/Attribute.php b/include/thirdparty/less.php/____4.1/Tree/Attribute.php similarity index 100% rename from include/thirdparty/less.php/____4.0.0/Tree/Attribute.php rename to include/thirdparty/less.php/____4.1/Tree/Attribute.php diff --git a/include/thirdparty/less.php/____4.0.0/Tree/Call.php b/include/thirdparty/less.php/____4.1/Tree/Call.php similarity index 100% rename from include/thirdparty/less.php/____4.0.0/Tree/Call.php rename to include/thirdparty/less.php/____4.1/Tree/Call.php diff --git a/include/thirdparty/less.php/____4.0.0/Tree/Color.php b/include/thirdparty/less.php/____4.1/Tree/Color.php similarity index 100% rename from include/thirdparty/less.php/____4.0.0/Tree/Color.php rename to include/thirdparty/less.php/____4.1/Tree/Color.php diff --git a/include/thirdparty/less.php/____4.0.0/Tree/Comment.php b/include/thirdparty/less.php/____4.1/Tree/Comment.php similarity index 100% rename from include/thirdparty/less.php/____4.0.0/Tree/Comment.php rename to include/thirdparty/less.php/____4.1/Tree/Comment.php diff --git a/include/thirdparty/less.php/____4.0.0/Tree/Condition.php b/include/thirdparty/less.php/____4.1/Tree/Condition.php similarity index 100% rename from include/thirdparty/less.php/____4.0.0/Tree/Condition.php rename to include/thirdparty/less.php/____4.1/Tree/Condition.php diff --git a/include/thirdparty/less.php/____4.0.0/Tree/DefaultFunc.php b/include/thirdparty/less.php/____4.1/Tree/DefaultFunc.php similarity index 100% rename from include/thirdparty/less.php/____4.0.0/Tree/DefaultFunc.php rename to include/thirdparty/less.php/____4.1/Tree/DefaultFunc.php diff --git a/include/thirdparty/less.php/____4.0.0/Tree/DetachedRuleset.php b/include/thirdparty/less.php/____4.1/Tree/DetachedRuleset.php similarity index 100% rename from include/thirdparty/less.php/____4.0.0/Tree/DetachedRuleset.php rename to include/thirdparty/less.php/____4.1/Tree/DetachedRuleset.php diff --git a/include/thirdparty/less.php/____4.0.0/Tree/Dimension.php b/include/thirdparty/less.php/____4.1/Tree/Dimension.php similarity index 100% rename from include/thirdparty/less.php/____4.0.0/Tree/Dimension.php rename to include/thirdparty/less.php/____4.1/Tree/Dimension.php diff --git a/include/thirdparty/less.php/____4.0.0/Tree/Directive.php b/include/thirdparty/less.php/____4.1/Tree/Directive.php similarity index 51% rename from include/thirdparty/less.php/____4.0.0/Tree/Directive.php rename to include/thirdparty/less.php/____4.1/Tree/Directive.php index dfada84..0cc1fe9 100644 --- a/include/thirdparty/less.php/____4.0.0/Tree/Directive.php +++ b/include/thirdparty/less.php/____4.1/Tree/Directive.php @@ -9,26 +9,37 @@ class Less_Tree_Directive extends Less_Tree { public $rules; public $index; public $isReferenced; + public $isRooted; public $currentFileInfo; public $debugInfo; public $type = 'Directive'; - public function __construct( $name, $value = null, $rules = null, $index = null, $currentFileInfo = null, $debugInfo = null ) { + public function __construct( $name, $value = null, $rules = null, $index = null, $isRooted = false, $currentFileInfo = null, $debugInfo = null ) { $this->name = $name; $this->value = $value; + if ( $rules ) { - $this->rules = $rules; - $this->rules->allowImports = true; + if ( is_array( $rules ) ) { + $this->rules = $rules; + } else { + $this->rules = [ $rules ]; + $this->rules[0]->selectors = $this->emptySelectors(); + } + + foreach ( $this->rules as $rule ) { + $rule->allowImports = true; + } } $this->index = $index; + $this->isRooted = $isRooted; $this->currentFileInfo = $currentFileInfo; $this->debugInfo = $debugInfo; } public function accept( $visitor ) { if ( $this->rules ) { - $this->rules = $visitor->visitObj( $this->rules ); + $this->rules = $visitor->visitArray( $this->rules ); } if ( $this->value ) { $this->value = $visitor->visitObj( $this->value ); @@ -47,7 +58,7 @@ class Less_Tree_Directive extends Less_Tree { $this->value->genCSS( $output ); } if ( $this->rules ) { - Less_Tree::outputRuleset( $output, [ $this->rules ] ); + Less_Tree::outputRuleset( $output, $this->rules ); } else { $output->add( ';' ); } @@ -56,27 +67,41 @@ class Less_Tree_Directive extends Less_Tree { public function compile( $env ) { $value = $this->value; $rules = $this->rules; + + // Media stored inside other directive should not bubble over it + // backup media bubbling information + $mediaPathBackup = $env->mediaPath; + $mediaPBlocksBackup = $env->mediaBlocks; + // Deleted media bubbling information + $env->mediaPath = []; + $env->mediaBlocks = []; + if ( $value ) { $value = $value->compile( $env ); } if ( $rules ) { - $rules = $rules->compile( $env ); + // Assuming that there is only one rule at this point - that is how parser constructs the rule + $rules = $rules[0]->compile( $env ); $rules->root = true; } - return new Less_Tree_Directive( $this->name, $value, $rules, $this->index, $this->currentFileInfo, $this->debugInfo ); + // Restore media bubbling information + $env->mediaPath = $mediaPathBackup; + $env->mediaBlocks = $mediaPBlocksBackup; + + return new Less_Tree_Directive( $this->name, $value, $rules, $this->index, $this->isRooted, $this->currentFileInfo, $this->debugInfo ); } public function variable( $name ) { if ( $this->rules ) { - return $this->rules->variable( $name ); + return $this->rules[0]->variable( $name ); } } public function find( $selector ) { if ( $this->rules ) { - return $this->rules->find( $selector, $this ); + return $this->rules[0]->find( $selector, $this ); } } @@ -85,8 +110,15 @@ class Less_Tree_Directive extends Less_Tree { public function markReferenced() { $this->isReferenced = true; if ( $this->rules ) { - Less_Tree::ReferencedArray( $this->rules->rules ); + Less_Tree::ReferencedArray( $this->rules ); } } + public function emptySelectors() { + $el = new Less_Tree_Element( '', '&', $this->index, $this->currentFileInfo ); + $sels = [ new Less_Tree_Selector( [ $el ], [], null, $this->index, $this->currentFileInfo ) ]; + $sels[0]->mediaEmpty = true; + return $sels; + } + } diff --git a/include/thirdparty/less.php/____4.0.0/Tree/Element.php b/include/thirdparty/less.php/____4.1/Tree/Element.php similarity index 100% rename from include/thirdparty/less.php/____4.0.0/Tree/Element.php rename to include/thirdparty/less.php/____4.1/Tree/Element.php diff --git a/include/thirdparty/less.php/____4.0.0/Tree/Expression.php b/include/thirdparty/less.php/____4.1/Tree/Expression.php similarity index 100% rename from include/thirdparty/less.php/____4.0.0/Tree/Expression.php rename to include/thirdparty/less.php/____4.1/Tree/Expression.php diff --git a/include/thirdparty/less.php/____4.0.0/Tree/Extend.php b/include/thirdparty/less.php/____4.1/Tree/Extend.php similarity index 100% rename from include/thirdparty/less.php/____4.0.0/Tree/Extend.php rename to include/thirdparty/less.php/____4.1/Tree/Extend.php diff --git a/include/thirdparty/less.php/____4.0.0/Tree/Import.php b/include/thirdparty/less.php/____4.1/Tree/Import.php similarity index 93% rename from include/thirdparty/less.php/____4.0.0/Tree/Import.php rename to include/thirdparty/less.php/____4.1/Tree/Import.php index fc5e81d..f8d981e 100644 --- a/include/thirdparty/less.php/____4.0.0/Tree/Import.php +++ b/include/thirdparty/less.php/____4.1/Tree/Import.php @@ -227,23 +227,26 @@ class Less_Tree_Import extends Less_Tree { foreach ( $import_dirs as $rootpath => $rooturi ) { if ( is_callable( $rooturi ) ) { - list( $path, $uri ) = call_user_func( $rooturi, $evald_path ); - if ( is_string( $path ) ) { - $full_path = $path; - return [ $full_path, $uri ]; + $res = $rooturi( $evald_path ); + if ( $res && is_string( $res[0] ) ) { + return [ + Less_Environment::normalizePath( $res[0] ), + Less_Environment::normalizePath( $res[1] ?? dirname( $evald_path ) ) + ]; } } elseif ( !empty( $rootpath ) ) { - $path = rtrim( $rootpath, '/\\' ) . '/' . ltrim( $evald_path, '/\\' ); - if ( file_exists( $path ) ) { - $full_path = Less_Environment::normalizePath( $path ); - $uri = Less_Environment::normalizePath( dirname( $rooturi . $evald_path ) ); - return [ $full_path, $uri ]; - } elseif ( file_exists( $path . '.less' ) ) { - $full_path = Less_Environment::normalizePath( $path . '.less' ); - $uri = Less_Environment::normalizePath( dirname( $rooturi . $evald_path . '.less' ) ); - return [ $full_path, $uri ]; + return [ + Less_Environment::normalizePath( $path ), + Less_Environment::normalizePath( dirname( $rooturi . $evald_path ) ) + ]; + } + if ( file_exists( $path . '.less' ) ) { + return [ + Less_Environment::normalizePath( $path . '.less' ), + Less_Environment::normalizePath( dirname( $rooturi . $evald_path . '.less' ) ) + ]; } } } diff --git a/include/thirdparty/less.php/____4.0.0/Tree/Javascript.php b/include/thirdparty/less.php/____4.1/Tree/Javascript.php similarity index 100% rename from include/thirdparty/less.php/____4.0.0/Tree/Javascript.php rename to include/thirdparty/less.php/____4.1/Tree/Javascript.php diff --git a/include/thirdparty/less.php/____4.0.0/Tree/Keyword.php b/include/thirdparty/less.php/____4.1/Tree/Keyword.php similarity index 100% rename from include/thirdparty/less.php/____4.0.0/Tree/Keyword.php rename to include/thirdparty/less.php/____4.1/Tree/Keyword.php diff --git a/include/thirdparty/less.php/____4.0.0/Tree/Media.php b/include/thirdparty/less.php/____4.1/Tree/Media.php similarity index 100% rename from include/thirdparty/less.php/____4.0.0/Tree/Media.php rename to include/thirdparty/less.php/____4.1/Tree/Media.php diff --git a/include/thirdparty/less.php/____4.0.0/Tree/Mixin/Call.php b/include/thirdparty/less.php/____4.1/Tree/Mixin/Call.php similarity index 100% rename from include/thirdparty/less.php/____4.0.0/Tree/Mixin/Call.php rename to include/thirdparty/less.php/____4.1/Tree/Mixin/Call.php diff --git a/include/thirdparty/less.php/____4.0.0/Tree/Mixin/Definition.php b/include/thirdparty/less.php/____4.1/Tree/Mixin/Definition.php similarity index 100% rename from include/thirdparty/less.php/____4.0.0/Tree/Mixin/Definition.php rename to include/thirdparty/less.php/____4.1/Tree/Mixin/Definition.php diff --git a/include/thirdparty/less.php/____4.0.0/Tree/NameValue.php b/include/thirdparty/less.php/____4.1/Tree/NameValue.php similarity index 100% rename from include/thirdparty/less.php/____4.0.0/Tree/NameValue.php rename to include/thirdparty/less.php/____4.1/Tree/NameValue.php diff --git a/include/thirdparty/less.php/____4.0.0/Tree/Negative.php b/include/thirdparty/less.php/____4.1/Tree/Negative.php similarity index 100% rename from include/thirdparty/less.php/____4.0.0/Tree/Negative.php rename to include/thirdparty/less.php/____4.1/Tree/Negative.php diff --git a/include/thirdparty/less.php/____4.0.0/Tree/Operation.php b/include/thirdparty/less.php/____4.1/Tree/Operation.php similarity index 100% rename from include/thirdparty/less.php/____4.0.0/Tree/Operation.php rename to include/thirdparty/less.php/____4.1/Tree/Operation.php diff --git a/include/thirdparty/less.php/____4.0.0/Tree/Paren.php b/include/thirdparty/less.php/____4.1/Tree/Paren.php similarity index 100% rename from include/thirdparty/less.php/____4.0.0/Tree/Paren.php rename to include/thirdparty/less.php/____4.1/Tree/Paren.php diff --git a/include/thirdparty/less.php/____4.0.0/Tree/Quoted.php b/include/thirdparty/less.php/____4.1/Tree/Quoted.php similarity index 100% rename from include/thirdparty/less.php/____4.0.0/Tree/Quoted.php rename to include/thirdparty/less.php/____4.1/Tree/Quoted.php diff --git a/include/thirdparty/less.php/____4.0.0/Tree/Rule.php b/include/thirdparty/less.php/____4.1/Tree/Rule.php similarity index 100% rename from include/thirdparty/less.php/____4.0.0/Tree/Rule.php rename to include/thirdparty/less.php/____4.1/Tree/Rule.php diff --git a/include/thirdparty/less.php/____4.0.0/Tree/Ruleset.php b/include/thirdparty/less.php/____4.1/Tree/Ruleset.php similarity index 100% rename from include/thirdparty/less.php/____4.0.0/Tree/Ruleset.php rename to include/thirdparty/less.php/____4.1/Tree/Ruleset.php diff --git a/include/thirdparty/less.php/____4.0.0/Tree/RulesetCall.php b/include/thirdparty/less.php/____4.1/Tree/RulesetCall.php similarity index 100% rename from include/thirdparty/less.php/____4.0.0/Tree/RulesetCall.php rename to include/thirdparty/less.php/____4.1/Tree/RulesetCall.php diff --git a/include/thirdparty/less.php/____4.0.0/Tree/Selector.php b/include/thirdparty/less.php/____4.1/Tree/Selector.php similarity index 100% rename from include/thirdparty/less.php/____4.0.0/Tree/Selector.php rename to include/thirdparty/less.php/____4.1/Tree/Selector.php diff --git a/include/thirdparty/less.php/____4.0.0/Tree/UnicodeDescriptor.php b/include/thirdparty/less.php/____4.1/Tree/UnicodeDescriptor.php similarity index 100% rename from include/thirdparty/less.php/____4.0.0/Tree/UnicodeDescriptor.php rename to include/thirdparty/less.php/____4.1/Tree/UnicodeDescriptor.php diff --git a/include/thirdparty/less.php/____4.0.0/Tree/Unit.php b/include/thirdparty/less.php/____4.1/Tree/Unit.php similarity index 100% rename from include/thirdparty/less.php/____4.0.0/Tree/Unit.php rename to include/thirdparty/less.php/____4.1/Tree/Unit.php diff --git a/include/thirdparty/less.php/____4.0.0/Tree/UnitConversions.php b/include/thirdparty/less.php/____4.1/Tree/UnitConversions.php similarity index 100% rename from include/thirdparty/less.php/____4.0.0/Tree/UnitConversions.php rename to include/thirdparty/less.php/____4.1/Tree/UnitConversions.php diff --git a/include/thirdparty/less.php/____4.0.0/Tree/Url.php b/include/thirdparty/less.php/____4.1/Tree/Url.php similarity index 100% rename from include/thirdparty/less.php/____4.0.0/Tree/Url.php rename to include/thirdparty/less.php/____4.1/Tree/Url.php diff --git a/include/thirdparty/less.php/____4.0.0/Tree/Value.php b/include/thirdparty/less.php/____4.1/Tree/Value.php similarity index 100% rename from include/thirdparty/less.php/____4.0.0/Tree/Value.php rename to include/thirdparty/less.php/____4.1/Tree/Value.php diff --git a/include/thirdparty/less.php/____4.0.0/Tree/Variable.php b/include/thirdparty/less.php/____4.1/Tree/Variable.php similarity index 100% rename from include/thirdparty/less.php/____4.0.0/Tree/Variable.php rename to include/thirdparty/less.php/____4.1/Tree/Variable.php diff --git a/include/thirdparty/less.php/____4.0.0/Version.php b/include/thirdparty/less.php/____4.1/Version.php similarity index 89% rename from include/thirdparty/less.php/____4.0.0/Version.php rename to include/thirdparty/less.php/____4.1/Version.php index 0c4c93e..4324805 100644 --- a/include/thirdparty/less.php/____4.0.0/Version.php +++ b/include/thirdparty/less.php/____4.1/Version.php @@ -6,7 +6,7 @@ class Less_Version { /* Current release version of less.php */ - public const version = '4.0.0'; + public const version = '4.1.0'; /* Upstream less.js version that this release should be compatible with */ public const less_version = '2.5.3'; diff --git a/include/thirdparty/less.php/____4.0.0/Visitor.php b/include/thirdparty/less.php/____4.1/Visitor.php similarity index 100% rename from include/thirdparty/less.php/____4.0.0/Visitor.php rename to include/thirdparty/less.php/____4.1/Visitor.php diff --git a/include/thirdparty/less.php/____4.0.0/Visitor/extendFinder.php b/include/thirdparty/less.php/____4.1/Visitor/extendFinder.php similarity index 100% rename from include/thirdparty/less.php/____4.0.0/Visitor/extendFinder.php rename to include/thirdparty/less.php/____4.1/Visitor/extendFinder.php diff --git a/include/thirdparty/less.php/____4.0.0/Visitor/import.php b/include/thirdparty/less.php/____4.1/Visitor/import.php similarity index 100% rename from include/thirdparty/less.php/____4.0.0/Visitor/import.php rename to include/thirdparty/less.php/____4.1/Visitor/import.php diff --git a/include/thirdparty/less.php/____4.0.0/Visitor/joinSelector.php b/include/thirdparty/less.php/____4.1/Visitor/joinSelector.php similarity index 85% rename from include/thirdparty/less.php/____4.0.0/Visitor/joinSelector.php rename to include/thirdparty/less.php/____4.1/Visitor/joinSelector.php index a106830..9d85f10 100644 --- a/include/thirdparty/less.php/____4.0.0/Visitor/joinSelector.php +++ b/include/thirdparty/less.php/____4.1/Visitor/joinSelector.php @@ -64,4 +64,12 @@ class Less_Visitor_joinSelector extends Less_Visitor { } } + public function visitDirective( $directiveNode ) { + $context = end( $this->contexts ); + + if ( $directiveNode->rules && count( $directiveNode->rules ) > 0 ) { + $directiveNode->rules[0]->root = $directiveNode->isRooted || count( $context ) === 0; + } + } + } diff --git a/include/thirdparty/less.php/____4.0.0/Visitor/processExtends.php b/include/thirdparty/less.php/____4.1/Visitor/processExtends.php similarity index 100% rename from include/thirdparty/less.php/____4.0.0/Visitor/processExtends.php rename to include/thirdparty/less.php/____4.1/Visitor/processExtends.php diff --git a/include/thirdparty/less.php/____4.0.0/Visitor/toCSS.php b/include/thirdparty/less.php/____4.1/Visitor/toCSS.php similarity index 100% rename from include/thirdparty/less.php/____4.0.0/Visitor/toCSS.php rename to include/thirdparty/less.php/____4.1/Visitor/toCSS.php diff --git a/include/thirdparty/less.php/____4.0.0/VisitorReplacing.php b/include/thirdparty/less.php/____4.1/VisitorReplacing.php similarity index 100% rename from include/thirdparty/less.php/____4.0.0/VisitorReplacing.php rename to include/thirdparty/less.php/____4.1/VisitorReplacing.php diff --git a/include/thirdparty/less.php/____4.0.0/bin/lessc b/include/thirdparty/less.php/____4.1/bin/lessc similarity index 100% rename from include/thirdparty/less.php/____4.0.0/bin/lessc rename to include/thirdparty/less.php/____4.1/bin/lessc diff --git a/include/thirdparty/less.php/____4.0.0/bin/lessc.inc.php b/include/thirdparty/less.php/____4.1/lessc.inc.php similarity index 100% rename from include/thirdparty/less.php/____4.0.0/bin/lessc.inc.php rename to include/thirdparty/less.php/____4.1/lessc.inc.php diff --git a/include/thirdparty/less.php/bin/lessc b/include/thirdparty/less.php/bin/lessc new file mode 100644 index 0000000..7e3d128 --- /dev/null +++ b/include/thirdparty/less.php/bin/lessc @@ -0,0 +1,191 @@ +#!/usr/bin/env php + false, 'relativeUrls' => false); +$silent = false; +$watch = false; +$rootpath = ''; + +// Check for arguments +array_shift($argv); +if (!count($argv)) { + $argv[] = '-h'; +} + +// parse arguments +foreach ($argv as $key => $arg) { + if (preg_match('/^--?([a-z][0-9a-z-]*)(?:=([^\s]+))?$/i', $arg, $matches)) { + $option = $matches[1]; + $value = isset($matches[2]) ? $matches[2] : false; + unset($argv[$key]); + + switch ($option) { + case 'h': + case 'help': + echo << 1) { + $output = array_pop($argv); + $inputs = $argv; +} +else { + $inputs = $argv; + $output = false; +} + +if (!count($inputs)) { + echo("lessc: no input files\n"); + exit; +} + +if ($watch) { + if (!$output) { + echo("lessc: you must specify the output file if --watch is given\n"); + exit; + } + + $lastAction = 0; + + echo("lessc: watching input files\n"); + + while (1) { + clearstatcache(); + + $updated = false; + foreach ($inputs as $input) { + if ($input == '-') { + if (count($inputs) == 1) { + echo("lessc: during watching files is not possible to watch stdin\n"); + exit; + } + else { + continue; + } + } + + if (filemtime($input) > $lastAction) { + $updated = true; + break; + } + } + + if ($updated) { + $lastAction = time(); + $parser = new Less_Parser($env); + foreach ($inputs as $input) { + try { + $parser->parseFile($input, $rootpath); + } + catch (Exception $e) { + echo("lessc: " . $e->getMessage() . " \n"); + continue; // Invalid processing + } + } + + file_put_contents($output, $parser->getCss()); + echo("lessc: output file recompiled\n"); + } + + sleep(1); + } +} +else { + $parser = new Less_Parser($env); + foreach ($inputs as $input) { + if ($input == '-') { + $content = file_get_contents('php://stdin'); + $parser->parse($content); + } + else { + try { + $parser->parseFile($input); + } + catch (Exception $e) { + if (!$silent) { + echo("lessc: " . ((string)$e) . " \n"); + } + } + } + } + + if ($output) { + file_put_contents($output, $parser->getCss()); + } + else { + echo $parser->getCss(); + } +} diff --git a/include/thirdparty/less.php/lessc.inc.php b/include/thirdparty/less.php/lessc.inc.php new file mode 100644 index 0000000..a3c66dd --- /dev/null +++ b/include/thirdparty/less.php/lessc.inc.php @@ -0,0 +1,274 @@ +importDir = (array)$dirs; + } + + public function addImportDir( $dir ) { + $this->importDir = (array)$this->importDir; + $this->importDir[] = $dir; + } + + public function setFormatter( $name ) { + $this->formatterName = $name; + } + + public function setPreserveComments( $preserve ) { + } + + public function registerFunction( $name, $func ) { + $this->libFunctions[$name] = $func; + } + + public function unregisterFunction( $name ) { + unset( $this->libFunctions[$name] ); + } + + public function setVariables( $variables ) { + foreach ( $variables as $name => $value ) { + $this->setVariable( $name, $value ); + } + } + + public function setVariable( $name, $value ) { + $this->registeredVars[$name] = $value; + } + + public function unsetVariable( $name ) { + unset( $this->registeredVars[$name] ); + } + + public function setOptions( $options ) { + foreach ( $options as $name => $value ) { + $this->setOption( $name, $value ); + } + } + + public function setOption( $name, $value ) { + $this->options[$name] = $value; + } + + public function parse( $buffer, $presets = [] ) { + $this->setVariables( $presets ); + + $parser = new Less_Parser( $this->getOptions() ); + $parser->setImportDirs( $this->getImportDirs() ); + foreach ( $this->libFunctions as $name => $func ) { + $parser->registerFunction( $name, $func ); + } + $parser->parse( $buffer ); + if ( count( $this->registeredVars ) ) { + $parser->ModifyVars( $this->registeredVars ); + } + + return $parser->getCss(); + } + + protected function getOptions() { + $options = [ 'relativeUrls' => false ]; + switch ( $this->formatterName ) { + case 'compressed': + $options['compress'] = true; + break; + } + if ( is_array( $this->options ) ) { + $options = array_merge( $options, $this->options ); + } + return $options; + } + + protected function getImportDirs() { + $dirs_ = (array)$this->importDir; + $dirs = []; + foreach ( $dirs_ as $dir ) { + $dirs[$dir] = ''; + } + return $dirs; + } + + public function compile( $string, $name = null ) { + $oldImport = $this->importDir; + $this->importDir = (array)$this->importDir; + + $this->allParsedFiles = []; + + $parser = new Less_Parser( $this->getOptions() ); + $parser->SetImportDirs( $this->getImportDirs() ); + if ( count( $this->registeredVars ) ) { + $parser->ModifyVars( $this->registeredVars ); + } + foreach ( $this->libFunctions as $name => $func ) { + $parser->registerFunction( $name, $func ); + } + $parser->parse( $string ); + $out = $parser->getCss(); + + $parsed = Less_Parser::AllParsedFiles(); + foreach ( $parsed as $file ) { + $this->addParsedFile( $file ); + } + + $this->importDir = $oldImport; + + return $out; + } + + public function compileFile( $fname, $outFname = null ) { + if ( !is_readable( $fname ) ) { + throw new Exception( 'load error: failed to find ' . $fname ); + } + + $pi = pathinfo( $fname ); + + $oldImport = $this->importDir; + + $this->importDir = (array)$this->importDir; + $this->importDir[] = Less_Parser::AbsPath( $pi['dirname'] ) . '/'; + + $this->allParsedFiles = []; + $this->addParsedFile( $fname ); + + $parser = new Less_Parser( $this->getOptions() ); + $parser->SetImportDirs( $this->getImportDirs() ); + if ( count( $this->registeredVars ) ) { + $parser->ModifyVars( $this->registeredVars ); + } + foreach ( $this->libFunctions as $name => $func ) { + $parser->registerFunction( $name, $func ); + } + $parser->parseFile( $fname ); + $out = $parser->getCss(); + + $parsed = Less_Parser::AllParsedFiles(); + foreach ( $parsed as $file ) { + $this->addParsedFile( $file ); + } + + $this->importDir = $oldImport; + + if ( $outFname !== null ) { + return file_put_contents( $outFname, $out ); + } + + return $out; + } + + public function checkedCompile( $in, $out ) { + if ( !is_file( $out ) || filemtime( $in ) > filemtime( $out ) ) { + $this->compileFile( $in, $out ); + return true; + } + return false; + } + + /** + * Execute lessphp on a .less file or a lessphp cache structure + * + * The lessphp cache structure contains information about a specific + * less file having been parsed. It can be used as a hint for future + * calls to determine whether or not a rebuild is required. + * + * The cache structure contains two important keys that may be used + * externally: + * + * compiled: The final compiled CSS + * updated: The time (in seconds) the CSS was last compiled + * + * The cache structure is a plain-ol' PHP associative array and can + * be serialized and unserialized without a hitch. + * + * @param mixed $in Input + * @param bool $force Force rebuild? + * @return array lessphp cache structure + */ + public function cachedCompile( $in, $force = false ) { + // assume no root + $root = null; + + if ( is_string( $in ) ) { + $root = $in; + } elseif ( is_array( $in ) and isset( $in['root'] ) ) { + if ( $force or !isset( $in['files'] ) ) { + // If we are forcing a recompile or if for some reason the + // structure does not contain any file information we should + // specify the root to trigger a rebuild. + $root = $in['root']; + } elseif ( isset( $in['files'] ) and is_array( $in['files'] ) ) { + foreach ( $in['files'] as $fname => $ftime ) { + if ( !file_exists( $fname ) or filemtime( $fname ) > $ftime ) { + // One of the files we knew about previously has changed + // so we should look at our incoming root again. + $root = $in['root']; + break; + } + } + } + } else { + // TODO: Throw an exception? We got neither a string nor something + // that looks like a compatible lessphp cache structure. + return null; + } + + if ( $root !== null ) { + // If we have a root value which means we should rebuild. + $out = []; + $out['root'] = $root; + $out['compiled'] = $this->compileFile( $root ); + $out['files'] = $this->allParsedFiles(); + $out['updated'] = time(); + return $out; + } else { + // No changes, pass back the structure + // we were given initially. + return $in; + } + } + + public function ccompile( $in, $out, $less = null ) { + if ( $less === null ) { + $less = new self; + } + return $less->checkedCompile( $in, $out ); + } + + public static function cexecute( $in, $force = false, $less = null ) { + if ( $less === null ) { + $less = new self; + } + return $less->cachedCompile( $in, $force ); + } + + public function allParsedFiles() { + return $this->allParsedFiles; + } + + protected function addParsedFile( $file ) { + $this->allParsedFiles[Less_Parser::AbsPath( $file )] = filemtime( $file ); + } +} diff --git a/include/tool/Output/Css.php b/include/tool/Output/Css.php index 0dc4d70..eefcaa9 100644 --- a/include/tool/Output/Css.php +++ b/include/tool/Output/Css.php @@ -4,7 +4,7 @@ namespace gp\tool\Output; class Css{ - + public $parser; /** * Convert a .scss or .less files to .css and include it in the page *