Skip to content

Instantly share code, notes, and snippets.

@m4rw3r m4rw3r/gist:917895
Created Apr 13, 2011

Embed
What would you like to do?
Router cache file generated by InjectFramework
<?php
/**
* Route cache file generated on 2011-04-13 18:33:34 by Inject Framework Router
* (Inject\Web\Router\Generator).
*/
/*
Routes.php:
$this->root()->to('Test#index');
$this->match('archive/:year/:month', array('year' => '\d{4}', 'month' => '1[0-2]|0[1-9]'))
->to('Blog#archive')->name('blog_archive');
// Callback (only string-callbacks are allowed, so no objects or closures yet)
$this->match('testing')->to('Sample\\SimpleApp::run')->name('simpleapp');
// Redirect to other site, temporary
$this->match('about')->to($this->redirect('http\://www.google.com', 302));
// REST route
$this->resources('test');
*/
namespace Inject\Web\Router;
// Generated from data from the Core\Engine instance
$controllers = array (
'blog' => '\\Sample\\Controller\\Blog',
'test' => '\\Sample\\Controller\\Test',
);
// $engine comes from outside this file
$router = function($env) use($engine, $controllers)
{
$matches = array();
if($env['PATH_INFO'] == '/')
{
$env['web.route_params'] = array (
'action' => 'index',
);
return \Sample\Controller\Test::stack($engine, 'index')->run($env);
}
if(stripos($env['PATH_INFO'], '/archive/') === 0)
{
if(preg_match('#^/archive/(?<year>\\d{4})/(?<month>1[0-2]|0[1-9])$#ui', $env['PATH_INFO'], $match))
{
$matches = array_merge($matches, $match);
$env['web.route_params'] = array_intersect_key(array_merge(array (
'action' => 'index',
), $matches), array (
'year' => 0,
'month' => 1,
));
return \Sample\Controller\Blog::stack($engine, 'archive')->run($env);
}
}
// Callback
if(strtolower($env['PATH_INFO']) == '/testing')
{
$env['web.route_params'] = array (
);
return call_user_func('Sample\\SimpleApp::run', $env);
}
// Redirect:
if(strtolower($env['PATH_INFO']) == '/about')
{
$env['web.route_params'] = array (
);
// TODO: How to inject class used for Request->getDefaultUrlOptions()?
// TODO: Remove the lines below if the generated path is a full URL
$req = new \Inject\Web\Request($env);
$url = \Inject\Web\Request::urlFor(array_merge($req->getDefaultUrlOptions(), array('path' => 'http://www.google.com')));
return array(302, array('Location' => $url), '');
}
if(strtolower($env['PATH_INFO']) == '/test')
{
if(isset($env['REQUEST_METHOD']) && $env['REQUEST_METHOD'] === 'GET')
{
$env['web.route_params'] = array (
'action' => 'index',
);
return \Sample\Controller\Test::stack($engine, 'index')->run($env);
}
if(isset($env['REQUEST_METHOD']) && $env['REQUEST_METHOD'] === 'POST')
{
$env['web.route_params'] = array (
'action' => 'index',
);
return \Sample\Controller\Test::stack($engine, 'create')->run($env);
}
}
if(strtolower($env['PATH_INFO']) == '/test/new')
{
$env['web.route_params'] = array (
'action' => 'index',
);
return \Sample\Controller\Test::stack($engine, 'newform')->run($env);
}
if(stripos($env['PATH_INFO'], '/test/') === 0)
{
if(preg_match('#^/test/(?<test_id>\\w+)$#ui', $env['PATH_INFO'], $match))
{
$matches = array_merge($matches, $match);
if(isset($env['REQUEST_METHOD']) && $env['REQUEST_METHOD'] === 'GET')
{
$env['web.route_params'] = array_intersect_key(array_merge(array (
'action' => 'index',
), $matches), array (
'test_id' => 0,
));
return \Sample\Controller\Test::stack($engine, 'show')->run($env);
}
if(isset($env['REQUEST_METHOD']) && $env['REQUEST_METHOD'] === 'PUT')
{
$env['web.route_params'] = array_intersect_key(array_merge(array (
'action' => 'index',
), $matches), array (
'test_id' => 0,
));
return \Sample\Controller\Test::stack($engine, 'update')->run($env);
}
if(isset($env['REQUEST_METHOD']) && $env['REQUEST_METHOD'] === 'DELETE')
{
$env['web.route_params'] = array_intersect_key(array_merge(array (
'action' => 'index',
), $matches), array (
'test_id' => 0,
));
return \Sample\Controller\Test::stack($engine, 'destroy')->run($env);
}
}
if(preg_match('#^/test/(?<test_id>\\w+)/edit$#ui', $env['PATH_INFO'], $match))
{
$matches = array_merge($matches, $match);
$env['web.route_params'] = array_intersect_key(array_merge(array (
'action' => 'index',
), $matches), array (
'test_id' => 0,
));
return \Sample\Controller\Test::stack($engine, 'edit')->run($env);
}
}
return array(404, array('X-Cascade' => 'pass'), '');
};
$reverse = array(
'root' => function($options)
{
return '/';
},
'blog_archive' => function($options)
{
return (empty($options['year']) OR empty($options['month']) ? array (
0 => 'year',
1 => 'month',
) : '/archive/'.$options['year'].'/'.$options['month']);
},
'simpleapp' => function($options)
{
return '/testing';
},
'test' => function($options)
{
return '/test';
},
'create_test' => function($options)
{
return '/test';
},
'new_test' => function($options)
{
return '/test/new';
},
'show_test' => function($options)
{
return (empty($options['test_id']) ? array (
0 => 'test_id',
) : '/test/'.$options['test_id']);
},
'update_test' => function($options)
{
return (empty($options['test_id']) ? array (
0 => 'test_id',
) : '/test/'.$options['test_id']);
},
'delete_test' => function($options)
{
return (empty($options['test_id']) ? array (
0 => 'test_id',
) : '/test/'.$options['test_id']);
},
'edit_test' => function($options)
{
return (empty($options['test_id']) ? array (
0 => 'test_id',
) : '/test/'.$options['test_id'].'/edit');
}
);
return array($router, $reverse);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.