本文整理汇总了PHP中Illuminate\Routing\RouteCollection类的典型用法代码示例。如果您正苦于以下问题:PHP RouteCollection类的具体用法?PHP RouteCollection怎么用?PHP RouteCollection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RouteCollection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testGeneratorDefaultsToApplicationRoutes
public function testGeneratorDefaultsToApplicationRoutes()
{
$this->routes->push($app = new IlluminateRouteCollection());
$app->add(new IlluminateRoute(['GET'], '/app', ['as' => 'foo', 'controller' => 'FooController@foo']));
$this->routes->push($api = new ApiRouteCollection('v1'));
$api->add(new ApiRoute(['GET'], '/api', ['as' => 'foo', 'controller' => 'FooController@foo']));
$this->assertEquals('http://www.foo.com/app', $this->url->route('foo'));
$this->assertEquals('http://www.foo.com/app', $this->url->action('FooController@foo'));
}
示例2: mergeExistingRoutes
/**
* Merge the existing routes with the new routes.
*
* @param \Illuminate\Routing\RouteCollection $routes
*
* @return \Illuminate\Routing\RouteCollection
*/
protected function mergeExistingRoutes(RouteCollection $routes)
{
if (!isset($this->oldRoutes)) {
$this->oldRoutes = $this->router->getRoutes();
}
foreach ($this->oldRoutes as $route) {
$routes->add($route);
}
return $routes;
}
示例3: getRoutesByPrefix
/**
* @param string $prefix
*
* @return RouteCollection
*/
public static function getRoutesByPrefix($prefix)
{
$prefix = ltrim(trim($prefix), '/');
$routes = self::getRoutes();
$prefixLength = strlen($prefix);
$filteredRoutes = new RouteCollection();
foreach ($routes as $route) {
$uri = ltrim(trim($route->getUri()), '/');
if (substr($uri, 0, $prefixLength) == $prefix) {
$filteredRoutes->add($route);
}
}
return $filteredRoutes;
}
示例4: fire
/**
* Execute the console command.
*
* @return boolean
*/
public function fire()
{
$this->call('route:clear');
$routes = $this->getFreshApplicationRoutes();
if (count($routes) == 0) {
$this->error("Your application doesn't have any routes.");
return false;
}
$languages = $this->laravel['config']['app.supported_locales'];
$baseLanguage = $this->laravel['config']['app.locale'];
foreach ($languages as $language) {
$fileList[$language] = $this->files->allFiles(sprintf('%s/resources/lang/%s/routes', $this->laravel->basePath(), $language));
}
$localizedURIs = [];
if (!empty($fileList) && is_array($fileList)) {
/**
* @var \Symfony\Component\Finder\SplFileInfo $file
*/
foreach ($fileList as $language => $files) {
foreach ($files as $file) {
$category = $file->getBasename('.php');
$localizedURIs[$language][$category] = (include $file->getRealPath());
}
}
}
$localizedRouteCollection = new RouteCollection();
foreach ($languages as $language) {
/**
* @var \Illuminate\Routing\Route $route
*/
foreach ($routes as $route) {
//Keeping only our route information
$route->prepareForSerialization();
$action = $route->getAction();
if (isset($action['category']) && isset($action['as'])) {
if (isset($localizedURIs[$language][$action['category']][$action['as']])) {
$tmp = clone $route;
$tmp->setUri($localizedURIs[$language][$action['category']][$action['as']]);
$action['as'] = $language . '.' . $action['as'];
$tmp->setAction($action);
}
}
$localizedRouteCollection->add($tmp);
}
}
$this->files->put($this->laravel->getCachedRoutesPath(), $this->buildRouteCacheFile($localizedRouteCollection));
$this->info('Localized routes cached successfully!');
return true;
}
示例5: resolveControllerByName
/**
* @param RouteCollection $routes
*
* @return Controller
*
* @throws ShapeShifterException
*/
protected function resolveControllerByName(RouteCollection $routes)
{
$contr = $routes->getByName($this->destination);
if (!$contr) {
throw new ShapeShifterException("Route [{$this->destination}] does not exist");
}
list($class) = explode('@', $contr->getActionName());
return app($class);
}
示例6: getRoutes
protected function getRoutes()
{
if (isset($this->routeCol)) {
return;
}
$this->routeCol = $this->app['router']->getRoutes();
$routes = $this->routeCol->getRoutes();
array_walk($routes, function ($route) {
foreach ($route->getMethods() as $method) {
$this->routes[$method . '.' . $route->getUri()] = true;
}
});
}
示例7: findRoute
/**
* Find the route matching a given request.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Routing\Route
*/
protected function findRoute($request)
{
$this->current = $route = $this->routes->match($request);
//return $this->substituteBindings($route);
// 目前不支持bind
return $route;
}
示例8: check
/**
* Determine if a route in the array matches the request.
*
* @param array $routes
* @param \Illuminate\http\Request $request
* @param bool $includingMethod
*
* @return \Illuminate\Routing\Route|null
*/
protected function check(array $routes, $request, $includingMethod = true)
{
$foundRoute = parent::check($routes, $request, $includingMethod);
// If no route found, check if the 404 route is set, if so, return that route as our found route.
if (!$foundRoute && isset($routes['404'])) {
$foundRoute = $routes['404'];
}
return $foundRoute;
}
示例9: action
/**
* Get the URL to a controller action.
*
* @param string $action
* @param mixed $parameters
* @param bool $absolute
* @return string
*/
public function action($action, $parameters = array(), $absolute = true)
{
if ($this->rootNamespace && !(strpos($action, '\\') === 0)) {
$action = $this->rootNamespace . '\\' . $action;
} else {
$action = trim($action, '\\');
}
return $this->route($action, $parameters, $absolute, $this->routes->getByAction($action));
}
示例10: action
/**
* Get the URL to a controller action.
*
* @param string $action
* @param mixed $parameters
* @param bool $absolute
* @return string
*
* @throws \InvalidArgumentException
*/
public function action($action, $parameters = [], $absolute = true)
{
if ($this->rootNamespace && !(strpos($action, '\\') === 0)) {
$action = $this->rootNamespace . '\\' . $action;
} else {
$action = trim($action, '\\');
}
if (!is_null($route = $this->routes->getByAction($action))) {
return $this->toRoute($route, $parameters, $absolute);
}
throw new InvalidArgumentException("Action {$action} not defined.");
}
示例11: match
/**
* Find the first route matching a given request.
*
* @param \Illuminate\Http\Request $request
*
* @return \Illuminate\Routing\Route
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
*/
public function match(Request $request)
{
$hasWpParams = $request->path() == '/' && ($request->has('p') || $request->has('post_id'));
if ($hasWpParams && ($route = $this->findMatchingWordPressPost($request))) {
return $route;
}
try {
return parent::match($request);
} catch (NotFoundHttpException $e) {
if ($route = $this->findMatchingWordPressPost($request)) {
return $route;
}
throw $e;
}
}
示例12: makesByType
/**
* Make permission instances by type
*
* @param string $type type string
* @param MemberEntityInterface $user user instance
* @param string $siteKey site key
* @return Permission[]
* @throws NotMatchedInstanceException
*/
public function makesByType($type, MemberEntityInterface $user = null, $siteKey = 'default')
{
$user = $user ?: $this->auth->user();
$permissions = [];
$registereds = $this->repo->fetchByType($siteKey, $type);
foreach ($registereds as $registered) {
$ancestors = array_filter($registereds, function ($item) use($registered) {
$itemNames = explode('.', $item->name);
$registeredNames = explode('.', $registered->name);
if (count($itemNames) >= count($registeredNames)) {
return false;
}
for ($i = 0; $i < count($itemNames); $i++) {
if ($itemNames[$i] !== $registeredNames[$i]) {
return false;
}
}
return true;
});
if (count($ancestors) > 0) {
uasort($ancestors, [$this, 'cmp']);
}
foreach ($ancestors as $ancestor) {
$registered->addParent($ancestor);
}
if (isset($this->extends[$type]) === true) {
$permission = $this->extends[$type]($registered->name, $user, $registered);
if ($permission instanceof Permission === false) {
throw new NotMatchedInstanceException(['type' => $type]);
}
$permissions[$registered->name] = $permission;
} else {
switch ($type) {
case 'route':
$route = $this->routes->getByName($registered->name);
$permissions[$registered->name] = new RoutePermission($route, $user, $registered);
break;
case 'instance':
$permissions[$registered->name] = new InstancePermission($registered->name, $user, $registered);
break;
}
}
}
return $permissions;
}
示例13: has
/**
* Check if a route with the given name exists.
*
* @param string $name
* @return bool
*/
public function has($name)
{
return $this->routes->hasNamedRoute($name);
}
示例14: action
/**
* Get the URL to a controller action.
*
* @param string $action
* @param mixed $parameters
* @param bool $absolute
* @return string
*/
public function action($action, $parameters = array(), $absolute = true)
{
return $this->route($action, $parameters, $absolute, $this->routes->getByAction($action));
}
示例15: getRouteForRequest
/**
* @param Request $request
*
* @return \Illuminate\Routing\Route|null
*/
public function getRouteForRequest(Request $request)
{
$routes = $this->collection->get($request->getMethod());
return $this->collection->check($routes, $request);
}