| 1 |
<?php |
| 2 |
|
| 3 |
namespace TijsVerkoyen\CssToInlineStyles\Css\Property; |
| 4 |
|
| 5 |
use Symfony\Component\CssSelector\Node\Specificity; |
| 6 |
|
| 7 |
final class Property |
| 8 |
{ |
| 9 |
/** |
| 10 |
* @var string |
| 11 |
*/ |
| 12 |
private $name; |
| 13 |
|
| 14 |
/** |
| 15 |
* @var string |
| 16 |
*/ |
| 17 |
private $value; |
| 18 |
|
| 19 |
/** |
| 20 |
* @var Specificity|null |
| 21 |
*/ |
| 22 |
private $originalSpecificity; |
| 23 |
|
| 24 |
/** |
| 25 |
* Property constructor. |
| 26 |
* @param string $name |
| 27 |
* @param string $value |
| 28 |
* @param Specificity|null $specificity |
| 29 |
*/ |
| 30 |
public function __construct($name, $value, ?Specificity $specificity = null) |
| 31 |
{ |
| 32 |
$this->name = $name; |
| 33 |
$this->value = $value; |
| 34 |
$this->originalSpecificity = $specificity; |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* Get name |
| 39 |
* |
| 40 |
* @return string |
| 41 |
*/ |
| 42 |
public function getName() |
| 43 |
{ |
| 44 |
return $this->name; |
| 45 |
} |
| 46 |
|
| 47 |
/** |
| 48 |
* Get value |
| 49 |
* |
| 50 |
* @return string |
| 51 |
*/ |
| 52 |
public function getValue() |
| 53 |
{ |
| 54 |
return $this->value; |
| 55 |
} |
| 56 |
|
| 57 |
/** |
| 58 |
* Get originalSpecificity |
| 59 |
* |
| 60 |
* @return Specificity|null |
| 61 |
*/ |
| 62 |
public function getOriginalSpecificity() |
| 63 |
{ |
| 64 |
return $this->originalSpecificity; |
| 65 |
} |
| 66 |
|
| 67 |
/** |
| 68 |
* Is this property important? |
| 69 |
* |
| 70 |
* @return bool |
| 71 |
*/ |
| 72 |
public function isImportant() |
| 73 |
{ |
| 74 |
return (stripos($this->value, '!important') !== false); |
| 75 |
} |
| 76 |
|
| 77 |
/** |
| 78 |
* Get the textual representation of the property |
| 79 |
* |
| 80 |
* @return string |
| 81 |
*/ |
| 82 |
public function toString() |
| 83 |
{ |
| 84 |
return sprintf( |
| 85 |
'%1$s: %2$s;', |
| 86 |
$this->name, |
| 87 |
$this->value |
| 88 |
); |
| 89 |
} |
| 90 |
} |
| 91 |
|