Skip to content

Instantly share code, notes, and snippets.

View gquemener's full-sized avatar
🏄‍♂️

Gildas Quéméner gquemener

🏄‍♂️
View GitHub Profile
<?php
interface Bonus
{
public function apply(Amount $amount): Amount;
}
class AbsoluteBonus implements Bonus
{
public static function fromInt(int $value): self
@gquemener
gquemener / Command.php
Last active July 29, 2020 17:51
Self validating command (using symfony validator)
<?php
abstract class Command
{
// Self-validating command
public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addConstraint(
new Callback(function(Command $command, ExecutionContextInterface $context) {
$reflClass = new \ReflectionClass($command);
<?php
class A
{
}
class B
{
}
class C
{
<?php
require __DIR__.'/vendor/autoload.php';
use Rx\Observable;
use Rx\Observer\CallbackObserver;
$events = Observable::fromArray([
['name' => 'account_was_created', 'payload' => ['id' => 1, 'owner' => 'Gildas Quéméner']],
['name' => 'deposit_was_performed', 'payload' => ['id' => 1, 'amount' => 100]],
<?php
require __DIR__.'/vendor/autoload.php';
use Rx\Observable;
use Rx\Observer\CallbackObserver;
$events = Observable::fromArray([
['name' => 'account_was_created', 'payload' => ['id' => 1, 'owner' => 'Gildas Quéméner']],
['name' => 'deposit_was_performed', 'payload' => ['id' => 1, 'amount' => 100]],
<?php
class Repository
{
public function findAll(): array
{
return $this->connection->project(
sprintf('SELECT * FROM %s', self::TABLE_NAME),
[],
function(array $row): Domain\MyObject {
return Domain\MyObject::fromArray($row);
<?php
declare(strict_types=1);
namespace App\ServiceBus\Plugin;
use Prooph\Common\Event\ActionEvent;
use Prooph\Common\Messaging\Query;
use Prooph\ServiceBus\MessageBus;
use Prooph\ServiceBus\QueryBus;
<?php
declare (strict_types = 1);
namespace App\EventListener;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpFoundation\Response;
<?php
$files = $argv;
unset($files[0]);
$packages = [];
foreach ($files as $file) {
$composer = json_decode(file_get_contents($file), true);
$requirements = $composer['require'];
export default function(eventTracker) {
return store => next => action => {
eventTracker.trackEvent(action.type);
return next(action);
};
}