[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * Unit 5 * 6 * @package Less 7 * @subpackage tree 8 */ 9 class Less_Tree_Unit extends Less_Tree{ 10 11 var $numerator = array(); 12 var $denominator = array(); 13 public $backupUnit; 14 public $type = 'Unit'; 15 16 public function __construct($numerator = array(), $denominator = array(), $backupUnit = null ){ 17 $this->numerator = $numerator; 18 $this->denominator = $denominator; 19 $this->backupUnit = $backupUnit; 20 } 21 22 public function __clone(){ 23 } 24 25 /** 26 * @see Less_Tree::genCSS 27 */ 28 public function genCSS( $output ){ 29 30 if( $this->numerator ){ 31 $output->add( $this->numerator[0] ); 32 }elseif( $this->denominator ){ 33 $output->add( $this->denominator[0] ); 34 }elseif( !Less_Parser::$options['strictUnits'] && $this->backupUnit ){ 35 $output->add( $this->backupUnit ); 36 return ; 37 } 38 } 39 40 public function toString(){ 41 $returnStr = implode('*',$this->numerator); 42 foreach($this->denominator as $d){ 43 $returnStr .= '/'.$d; 44 } 45 return $returnStr; 46 } 47 48 public function __toString(){ 49 return $this->toString(); 50 } 51 52 53 /** 54 * @param Less_Tree_Unit $other 55 */ 56 public function compare($other) { 57 return $this->is( $other->toString() ) ? 0 : -1; 58 } 59 60 public function is($unitString){ 61 return $this->toString() === $unitString; 62 } 63 64 public function isLength(){ 65 $css = $this->toCSS(); 66 return !!preg_match('/px|em|%|in|cm|mm|pc|pt|ex/',$css); 67 } 68 69 public function isAngle() { 70 return isset( Less_Tree_UnitConversions::$angle[$this->toCSS()] ); 71 } 72 73 public function isEmpty(){ 74 return !$this->numerator && !$this->denominator; 75 } 76 77 public function isSingular() { 78 return count($this->numerator) <= 1 && !$this->denominator; 79 } 80 81 82 public function usedUnits(){ 83 $result = array(); 84 85 foreach(Less_Tree_UnitConversions::$groups as $groupName){ 86 $group = Less_Tree_UnitConversions::${$groupName}; 87 88 foreach($this->numerator as $atomicUnit){ 89 if( isset($group[$atomicUnit]) && !isset($result[$groupName]) ){ 90 $result[$groupName] = $atomicUnit; 91 } 92 } 93 94 foreach($this->denominator as $atomicUnit){ 95 if( isset($group[$atomicUnit]) && !isset($result[$groupName]) ){ 96 $result[$groupName] = $atomicUnit; 97 } 98 } 99 } 100 101 return $result; 102 } 103 104 public function cancel(){ 105 $counter = array(); 106 $backup = null; 107 108 foreach($this->numerator as $atomicUnit){ 109 if( !$backup ){ 110 $backup = $atomicUnit; 111 } 112 $counter[$atomicUnit] = ( isset($counter[$atomicUnit]) ? $counter[$atomicUnit] : 0) + 1; 113 } 114 115 foreach($this->denominator as $atomicUnit){ 116 if( !$backup ){ 117 $backup = $atomicUnit; 118 } 119 $counter[$atomicUnit] = ( isset($counter[$atomicUnit]) ? $counter[$atomicUnit] : 0) - 1; 120 } 121 122 $this->numerator = array(); 123 $this->denominator = array(); 124 125 foreach($counter as $atomicUnit => $count){ 126 if( $count > 0 ){ 127 for( $i = 0; $i < $count; $i++ ){ 128 $this->numerator[] = $atomicUnit; 129 } 130 }elseif( $count < 0 ){ 131 for( $i = 0; $i < -$count; $i++ ){ 132 $this->denominator[] = $atomicUnit; 133 } 134 } 135 } 136 137 if( !$this->numerator && !$this->denominator && $backup ){ 138 $this->backupUnit = $backup; 139 } 140 141 sort($this->numerator); 142 sort($this->denominator); 143 } 144 145 146 } 147
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |