Created
March 10, 2018 17:34
-
-
Save rodrigoSyscop/41fc1084cc04ff8623c022b8cf48c845 to your computer and use it in GitHub Desktop.
framework/src/app.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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