Skip to content

Instantly share code, notes, and snippets.

Ryan Weaver weaverryan

Block or report user

Report or block weaverryan

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@weaverryan
weaverryan / AccessDeniedHandler.php
Created Mar 22, 2017
Access Denied Flash Message
View AccessDeniedHandler.php
<?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
weaverryan / README.md
Created Aug 4, 2016
Testing Questions with my Answers (fwtw)
View README.md

From a user on KnpUniversity.com:

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.

However

View SomeAutowiredService.php
<?php
class SomeAutowiredService
{
use UrlGeneratorTrait;
public function doSomething()
{
$url = $this->generateUrl('homepage');
@weaverryan
weaverryan / Link.php
Created Mar 21, 2016
KnpUniversity Symfony REST: Using @link with the PaginatedCollection (http://knpuniversity.com/screencast/symfony-rest3/evaluating-expression)
View Link.php
@weaverryan
weaverryan / security.yml
Last active Mar 23, 2016
Symfony: Showing the "Username not found" message on login
View security.yml
security:
# show the "Username not found" error message
# yep, that easy
hide_user_not_found: false
@weaverryan
weaverryan / config.yml
Last active Feb 10, 2016
cache configuration
View config.yml
cache:
adapters:
my_adapter:
type: array
default_lifetime: 600
other_adapter:
type: apc
caches:
# creates a service cache.store_cool_stuff
@weaverryan
weaverryan / index.php
Created Oct 29, 2015
Potential Symfony MicroKernel example
View index.php
<?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
weaverryan / AppKernel.php
Last active Oct 5, 2015
AppKernel with new loading
View AppKernel.php
<?php
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
@weaverryan
weaverryan / UNSTUCK.md
Last active Aug 29, 2015
SummerCamp OO - Don't get stuck!
View UNSTUCK.md

Are you stuck and not ready for the next step?

http://nooooooooooooooo.com

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).

@weaverryan
weaverryan / README.md
Last active Aug 29, 2015
SummerCamp OO Setup
View README.md

Welcome to the OO workshop!

To get started, make sure everything is loading ok! If you're having any problems at all, just ask!

A) Start up the virtual machine! Here are the Virtual Machine Instructions

B) From the command line, ssh into the machine and move into our directory

You can’t perform that action at this time.