Skip to content

Instantly share code, notes, and snippets.

@rodrigoSyscop
Created March 10, 2018 17:34
Show Gist options
  • Save rodrigoSyscop/41fc1084cc04ff8623c022b8cf48c845 to your computer and use it in GitHub Desktop.
Save rodrigoSyscop/41fc1084cc04ff8623c022b8cf48c845 to your computer and use it in GitHub Desktop.
framework/src/app.php
<?php //framework/src/app.php
use Symfony\Component\Routing;
use Symfony\Component\HttpFoundation\Response;
function is_leap_year($year = null) {
if (null === $year) {
$year = date('Y');
}
return 0 === $year % 400 || (0 === $year % 4 && 0 !== $year % 100);
}
$routes = new Routing\RouteCollection();
$routes->add('leap_year', new Routing\Route('/is_leap_year/{year}', array(
'year' => null,
'_controller' => function ($request) {
if (is_leap_year($request->attributes->get('year'))) {
return new Response('Yep, this is a leap year!');
}
return new Response('Nope, this is not a leap year.');
}
)));
return $routes;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment