Skip to content

Instantly share code, notes, and snippets.

@dbu
dbu / OAuthEsmtpTransportFactoryDecorator.php
Last active April 18, 2024 13:11
Send emails with Symfony Mailer through Outlook / office365 with OAuth
<?php
declare(strict_types=1);
namespace App\Infrastructure\Email;
use Symfony\Component\Mailer\Transport\Dsn;
use Symfony\Component\Mailer\Transport\Smtp\Auth\AuthenticatorInterface;
use Symfony\Component\Mailer\Transport\Smtp\EsmtpTransport;
use Symfony\Component\Mailer\Transport\Smtp\EsmtpTransportFactory;
@dbu
dbu / CacheWarmerCompilerPass.php
Last active March 4, 2024 15:13
Conditionally tag a service in Symfony
<?php
// src/DependencyInjection/CacheWarmerCompilerPass.php
namespace App\DependencyInjection;
use App\Cache\MyCacheWarmer;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Exception\EnvNotFoundException;
@dbu
dbu / CommandHelper.php
Created May 9, 2019 11:08
typed options and arguments for symfony console
abstract class CommandHelper
{
public static function getStringOption(InputInterface $input, string $name): ?string
{
$optionData = $input->getOption($name);
if (null !== $optionData && !\is_string($optionData)) {
throw new \InvalidArgumentException(sprintf('Invalid data provided for --%s', $name));
}
@dbu
dbu / DoctrineEncryptListener.php
Last active February 10, 2024 11:18
encrypting doctrine fields
<?php
namespace App\EventListener;
use App\Doctrine\Encryption\EncryptingEntityInterface;
use App\Doctrine\Encryption\EncryptorInterface;
use Doctrine\Common\EventSubscriber;
use Doctrine\ORM\Event\LifecycleEventArgs;
use Doctrine\ORM\Event\PreFlushEventArgs;
use Doctrine\ORM\Events;
@dbu
dbu / git-status-recursive
Created May 31, 2012 14:14
recursive git status
#!/usr/bin/php
<?php
$repos = array();
exec('find -type d -name .git | sed -e "s/\.git//"', $repos);
foreach ($repos as $repo) {
$status = shell_exec("cd $repo && git status");
if (false == strpos($status, 'nothing to commit (working directory clean)')) {
echo "$repo\n" . str_repeat('-', strlen($repo)) . "\n$status\n\n";
}
}
@dbu
dbu / CaseInsensitiveStringFilter.php
Last active July 18, 2023 18:04
Case insensitive filtering with sonata admin in postgres
<?php
namespace Liip\AcmeBundle\Filter;
use Sonata\AdminBundle\Form\Type\Filter\ChoiceType;
use Sonata\AdminBundle\Datagrid\ProxyQueryInterface;
use Sonata\DoctrineORMAdminBundle\Filter\StringFilter;
class CaseInsensitiveStringFilter extends StringFilter
{
@dbu
dbu / 2021-04-04-pictures.md.raw
Last active April 6, 2021 15:19
image gallery for sculpin with rokka.io and bootstrap. example for the article at https://www.liip.ch/en/blog/integrating-rokka-io-with-the-sculpin-static-site-generator
# the file is markdown, but gist renders markdown. remove ".raw" and this line
---
title: Pictures example post
images:
-
file: TestImage.jpg
caption: This is a test
note: Additional stuff to print next to the image
-
file: TestImage2.jpg
@dbu
dbu / MutableAclProvider.php
Created November 1, 2012 11:49
Doctrine ACL MutableAclProvider
/**
* An implementation of the MutableAclProviderInterface using Doctrine DBAL.
*
* @author Stefan Paschke <stefan.paschke@liip.ch>
*/
class MutableAclProvider extends BaseMutableAclProvider
{
/**
* Get the entities Ids for the className that match the given role & mask
*
@dbu
dbu / SynchronizeTranslationsCommand.php
Created June 28, 2013 07:21
Synchronize Translations
<?php
namespace Dbu\UtilBundle\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Translation\MessageCatalogue;
use Symfony\Component\Translation\Loader\LoaderInterface;
@dbu
dbu / ValidateServiceDefinitions.php
Created April 18, 2019 12:02
symfony compiler pass to detect invalid classes on service configurations
<?php
declare(strict_types=1);
namespace Infrastructure\Symfony\DependencyInjection\Compiler;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;