Skip to content

Instantly share code, notes, and snippets.

@mikemix
mikemix / AbstractTypedDataMapper.php
Last active December 28, 2022 18:47
Symfony Form Data Mapper helper
<?php
declare(strict_types=1);
namespace App\Form\DataMapper;
use Symfony\Component\Form\DataMapperInterface;
use Symfony\Component\Form\Exception\UnexpectedTypeException;
use Symfony\Component\Form\FormInterface;
<?php
final class RandomImageSource implements ImageSourceInterface
{
/** {@inheritDoc} */
public function __invoke(string $imageId, string $imageFormat): ImageInterface
{
return new ImmutableImage($imageId, $imageFormat, static function () use ($imageId): string {
$randomImageUrl = \sprintf('https://picsum.photos/seed/%s/1000/1000', \sha1($imageId));
$randomImageData = \file_get_contents($randomImageUrl);
<?php
final class IndexAction
{
private const YEAR = 31536000;
public function __construct(
private readonly ChecksumValidatorInterface $checksumValidator,
private readonly SupportedImagesInterface $supportedFormats,
private readonly SizeFactoryInterface $sizeFactory,
<?php
final class UrlGenerateCommand extends Command
{
private readonly RouterInterface $router;
public function __construct(
RouterInterface $router,
) {
parent::__construct();
@mikemix
mikemix / thumbgun.www-data.dockerfile
Created August 28, 2022 19:32
Recreating www-data user in Alpine
ARG USER_UID=82
ARG USER_GID=82
# Recreate www-data user with user id matching the host
RUN deluser --remove-home www-data && \
addgroup -S -g ${USER_GID} www-data && \
adduser -u ${USER_UID} -D -S -G www-data www-data
<?php
declare(strict_types=1);
namespace App\Notification\Impl;
use App\Notification\EmailAddress;
use App\Notification\EmailNotificationInterface;
final class EmailNotification implements EmailNotificationInterface
<?php
declare(strict_types=1);
namespace App\User\Notification;
use App\Notification\EmailNotificationInterface;
use App\Notification\NotificationManagerInterface;
use App\Events\PostRegistrationEvent;
use App\User\Notification\WelcomeGreetingEmailNotificationFactory;
<?php
declare(strict_types=1);
namespace App\Notification\Implementation;
use App\Notification\NotificationInterface;
use App\Notification\TransportInterface;
/**
<?php
declare(strict_types=1);
namespace App\User\Notification;
use App\Notification\EmailAdddress;
use App\Notification\EmailNotificationInterface;
use App\Notification\Impl\EmailNotification;
use App\Template\TemplateEngine;
<?php
declare(strict_types=1);
namespace App\Notification;
/**
* E-mail notification
*/
interface EmailNotificationInterface extends NotificationInterface