Skip to content

Instantly share code, notes, and snippets.

{% extends "layout.html.twig" %}
{% block content %}
Welcome to your new Symfony <del>Silex</del> Application!
{% endblock %}
index:
path: /
defaults: { _controller: 'App\Controller\IndexController::homepage' }
<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class IndexController extends Controller
{
public function homepage()
{
return $this->render('index.html.twig');
<?php
namespace App\EventSubscriber;
use function json_last_error;
use function json_last_error_msg;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\HttpKernel\KernelEvents;
@peterlafferty
peterlafferty / silex-language-api-custom-locale-parsing.php
Created November 15, 2017 21:31
example silex app for custom parsing of accept-header and matching it to a locale
<?php
require_once __DIR__ . '/../vendor/autoload.php';
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\AcceptHeader;
$app = new Silex\Application();
@peterlafferty
peterlafferty / silex-language-codes.php
Last active November 15, 2017 20:48
parsing Accept-Language and setting Content-Language headers in Silex
<?php
require_once __DIR__ . '/../vendor/autoload.php';
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
$app = new Silex\Application();
@peterlafferty
peterlafferty / index.php
Created November 9, 2017 23:41
example silex application for use with integration test that runs built in php web server
<?php
// web/index.php
require_once __DIR__.'/vendor/autoload.php';
$app = new Silex\Application();
$app->get('/testpage/', function () {
return "LOL";
});
@peterlafferty
peterlafferty / IntegrationTest.php
Last active August 30, 2019 16:42
example integration test in PHPUnit which starts the build in web server
<?php
use PHPUnit\Framework\TestCase;
use Symfony\Component\Process\Process;
use GuzzleHttp\Client;
class IntegrationTest extends TestCase
{
/** @var Process */
private static $process;
@peterlafferty
peterlafferty / tddexampleindex.php
Created October 25, 2017 20:21
web/index.php showing how to not passing di container in to controllers
<?php
require_once __DIR__ . '/../vendor/autoload.php';
use Symfony\Component\HttpFoundation\Request;
use pl\tddcontroller\TddController;
$app = new Silex\Application();
$app['controller.tdd'] = function () use ($app) {
@peterlafferty
peterlafferty / TddControllerTest.php
Created October 25, 2017 20:20
unit test for silex controller
<?php
use pl\tddcontroller\TddController;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\JsonResponse;
class TddControllerTest extends TestCase
{
/** @var TddController */
private $controller;