Skip to content

Instantly share code, notes, and snippets.

Avatar

Gabriel Ostrolucký ostrolucky

View GitHub Profile
View array_select.php
<?php
function array_select(array $array, array $filter): array
{
return array_map(function (array $object) use ($filter) {
$object = array_intersect_key($object, $filter);
foreach ($object as $key => $value) {
if (is_array($filter[$key])) {
$object[$key] = array_select($object[$key], $filter[$key]);
@ostrolucky
ostrolucky / transcript.txt
Created Apr 20, 2019
Using lldb to debug PHP code
View transcript.txt
Guilhermes-MacBook-Pro:orm guilhermeblanco$ lldb /usr/local/Cellar/php/7.3.2/bin/php
(lldb) target create "/usr/local/Cellar/php/7.3.2/bin/php"
Current executable set to '/usr/local/Cellar/php/7.3.2/bin/php' (x86_64).
(lldb) run ./vendor/bin/phpunit tests/Doctrine/Tests/ORM/Functional/PaginationTest.php --filter testIterateWithOutputWalkersWithRegularJoinWithComplexOrderByReferencingJoined
Process 99416 launched: '/usr/local/Cellar/php/7.3.2/bin/php' (x86_64)
PHPUnit 7.5.6 by Sebastian Bergmann and contributors.
Runtime: PHP 7.3.2 with Xdebug 2.7.0RC2
Configuration: /Users/guilhermeblanco/doctrine/orm/phpunit.xml.dist
@ostrolucky
ostrolucky / macflife.d
Created Mar 25, 2019
This script is from the DTrace book, and traces the creation and deletion of files
View macflife.d
#!/usr/sbin/dtrace -s
/*
* maclife.d
*
* Example script from Chapter 5 of the book: DTrace: Dynamic Tracing in
* Oracle Solaris, Mac OS X, and FreeBSD", by Brendan Gregg and Jim Mauro,
* Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.
*
* See the book for the script description and warnings. Many of these are
* provided as example solutions, and will need changes to work on your OS.
@ostrolucky
ostrolucky / conflict-free-merge.sh
Created Dec 15, 2018
Apply only changes which are mergeable to upper branch without conflicts
View conflict-free-merge.sh
UPPERBRANCH=master
BOTTOMBRANCH=3.4
DIR="src"
git checkout $BOTTOMBRANCH
php-cs-fixer fix $DIR --rules='{"array_syntax": {"syntax": "short"}}'
git diff > patch.patch && splitpatch patch.patch && rm patch.patch
git checkout $UPPERBRANCH --force
mkdir -p nonworkingpatches workingpatches && rm -rf nonworkingpatches/* workingpatches/*
for patchfile in *.patch*; do
@ostrolucky
ostrolucky / SoapClient.php
Last active Oct 10, 2019
SOAP with custom HTTP client
View SoapClient.php
<?php
namespace AppBundle\DataProvider;
use GuzzleHttp\Psr7\Request;
use Http\Client\Exception\HttpException;
use Http\Client\HttpClient;
/**
* Wrapper around PHP SoapClient to use a HttpClient instead of php, allows better control over the request.
View RouteHistorySubscriber.php
<?php
declare(strict_types=1);
namespace App\EventListener;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
View StripeHttplugClient.php
<?php
declare(strict_types=1);
namespace App\Service\Http;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Uri;
use Http\Client\HttpClient;
use Stripe\HttpClient\ClientInterface;
View currency mapping.xml
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
https://raw.github.com/doctrine/doctrine2/master/doctrine-mapping.xsd">
<embeddable name="Money\Currency">
<field name="code" length="3" />
</embeddable>
</doctrine-mapping>
@ostrolucky
ostrolucky / yaml-custom-tags.php
Last active Jan 3, 2018
Example usage Symfony Yaml custom tags
View yaml-custom-tags.php
<?php
require 'vendor/autoload.php';
$parsed = \Symfony\Component\Yaml\Yaml::parse(<<<YAML
test:
a: !b64baby stuff
b: foo
YAML
@ostrolucky
ostrolucky / UniqueDTO.php
Created Dec 17, 2017
UniqueDTOValidator
View UniqueDTO.php
<?php
declare(strict_types=1);
namespace App\Validator\Constraints;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
/**
* Checks if entity associatied to DTO is unique.