Skip to content

Instantly share code, notes, and snippets.

Ryan Weaver weaverryan

View GitHub Profile
weaverryan / FooController.php
Last active Apr 18, 2017
Autowiring controller args
View FooController.php
namespace AppBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Psr\Log\LoggerInterface;
* This class is now a service, so you can use normal __construct DI if you want!
weaverryan / AccessDeniedHandler.php
Created Mar 22, 2017
Access Denied Flash Message
View AccessDeniedHandler.php
namespace AppBundle\Security;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Component\Security\Http\Authorization\AccessDeniedHandlerInterface;
use Symfony\Component\Routing\RouterInterface;
class AccessDeniedHandler implements AccessDeniedHandlerInterface
weaverryan /
Created Aug 4, 2016
Testing Questions with my Answers (fwtw)

From a user on

How do you manage testing form validation situations?

For form validation situations, I typically only write 2 scenarios (or sometimes just 1): one that checks that if I submit invalid data, that I see a validation error (I don’t, however assert that all of the validation errors are there – just that the form has some validation errors). Second, I write a scenario that checks a successful form submit.

For me, creating many scenarios to submit a form and check for the different validation errors is over-kill. 99% of the time, adding validation – in Symfony for example – is just one line of code. If we write a scenario for each, we now have one scenario just to test whether or not one line of code is present. For this, I check the validation errors manually – just to make sure I didn’t forget them. I’m not worried about a regression, because it’s highly unlikely that we’ll accidentally remove a line of validation and introduce a bug.


View SomeAutowiredService.php
class SomeAutowiredService
use UrlGeneratorTrait;
public function doSomething()
$url = $this->generateUrl('homepage');
weaverryan / Link.php
Created Mar 21, 2016
KnpUniversity Symfony REST: Using @link with the PaginatedCollection (
View Link.php
weaverryan / security.yml
Last active Mar 23, 2016
Symfony: Showing the "Username not found" message on login
View security.yml
# show the "Username not found" error message
# yep, that easy
hide_user_not_found: false
weaverryan / config.yml
Last active Feb 10, 2016
cache configuration
View config.yml
type: array
default_lifetime: 600
type: apc
# creates a service cache.store_cool_stuff
weaverryan / index.php
Created Oct 29, 2015
Potential Symfony MicroKernel example
View index.php
require_once __DIR__.'/../vendor/autoload.php';
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\MicroKernel;
use Symfony\Component\Routing\RouteCollectionBuilder;
weaverryan / AppKernel.php
Last active Oct 5, 2015
AppKernel with new loading
View AppKernel.php
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;
class AppKernel extends Kernel
public function registerBundles()
$bundles = array(
weaverryan /
Last active Aug 29, 2015
SummerCamp OO - Don't get stuck!

Are you stuck and not ready for the next step?

Actually, no problem! You can just skip up to the starting point of whatever we're working on right now.

For example, if you get stuck on "Register the PDO service", you can just move to the step03-register-pdo-service branch and keep coding along with us on the next step (all explained below).

You can’t perform that action at this time.