Skip to content

Commit 0add279

Browse files
miladrahimiMilad Rahimi
authored and
Milad Rahimi
committed
Add GroupAttributes enum
1 parent aff36ce commit 0add279

File tree

3 files changed

+28
-11
lines changed

3 files changed

+28
-11
lines changed

README.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,7 @@ To group the routes you can follow the example below.
493493

494494
```
495495
use MiladRahimi\PhpRouter\Router;
496+
use MiladRahimi\PhpRouter\Enums\GroupAttributes;
496497
497498
$router = new Router();
498499
@@ -501,9 +502,9 @@ $router->group(['prefix' => '/admin'], function (Router $router) {
501502
});
502503
503504
$attributes = [
504-
RouteAttributes::MIDDLEWARE => SampleMiddleware::class,
505-
RouteAttributes::PREFIX => '/shop',
506-
RouteAttributes::DOMAIN => 'shop.example.com',
505+
GroupAttributes::MIDDLEWARE => SampleMiddleware::class,
506+
GroupAttributes::PREFIX => '/shop',
507+
GroupAttributes::DOMAIN => 'shop.example.com',
507508
];
508509
509510
$router->group($attributes, function (Router $router) {
@@ -513,7 +514,7 @@ $router->group($attributes, function (Router $router) {
513514
$router->dispatch();
514515
```
515516

516-
As you can see in the examples, you can `RouteAttributes` enum instead of memorizing route attribute names!
517+
As you can see in the examples, you can `GroupAttributes` enum instead of memorizing route attribute names!
517518

518519
## Base URI
519520
Your project may be in a subdirectory, so all of your route URIs will starts with the subdirectory name.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: Milad Rahimi <[email protected]>
5+
* Date: 6/23/2018 AD
6+
* Time: 01:38
7+
*/
8+
9+
namespace MiladRahimi\PhpRouter\Enums;
10+
11+
class GroupAttributes
12+
{
13+
const MIDDLEWARE = RouteAttributes::MIDDLEWARE;
14+
const DOMAIN = RouteAttributes::DOMAIN;
15+
const PREFIX = RouteAttributes::PREFIX;
16+
}

tests/GroupingTest.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
namespace MiladRahimi\PhpRouter\Tests;
1010

11+
use MiladRahimi\PhpRouter\Enums\GroupAttributes;
1112
use MiladRahimi\PhpRouter\Enums\HttpMethods;
12-
use MiladRahimi\PhpRouter\Enums\RouteAttributes;
1313
use MiladRahimi\PhpRouter\Router;
1414
use MiladRahimi\PhpRouter\Tests\Classes\SampleMiddleware;
1515
use Throwable;
@@ -40,7 +40,7 @@ public function test_middleware_object()
4040
$groupMiddleware = new SampleMiddleware(777);
4141

4242
$groupAttributes = [
43-
RouteAttributes::MIDDLEWARE => $groupMiddleware,
43+
GroupAttributes::MIDDLEWARE => $groupMiddleware,
4444
];
4545

4646
$router = $this->createRouter();
@@ -61,7 +61,7 @@ public function test_middleware_object()
6161
public function test_string_middleware()
6262
{
6363
$groupAttributes = [
64-
RouteAttributes::MIDDLEWARE => SampleMiddleware::class,
64+
GroupAttributes::MIDDLEWARE => SampleMiddleware::class,
6565
];
6666

6767
$router = $this->createRouter();
@@ -84,7 +84,7 @@ public function test_middleware_it_should_ignore_group_middleware_where_route_mi
8484
$routeMiddleware = new SampleMiddleware(1002);
8585

8686
$groupAttributes = [
87-
RouteAttributes::MIDDLEWARE => $groupMiddleware,
87+
GroupAttributes::MIDDLEWARE => $groupMiddleware,
8888
];
8989

9090
$router = $this->createRouter();
@@ -108,7 +108,7 @@ public function test_prefix()
108108
$this->mockRequest(HttpMethods::GET, 'http://example.com/group/page');
109109

110110
$groupAttributes = [
111-
RouteAttributes::PREFIX => '/group',
111+
GroupAttributes::PREFIX => '/group',
112112
];
113113

114114
$router = $this->createRouter();
@@ -130,7 +130,7 @@ public function test_domain()
130130
$this->mockRequest(HttpMethods::GET, 'http://sub.domain.tld/');
131131

132132
$groupAttributes = [
133-
RouteAttributes::DOMAIN => 'sub.domain.tld',
133+
GroupAttributes::DOMAIN => 'sub.domain.tld',
134134
];
135135

136136
$router = $this->createRouter();
@@ -152,7 +152,7 @@ public function test_domain_it_should_ignore_group_domain_where_route_domain_is_
152152
$this->mockRequest(HttpMethods::GET, 'http://sub2.domain.tld/');
153153

154154
$groupAttributes = [
155-
RouteAttributes::DOMAIN => 'sub1.domain.tld',
155+
GroupAttributes::DOMAIN => 'sub1.domain.tld',
156156
];
157157

158158
$router = $this->createRouter();

0 commit comments

Comments
 (0)