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 / ApiTestCase.php
Last active Sep 23, 2019
Example Symfony ApiTestCase (from WIP KnpUniversity Symfony REST tutorial)
View ApiTestCase.php
<?php
namespace AppBundle\Tests\Controller\Api;
use Doctrine\Common\DataFixtures\Purger\ORMPurger;
use Doctrine\ORM\EntityManager;
use Exception;
use GuzzleHttp\Client;
use GuzzleHttp\Message\ResponseInterface;
use GuzzleHttp\Subscriber\History;
@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 / Controller.php
Created Apr 21, 2015
Collecting Form Errors
View Controller.php
<?php
// put this in your controller
protected function getErrorsFromForm(FormInterface $form)
{
$errors = array();
foreach ($form->getErrors() as $error) {
$errors[] = $error->getMessage();
}
@weaverryan
weaverryan / UniversityExtension.php
Last active Jul 9, 2018
Twig Extension with ContainerInterface injected
View UniversityExtension.php
<?php
class UniversityExtension extends \Twig_Extension
{
private $container;
/**
* An internal cache used to prevent creating this chain loader multiple times
*/
private $twigChainLoader;
@weaverryan
weaverryan / console.php
Last active May 14, 2018
working on console
View console.php
#!/usr/bin/env php
<?php
use App\Kernel;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Debug\Debug;
use Symfony\Component\Dotenv\Dotenv;
set_time_limit(0);
@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 / FeatureContext.php
Created Jun 19, 2012
Behat Definition to help click generic links on different rows of a table
View FeatureContext.php
<?php
// ...
class FeatureContext extends MinkContext
{
/**
* Looks for a table, then looks for a row that contains the given text.
* Once it finds the right row, it clicks a link in that row.
*
@weaverryan
weaverryan / deets.md
Created Feb 8, 2018
PhpStorm Users with Symfony!
View deets.md

PhpStorm has some AWESOME plugins for Symfony.

To install them:

  1. Open the PhpStorm "Preferences"
  2. Search "Symfony" and select the top-level Plugin menu item
  3. Near the bottom, click the "Browse Repositories" button

Browse Repositories

@weaverryan
weaverryan / Comment.php
Last active Feb 8, 2018
Symfony Demo with make:entity --regenerate --overwrite
View Comment.php
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
@weaverryan
weaverryan / test-maker.md
Created Feb 8, 2018
How to help test the new make:entity Command
View test-maker.md
  1. In your composer.json file, add the weaverryan fork:
    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/weaverryan/maker-bundle"
        }
    ],
You can’t perform that action at this time.