Laravel version update
Laravel version update
This commit is contained in:
122
vendor/tijsverkoyen/css-to-inline-styles/src/Css/Property/Processor.php
vendored
Normal file
122
vendor/tijsverkoyen/css-to-inline-styles/src/Css/Property/Processor.php
vendored
Normal file
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
|
||||
namespace TijsVerkoyen\CssToInlineStyles\Css\Property;
|
||||
|
||||
use Symfony\Component\CssSelector\Node\Specificity;
|
||||
|
||||
class Processor
|
||||
{
|
||||
/**
|
||||
* Split a string into seperate properties
|
||||
*
|
||||
* @param string $propertiesString
|
||||
* @return array
|
||||
*/
|
||||
public function splitIntoSeparateProperties($propertiesString)
|
||||
{
|
||||
$propertiesString = $this->cleanup($propertiesString);
|
||||
|
||||
$properties = (array) explode(';', $propertiesString);
|
||||
$keysToRemove = array();
|
||||
$numberOfProperties = count($properties);
|
||||
|
||||
for ($i = 0; $i < $numberOfProperties; $i++) {
|
||||
$properties[$i] = trim($properties[$i]);
|
||||
|
||||
// if the new property begins with base64 it is part of the current property
|
||||
if (isset($properties[$i + 1]) && strpos(trim($properties[$i + 1]), 'base64,') === 0) {
|
||||
$properties[$i] .= ';' . trim($properties[$i + 1]);
|
||||
$keysToRemove[] = $i + 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($keysToRemove)) {
|
||||
foreach ($keysToRemove as $key) {
|
||||
unset($properties[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
return array_values($properties);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $string
|
||||
* @return mixed|string
|
||||
*/
|
||||
private function cleanup($string)
|
||||
{
|
||||
$string = str_replace(array("\r", "\n"), '', $string);
|
||||
$string = str_replace(array("\t"), ' ', $string);
|
||||
$string = str_replace('"', '\'', $string);
|
||||
$string = preg_replace('|/\*.*?\*/|', '', $string);
|
||||
$string = preg_replace('/\s\s+/', ' ', $string);
|
||||
|
||||
$string = trim($string);
|
||||
$string = rtrim($string, ';');
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a property-string into an object
|
||||
*
|
||||
* @param string $property
|
||||
* @return Property|null
|
||||
*/
|
||||
public function convertToObject($property, Specificity $specificity = null)
|
||||
{
|
||||
if (strpos($property, ':') === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
list($name, $value) = explode(':', $property, 2);
|
||||
|
||||
$name = trim($name);
|
||||
$value = trim($value);
|
||||
|
||||
if ($value === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Property($name, $value, $specificity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert an array of property-strings into objects
|
||||
*
|
||||
* @param array $properties
|
||||
* @return Property[]
|
||||
*/
|
||||
public function convertArrayToObjects(array $properties, Specificity $specificity = null)
|
||||
{
|
||||
$objects = array();
|
||||
|
||||
foreach ($properties as $property) {
|
||||
$object = $this->convertToObject($property, $specificity);
|
||||
if ($object === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$objects[] = $object;
|
||||
}
|
||||
|
||||
return $objects;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the property-string for multiple properties
|
||||
*
|
||||
* @param array $properties
|
||||
* @return string
|
||||
*/
|
||||
public function buildPropertiesString(array $properties)
|
||||
{
|
||||
$chunks = array();
|
||||
|
||||
foreach ($properties as $property) {
|
||||
$chunks[] = $property->toString();
|
||||
}
|
||||
|
||||
return implode(' ', $chunks);
|
||||
}
|
||||
}
|
||||
90
vendor/tijsverkoyen/css-to-inline-styles/src/Css/Property/Property.php
vendored
Normal file
90
vendor/tijsverkoyen/css-to-inline-styles/src/Css/Property/Property.php
vendored
Normal file
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
namespace TijsVerkoyen\CssToInlineStyles\Css\Property;
|
||||
|
||||
use Symfony\Component\CssSelector\Node\Specificity;
|
||||
|
||||
final class Property
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $value;
|
||||
|
||||
/**
|
||||
* @var Specificity
|
||||
*/
|
||||
private $originalSpecificity;
|
||||
|
||||
/**
|
||||
* Property constructor.
|
||||
* @param $name
|
||||
* @param $value
|
||||
* @param Specificity|null $specificity
|
||||
*/
|
||||
public function __construct($name, $value, Specificity $specificity = null)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->value = $value;
|
||||
$this->originalSpecificity = $specificity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getValue()
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get originalSpecificity
|
||||
*
|
||||
* @return Specificity
|
||||
*/
|
||||
public function getOriginalSpecificity()
|
||||
{
|
||||
return $this->originalSpecificity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this property important?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isImportant()
|
||||
{
|
||||
return (stripos($this->value, '!important') !== false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the textual representation of the property
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function toString()
|
||||
{
|
||||
return sprintf(
|
||||
'%1$s: %2$s;',
|
||||
$this->name,
|
||||
$this->value
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user