本文整理汇总了PHP中Illuminate\Routing\Router::macro方法的典型用法代码示例。如果您正苦于以下问题:PHP Router::macro方法的具体用法?PHP Router::macro怎么用?PHP Router::macro使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Routing\Router
的用法示例。
在下文中一共展示了Router::macro方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: registerMacros
protected function registerMacros(Router $router)
{
$router->macro('module', function ($module, $sortable = false) use($router) {
$controller = ucfirst($module) . 'Controller';
if ($sortable) {
$router->patch("{$module}/changeOrder", $controller . '@changeOrder');
}
$router->resource($module, $controller);
});
$this->app['paginateroute']->registerMacros();
}
示例2: enableGenericResourceRouting
/**
* Set up the generic resource routes + controller.
*
* @param Router $router
* @return void
*/
protected function enableGenericResourceRouting(Router $router)
{
$app = $this->app;
$app->bind('eloquentjs.router', RouteRegistrar::class);
$app->when(RouteRegistrar::class)->needs('$controller')->give(GenericController::class);
$app->when(GenericController::class)->needs(Model::class)->give(function ($app) {
if ($resource = $app['eloquentjs.router']->getCurrentResource()) {
return $app->make($resource);
}
});
$router->macro('eloquent', function ($uri, $resource, $options = []) use($app) {
$app['eloquentjs.router']->addRoute($uri, $resource, $options);
});
}
示例3: macro
/**
* Register a custom macro.
*
* @param string $name
* @param callable $macro
* @return void
* @static
*/
public static function macro($name, $macro)
{
\Illuminate\Routing\Router::macro($name, $macro);
}
示例4: registerMacros
/**
* @param \Illuminate\Routing\Router $router
*/
protected function registerMacros(Router $router)
{
$router->macro('redirect', function ($url, $action) use($router) {
$router->get($url, function () use($action) {
return redirect()->action($action);
});
});
$router->macro('module', function ($slug, $className, $sortable = false) use($router) {
if ($sortable) {
$router->patch("{$slug}/changeOrder", "{$className}Controller@changeOrder");
}
$router->resource($slug, "{$className}Controller");
});
$router->macro('articleList', function ($technicalNamePrefix, $action) use($router) {
$articles = app(ArticleRepository::class)->getWithTechnicalNameLike($technicalNamePrefix);
$router->get(app()->getLocale() . '/' . fragment_slug("navigation.{$technicalNamePrefix}"), function () use($articles) {
return redirect(route("{$articles->first()->technical_name}"));
})->name($technicalNamePrefix);
$articles->map(function ($article) use($technicalNamePrefix, $action, $router) {
$router->get(app()->getLocale() . '/' . fragment_slug("navigation.{$technicalNamePrefix}") . '/' . $article->url, $action)->name("{$article->technical_name}");
});
});
}
示例5: registerInstanceMacro
/**
* Register Router Macro called Instance
* 플러그인에에서 등록한 route pattern 형태로 등록하여 instance route 를 찾을 수 있도록 하는
* 매크로 등록
*
* @param Router $router to register macro
*
* @return void
*/
protected function registerInstanceMacro(Router $router)
{
static $seq = 1;
$instanceMacro = function ($key, Closure $callback, $routeOptions = null) use(&$seq) {
$pattern = '{instanceGroup' . $seq++ . '}';
$attributes = ['prefix' => $pattern, 'module' => $key, 'middleware' => ['access']];
if ($routeOptions !== null and is_array($routeOptions)) {
$routeOptions = array_except($routeOptions, ['prefix', 'middleware']);
$attributes = array_merge($attributes, $routeOptions);
if (isset($routeOptions['middleware'])) {
$attributes['middleware'] .= '|' . $routeOptions['middleware'];
}
}
$this->group($attributes, $callback);
};
$router->macro('instance', $instanceMacro);
}
示例6: registerInstanceMacro
/**
* Register Router Macro called Instance
* 플러그인에에서 등록한 route pattern 형태로 등록하여 instance route 를 찾을 수 있도록 하는
* 매크로 등록
*
* @param Router $router to register macro
*
* @return void
*/
protected function registerInstanceMacro(Router $router)
{
$instanceMacro = function ($key, Closure $callback, $routeOptions = null) {
$pattern = sprintf("%s%s%s", "{", preg_replace("/[@\\/]/", "_", $key), "}");
$attributes = ['prefix' => $pattern, 'module' => $key, 'middleware' => ['access']];
if ($routeOptions !== null and is_array($routeOptions)) {
$routeOptions = array_except($routeOptions, ['prefix', 'middleware']);
$attributes = array_merge($attributes, $routeOptions);
if (isset($routeOptions['middleware'])) {
$attributes['middleware'] .= '|' . $routeOptions['middleware'];
}
}
$this->group($attributes, $callback);
};
$router->macro('instance', $instanceMacro);
}
示例7: registerFixedMacro
/**
* Register Router Macro called Fixed
* fixed 로 호출할 수 있는 Router 매크로를 등록하여
* 플러그인 고유한 URL 을 가져갈 수 있도록 한다.
*
* @param Router $router to register macro
*
* @return void
*/
protected function registerFixedMacro(Router $router)
{
$fixedMacro = function ($key, Closure $callback, $routeOptions = null) {
$newKey = str_replace('@', '/', $key);
$attributes = ['prefix' => config('xe.routing.fixedPrefix') . '/' . $newKey];
if ($routeOptions !== null and is_array($routeOptions)) {
$routeOptions = array_except($routeOptions, ['prefix']);
$attributes = array_merge($attributes, $routeOptions);
}
$this->group($attributes, $callback);
};
$router->macro('fixed', $fixedMacro);
}