本文整理汇总了PHP中Illuminate\Routing\Router::matched方法的典型用法代码示例。如果您正苦于以下问题:PHP Router::matched方法的具体用法?PHP Router::matched怎么用?PHP Router::matched使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Routing\Router
的用法示例。
在下文中一共展示了Router::matched方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: boot
/**
* Define your route model bindings, pattern filters, etc.
*
* @param \Illuminate\Routing\Router $router
* @return void
*/
public function boot(Router $router)
{
// Sets up our routing tokens.
$router->pattern('board', Board::URI_PATTERN);
$router->pattern('id', '[1-9]\\d*');
$router->model('ban', '\\App\\Ban');
$router->model('board', '\\App\\Board');
$router->model('post', '\\App\\Post');
$router->model('report', '\\App\\Report');
$router->model('role', '\\App\\Role');
$router->bind('user', function ($value, $route) {
if (is_numeric($value)) {
return \App\User::find($value);
} else {
if (preg_match('/^[a-z0-9]{1,64}\\.(?P<id>\\d+)$/i', $value, $matches)) {
return \App\User::find($matches['id']);
}
}
});
$router->bind('role', function ($value, $route) {
if (is_numeric($value)) {
return \App\Role::find($value);
} else {
if (preg_match('/^[a-z0-9]{1,64}\\.(?P<id>\\d+)$/i', $value, $matches)) {
return \App\Role::find($matches['id']);
}
}
});
$router->bind('post_id', function ($value, $route) {
$board = $route->getParameter('board');
if (is_numeric($value) && $board instanceof Board) {
return $board->getThreadByBoardId($value);
}
});
// Binds a matched instance of a {board} as a singleton instance.
$router->matched(function ($route, $request) {
// Binds the board to the application if it exists.
$board = $route->getParameter('board');
if ($board instanceof Board && $board->exists) {
$board->applicationSingleton = true;
//$this->app->instance("\App\Board", $board);
$this->app->singleton("\\App\\Board", function ($app) use($board) {
return $board->load(['assets', 'settings']);
});
}
// Binds the post to the application if it exists.
$post = $route->getParameter('post_id');
if ($post instanceof Post && $post->exists) {
$route->setParameter('post', $post);
//$this->app->instance("\App\Post", $post);
$this->app->singleton("\\App\\Post", function ($app) use($post) {
return $post;
});
}
});
parent::boot($router);
}
示例2: forRoute
/**
* Handle route decodable params
*
* @param \Illuminate\Routing\Router $route
* @param $configKey
*/
protected function forRoute($route, $configKey)
{
$route->matched(function ($route) use($configKey) {
/**
* @var \Illuminate\Routing\Route $route
*/
foreach ($route->parameters() as $parameterKey => $parameterValue) {
if (Str::startsWith($parameterKey, $configKey)) {
$route->setParameter($parameterKey, BijectiveShortener::decodeToInteger($parameterValue));
}
}
});
}
示例3: boot
/**
* Define your route model bindings, pattern filters, etc.
*
* @param \Illuminate\Routing\Router $router
* @return void
*/
public function boot(Router $router)
{
// Sets up our routing tokens.
$router->pattern('board', Board::URI_PATTERN);
$router->pattern('id', '[1-9]\\d*');
$router->model('board', 'App\\Board');
$router->model('post', 'App\\Post');
$router->model('report', 'App\\Report');
$router->model('role', 'App\\Role');
// Binds a matched instance of a {board} as a singleton instance.
$app = $this->app;
$router->matched(function ($route, $request) use($app) {
// Binds the board to the application if it exists.
$board = $route->getParameter('board');
if ($board instanceof Board && $board->exists) {
$board->applicationSingleton = true;
$app->instance("\\App\\Board", $board);
$app->singleton("\\App\\Board", function ($app) use($board) {
return $board->load('settings');
});
}
});
parent::boot($router);
}
示例4: matched
/**
* Register a route matched event listener.
*
* @param string|callable $callback
* @return void
* @static
*/
public static function matched($callback)
{
\Illuminate\Routing\Router::matched($callback);
}
示例5: boot
/**
* Define your route model bindings, pattern filters, etc.
*
* @param \Illuminate\Routing\Router $router
* @return void
*/
public function boot(Router $router)
{
// Sets up our routing tokens.
$router->pattern('attachment', '[0-9]\\d*');
$router->pattern('board', Board::URI_PATTERN);
$router->pattern('id', '[0-9]\\d*');
$router->model('attachment', '\\App\\FileAttachment');
$router->model('ban', '\\App\\Ban');
$router->model('board', '\\App\\Board');
$router->model('page', '\\App\\Page');
$router->model('post', '\\App\\Post');
$router->model('report', '\\App\\Report');
$router->model('role', '\\App\\Role');
$router->bind('user', function ($value, $route) {
if (is_numeric($value)) {
return User::find($value);
} else {
if (preg_match('/^[a-z0-9]{1,64}\\.(?P<id>\\d+)$/i', $value, $matches)) {
return User::find($matches['id']);
}
}
});
$router->bind('page', function ($value, $route) {
if (is_numeric($value)) {
return Page::find($value);
} else {
if (preg_match('/^[a-z0-9]{1,64}\\.(?P<id>\\d+)$/i', $value, $matches)) {
return Page::find($matches['id']);
}
}
});
$router->bind('page_title', function ($value, $route) {
$board = $route->getParameter('board');
return Page::where(['board_uri' => $board instanceof Board ? $board->board_uri : null, 'title' => $value])->first();
});
$router->bind('board', function ($value, $route) {
$board = Board::getBoardForRouter($this->app, $value);
if ($board) {
$board->applicationSingleton = true;
return $board;
}
return abort(404);
});
$router->bind('attachment', function ($value, $route) {
return \App\FileAttachment::where('is_deleted', false)->with('storage')->find($value);
});
$router->bind('role', function ($value, $route) {
if (is_numeric($value)) {
return \App\Role::find($value);
} else {
if (preg_match('/^[a-z0-9]{1,64}\\.(?P<id>\\d+)$/i', $value, $matches)) {
return \App\Role::find($matches['id']);
}
}
});
$router->bind('post_id', function ($value, $route) {
$board = $route->getParameter('board');
if (!$board instanceof Board) {
$board = $this->app->make("\\App\\Board");
}
if (is_numeric($value) && $board instanceof Board) {
return $board->getThreadByBoardId($value);
}
});
// Binds a matched instance of a {board} as a singleton instance.
$router->matched(function ($route, $request) {
$board = $route->getParameter('board');
if ($board instanceof Board && $board->exists) {
// Binds the board to the application if it exists.
$this->app->singleton("\\App\\Board", function ($app) use($board) {
return $board;
});
}
// Binds the post to the application if it exists.
$post = $route->getParameter('post_id');
if ($post instanceof Post && $post->exists) {
$route->setParameter('post', $post);
//$this->app->instance("\App\Post", $post);
$this->app->singleton("\\App\\Post", function ($app) use($post) {
return $post;
});
}
});
parent::boot($router);
}