Skip to content

Instantly share code, notes, and snippets.

View GromNaN's full-sized avatar
🚲
☀️

Jérôme Tamarelle GromNaN

🚲
☀️
View GitHub Profile
<?php
use MongoDB\BSON\Document;
use PhpBench\Attributes\Groups;
use PhpBench\Attributes\Iterations;
use PhpBench\Attributes\Revs;
#[Iterations(30)]
class CreateObjectBench
{
@GromNaN
GromNaN / async-twig.php
Last active May 6, 2024 09:57
Asynchronous Twig PHP
<?php
/**
* Demo ReactPHP application using Twig in yielding mode with an async function.
*/
namespace App;
use Exception;
use Psr\Http\Message\ServerRequestInterface;
@GromNaN
GromNaN / composer-link
Last active November 11, 2023 08:08
composer-link
@GromNaN
GromNaN / RequestMatcherFactory.php
Last active November 24, 2022 12:06
RequestMatcherFactory for Symfony 6.2+, compatible with older versions.
<?php
use Symfony\Component\HttpFoundation\ChainRequestMatcher;
use Symfony\Component\HttpFoundation\RequestMatcher;
use Symfony\Component\HttpFoundation\RequestMatcherInterface;
class RequestMatcherFactory
{
public function getRequestMatcher(array $config): RequestMatcherInterface
{
@GromNaN
GromNaN / Foo.php
Last active July 12, 2022 19:25
Autoload
<?php
namespace App;
class Foo
{
}
class Bar
{
@GromNaN
GromNaN / .gitlab-ci.yml
Last active April 27, 2022 17:26
Gitlab CI cache key based on multiple files
build:
image: node:alpine
script:
# Skip build if files are already in cache
- .gitlab-ci/git-tree-changed.sh .gitlab-cache-key '\.(css|js|json)$' ./frontend ./other-frontend-dir ./public/yet-another || (cd ./frontend && npm ci && npm run build)
variables:
# $CACHE_KEY_INDEX is set in project variable, and must be updated each time the CI cache is clear
# Waiting for the issue to be fixed: https://gitlab.com/gitlab-org/gitlab/-/issues/360438#note_923272903
CACHE_FALLBACK_KEY: ${CI_DEFAULT_BRANCH}-build-${CACHE_KEY_INDEX}
cache:
@GromNaN
GromNaN / RevoltHttpClient.php
Last active December 18, 2023 16:05
Fiber powered Symfony HttpClient with Revolt (and AMPHP)
<?php
namespace App;
use Revolt\EventLoop;
use Symfony\Contracts\HttpClient\HttpClientInterface;
class RevoltHttpClient
{
private int $requests = 0;
@GromNaN
GromNaN / MysqlStore.php
Created January 31, 2022 08:17
MysqlStore for Symfony Lock using `GET_LOCK`
<?php
namespace PMD\ONE\CoreBundle\Lock\Store;
use Doctrine\DBAL\Connection;
use Symfony\Component\Lock\Exception\InvalidArgumentException;
use Symfony\Component\Lock\Exception\LockConflictedException;
use Symfony\Component\Lock\Key;
use Symfony\Component\Lock\PersistingStoreInterface;
@GromNaN
GromNaN / RouterTest.php
Created December 15, 2021 20:43
Symfony Integration test for route configuration: controller does neither exist as service nor as class
<?php
namespace Tests\Integration;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\Routing\RouterInterface;
<?php
namespace Testing;
/**
* Authentication on a Vault server using AWS IAM
* https://www.vaultproject.io/api-docs/auth/aws#login
*/
use AsyncAws\Core\AwsClientFactory;