Skip to content

Instantly share code, notes, and snippets.

View kriswallsmith's full-sized avatar

Kris Wallsmith kriswallsmith

  • Portland, Oregon USA
  • 10:04 (UTC -07:00)
View GitHub Profile
@kriswallsmith
kriswallsmith / Chain.php
Last active February 13, 2024 15:07
Symfony Messenger message chaining
<?php
declare(strict_types=1);
namespace App\Messenger\Chain;
use App\Messenger\Chain\Stamp\ChainStamp;
use Symfony\Component\Messenger\Envelope;
use Symfony\Component\Messenger\Stamp\StampInterface;
<?php
class WidgetManager
{
private $em;
private $factory;
private $manipulator;
private $dispatcher;
public function __construct(ObjectManager $em, SnapshotFactory $factory, WidgetManipulator $manipulator, EventDispatcherInterface $dispatcher)
@kriswallsmith
kriswallsmith / 01_before.php
Created September 10, 2013 19:54
I could really go for an array_index() function right now.
<?php
$widgets = array_combine(
array_map(
function($widget) {
return $widget->getId();
},
$widgets
),
$widgets
@kriswallsmith
kriswallsmith / test.php
Last active December 20, 2015 00:29
A test harness for your Symfony2 project. Runs functional tests in chunks.
#!/usr/bin/env php
<?php
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input\ArrayInput as Input;
use Symfony\Component\Console\Input\InputOption as Option;
require_once __DIR__.'/../vendor/autoload.php';
/** Outputs and runs a command. */
@kriswallsmith
kriswallsmith / gist:5819198
Last active December 18, 2015 17:29
How do you walk a paginated API?
<?php
function walk($callback)
{
$page = 1;
do {
$results = fetch($page++, 100);
foreach ($results as $result) {
call_user_func($callback, $result);
@kriswallsmith
kriswallsmith / QSAListener.php
Created August 8, 2012 18:23
implements QSA on Symfony2 redirects
<?php
use JMS\DiExtraBundle\Annotation as DI;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
/** @DI\Service */
class QSAListener
{
private $blacklist;
<?php
namespace OpenSky\Bundle\MainBundle\Listener;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Component\Security\Core\SecurityContextInterface;
/**
* Listens to kernel.request after the router and checks required role.
<?php
namespace Kris\JunkBundle\Tests\Controller;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class DefaultControllerTest extends WebTestCase
{
/**
* @dataProvider asdf
<?php
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Http\AccessMapInterface;
class DelegatingAccessMap implements AccessMapInterface
{
/**
* @var array A map of path prefix to delegate map
*/
<?php
class aPage extends PluginaPage
{
/**
* A shortcut method for loading fixture data.
*
* With this method in place you can simplify your aPage fixture file to a
* much more concise syntax using the "initial_areas" entry.
*