Skip to content

Instantly share code, notes, and snippets.

@vudaltsov
Last active February 16, 2023 18:40
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save vudaltsov/eb53927894cb467588e67352e2d8f1d9 to your computer and use it in GitHub Desktop.
Save vudaltsov/eb53927894cb467588e67352e2d8f1d9 to your computer and use it in GitHub Desktop.
<?php
declare(strict_types=1);
namespace HappyInc\Infrastructure;
/**
* @psalm-pure
*/
function mb_ucfirst(string $string): string
{
return mb_strtoupper(mb_substr($string, 0, 1)).mb_substr($string, 1);
}
/**
* @throws JsonException
*/
function jsonEncode(mixed $data, int $flags = 0): string
{
return json_encode($data, $flags | JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE);
}
/**
* @template TValue
* @template TValues of iterable<TValue>
* @param TValues $values
* @return (TValues is non-empty-array ? non-empty-list<TValue> : list<TValue>)
*/
function toList(iterable $values): array
{
if (is_array($values)) {
return array_values($values);
}
return iterator_to_array($values, false);
}
function tempFile(?string $prefix = null): string
{
return tempnam(sys_get_temp_dir(), $prefix ?? uniqid());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment