Skip to content

Instantly share code, notes, and snippets.

View weaverryan's full-sized avatar

Ryan Weaver weaverryan

View GitHub Profile
@weaverryan
weaverryan / details.md
Created November 18, 2017 07:52
SymfonyCon Hackday Details
@weaverryan
weaverryan / CoolStuff.php
Last active November 6, 2017 22:01
Autowireable & Auto-registered Repository Services in Doctrine 1.8
<?php
// Coming in DoctrineBundle 1.8: https://github.com/doctrine/DoctrineBundle/pull/727
/* *********************
src/Entity/CoolStuff.php
/* ********************* */
/**
* @ORM\Entity(repositoryClass="App\Repository\CoolStuffRepository")
*/
class CoolStuff
@weaverryan
weaverryan / FooController.php
Last active April 18, 2017 13:58
Autowiring controller args
<?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
weaverryan / AccessDeniedHandler.php
Created March 22, 2017 17:26
Access Denied Flash Message
<?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 August 4, 2016 21:04
Testing Questions with my Answers (fwtw)

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

<?php
class SomeAutowiredService
{
use UrlGeneratorTrait;
public function doSomething()
{
$url = $this->generateUrl('homepage');
@weaverryan
weaverryan / Link.php
Created March 21, 2016 15:20
KnpUniversity Symfony REST: Using @link with the PaginatedCollection (http://knpuniversity.com/screencast/symfony-rest3/evaluating-expression)
@weaverryan
weaverryan / security.yml
Last active March 23, 2016 18:32
Symfony: Showing the "Username not found" message on login
security:
# show the "Username not found" error message
# yep, that easy
hide_user_not_found: false
@weaverryan
weaverryan / config.yml
Last active February 10, 2016 17:48
cache configuration
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 October 29, 2015 18:20
Potential Symfony MicroKernel example
<?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;