當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Board::getBoardForRouter方法代碼示例

本文整理匯總了PHP中app\Board::getBoardForRouter方法的典型用法代碼示例。如果您正苦於以下問題:PHP Board::getBoardForRouter方法的具體用法?PHP Board::getBoardForRouter怎麽用?PHP Board::getBoardForRouter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在app\Board的用法示例。


在下文中一共展示了Board::getBoardForRouter方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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('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('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('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);
 }
開發者ID:LulzNews,項目名稱:infinity-next,代碼行數:77,代碼來源:RouteServiceProvider.php


注:本文中的app\Board::getBoardForRouter方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。