- md5
- f1a6fc0abd1d6cbe57989ea54b38688b
- sha1
- 35e3bdf04b2807454438a07a710615a1ea4ca76b
- sha256
- b27d380bf8b2f2d8b358a3d21e77542387aed96a5be9a2c8c5051e8092da14c1
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
<?php
namespace OzdemirBurak\Iris\Traits;
trait RgbTrait
{
/**
* @var string|int
*/
protected $red;
/**
* @var string|int
*/
protected $green;
/**
* @var string|int
*/
protected $blue;
/**
* @param int|string $red
*
* @return int|string|$this
*/
public function red($red = null)
{
if ($red !== null) {
$this->validateAndSet('red', $red);
return $this;
}
return !empty($this->castsInteger) ? (int) $this->red : $this->red;
}
/**
* @param float|int|string $green
*
* @return float|int|string|$this
*/
public function green($green = null)
{
if ($green !== null) {
$this->validateAndSet('green', $green);
return $this;
}
return !empty($this->castsInteger) ? (int) $this->green : $this->green;
}
/**
* @param float|int|string $blue
*
* @return float|int|string|$this
*/
public function blue($blue = null)
{
if ($blue !== null) {
$this->validateAndSet('blue', $blue);
return $this;
}
return !empty($this->castsInteger) ? (int) $this->blue : $this->blue;
}
/**
* @return array
*/
public function values()
{
return [
$this->red(),
$this->green(),
$this->blue()
];
}
/**
* @param string $property
* @param float|int|string $value
*/
protected function validateAndSet($property, $value)
{
if (!empty($this->castsInteger)) {
$this->{$property} = $value >= 0 && $value <= 255 ? (int) round($value) : $this->{$property};
} else {
$value = strlen($value) === 1 ? $value . $value : $value;
$this->{$property} = preg_match('/^[a-f0-9]{2}$/i', $value) ? $value : $this->{$property};
}
}
}
The same content is in 9 releases, Joomla 4.0.0-alpha11 to 4.0.0-beta7. See them all, or every version of this file.