Skip to content

Instantly share code, notes, and snippets.

View vudaltsov's full-sized avatar
🐘

Valentin Udaltsov vudaltsov

🐘
View GitHub Profile
<?php
/**
* @psalm-pure
* @template T
* @template TArray of array<T>
* @param TArray $values
* @return (TArray is non-empty-array<T> ? T : ?T)
*/
function array_value_first(array $values): mixed
@vudaltsov
vudaltsov / php_errors.yaml
Created February 14, 2022 18:47
Symfony php_errors config
framework:
php_errors:
log:
!php/const E_ERROR: !php/const Psr\Log\LogLevel::CRITICAL
!php/const E_WARNING: !php/const Psr\Log\LogLevel::CRITICAL
!php/const E_PARSE: !php/const Psr\Log\LogLevel::CRITICAL
!php/const E_NOTICE: !php/const Psr\Log\LogLevel::CRITICAL
!php/const E_CORE_ERROR: !php/const Psr\Log\LogLevel::CRITICAL
!php/const E_CORE_WARNING: !php/const Psr\Log\LogLevel::CRITICAL
!php/const E_COMPILE_ERROR: !php/const Psr\Log\LogLevel::CRITICAL
<?php
declare(strict_types=1);
namespace HappyInc\Infrastructure\Migrations;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
@vudaltsov
vudaltsov / Interpolator.php
Last active June 3, 2022 18:37
PHP Interpolator
<?php
declare(strict_types=1);
final class Interpolator
{
public function __construct(
private string $format = '%s',
) {
}
@vudaltsov
vudaltsov / test.php
Last active April 5, 2021 21:03
sqlite vs vimeo/php-mysql-engine
<?php
declare(strict_types=1);
require_once __DIR__.'/vendor/autoload.php';
const ITERATIONS = 10_000;
$stopwatch = new \Symfony\Component\Stopwatch\Stopwatch();
$event = $stopwatch->start('db');
<?php
/**
* @return array<string, mixed>
*/
function objectToArray(object $object): array
{
return (fn (): array => get_object_vars($this))->call($object);
}
@vudaltsov
vudaltsov / .env.local
Last active October 6, 2020 14:05
Symfony Mailer simple internal smpt transport
MAILER_DSN=insmtp://0.0.0.0
<?php
declare(strict_types=1);
/**
* Computes the difference between two dates in milliseconds.
*
* @psalm-pure
*
* @return int $a - $b

Полезные пакеты для замера использованной памяти

Пример корректной обработки утечек памяти для worker

Про параметр $real_usage в memory_get_usage()

<?php
declare(strict_types=1);
namespace Infrastructure\Uuid;
use Ramsey\Uuid\Nonstandard\UuidV6;
use Ramsey\Uuid\Rfc4122\UuidV1;
use Ramsey\Uuid\Uuid;