Skip to content

Instantly share code, notes, and snippets.

View coreymcmahon's full-sized avatar

Corey McMahon coreymcmahon

View GitHub Profile
@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: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 / 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 / front.php
Created June 14, 2012 11:04
Defining an event listener that adds a HTML comment to the Response body - http://www.symfonycentral.com
<?php
require_once __DIR__.'/../vendor/.composer/autoload.php';
// ... etc
use Symfony\Component\EventDispatcher\EventDispatcher;
$dispatcher = new EventDispatcher();
$dispatcher->addListener('response', function (Simplex\ResponseEvent $event) {
$response = $event->getResponse();
@coreymcmahon
coreymcmahon / FrameworkTest.php
Created June 14, 2012 10:54
Example of a Unit test for our PHP framework, Simplex - http://www.symfonycentral.com
<?php
namespace Simplex\Tests;
use Simplex\Framework;
class FrameworkTest extends \PHPUnit_Framework_TestCase
{
public function testNotFoundHandling()
{
$this->assertEquals(/* test condition in here */);
@coreymcmahon
coreymcmahon / Framework.php
Created June 14, 2012 10:48
Using interfaces so that our Framework calls are mockable for testing purposes - http://www.symfonycentral.com
<?php
namespace Simplex;
use Symfony\Component\Routing\Matcher\UrlMatcherInterface;
use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface;
class Framework
{
public function __construct(UrlMatcherInterface $matcher, ControllerResolverInterface $resolver)
{
@coreymcmahon
coreymcmahon / LeapYear.php
Created June 14, 2012 10:45
Defining a model in the Calendar\Model namespace - http://www.symfonycentral.com
<?php
namespace Calendar\Model;
class LeapYear
{
// ... code for function isLeapYear in here
}
@coreymcmahon
coreymcmahon / LeapYearController.php
Created June 14, 2012 10:44
Defining a controller in the Calendar\Controller namespace - http://www.symfonycentral.com
<?php
namespace Calendar\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Calendar\Model\LeapYear;
class LeapYearController
{
// ... controller code in here
@coreymcmahon
coreymcmahon / Framework.php
Created June 14, 2012 10:41
Using namespacing in the Simplex framework - http://www.symfonycentral.com
<?php
namespace Simplex;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Matcher\UrlMatcher;
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
use Symfony\Component\HttpKernel\Controller\ControllerResolver;
class Framework
@coreymcmahon
coreymcmahon / front.php
Created June 2, 2012 04:26
Our new front controller using HTTP Foundation - http://www.symfonycentral.com
<?php
// ...
$request = Request::createFromGlobals();
$routes->add('leap_year', new Routing\Route('/is_leap_year/{year}', array(
'year' => null,
'_controller' => 'LeapYearController::indexAction',
)));