本文整理汇总了PHP中Route::all方法的典型用法代码示例。如果您正苦于以下问题:PHP Route::all方法的具体用法?PHP Route::all怎么用?PHP Route::all使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Route
的用法示例。
在下文中一共展示了Route::all方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createJson
public function createJson()
{
$routes = Route::all();
$paths_array = array();
$updatedPaths = '';
foreach ($routes as $route) {
$route_name = $route->name;
$route_array = array();
$methods = $route->methods;
foreach ($methods as $method) {
$method_name = $method->method;
$updatedPaths = $updatedPaths . ' ' . $method_name . " " . $route_name . ' <br/>';
$method_description = $method->description;
$method_tags = $method->tags;
$parameters = $method->parameters;
$method_array = array('description' => $method_description, 'tags' => [$method_tags], 'parameters' => $parameters, 'responses' => array('200' => array('description' => 'OK')));
$route_array[$method_name] = $method_array;
$method_array = NULL;
}
//foreach method
$paths_array[$route_name] = $route_array;
$route_array = NULL;
}
//foreach route
$final_array = array('swagger' => '2.0', 'info' => array('version' => '0.0.1', 'title' => 'MY REST API'), 'host' => 'example.com', 'basePath' => '/appx_api', 'schemes' => ['http', 'https'], 'consumes' => ['application/json'], 'produces' => ['application/json'], 'paths' => $paths_array);
$fp = fopen('storage/api.json', 'w');
fwrite($fp, json_encode($final_array));
fclose($fp);
return $updatedPaths;
}
示例2: create_tests
/**
* Get an array of Route_Tester objects from the config settings
*
* @param $tests A URL to test, or an array of URLs to test.
* @returns array An array of Route_Tester objects
*/
public static function create_tests($tests)
{
if (is_string($tests)) {
$tests = array($tests);
}
$array = array();
// Get the url and optional expected_params from the config
foreach ($tests as $key => $value) {
$current = new Route_Tester();
if (is_array($value)) {
$url = $key;
$current->expected_params = $value;
} else {
$url = $value;
}
$current->url = trim($url, '/');
// Test each route, and save the route and params if it matches
foreach (Route::all() as $route) {
if ($current->params = $route->matches(Request::factory($current->url))) {
$current->route = Route::name($route);
$current->params = array_merge(array('route' => $current->route), $current->params);
break;
}
}
$array[] = $current;
}
return $array;
}
示例3: routeList
public function routeList()
{
$routes = Route::all();
//array of all routes
$routes_array = json_decode($routes, TRUE);
//var_dump($routes_array); //correct
$allMethods = array();
foreach ($routes_array as $route) {
//each route access
//get route object
$api = Route::find($route['id']);
//echo $api."<br>"; //correct
//get all methods of this route and push to allMethods array
$routeMethods = $api->methods;
//echo $routeMethods."<br>";
foreach ($routeMethods as $routeMethod) {
// echo $routeMethod."<br>";
$method = $routeMethod->method;
$description = $routeMethod->description;
$routeMethod_array = array();
$routeMethod_array['route'] = $route['name'];
$routeMethod_array['method'] = $routeMethod->method;
$routeMethod_array['tags'] = $routeMethod->tags;
$routeMethod_array['method_id'] = $routeMethod->id;
$routeMethod_array['description'] = $routeMethod->description;
array_push($allMethods, $routeMethod_array);
$routeMethod_array = NULL;
}
}
//foreach
return $allMethods;
}
示例4: find
/**
* Find the first route matching the given URI
*
* @param string uri
* @return route|false
*/
public static function find($uri)
{
foreach (Route::all() as $route) {
if ($route->matches($uri)) {
return $route;
}
}
return FALSE;
}
示例5: test_set_without_resource
public function test_set_without_resource()
{
$this->markTestSkipped();
$route = Route::set('route_without_resource', 'routing/<id>', array('id' => '[1-9]\\d*'), array('resource' => 'some_resource', 'method' => 'get'))->defaults(array('controller' => 'routes', 'action' => 'show'));
$this->assertSame(array('route_without_resource' => $route), Route::all());
$this->assertEquals('some_resource', $route->resource_name());
$this->setExpectedException('Kohana_Exception');
$route->resource();
$this->assertEquals('GET', $route->method());
}
示例6: simulate_uri
function simulate_uri($uri)
{
foreach (Route::all() as $route) {
$route->compile();
if ($route->matches($uri)) {
//var_dump($route->getData());
call_user_func_array($route->getCallback(), $route->getData());
}
}
}
示例7: action_url
/**
* Fetches a url based on a action of controller.
*
* echo URL::action_url('foo', 'bar', array('id' => 1));
*
* @param string $action_name Action name
* @param mixed $controller_name Controller name
* @param array $params route parameters
* @return string
* @uses Request::initial
* @uses Route::all
* @uses Route::uri
* @uses Route::matches
*/
public static function action_url($action_name, $controller_name = '', array $params = NULL)
{
$request = Request::current();
$controller = !empty($controller_name) ? $controller_name : $request->controller();
$directory = $request->directory();
if (is_null($params)) {
$params = array('directory' => $directory, 'controller' => $controller, 'action' => $action_name);
} else {
$params = array_merge($params, array('controller' => $controller, 'action' => $action_name));
if (!isset($params['directory'])) {
$params['directory'] = $directory;
}
if (empty($params['directory'])) {
unset($params['directory']);
}
}
$cache_key = 'URL::action_url::';
foreach ($params as $key => $value) {
$cache_key .= $key . $value;
}
if (!($url = Kohana::cache($cache_key))) {
$select_route = Route::get('default');
$routes = Route::all();
foreach ($routes as $route_name => $route) {
$match_url = $route->uri($params);
$match_params = $route->matches($match_url);
if ($match_params == $params) {
$select_route = $route;
$url = $match_url;
break;
}
}
if (empty($url)) {
$url = $select_route->uri($params);
}
$paths = explode('/', $url);
while (array_pop($paths)) {
$match_url = implode('/', $paths);
$match_params = $route->matches($match_url);
if ($match_params == $params) {
$url = $match_url;
} else {
break;
}
}
if (Kohana::$caching === TRUE) {
Kohana::cache($cache_key, $url);
}
}
return $url;
}
示例8: action_check
function action_check()
{
$all_routes = Route::all();
$errors = array();
$routes = array();
$results = array();
$validation = Validate::factory($_POST)->filter('tests', 'trim')->rule('route_id', 'is_array')->rule('route_id', 'count')->rule('tests', 'not_empty');
$submitted = $validation->check();
$data = $validation->as_array();
if ($submitted) {
$data['tests'] = str_replace("\n\r", "\n", $data['tests']);
$tests = explode("\n", $data['tests']);
for ($test = 0, $test_count = count($tests); $test < $test_count; ++$test) {
$tests[$test] = trim(trim($tests[$test], '/'));
}
foreach ((array) $data['route_id'] as $route_id) {
$route = NULL;
if ($route_id === '::CREATE::') {
// Create a route on the fly
$route_id = 'KohanaRocksMySocks';
$route = new Route($route_id, $data['route_uri']);
} else {
$route = Route::get($route_id);
}
$route_id = $route_id . ' - <em>' . htmlspecialchars($route->uri) . '</em>';
$results[$route_id] = array();
foreach ($tests as $test) {
$matches = $route->matches($test);
// Make the test display as /
if (empty($test)) {
$test = '/';
}
// Store the result and the parsed parameters
$results[$route_id][$test] = array('matched' => $matches !== FALSE, 'params' => $matches !== FALSE ? $matches : array());
}
}
}
$this->template->title = 'Check your Routes';
$this->template->body = new View('devils/routes/check');
$this->template->body->data = $data;
$this->template->body->defined_routes = $all_routes;
$this->template->body->errors = $validation->errors();
$this->template->body->results = $results;
}
示例9: before
/**
* Loads the template [View] object.
*/
public function before()
{
parent::before();
if ($this->auto_render === TRUE) {
if ($this->request->is_ajax() === TRUE) {
// Load the template
$this->template = View::factory('system/ajax');
} else {
$this->template = View::factory($this->template);
}
// Initialize empty values
$this->template->title = NULL;
$this->template->content = NULL;
$this->breadcrumbs = Breadcrumbs::factory();
$routes = Route::all();
if (isset($routes['backend'])) {
$this->breadcrumbs->add(UI::icon('home'), Route::get('backend')->uri());
}
$this->init_media();
}
}
示例10: __construct
public function __construct($uri)
{
$uri = trim($uri, '/');
$routes = Route::all();
foreach ($routes as $name => $route) {
$params = $route->matches($uri);
if ($params) {
$this->uri = $uri;
$this->route = $route;
if (isset($params['directory'])) {
$this->directory = $params['directory'];
}
$this->controller = $params['controller'];
if (isset($params['action'])) {
$this->action = $params['action'];
}
unset($params['controller'], $params['action'], $params['directory']);
$this->_params = $params;
break;
}
}
}
示例11: __construct
/**
* Creates a new request object for the given URI. New requests should be
* created using the [Request::instance] or [Request::factory] methods.
*
* $request = new Request($uri);
*
* @param string URI of the request
* @return void
* @throws Kohana_Request_Exception
* @uses Route::all
* @uses Route::matches
*/
public function __construct($uri)
{
// Remove trailing slashes from the URI
$uri = trim($uri, '/');
// Load routes
$routes = Route::all();
foreach ($routes as $name => $route) {
if ($params = $route->matches($uri)) {
// Store the URI
$this->uri = $uri;
// Store the matching route
$this->route = $route;
if (isset($params['directory'])) {
// Controllers are in a sub-directory
$this->directory = $params['directory'];
}
// Store the controller
$this->controller = $params['controller'];
if (isset($params['action'])) {
// Store the action
$this->action = $params['action'];
} else {
// Use the default action
$this->action = Route::$default_action;
}
// These are accessible as public vars and can be overloaded
unset($params['controller'], $params['action'], $params['directory']);
// Params cannot be changed once matched
$this->_params = $params;
return;
}
}
// No matching route for this URI
$this->status = 404;
throw new Kohana_Request_Exception('Unable to find a route to match the URI: :uri', array(':uri' => $uri));
}
示例12: test_cache_append_routes
/**
* Check appending cached routes. See http://dev.kohanaframework.org/issues/4347
*
* @test
* @covers Route::cache
*/
public function test_cache_append_routes()
{
$cached = Route::all();
// First we create the cache
Route::cache(TRUE);
// Now lets modify the "current" routes
Route::set('nonsensical_route', 'flabbadaga/ding_dong');
$modified = Route::all();
// Then try and load said cache
$this->assertTrue(Route::cache(NULL, TRUE));
// Check the route cache flag
$this->assertTrue(Route::$cache);
// And if all went ok the nonsensical route should exist with the other routes...
$this->assertEquals(Route::all(), $cached + $modified);
}
示例13: function
echo $customPanelName;
?>
= ['<?php
echo $customPanelName;
?>
'];
<?php
}
?>
var main = <?php
echo $jsSettings;
?>
;
var custom = {
<?php
if (array_key_exists('elfinder', Route::all())) {
?>
fmOpen : function(callback) {
$('<div id="myelfinder" />').elfinder({
url : '<?php
echo URL::site(Route::get('elfinder')->uri(), TRUE);
?>
',
lang : '<?php
echo Kohana::$config->load('elfinder-js.lang');
?>
',
dialog : { width : 900, modal : true, title : 'elFinder - file manager for web' },
closeOnEditorCallback : true,
editorCallback : callback
})
示例14: test_cache_stores_route_objects
/**
* If Route::cache() was able to restore routes from the cache then
* it should return TRUE and load the cached routes
*
* @test
* @covers Route::cache
*/
public function test_cache_stores_route_objects()
{
$routes = Route::all();
// First we create the cache
Route::cache(TRUE);
// Now lets modify the "current" routes
Route::set('nonsensical_route', 'flabbadaga/ding_dong');
// Then try and load said cache
$this->assertTrue(Route::cache());
// Check the route cache flag
$this->assertTrue(Route::$cache);
// And if all went ok the nonsensical route should be gone...
$this->assertEquals($routes, Route::all());
}
示例15:
<?php
Route::all('/testas', 'Modules\\Testas\\Controllers\\TestasController');