qrcode.chapril.org/vendor/wikimedia/less.php/lib/Less/Environment.php

154 lines
2.7 KiB
PHP
Raw Normal View History

2021-02-15 21:29:38 +01:00
<?php
/**
2023-07-07 22:33:10 +02:00
* @private
2021-02-15 21:29:38 +01:00
*/
class Less_Environment {
2023-07-07 22:33:10 +02:00
/**
* Information about the current file - for error reporting and importing and making urls relative etc.
*
* - rootpath: rootpath to append to URLs
*
* @var array|null $currentFileInfo;
*/
public $currentFileInfo;
2021-02-15 21:29:38 +01:00
2023-07-07 22:33:10 +02:00
/* Whether we are currently importing multiple copies */
public $importMultiple = false;
2021-02-15 21:29:38 +01:00
/**
* @var array
*/
2023-07-07 22:33:10 +02:00
public $frames = [];
2021-02-15 21:29:38 +01:00
/**
* @var array
*/
2023-07-07 22:33:10 +02:00
public $mediaBlocks = [];
2021-02-15 21:29:38 +01:00
/**
* @var array
*/
2023-07-07 22:33:10 +02:00
public $mediaPath = [];
2021-02-15 21:29:38 +01:00
public static $parensStack = 0;
public static $tabLevel = 0;
public static $lastRule = false;
public static $_outputMap;
public static $mixin_stack = 0;
/**
* @var array
*/
2023-07-07 22:33:10 +02:00
public $functions = [];
2021-02-15 21:29:38 +01:00
public function Init() {
self::$parensStack = 0;
self::$tabLevel = 0;
self::$lastRule = false;
self::$mixin_stack = 0;
if ( Less_Parser::$options['compress'] ) {
2023-07-07 22:33:10 +02:00
self::$_outputMap = [
2021-02-15 21:29:38 +01:00
',' => ',',
': ' => ':',
'' => '',
' ' => ' ',
':' => ' :',
'+' => '+',
'~' => '~',
'>' => '>',
'|' => '|',
'^' => '^',
'^^' => '^^'
2023-07-07 22:33:10 +02:00
];
2021-02-15 21:29:38 +01:00
} else {
2023-07-07 22:33:10 +02:00
self::$_outputMap = [
2021-02-15 21:29:38 +01:00
',' => ', ',
': ' => ': ',
'' => '',
' ' => ' ',
':' => ' :',
'+' => ' + ',
'~' => ' ~ ',
'>' => ' > ',
'|' => '|',
'^' => ' ^ ',
'^^' => ' ^^ '
2023-07-07 22:33:10 +02:00
];
2021-02-15 21:29:38 +01:00
}
}
2023-07-07 22:33:10 +02:00
public function copyEvalEnv( $frames = [] ) {
2021-02-15 21:29:38 +01:00
$new_env = new Less_Environment();
$new_env->frames = $frames;
return $new_env;
}
public static function isMathOn() {
2023-07-07 22:33:10 +02:00
return !Less_Parser::$options['strictMath'] || self::$parensStack;
2021-02-15 21:29:38 +01:00
}
public static function isPathRelative( $path ) {
return !preg_match( '/^(?:[a-z-]+:|\/)/', $path );
}
/**
* Canonicalize a path by resolving references to '/./', '/../'
* Does not remove leading "../"
2023-07-07 22:33:10 +02:00
* @param string $path or url
2021-02-15 21:29:38 +01:00
* @return string Canonicalized path
*/
public static function normalizePath( $path ) {
$segments = explode( '/', $path );
$segments = array_reverse( $segments );
2023-07-07 22:33:10 +02:00
$path = [];
2021-02-15 21:29:38 +01:00
$path_len = 0;
while ( $segments ) {
$segment = array_pop( $segments );
switch ( $segment ) {
case '.':
2023-07-07 22:33:10 +02:00
break;
2021-02-15 21:29:38 +01:00
case '..':
2023-07-07 22:33:10 +02:00
// @phan-suppress-next-line PhanTypeInvalidDimOffset False positive
2021-02-15 21:29:38 +01:00
if ( !$path_len || ( $path[$path_len - 1] === '..' ) ) {
$path[] = $segment;
$path_len++;
} else {
array_pop( $path );
$path_len--;
}
2023-07-07 22:33:10 +02:00
break;
2021-02-15 21:29:38 +01:00
default:
$path[] = $segment;
$path_len++;
2023-07-07 22:33:10 +02:00
break;
2021-02-15 21:29:38 +01:00
}
}
return implode( '/', $path );
}
public function unshiftFrame( $frame ) {
array_unshift( $this->frames, $frame );
}
public function shiftFrame() {
return array_shift( $this->frames );
}
}