Skip to content

Instantly share code, notes, and snippets.

View vudaltsov's full-sized avatar
🐘

Valentin Udaltsov vudaltsov

🐘
View GitHub Profile
@vudaltsov
vudaltsov / AppKernel.php
Last active July 19, 2020 19:56
Removing unnecessary Symfony services via a compiler pass
<?php
declare(strict_types=1);
namespace Application;
use Application\DependencyInjection\RemoveObjectNormalizerPass;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
use Symfony\Component\DependencyInjection\ContainerBuilder;
<?php
declare(strict_types=1);
namespace App\Console;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
@vudaltsov
vudaltsov / Php74ReflectionExtractor.php
Created May 3, 2020 19:49
Symfony <5.1 PHP 7.4 property types support
<?php
declare(strict_types=1);
namespace App\PropertyInfo;
use Symfony\Component\PropertyInfo\PropertyTypeExtractorInterface;
use Symfony\Component\PropertyInfo\Type;
final class Php74ReflectionExtractor implements PropertyTypeExtractorInterface
@vudaltsov
vudaltsov / A.php
Last active June 23, 2020 09:45
Symfony decorator
<?php
declare(strict_types=1);
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
final class A implements I, LoggerAwareInterface
{
use LoggerAwareTrait;
<?php
declare(strict_types=1);
namespace Infrastructure\Messaging;
use Doctrine\Persistence\ManagerRegistry;
use Psr\Log\LoggerInterface;
use Symfony\Component\Messenger\Envelope;
use Symfony\Component\Messenger\Middleware\MiddlewareInterface;
<?php
declare(strict_types=1);
namespace Infrastructure\Uuid;
use Ramsey\Uuid\Nonstandard\UuidV6;
use Ramsey\Uuid\Rfc4122\UuidV1;
use Ramsey\Uuid\Uuid;

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

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

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

<?php
declare(strict_types=1);
/**
* Computes the difference between two dates in milliseconds.
*
* @psalm-pure
*
* @return int $a - $b
@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
/**
* @return array<string, mixed>
*/
function objectToArray(object $object): array
{
return (fn (): array => get_object_vars($this))->call($object);
}