Skip to content

Instantly share code, notes, and snippets.

View jwage's full-sized avatar
💭
I am still here.

Jonathan H. Wage jwage

💭
I am still here.
View GitHub Profile
@jwage
jwage / SplClassLoader.php
Last active April 9, 2024 21:04
Add MIT license.
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
@jwage
jwage / MessageBus.php
Created March 6, 2024 18:52
Symfony MessageBusInterface implementation that handles AMQPConnectionException and retries
<?php
declare(strict_types=1);
namespace App\Messenger;
use AMQPConnectionException;
use App\Event\Messenger\WorkerMessageDispatchedEvent;
use App\Messenger\Stamp\DispatchedAtStamp;
use Psr\Log\LoggerInterface;
@jwage
jwage / .php_cs
Last active May 3, 2023 06:42
php-cs-fixer git pre commit hook
<?php
return Symfony\CS\Config\Config::create()
->level(Symfony\CS\FixerInterface::SYMFONY_LEVEL)
->fixers([
'short_array_syntax',
'ordered_use',
])
;
@jwage
jwage / fixmocks.php
Created November 7, 2022 23:29
Add PHPUnit MockObject type hints to satisfy static analysis
<?php
$file = $argv[1];
$code = file_get_contents($file);
preg_match_all('/\$this->(.*)\s+=\s+\$this->createMock\((.*)::class\);/', $code, $matches);
foreach ($matches[2] as $key => $className) {
$propertyName = trim($matches[1][$key]);
@jwage
jwage / Cartesian.php
Created April 22, 2014 20:30
PHP Cartesian Function
<?php
$attributeValues = array(
'color' => array('Red', 'White', 'Blue'),
'size' => array(1, 2, 3, 4),
'fabric' => array('Cloth', 'Silk')
);
class Cartesian
{
@jwage
jwage / Banks.php
Last active November 12, 2018 02:42
<?php
declare(strict_types=1);
namespace Banks\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
<?php
namespace App\Component\HttpKernel\CacheWarmer;
use Spork\Batch\Strategy\ChunkStrategy;
use Spork\ProcessManager;
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerAggregate;
class SporkCacheWarmerAggregate extends CacheWarmerAggregate
{
@jwage
jwage / Doctrine MongoDB ODM Tail Cursor Command Daemon
Created February 6, 2011 00:01
This is a Symfony2 Doctrine MongoDB ODM Tail Cursor console command. It can be ran as a daemon and it will tail a mongodb collection with a tailable cursor and process the documents with a given service as the "processor". You must specify the document, t
<?php
namespace MyCompany\Bundle\MyBundle\Command;
use Symfony\Bundle\FrameworkBundle\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\HttpFoundation\Request;
<?php
// original
foreach ($this->migrationTable->getColumnNames() as $columnName) {
if (! $table->hasColumn($columnName)) {
$this->upToDate = false;
break;
}
}
@jwage
jwage / pre-commit
Last active February 6, 2018 16:49
#!/usr/bin/env bash
ROOT="/data/devo/current"
echo "OpenSky pre commit hook start"
PHP_CS_FIXER="vendor/bin/php-cs-fixer"
HAS_PHP_CS_FIXER=false
HAS_JSHINT=false