MDL-63086 block_rss_client: Move skip time calculation to task
[moodle.git] / lib / lessphp / Environment.php
blobb2203014f04252bbfe8f820a6a1032d4e49c7511
1 <?php
4 /**
5 * Environment
7 * @package Less
8 * @subpackage environment
9 */
10 class Less_Environment{
12 //public $paths = array(); // option - unmodified - paths to search for imports on
13 //public static $files = array(); // list of files that have been imported, used for import-once
14 //public $rootpath; // option - rootpath to append to URL's
15 //public static $strictImports = null; // option -
16 //public $insecure; // option - whether to allow imports from insecure ssl hosts
17 //public $processImports; // option - whether to process imports. if false then imports will not be imported
18 //public $javascriptEnabled; // option - whether JavaScript is enabled. if undefined, defaults to true
19 //public $useFileCache; // browser only - whether to use the per file session cache
20 public $currentFileInfo; // information about the current file - for error reporting and importing and making urls relative etc.
22 public $importMultiple = false; // whether we are currently importing multiple copies
25 /**
26 * @var array
28 public $frames = array();
30 /**
31 * @var array
33 public $mediaBlocks = array();
35 /**
36 * @var array
38 public $mediaPath = array();
40 public static $parensStack = 0;
42 public static $tabLevel = 0;
44 public static $lastRule = false;
46 public static $_outputMap;
48 public static $mixin_stack = 0;
50 /**
51 * @var array
53 public $functions = array();
56 public function Init(){
58 self::$parensStack = 0;
59 self::$tabLevel = 0;
60 self::$lastRule = false;
61 self::$mixin_stack = 0;
63 if( Less_Parser::$options['compress'] ){
65 Less_Environment::$_outputMap = array(
66 ',' => ',',
67 ': ' => ':',
68 '' => '',
69 ' ' => ' ',
70 ':' => ' :',
71 '+' => '+',
72 '~' => '~',
73 '>' => '>',
74 '|' => '|',
75 '^' => '^',
76 '^^' => '^^'
79 }else{
81 Less_Environment::$_outputMap = array(
82 ',' => ', ',
83 ': ' => ': ',
84 '' => '',
85 ' ' => ' ',
86 ':' => ' :',
87 '+' => ' + ',
88 '~' => ' ~ ',
89 '>' => ' > ',
90 '|' => '|',
91 '^' => ' ^ ',
92 '^^' => ' ^^ '
99 public function copyEvalEnv($frames = array() ){
100 $new_env = new Less_Environment();
101 $new_env->frames = $frames;
102 return $new_env;
106 public static function isMathOn(){
107 return !Less_Parser::$options['strictMath'] || Less_Environment::$parensStack;
110 public static function isPathRelative($path){
111 return !preg_match('/^(?:[a-z-]+:|\/)/',$path);
116 * Canonicalize a path by resolving references to '/./', '/../'
117 * Does not remove leading "../"
118 * @param string path or url
119 * @return string Canonicalized path
122 public static function normalizePath($path){
124 $segments = explode('/',$path);
125 $segments = array_reverse($segments);
127 $path = array();
128 $path_len = 0;
130 while( $segments ){
131 $segment = array_pop($segments);
132 switch( $segment ) {
134 case '.':
135 break;
137 case '..':
138 if( !$path_len || ( $path[$path_len-1] === '..') ){
139 $path[] = $segment;
140 $path_len++;
141 }else{
142 array_pop($path);
143 $path_len--;
145 break;
147 default:
148 $path[] = $segment;
149 $path_len++;
150 break;
154 return implode('/',$path);
158 public function unshiftFrame($frame){
159 array_unshift($this->frames, $frame);
162 public function shiftFrame(){
163 return array_shift($this->frames);