Skip to content

Instantly share code, notes, and snippets.

View coreymcmahon's full-sized avatar

Corey McMahon coreymcmahon

View GitHub Profile
@coreymcmahon
coreymcmahon / Framework.php
Created June 14, 2012 11:07
Telling the Event Dispatcher when the 'response' Event has occurred - http://www.symfonycentral.com
<?php
namespace Simplex;
// ... etc
use Symfony\Component\EventDispatcher\EventDispatcher;
class Framework
{
// ... etc
@coreymcmahon
coreymcmahon / Framework.php
Created June 14, 2012 11:28
Implementing HttpKernel\HttpKernelInterface in Simplex - http://www.symfonycentral.com
<?php
use Symfony\Component\HttpKernel\HttpKernelInterface;
class Framework implements HttpKernelInterface
{
// ... etc
public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
{
// ... etc
@coreymcmahon
coreymcmahon / front.php
Created June 14, 2012 11:34
Adding Caching to Simplex via the HttpKernel component - http://www.symfonycentral.com
<?php
use Symfony\Component\HttpKernel\HttpCache\HttpCache;
use Symfony\Component\HttpKernel\HttpCache\Store;
$framework = new Simplex\Framework($dispatcher, $matcher, $resolver);
$framework = new HttpCache($framework, new Store(__DIR__.'/../cache'));
$framework->handle($request)->send();
@coreymcmahon
coreymcmahon / Framework.php
Created June 14, 2012 11:43
By extending HttpKernel we can significantly reduce our framework's code - http://www.symfonycentral.com
<?php
namespace Simplex;
use Symfony\Component\HttpKernel\HttpKernel;
class Framework extends HttpKernel
{
}
@coreymcmahon
coreymcmahon / ErrorController.php
Created June 14, 2012 11:52
Example of an Exception Controller that responds to exception events in our framework - http://www.symfonycentral.com
<?php
namespace Calendar\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\FlattenException;
class ErrorController
{
public function exceptionAction(FlattenException $exception)
{
@coreymcmahon
coreymcmahon / front.php
Created June 14, 2012 11:53
Attaching the ExceptionHandler in our HttpKernel based framework - http://www.symfonycentral.com
<?php
require_once __DIR__.'/../vendor/.composer/autoload.php';
use Symfony\Component\HttpKernel;
// ...
$listener = new HttpKernel\EventListener\ExceptionListener('Calendar\\Controller\\ErrorController::exceptionAction');
$dispatcher->addSubscriber($listener);
@coreymcmahon
coreymcmahon / front.php
Created June 14, 2012 12:13
Using a "heavy front controller" to manage dependencies - http://www.symfonycentral.com
<?php
require_once __DIR__.'/../vendor/.composer/autoload.php';
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing;
use Symfony\Component\HttpKernel;
use Symfony\Component\EventDispatcher\EventDispatcher;
$request = Request::createFromGlobals();
@coreymcmahon
coreymcmahon / Framework.php
Created June 14, 2012 12:15
Shifting code to the framework core to manage dependencies - http://www.symfonycentral.com
<?php
namespace Simplex;
use Symfony\Component\Routing;
use Symfony\Component\HttpKernel;
use Symfony\Component\EventDispatcher\EventDispatcher;
class Framework extends HttpKernel\HttpKernel
{
public function __construct($routes)
@coreymcmahon
coreymcmahon / container.php
Created June 14, 2012 12:22
Introducing dependency injection into Simplex - http://www.symfonycentral.com
<?php
// example.com/src/container.php
use Symfony\Component\DependencyInjection;
use Symfony\Component\DependencyInjection\Reference;
$sc = new DependencyInjection\ContainerBuilder();
$sc->register('context', 'Symfony\Component\Routing\RequestContext');
$sc->register('matcher', 'Symfony\Component\Routing\Matcher\UrlMatcher')
@coreymcmahon
coreymcmahon / front.php
Created June 14, 2012 12:33
Using the default implementation of HttpKernel\HttpKernel instead of our own framework code - http://www.symfonycentral.com
<?php
require_once __DIR__.'/../vendor/.composer/autoload.php';
use Symfony\Component\HttpKernel;
// ...
$framework = new Simplex\Framework($dispatcher, $resolver);
$response = $framework->handle($request);
$response->send();