Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/jeijei4/php_stringify


https://github.com/jeijei4/php_stringify

Last synced: 21 days ago
JSON representation

Awesome Lists containing this project

README

        

# PHP stringify

```php
stringify(
$formatter->format(new DateTimeImmutable(
$value->format("Y-m-d H:i:s.vp"),
$timezone
))
);
}

return $this->stringify($value->format("Y-m-d H:i:s.vp"));
}

if ($value instanceof UnitEnum) {
return $value->name;
}

if (is_object($value)) {
if (method_exists($value, '__toString')) {
return $this->stringify($value->__toString());
}

return json_encode($value, JSON_PRETTY_PRINT);
}

if (is_array($value)) {
return json_encode($value, JSON_PRETTY_PRINT);
}

if (is_string($value)) {
return '"' . $value . '"';
}

if (is_resource($value)) {
return 'resource;' . get_resource_type($value);
}

if (null === $value) {
return 'null';
}

if (false === $value) {
return 'false';
}

if (true === $value) {
return 'true';
}

if (is_scalar($value)) {
$val = (string)$value;

if (mb_strlen($val) > 100) {
return mb_substr($val, 0, 97) . "...";
}

return $val;
}

return gettype($value);
}
```