Skip to content

Instantly share code, notes, and snippets.

@ostrolucky
ostrolucky / UniqueDTO.php
Created December 17, 2017 01:20
UniqueDTOValidator
<?php
declare(strict_types=1);
namespace App\Validator\Constraints;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
/**
* Checks if entity associatied to DTO is unique.
@ostrolucky
ostrolucky / array_flatten.php
Created October 20, 2017 22:24
Array flatten algorithms benchmark
<?php
$array = [1, 2, 3, 4, [], [5, 6], 7, 8, [9], [10, [11, 12], 13, [14, 15, 16, [17, [18, [19, 20, 21]]]]], 22, 23, 24, [25], 26, [27, [28], [29, [30, 31], [32], [33, [34, [35, 36], 37, 38, [39, 40]]]]]];
function laravel_flatten($array, $depth = INF)
{
return array_reduce($array, function ($result, $item) use ($depth) {
if (! is_array($item)) {
return array_merge($result, [$item]);
} elseif ($depth === 1) {
@ostrolucky
ostrolucky / services.yml
Last active July 20, 2018 08:53 — forked from zak10/symfony multi tenant kernel
symfony multi tenant kernel
catalog.kernel.request_event_listener:
class: App\CoreBundle\EventListener\KernelBootDatabaseSwitchListener
arguments: [@request, @doctrine.dbal.default_connection, @logger]
scope: request
tags:
- { name: kernel.event_listener, event: kernel.request, method: onKernelRequest }
@ostrolucky
ostrolucky / DataConnectionWrapper.php
Created August 23, 2017 22:02 — forked from Xymanek/DataConnectionWrapper.php
Symfony multi-tenant database
<?php
namespace AppBundle\Doctrine;
use AppBundle\Entity\Organisation;
use Doctrine\DBAL\Connection;
use Acme\Common\DatabaseNameResolver;
class DataConnectionWrapper extends Connection
{
/**
@ostrolucky
ostrolucky / Enum.php
Created June 22, 2017 17:17
PHP enum class by LtAramaki
<?php
abstract class Enum {
private $name;
private static $enums;
private function __construct($name) {
$this->name = $name;
}
/**
@ostrolucky
ostrolucky / ColumnHydrator.php
Last active January 3, 2022 11:53
Doctrine ColumnHydrator
<?php
declare(strict_types=1);
namespace App\ORM\Hydration;
use Doctrine\ORM\Internal\Hydration\ArrayHydrator;
/**
* Returns one-dimensional scalar array from query: mixed[][] => mixed[]
@ostrolucky
ostrolucky / SymfonyFormTransformer.php
Last active November 1, 2018 11:35
Convert Symfony Form to text values
<?php
class SymfonyFormTransformer {
/**
* @param FormInterface $form
* @return string
*/
public function transformFormToText(FormInterface $form)
{
$txt = '';
foreach ($form->getData() as $inputName => $inputValue) {