public function append($value) { if (is_scalar($value) || $value instanceof HString) { return $this->hString . $value; } throw new \InvalidArgumentException(sprintf("Cannot concatenate an HString with a %s", Helper::getType($value))); }
/** * @param HString|string $value * @return bool */ public function contains($value) { if (method_exists($value, "__toString")) { $value = $value->__toString(); } if (is_scalar($value)) { $this->value = (string) $value; } else { throw new \InvalidArgumentException(sprintf("%s cannot be converted to a string; it cannot be used as a search value within an HString", Helper::getType($value))); } return $this->containsValue(); }
private function convertToArray($item) { if (is_array($item)) { return $item; } if (is_string($item)) { return (new HString($item))->toArray(); } if ($item instanceof ContainerInterface) { return $item->toArray(); } throw new \InvalidArgumentException(sprintf("%s cannot be mapped", Helper::getType($item))); }
public function insert($value, $key = null) { if (is_scalar($value) || $value instanceof HString) { if (is_null($key)) { $key = $this->hString->count(); } elseif (is_numeric($key)) { $key = (int) $key; } else { throw new \InvalidArgumentException("Invalid array key"); } return $this->getPrefix($key) . $value . $this->getSuffix($key); } throw new \InvalidArgumentException(sprintf("Cannot insert %s into an HString", Helper::getType($value))); }
public function insert($value, $key = null) { if (is_scalar($value) || $value instanceof HString) { if (is_null($key)) { $key = strlen($this->hString); } elseif (is_numeric($key)) { $key = (int) $key; } else { throw new \InvalidArgumentException("Invalid array key"); } return substr_replace($this->hString, $value, $key, 0); } throw new \InvalidArgumentException(sprintf("Cannot insert %s into an HString", Helper::getType($value))); }
/** * (PHP 5 >= 5.1.0)<br/> * Constructs the object * * @link http://php.net/manual/en/serializable.unserialize.php * @param string $value <p> * The string representation of the object. * </p> * @return void */ public function unserialize($value) { if (is_scalar($value)) { $this->str = unserialize($value); } elseif (is_null($value)) { $this->str = null; } else { throw new \InvalidArgumentException(sprintf("HString cannot unserialize a %s", Helper::getType($value))); } }