/** * Gets or sets rgb * * @param string $rgb * @return string|self */ public function rgb($rgb = null) { if (null === $rgb) { return $this->property('rgb'); } return $this->property('rgb', Text::isRgb(trim($rgb)) ? trim($rgb) : ''); }
public function testBoolToString() { $number = mt_rand(); $string = self::randomString(); $this->assertSame('true', Text::boolToString(true)); $this->assertSame('false', Text::boolToString(false)); $this->assertSame($number, Text::boolToString($number)); $this->assertSame($string, Text::boolToString($string)); }
public function testBoolToString() { $number = mt_rand(1, 100); $string = $this->faker->word; $this->assertSame('true', Text::boolToString(true)); $this->assertSame('false', Text::boolToString(false)); $this->assertSame($number, Text::boolToString($number)); $this->assertSame($string, Text::boolToString($string)); }
/** * Add an array to xml. * * @param array $array. * @param string $namespace. * @return void */ public function addArray(array $array = [], $namespace = null) { foreach ($array as $name => $param) { if (is_array($param) and Text::isValidTagName($name)) { $textValue = null; if (isset($param['_'])) { $textValue = $param['_']; unset($param['_']); } if (is_numeric(key($param))) { foreach ($param as $value) { if (is_array($value)) { $this->addArray([$name => $value]); } else { $this->addChild($name, Text::boolToString($value), $namespace); } } } else { $child = $this->addChild($name, Text::boolToString($textValue), $namespace); foreach ($param as $key => $value) { if (!Text::isValidTagName($key)) { throw new Exception('Illegal character in tag name. tag: ' . $key); } if (is_array($value)) { if (is_numeric(key($value))) { foreach ($value as $k => $v) { if (is_array($v)) { $child->addArray([$key => $v]); } else { $child->addChild($key, Text::boolToString($v), $namespace); } } } else { $child->addArray([$key => $value]); } } else { $child->addAttribute($key, Text::boolToString($value)); } } } } else { if (!Text::isValidTagName($name)) { throw new Exception('Illegal character in tag name. tag: ' . $name); } $this->addChild($name, Text::boolToString($param), $namespace); } } return $this; }
/** * Method returning the xml representation of this class * * @param string $name * @return SimpleXML */ public function toXml($name = null) { $this->emit('before', [$this]); $name = !empty($name) ? $name : $this->className(); if (null !== $this->_value) { $xml = new SimpleXML('<' . $name . '>' . $this->_value . '</' . $name . '>'); } else { $xml = new SimpleXML('<' . $name . ' />'); } foreach ($this->_properties as $key => $value) { if ($value instanceof \Zimbra\Enum\Base) { $xml->addAttribute($key, $value->value()); } elseif (is_bool($value)) { $xml->addAttribute($key, Text::boolToString($value)); } else { $xml->addAttribute($key, $value); } } if (count($this->_children)) { foreach ($this->_children as $key => $value) { if ($value instanceof \Zimbra\Struct\Base) { $xml->append($value->toXml($key), $value->GetXmlNamespace()); } elseif ($value instanceof \Zimbra\Enum\Base) { $xml->addChild($key, $value->value()); } elseif (is_bool($value)) { $xml->addChild($key, Text::boolToString($value)); } elseif (is_array($value)) { foreach ($value as $child) { if ($child instanceof \Zimbra\Struct\Base) { $xml->append($child->toXml($key), $child->GetXmlNamespace()); } elseif ($child instanceof \Zimbra\Enum\Base) { $xml->addChild($key, $child->value()); } elseif (is_bool($child)) { $xml->addChild($key, Text::boolToString($child)); } else { $xml->addChild($key, $child); } } } else { $xml->addChild($key, $value); } } } $this->emit('after.xml', [$xml]); return $xml; }
/** * Sets rgb * * @param string $rgb * @return self */ public function setRgb($rgb) { return $this->setProperty('rgb', Text::isRgb(trim($rgb)) ? trim($rgb) : ''); }