Sample usage: Route::get('/agents/index', 'agents#index'); will match: GET /agents/index Route::post('/agents/save', 'agents#save'); will match: POST /agents/save Route::resource('agents'); will mapping RESTs methods (index, fresh, edit, show, create, update, destroy) Route::any('/agents/show_numbers', 'agents#show_numbers'); will match: POST or GET /agents/show_numbers Route::allowAll('/agents', 'agents'); will mapping any methods to all actions in controller To show all routes or routes per controller: Route::getRoutes(); Route::getRoutesForController('agents');
Inheritance: implements Ouzo\Routing\RouteInterface
示例#1
0
 /**
  * @test
  */
 public function shouldCreateRouteForResource()
 {
     //given
     GroupedRoute::resource('users');
     //when
     $routes = Route::getRoutes();
     //then
     Assert::thatArray($routes)->onMethod('getUri')->containsOnly('/api/users', '/api/users/fresh', '/api/users/:id/edit', '/api/users/:id', '/api/users', '/api/users/:id', '/api/users/:id', '/api/users/:id');
 }
示例#2
0
    public function __construct()
    {
        $this->routeRules = $routes = Route::getRoutes();
        $this->generatedFunctions .= 'function checkParameter(parameter) {
' . self::INDENT . 'if (parameter === null) {
' . self::INDENT . self::INDENT . 'throw new Error("Uri helper: Missing parameters");
' . self::INDENT . '}
}' . "\n\n";
        $this->generateFunctions();
    }
 /**
  * @test
  */
 public function shouldNotDisplayOutputBeforeHeadersAreSent()
 {
     //given
     $self = $this;
     $obLevel = ob_get_level();
     Mock::when($this->frontController->getHeaderSender())->send(Mock::any())->thenAnswer(function () use($self, $obLevel) {
         //if there's a nested buffer, nothing was sent to output
         $self->assertTrue(ob_get_level() > $obLevel);
         $self->expectOutputString('OUTPUT');
     });
     Route::allowAll('/sample', 'sample');
     //when
     $this->get('/sample/action');
     //then no exceptions
 }
 public function tearDown()
 {
     Route::$validate = true;
     parent::tearDown();
     Config::clearProperty('namespace', 'controller');
 }
示例#5
0
 /**
  * @return UriHelperGenerator
  */
 public static function generate()
 {
     return new self(Route::getRoutes());
 }
示例#6
0
文件: Router.php 项目: letsdrink/ouzo
 /**
  * @param $path
  * @param $requestType
  * @return RouteRule
  */
 private function findRouteRule($path, $requestType)
 {
     return Arrays::find(Route::getRoutes(), function (RouteRule $rule) use($path, $requestType) {
         return $rule->matches($path, $requestType);
     });
 }
    /**
     * @test
     */
    public function shouldNotGenerateCorrectAllowAllResource()
    {
        //given
        Route::allowAll('/api', 'api');
        //when
        $generated = JsUriHelperGenerator::generate()->getGeneratedFunctions();
        //then
        $expected = <<<FUNCT
function checkParameter(parameter) {
    if (parameter === null) {
        throw new Error("Uri helper: Missing parameters");
    }
}

FUNCT;
        $this->assertEquals($expected, $generated);
    }
示例#8
0
<?php

use Ouzo\Routing\Route;
Route::get('/', 'home#index');
Route::get('/new_game', 'games#new_game');
Route::get('/end_game', 'games#end_game');
Route::get('/test', 'games#test');
Route::get('/game_content', 'games#game_content');
Route::get('/games', 'games#index');
Route::get('/games/current', 'games#game');
Route::get('/games/:id', 'games#show');
Route::post('/games', 'games#create');
Route::post('/games/new', 'games#create_new');
Route::post('/games/restart', 'games#restart');
Route::post('/games/cancel', 'games#cancel');
Route::post('/games/next_player', 'games#next_player');
Route::post('/long_poll', 'events#poll');
Route::post('/hit', 'hits#index');
Route::resource('players');
示例#9
0
文件: routes.php 项目: letsdrink/ouzo
<?php

/*
 * Copyright (c) Ouzo contributors, http://ouzoframework.org
 * This file is made available under the MIT License (view the LICENSE file for more information).
 */
