Example #1
0
 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 . '&nbsp;' . $method_name . " " . $route_name . '&nbsp;<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;
 }
Example #2
0
 /**
  * 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;
 }
Example #3
0
 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;
 }
Example #4
0
 /**
  * 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;
 }
Example #5
0
 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());
 }
Example #6
0
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());
        }
    }
}
Example #7
0
 /**
  * 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;
 }
Example #8
0
 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;
 }
Example #9
0
 /**
  * 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();
     }
 }
Example #10
0
 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;
         }
     }
 }
Example #11
0
 /**
  * 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));
 }
 /**
  * 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);
 }
Example #13
0
    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
                })
Example #14
0
 /**
  * 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());
 }
Example #15
0
<?php

Route::all('/testas', 'Modules\\Testas\\Controllers\\TestasController');
Example #16
0
 /**
  * Checks if a page URI is available
  *
  * @param str $URI
  * @return boolean
  */
 public static function page_URI_available($URI)
 {
     $routes = Route::all();
     foreach ($routes as $name => $route) {
         if ($params = $route->matches($URI)) {
             if ($default_params = $route->matches('')) {
                 if ($params['controller'] != 'staticpage') {
                     return TRUE;
                 }
             }
             if (class_exists('controller_' . $params['controller']) && method_exists('controller_' . $params['controller'], 'action_' . $params['action'])) {
                 return FALSE;
             }
         }
     }
     return TRUE;
 }
Example #17
0
<?php

if (!($routes = Cache::read('routes', 'routes'))) {
    App::import("Model", "Routes.Route");
    $routesModel = new Route();
    $routes = $routesModel->all(null, array('order' => "length(Route.url) desc"));
    Cache::write('routes', $routes, 'routes');
}
foreach ($routes as $route) {
    $named_params = $route['NamedParams'];
    unset($route['NamedParams']);
    $params = $route['Params'];
    unset($route['Params']);
    $url = '/' . $route['Route']['url'];
    if (empty($route['Route']['plugin'])) {
        $route['Route']['plugin'] = false;
    }
    unset($route['Route']['id'], $route['Route']['user_id'], $route['Route']['url'], $route['Route']['lastupdate']);
    foreach ($named_params as $param) {
        $route['Route'][$param['name']] = $param['value'];
    }
    foreach ($params as $param) {
        array_push($route['Route'], $param['value']);
    }
    Router::connect($url . (strlen($url) == 1 ? '' : '/*'), $route['Route']);
}
Example #18
0
 /**
  * Returns all application routes
  *
  * @return array
  */
 public static function get_routes()
 {
     return Route::all();
 }
Example #19
0
?>
</div>

    <div class="col-md-3 span2">
        <div class="thumbnail highlight">
            <img src="<?php 
echo $topic->user->get_profile_image();
?>
" width="120" height="120" alt="<?php 
echo HTML::chars($topic->user->name);
?>
">
            <div class="caption">
                <p>
                    <?php 
if (in_array('profile', Route::all())) {
    ?>
                        <a href="<?php 
    echo Route::url('profile', array('seoname' => $topic->user->seoname));
    ?>
">
                            <?php 
    echo $topic->user->name;
    ?>
                        </a>
                    <?php 
} else {
    ?>
                        <?php 
    echo $topic->user->name;
    ?>
Example #20
0
 /**
  * Process a request to find a matching route
  *
  * @param   object  $request Request
  * @param   array   $routes  Route
  * @return  array
  */
 public static function process(Request $request, $routes = NULL)
 {
     // Load routes
     $routes = empty($routes) ? Route::all() : $routes;
     $params = NULL;
     foreach ($routes as $name => $route) {
         // We found something suitable
         if ($params = $route->matches($request)) {
             return array('params' => $params, 'route' => $route);
         }
     }
     return NULL;
 }
 public static function explain()
 {
     $routes = [];
     foreach (Route::all() as $name => $route) {
         $routes[] = str_pad($name, 40) . '| ' . str_pad((!empty($route->_defaults['directory']) ? $route->_defaults['directory'] : '') . $route->_defaults['controller'] . '#' . $route->_defaults['action'], 30) . '| ' . $route->_uri;
     }
     return implode("\n", $routes);
 }
Example #22
0
 /**
  * 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);
  *
  * KoJo Modification:
  *		The $uri can just be an array instead of using a route which is inapplicable inside Joomla
  *
  * @param   string  URI of the request
  * @return  void
  * @throws  Kohana_Request_Exception
  * @uses    Route::all
  * @uses    Route::matches
  */
 public function __construct($uri, $client = NULL)
 {
     // Set if the request is for the admin or site client
     $this->client = $client === 'admin' ? 'admin' : 'site';
     if (is_array($uri)) {
         if (!array_key_exists('option', $uri)) {
             throw new Kohana_Request_Exception('The extension should be specified using the option variable!');
         }
         $this->extension = $uri['option'];
         unset($uri['option']);
         $this->controller = Arr::get($uri, 'controller', NULL);
         unset($uri['controller']);
         $this->action = Arr::get($uri, 'action', NULL);
         unset($uri['action']);
         // Pass the rest of the variables to the params
         $this->_params = $uri;
         return;
     }
     // 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['extension'])) {
                 // Controllers are in an extension
                 $this->extension = $params['extension'];
             }
             // 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['extension']);
             // 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));
 }
 /**
  * @covers ::set_routes
  */
 public function test_set_routes()
 {
     $this->env->backup_and_set(array('site-versions.versions' => array('test' => array())));
     $this->assertCount(1, Route::all());
     $version = new Site_Version('test');
     $version->set_routes(array('homepage' => array('home(/<id>)', array('action' => '\\d+'), array('controller' => 'test', 'action' => 'index'))));
     $this->assertCount(2, Route::all());
     $expected = new Route('home(/<id>)', array('action' => '\\d+'));
     $expected->defaults(array('controller' => 'test', 'action' => 'index'));
     $this->assertEquals($expected, Route::get('homepage'));
 }
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($id)
 {
     $data = Route::all();
     return response()->json(json_encode($data));
 }
Example #25
0
function url(array $params, $route_name = null)
{
    //[url]
    if (empty($params['controller'])) {
        $params['controller'] = Request::current()->controller();
    }
    if (empty($params['action'])) {
        $params['action'] = Request::current()->action();
    }
    $route_name = $params['controller'] . '_' . $params['action'];
    $_routes_all = Route::all();
    if (isset($_routes_all[$route_name])) {
        $route = Route::get($route_name);
    } else {
        if (empty($params['controller'])) {
            $params['controller'] = Request::current()->controller();
        }
        if (isset($_routes_all[$params['controller']])) {
            $route = Route::get($params['controller']);
        } else {
            $route = Route::get('default');
        }
    }
    return '/' . $route->uri($params);
}
Example #26
0
<?php

Route::all('/posts/([0-9]+)/test', 'Modules\\Blog\\Controllers\\BlogController');
Route::get('/mintu', 'Modules\\Blog\\Controllers\\BlogController@mintu');
Route::get('/profile/([a-z]+)', 'Modules\\Blog\\Controllers\\BlogController@displayUserProfile');
Route::get('/([a-z]+)/([a-z]+)/([a-z]+)', 'Modules\\Blog\\Controllers\\BlogController@testCity');
Route::get('/products/([0-9]+)', 'Modules\\Blog\\Controllers\\BlogController@productDetails');
 /**
  * Process a request to find a matching route
  *
  * @param   object  $request Request
  * @param   array   $routes  Route
  * @return  array
  */
 public static function process(Request $request, $routes = NULL)
 {
     // Load routes
     $routes = empty($routes) ? Route::all() : $routes;
     $params = NULL;
     foreach ($routes as $name => $route) {
         // Use external routes for reverse routing only
         if ($route->is_external()) {
             continue;
         }
         // We found something suitable
         if ($params = $route->matches($request)) {
             return array('params' => $params, 'route' => $route);
         }
     }
     return NULL;
 }
 /**
  * @return array
  */
 private static function getRoutes()
 {
     $res = ['data' => [], 'total' => ['count' => 0]];
     /** @noinspection PhpUndefinedClassInspection */
     $res['data'] = Route::all();
     $res['total']['count'] = count($res['data']);
     return $res;
 }
Example #29
0
		table td.fail { color: #911; }
	#results { padding: 0.8em; color: #fff; font-size: 1.5em; }
	#results.pass { background: #191; }
	#results.fail { background: #911; }
	
</style>


<h1>Route Dump</h1>

<?php 
if (count(Route::all()) > 0) {
    ?>
	
	<?php 
    foreach (Route::all() as $route) {
        ?>
	<h3><?php 
        echo Route::name($route);
        ?>
</h3>
		<?php 
        $array = (array) $route;
        foreach ($array as $key => $value) {
            $new_key = substr($key, strrpos($key, "") + 1);
            $array[$new_key] = $value;
            unset($array[$key]);
        }
        ?>
		<table>
			<tr>
Example #30
0
 /**
  * Process URI
  *
  * @param   string  $uri  URI
  * @return  array|boolean
  * @uses    Route::all
  */
 private function _process_uri($uri)
 {
     // Load routes
     $routes = Route::all();
     $params = NULL;
     foreach ($routes as $name => $route) {
         // We found something suitable
         if ($params = $route->matches(Request::factory($uri))) {
             $params['route'] = (string) $name;
             return $params;
         }
     }
     return FALSE;
 }