Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View bizley's full-sized avatar
🖤
Kurald Galain user

Bizley bizley

🖤
Kurald Galain user
View GitHub Profile
@bizley
bizley / ConsecutiveCalls.php
Last active April 3, 2024 07:35
PHPUnit 10 withConsecutive() replacement (idea by nicolas-grekas)
<?php
declare(strict_types=1);
namespace App\Tests\Unit;
use PHPUnit\Framework\Assert;
use PHPUnit\Framework\Constraint\Constraint;
class ConsecutiveCalls extends Assert
@bizley
bizley / CustomEntityManager.php
Created September 4, 2022 11:02
Thread-safe business logic with Doctrine
<?php
namespace FavreBenjamin\Utils;
use Doctrine\Common\Persistence\ManagerRegistry;
use Doctrine\DBAL\Exception\RetryableException;
use Doctrine\ORM\EntityManagerInterface;
class CustomEntityManager
@bizley
bizley / DistinctFilter.php
Created July 18, 2021 18:19
API Platform Distinct ORM Filter
<?php
declare(strict_types=1);
namespace App\Doctrine\Filter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\AbstractContextAwareFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Util\QueryNameGeneratorInterface;
use Doctrine\ORM\QueryBuilder;
use Doctrine\Persistence\ManagerRegistry;
@bizley
bizley / web.php
Created April 30, 2021 09:06
FLoC Permissions Policy Header for Yii 2
<?php
/**
* This adds Permissions-Policy header to all Yii 2 app responses blocking FLoC.
* What is Federated Learning of Cohorts (FLoC)? - read https://web.dev/floc/
* Google’s FLoC Is a Terrible Idea - read https://www.eff.org/pl/deeplinks/2021/03/googles-floc-terrible-idea
*/
$config = [
// ... other configuration
'components' => [
@bizley
bizley / Entity.php
Last active May 18, 2021 14:09
API Platform custom filter for multiple alternative properties' values (ORM)
<?php
declare(strict_types=1);
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Doctrine\Filter\OrSearchFilter;
@bizley
bizley / Ocramius_PhpCache.php
Created October 31, 2019 21:37 — forked from Ocramius/Ocramius_PhpCache.php
Simple cache adapter based on var_export and include.
<?php
/**
* Simple php cache using var_export generated files
*
* @author Marco Pivetta <ocramius@gmail.com>
*/
class Ocramius_PhpCache {
const DEFAULT_TTL = 3600;
version: '3.7'
services:
reverse-proxy:
restart: always
networks:
- dev
container_name: traefik
image: traefik # The official Traefik docker image
command: --api --docker # Enables the web UI and tells Traefik to listen to docker
ports:
@bizley
bizley / Postman-pre-request.js
Created September 13, 2019 12:03
Pre-request for Postman to check if OAuth2 token expired and if so to refresh it.
let currentTime = Math.floor(Date.now() / 1000);
let tokenExpiration = pm.environment.get("token_expiration");
if (tokenExpiration && tokenExpiration <= currentTime) {
let apiUrl = pm.environment.get("api_url");
let refreshToken = pm.environment.get("refresh_token");
if (refreshToken) {
pm.sendRequest(
{
url: 'http://' + apiUrl + '/oauth/v2/token',
method: 'POST',
@bizley
bizley / install-docker.md
Created September 4, 2019 10:57 — forked from npearce/install-docker.md
Amazon Linux 2 - install docker & docker-compose using 'sudo amazon-linux-extras' command
@bizley
bizley / Sort by dependency
Last active July 4, 2019 07:50
Sorts array by elements dependency [item => [items item depends on]].
<?php
function sortByDependency($input)
{
$output = [];
$checkList = [];
$inputCount = count($input);
// while not all items are resolved: