Created
June 8, 2012 14:34
-
-
Save brtriver/2895933 to your computer and use it in GitHub Desktop.
routing php framework
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
{ | |
"require": { | |
"symfony/routing": "2.1.*", | |
"symfony/http-foundation": "2.1.*", | |
"symfony/config": "2.1.*", | |
"symfony/yaml": "2.1.*", | |
"pimple/pimple": "dev-master" | |
} | |
} |
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 | |
echo "hello " . h($name); | |
echo "<pre>"; | |
print_r($request->query->get('b', 'sss')); |
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 | |
ini_set('display_errors', 1); | |
error_reporting(-1); | |
require __DIR__ . '/vendor/composer/autoload.php'; | |
use Symfony\Component\Routing\Matcher\UrlMatcher; | |
use Symfony\Component\Routing\RequestContext; | |
use Symfony\Component\Routing\RouteCollection; | |
use Symfony\Component\HttpFoundation\Request; | |
$context = new RequestContext($_SERVER['REQUEST_URI']); | |
$matcher_file = __DIR__ . '/cache/ProjectUrlMatcher.php'; | |
if (file_exists($matcher_file)) { | |
require $matcher_file; | |
$router = new ProjectUrlMatcher($context); | |
} else { | |
$locator = new Symfony\Component\Config\FileLocator(array(__DIR__)); | |
$router = new Symfony\Component\Routing\Router( | |
new Symfony\Component\Routing\Loader\YamlFileLoader($locator), | |
"routing.yaml", | |
array('cache_dir' => __DIR__.'/cache'), | |
$context | |
); | |
} | |
$request = Request::createFromGlobals(); | |
try{ | |
extract($router->match($request->getPathInfo()), EXTR_SKIP); | |
require_once __DIR__ . '/' .$controller . ".php"; | |
} catch (Symfony\Component\Routing\Exception\ResourceNotFoundException $e) { | |
echo $e; | |
} | |
function h($v) { | |
return htmlspecialchars($v, ENT_QUOTES, mb_internal_encoding()); | |
} |
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
route1: | |
pattern: /foo | |
defaults: { controller: 'foo' } | |
route2: | |
pattern: /foo/bar | |
defaults: { controller: 'foobar' } | |
route3: | |
pattern: /hello/{name} | |
defaults: { controller: 'hello' } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment