Skip to content

Commit 3ce7030

Browse files
author
ju1ius
committed
remove use of deprecated methods
1 parent 804ed93 commit 3ce7030

File tree

1 file changed

+128
-49
lines changed

1 file changed

+128
-49
lines changed

lib/CSSRuleSet.php

Lines changed: 128 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ public function createShorthands()
156156
/**
157157
* Split shorthand border declarations (e.g. <tt>border: 1px red;</tt>)
158158
* Additional splitting happens in expandDimensionsShorthand
159+
* Multiple borders are not yet supported as of CSS3
159160
**/
160161
public function expandBorderShorthand()
161162
{
@@ -170,10 +171,16 @@ public function expandBorderShorthand()
170171
{
171172
if(!isset($aRules[$sBorderRule])) continue;
172173
$oRule = $aRules[$sBorderRule];
173-
foreach ($oRule->getValues() as $aValues)
174+
$mRuleValue = $oRule->getValue();
175+
$aValues = array();
176+
if(!$mRuleValue instanceof CSSRuleValueList) {
177+
$aValues[] = $mRuleValue;
178+
}
179+
else {
180+
$aValues = $mRuleValue->getListComponents();
181+
}
182+
foreach ($aValues as $mValue)
174183
{
175-
// multiple borders are not yet supported as of CSS3
176-
$mValue = $aValues[0];
177184
if($mValue instanceof CSSValue)
178185
{
179186
$mNewValue = clone $mValue;
@@ -229,7 +236,14 @@ public function expandDimensionsShorthand()
229236
{
230237
if(!isset($aRules[$sProperty])) continue;
231238
$oRule = $aRules[$sProperty];
232-
$aValues = $oRule->getValues();
239+
$mRuleValue = $oRule->getValue();
240+
$aValues = array();
241+
if(!$mRuleValue instanceof CSSRuleValueList) {
242+
$aValues[] = $mRuleValue;
243+
}
244+
else {
245+
$aValues = $mRuleValue->getListComponents();
246+
}
233247
$top = $right = $bottom = $left = null;
234248
switch(count($aValues))
235249
{
@@ -278,37 +292,44 @@ public function expandFontShorthand()
278292
'font-style' => 'normal', 'font-variant' => 'normal', 'font-weight' => 'normal',
279293
'font-size' => 'normal', 'line-height' => 'normal'
280294
);
281-
foreach($oRule->getValues() as $aValues)
295+
$mRuleValue = $oRule->getValue();
296+
$aValues = array();
297+
if(!$mRuleValue instanceof CSSRuleValueList) {
298+
$aValues[] = $mRuleValue;
299+
}
300+
else {
301+
$aValues = $mRuleValue->getListComponents();
302+
}
303+
foreach($aValues as $mValue)
282304
{
283-
$mValue = $aValues[0];
284305
if(!$mValue instanceof CSSValue)
285306
{
286-
$mValue = strtolower($mValue);
307+
$mValue = mb_strtolower($mValue);
287308
}
288309
if(in_array($mValue, array('normal', 'inherit')))
289310
{
290311
foreach (array('font-style', 'font-weight', 'font-variant') as $sProperty)
291312
{
292313
if(!isset($aFontProperties[$sProperty]))
293314
{
294-
$aFontProperties[$sProperty] = $aValues;
315+
$aFontProperties[$sProperty] = $mValue;
295316
}
296317
}
297318
}
298319
else if(in_array($mValue, array('italic', 'oblique')))
299320
{
300-
$aFontProperties['font-style'] = $aValues;
321+
$aFontProperties['font-style'] = $mValue;
301322
}
302323
else if($mValue == 'small-caps')
303324
{
304-
$aFontProperties['font-variant'] = $aValues;
325+
$aFontProperties['font-variant'] = $mValue;
305326
}
306327
else if(in_array($mValue, array('bold', 'bolder', 'lighter'))
307328
|| ($mValue instanceof CSSSize
308329
&& in_array($mValue->getSize(), range(100, 900, 100))
309330
)
310331
){
311-
$aFontProperties['font-weight'] = $aValues;
332+
$aFontProperties['font-weight'] = $mValue;
312333
}
313334
else if($mValue instanceof CSSRuleValueList && $mValue->getListSeparator() === '/')
314335
{
@@ -318,18 +339,17 @@ public function expandFontShorthand()
318339
}
319340
else if($mValue instanceof CSSSize && $mValue->getUnit() !== null)
320341
{
321-
$aFontProperties['font-size'] = $aValues;
342+
$aFontProperties['font-size'] = $mValue;
322343
}
323344
else
324345
{
325-
$aFontProperties['font-family'] = $aValues;
346+
$aFontProperties['font-family'] = $mValue;
326347
}
327348
}
328-
foreach ($aFontProperties as $sProperty => $aValues)
349+
foreach ($aFontProperties as $sProperty => $mValue)
329350
{
330-
if(!is_array($aValues)) $aValues = array($aValues);
331351
$oNewRule = new CSSRule($sProperty);
332-
$oNewRule->setValues(array($aValues));
352+
$oNewRule->addValue($mValue);
333353
$oNewRule->setIsImportant($oRule->getIsImportant());
334354
$this->addRule($oNewRule);
335355
}
@@ -352,41 +372,47 @@ public function expandBackgroundShorthand()
352372
'background-repeat' => array('repeat'), 'background-attachment' => array('scroll'),
353373
'background-position' => array(new CSSSize(0, '%'), new CSSSize(0, '%'))
354374
);
355-
$aValuesList = $oRule->getValues();
356-
if(count($aValuesList) == 1 && $aValuesList[0][0] == 'inherit')
375+
$mRuleValue = $oRule->getValue();
376+
$aValues = array();
377+
if(!$mRuleValue instanceof CSSRuleValueList) {
378+
$aValues[] = $mRuleValue;
379+
}
380+
else {
381+
$aValues = $mRuleValue->getListComponents();
382+
}
383+
if(count($aValues) == 1 && $aValues[0] == 'inherit')
357384
{
358-
foreach ($aBgProperties as $sProperty => $aValues) {
385+
foreach ($aBgProperties as $sProperty => $mValue) {
359386
$oNewRule = new CSSRule($sProperty);
360-
$oNewRule->addValue(array('inherit'));
387+
$oNewRule->addValue('inherit');
361388
$oNewRule->setIsImportant($oRule->getIsImportant());
362389
$this->addRule($oNewRule);
363390
}
364391
$this->removeRule('background');
365392
return;
366393
}
367394
$iNumBgPos = 0;
368-
foreach($aValuesList as $aValues)
395+
foreach($aValues as $mValue)
369396
{
370-
$mValue = $aValues[0];
371397
if(!$mValue instanceof CSSValue)
372398
{
373-
$mValue = strtolower($mValue);
399+
$mValue = mb_strtolower($mValue);
374400
}
375401
if ($mValue instanceof CSSURL)
376402
{
377-
$aBgProperties['background-image'] = $aValues;
403+
$aBgProperties['background-image'] = $mValue;
378404
}
379405
else if($mValue instanceof CSSColor)
380406
{
381-
$aBgProperties['background-color'] = $aValues;
407+
$aBgProperties['background-color'] = $mValue;
382408
}
383409
else if(in_array($mValue, array('scroll', 'fixed')))
384410
{
385-
$aBgProperties['background-attachment'] = $aValues;
411+
$aBgProperties['background-attachment'] = $mValue;
386412
}
387413
else if(in_array($mValue, array('repeat','no-repeat', 'repeat-x', 'repeat-y')))
388414
{
389-
$aBgProperties['background-repeat'] = $aValues;
415+
$aBgProperties['background-repeat'] = $mValue;
390416
}
391417
else if(in_array($mValue, array('left','center','right','top','bottom'))
392418
|| $mValue instanceof CSSSize
@@ -403,10 +429,10 @@ public function expandBackgroundShorthand()
403429
$iNumBgPos++;
404430
}
405431
}
406-
foreach ($aBgProperties as $sProperty => $aValues) {
432+
foreach ($aBgProperties as $sProperty => $mValue) {
407433
$oNewRule = new CSSRule($sProperty);
408434
$oNewRule->setIsImportant($oRule->getIsImportant());
409-
$oNewRule->addValue($aValues);
435+
$oNewRule->addValue($mValue);
410436
$this->addRule($oNewRule);
411437
}
412438
$this->removeRule('background');
@@ -424,8 +450,16 @@ public function createBackgroundShorthand()
424450
if(!isset($aRules[$sProperty])) continue;
425451
$oRule = $aRules[$sProperty];
426452
if(!$oRule->getIsImportant()) {
427-
foreach($aRules[$sProperty]->getValues() as $aValues) {
428-
$aNewValues[] = $aValues;
453+
$mRuleValue = $oRule->getValue();
454+
$aValues = array();
455+
if(!$mRuleValue instanceof CSSRuleValueList) {
456+
$aValues[] = $mRuleValue;
457+
}
458+
else {
459+
$aValues = $mRuleValue->getListComponents();
460+
}
461+
foreach($aValues as $mValue) {
462+
$aNewValues[] = $mValue;
429463
}
430464
$this->removeRule($sProperty);
431465
}
@@ -455,10 +489,17 @@ public function createBorderShorthand() {
455489
if(!isset($aRules[$sBorderRule])) continue;
456490
$oRule = $aRules[$sBorderRule];
457491
if(!$oRule->getIsImportant()) {
492+
$mRuleValue = $oRule->getValue();
493+
$aValues = array();
494+
if(!$mRuleValue instanceof CSSRuleValueList) {
495+
$aValues[] = $mRuleValue;
496+
}
497+
else {
498+
$aValues = $mRuleValue->getListComponents();
499+
}
458500
// Can't merge if multiple values !
459-
if(count($oRule->getValues()) > 1) continue;
460-
foreach($oRule->getValues() as $aValues) {
461-
$mValue = $aValues[0];
501+
if(count($aValues) > 1) continue;
502+
foreach($aValues as $mValue) {
462503
if($mValue instanceof CSSValue) {
463504
$mNewValue = clone $mValue;
464505
$aNewValues[] = $mNewValue;
@@ -472,7 +513,7 @@ public function createBorderShorthand() {
472513
if(count($aNewValues)) {
473514
$oNewRule = new CSSRule('border');
474515
foreach($aNewValues as $mNewValue) {
475-
$oNewRule->addValue(array($mNewValue));
516+
$oNewRule->addValue($mNewValue);
476517
}
477518
$this->addRule($oNewRule);
478519
foreach($aBorderRules as $sRuleName) {
@@ -516,8 +557,16 @@ public function createDimensionsShorthand()
516557
$aValues = array();
517558
foreach ($aPositions as $sPosition)
518559
{
519-
$aValuesList = $aRules[sprintf($sExpanded, $sPosition)]->getValues();
520-
$aValues[$sPosition] = $aValuesList[0];
560+
$oRule = $aRules[sprintf($sExpanded, $sPosition)];
561+
$mRuleValue = $oRule->getValue();
562+
$aRuleValues = array();
563+
if(!$mRuleValue instanceof CSSRuleValueList) {
564+
$aRuleValues[] = $mRuleValue;
565+
}
566+
else {
567+
$aRuleValues = $mRuleValue->getListComponents();
568+
}
569+
$aValues[$sPosition] = $aRuleValues;
521570
}
522571
$oNewRule = new CSSRule($sProperty);
523572
if((string)$aValues['left'][0] == (string)$aValues['right'][0])
@@ -582,35 +631,65 @@ public function createFontShorthand()
582631
if(isset($aRules[$sProperty]))
583632
{
584633
$oRule = $aRules[$sProperty];
585-
$aValuesList = $oRule->getValues();
586-
if($aValuesList[0][0] !== 'normal')
634+
$mRuleValue = $oRule->getValue();
635+
$aValues = array();
636+
if(!$mRuleValue instanceof CSSRuleValueList) {
637+
$aValues[] = $mRuleValue;
638+
}
639+
else {
640+
$aValues = $mRuleValue->getListComponents();
641+
}
642+
if($aValues[0] !== 'normal')
587643
{
588-
$oNewRule->addValue($aValuesList[0]);
644+
$oNewRule->addValue($aValues[0]);
589645
}
590646
}
591647
}
592648
// Get the font-size value
593-
$aFSValues = $aRules['font-size']->getValues();
649+
$oRule = $aRules['font-size'];
650+
$mRuleValue = $oRule->getValue();
651+
$aFSValues = array();
652+
if(!$mRuleValue instanceof CSSRuleValueList) {
653+
$aFSValues[] = $mRuleValue;
654+
}
655+
else {
656+
$aFSValues = $mRuleValue->getListComponents();
657+
}
594658
// But wait to know if we have line-height to add it
595659
if(isset($aRules['line-height']))
596660
{
597-
$aLHValues = $aRules['line-height']->getValues();
598-
if($aLHValues[0][0] !== 'normal')
661+
$oRule = $aRules['line-height'];
662+
$mRuleValue = $oRule->getValue();
663+
$aLHValues = array();
664+
if(!$mRuleValue instanceof CSSRuleValueList) {
665+
$aLHValues[] = $mRuleValue;
666+
}
667+
else {
668+
$aLHValues = $mRuleValue->getListComponents();
669+
}
670+
if($aLHValues[0] !== 'normal')
599671
{
600672
$val = new CSSRuleValueList('/');
601-
$val->addListComponent($aFSValues[0][0]);
602-
$val->addListComponent($aLHValues[0][0]);
603-
$oNewRule->addValue(array($val));
673+
$val->addListComponent($aFSValues[0]);
674+
$val->addListComponent($aLHValues[0]);
675+
$oNewRule->addValue($val);
604676
}
605677
}
606678
else
607679
{
608680
$oNewRule->addValue($aFSValues[0]);
609681
}
610-
611-
$aFFValues = $aRules['font-family']->getValues();
682+
$oRule = $aRules['font-family'];
683+
$mRuleValue = $oRule->getValue();
684+
$aFFValues = array();
685+
if(!$mRuleValue instanceof CSSRuleValueList) {
686+
$aFFValues[] = $mRuleValue;
687+
}
688+
else {
689+
$aFFValues = $mRuleValue->getListComponents();
690+
}
612691
$oFFValue = new CSSRuleValueList(',');
613-
$oFFValue->setListComponents($aFFValues[0]);
692+
$oFFValue->setListComponents($aFFValues);
614693
$oNewRule->addValue($oFFValue);
615694

616695
$this->addRule($oNewRule);

0 commit comments

Comments
 (0)