use Ouzo\Routing\Route;
Route::get('/', 'index#index');
Route::allowAll('/users', 'users', array('except' => array('new', 'select_outbound_for_user')));
Route::get('/agents/index', 'agents#index');
Route::post('/agents/index', 'agents#index');
Route::allowAll('/photos', 'photos');
Route::any('/agents/index', 'agents#index');
Route::resource('phones');
Route::get('/agents', 'agents#index', array('as' => 'my_name'));
Route::get('/agents/show/id/:id/call_id/:call_id', 'agents#show');
示例#10
0
 /**
  * @test
  */
 public function shouldSaveStatsIfDebugIsOn()
 {
     //given
     Config::overrideProperty('debug')->with(true);
     Session::remove('stats_queries');
     Route::get('/sample/save', 'sample#save');
     //when
     $this->get('/sample/save');
     //then
     $this->assertNotEmpty(Session::get('stats_queries'));
 }
示例#11
0
 /**
  * @test
  */
 public function shouldGetStringOutput()
 {
     //given
     Route::allowAll('/simple_test', 'simple_test');
     //when
     $this->get('/simple_test/string_output');
     //then
     $this->assertEquals('ONLY OUTPUT', $this->getActualContent());
 }
示例#12
0
 private function all()
 {
     $this->_renderRoutes(Route::getRoutes());
 }
示例#13
0
文件: Route.php 项目: letsdrink/ouzo
    }
    private static function createRouteAction($controller, $action)
    {
        return $controller . '#' . $action;
    }
    /**
     * @return RouteRule[]
     */
    public static function getRoutes()
    {
        return self::$routes;
    }
    public static function getRoutesForController($controller)
    {
        return Arrays::filter(self::getRoutes(), function (RouteRule $route) use($controller) {
            return Strings::equalsIgnoreCase($route->getController(), $controller);
        });
    }
    public static function group($name, $routeFunction)
    {
        GroupedRoute::setGroupName($name);
        $routeFunction();
    }
    public static function clear()
    {
        self::$routes = array();
        self::$routeKeys = array();
    }
}
Route::$isDebug = Config::getValue('debug');
示例#14
0
    /**
     * @test
     */
    public function shouldGenerateCorrectNestedResources()
    {
        //given
        Route::get('/api/users/:id/orders', 'api/users#orders');
        //when
        $generated = UriHelperGenerator::generate()->getGeneratedFunctions();
        //then
        $expected = <<<FUNCT
<?php
function checkParameter(\$parameter)
{
    if (!isset(\$parameter)) {
        throw new \\InvalidArgumentException("Missing parameters");
    }
}

function ordersUsersApiPath(\$id)
{
    checkParameter(\$id);
    return url("/api/users/\$id/orders");
}

function allGeneratedUriNames()
{
    return array('ordersUsersApiPath');
}
FUNCT;
        $this->assertEquals($expected, $generated);
    }
示例#15
0
 /**
  * @test
  */
 public function shouldInvokeFunctionCallback()
 {
     //given
     SampleController::$beforeActionResult = true;
     SampleController::$beforeCallback = function ($controller) {
         $controller->redirect('url');
         return true;
     };
     Route::any('/sample/action', 'sample#action');
     //when
     $this->get('/sample/action');
     //then
     $this->assertRedirectsTo('url');
 }
示例#16
0
 /**
  * @test
  */
 public function shouldParseParameterWithSpace()
 {
     //given
     Route::get("/cabinets/:color/:order_id", "SummaryOrderedCorpuses#index");
     $router = $this->_createRouter('GET', '/cabinets/Biały 101/18');
     //when
     $rule = $router->findRoute();
     //then
     $parameters = $rule->getParameters();
     $this->assertEquals('Biały 101', $parameters['color']);
     $this->assertEquals('18', $parameters['order_id']);
 }
示例#17
0
 /**
  * @test
  */
 public function shouldAddAllowAll()
 {
     //given
     Route::get('/user', 'User#index');
     Route::allowAll('/user', 'User');
     //when
     $routes = Route::getRoutes();
     //then
     $this->assertCount(2, $routes);
 }