Skip to content

Commit f9069aa

Browse files
authored
Rename "Middlewares" namespace to "Middleware" (#2499)
1 parent d5eb739 commit f9069aa

11 files changed

+35
-31
lines changed

docs/basic-usage/middleware.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ Note the property name difference between Laravel 10 and older versions of Larav
3434
// Laravel 10+ uses $middlewareAliases = [
3535
protected $middlewareAliases = [
3636
// ...
37-
'role' => \Spatie\Permission\Middlewares\RoleMiddleware::class,
38-
'permission' => \Spatie\Permission\Middlewares\PermissionMiddleware::class,
39-
'role_or_permission' => \Spatie\Permission\Middlewares\RoleOrPermissionMiddleware::class,
37+
'role' => \Spatie\Permission\Middleware\RoleMiddleware::class,
38+
'permission' => \Spatie\Permission\Middleware\PermissionMiddleware::class,
39+
'role_or_permission' => \Spatie\Permission\Middleware\RoleOrPermissionMiddleware::class,
4040
];
4141
```
4242

@@ -110,19 +110,19 @@ public function __construct()
110110

111111
## Use middleware static methods
112112

113-
All of the middlewares can also be applied by calling the static `using` method,
113+
All of the middleware can also be applied by calling the static `using` method,
114114
which accepts either a `|`-separated string or an array as input.
115115

116116
```php
117-
Route::group(['middleware' => [\Spatie\Permission\Middlewares\RoleMiddleware::using('manager')]], function () {
117+
Route::group(['middleware' => [\Spatie\Permission\Middleware\RoleMiddleware::using('manager')]], function () {
118118
//
119119
});
120120

121-
Route::group(['middleware' => [\Spatie\Permission\Middlewares\PermissionMiddleware::using('publish articles|edit articles')]], function () {
121+
Route::group(['middleware' => [\Spatie\Permission\Middleware\PermissionMiddleware::using('publish articles|edit articles')]], function () {
122122
//
123123
});
124124

125-
Route::group(['middleware' => [\Spatie\Permission\Middlewares\RoleOrPermissionMiddleware::using(['manager', 'edit articles'])]], function () {
125+
Route::group(['middleware' => [\Spatie\Permission\Middleware\RoleOrPermissionMiddleware::using(['manager', 'edit articles'])]], function () {
126126
//
127127
});
128128
```

docs/basic-usage/passport.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ The extended Client should either provide a `$guard_name` property or a `guardNa
3939
They should return a string that matches the [configured](https://laravel.com/docs/master/passport#installation) guard name for the passport driver.
4040

4141
## Middleware
42-
All middlewares provided by this package work with the Client.
42+
All middleware provided by this package work with the Client.
4343

4444
Do make sure that you only wrap your routes in the [`client`](https://laravel.com/docs/master/passport#via-middleware) middleware and not the `auth:api` middleware as well.
4545
Wrapping routes in the `auth:api` middleware currently does not work for the Client Credentials Grant.

docs/installation-lumen.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ Then, in `bootstrap/app.php`, uncomment the `auth` middleware, and register this
3434
```php
3535
$app->routeMiddleware([
3636
'auth' => App\Http\Middleware\Authenticate::class,
37-
'permission' => Spatie\Permission\Middlewares\PermissionMiddleware::class,
38-
'role' => Spatie\Permission\Middlewares\RoleMiddleware::class,
37+
'permission' => Spatie\Permission\Middleware\PermissionMiddleware::class,
38+
'role' => Spatie\Permission\Middleware\RoleMiddleware::class,
3939
]);
4040
```
4141

docs/upgrading.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,15 @@ eg: if you have a custom model you will need to make changes, including accessin
4040
3. Migrations will need to be upgraded. (They have been updated to anonymous-class syntax that was introduced in Laravel 8, AND some structural coding changes in the registrar class changed the way we extracted configuration settings in the migration files.) If you had not customized it from the original then replacing the contents of the file should be straightforward. Usually the only customization is if you've switched to UUIDs or customized MySQL index name lengths.
4141
**If you get the following error, it means your migration file needs upgrading: `Error: Access to undeclared static property Spatie\Permission\PermissionRegistrar::$pivotPermission`**
4242

43-
4. NOTE: For consistency with `PermissionMiddleware`, the `RoleOrPermissionMiddleware` has switched from only checking permissions provided by this package to using `canAny()` to check against any abilities registered by your application. This may have the effect of granting those other abilities (such as Super Admin) when using the `RoleOrPermissionMiddleware`, which previously would have failed silently.
43+
4. MIDDLEWARE:
4444

45-
5. In the unlikely event that you have customized the Wildcard Permissions feature by extending the `WildcardPermission` model, please note that the public interface has changed and you will need to update your extended model with the new method signatures.
45+
1. The `\Spatie\Permission\Middlewares\` namespace has been renamed to `\Spatie\Permission\Middleware\` (singular). Update your references to them in your `/app/Http/Kernel.php` and any routes that have the fully qualified path.
4646

47-
6. Test suites. If you have tests which manually clear the permission cache and re-register permissions, you no longer need to call `\Spatie\Permission\PermissionRegistrar::class)->registerPermissions();`. In fact, **calls to `->registerPermissions()` MUST be deleted from your tests**.
47+
2. NOTE: For consistency with `PermissionMiddleware`, the `RoleOrPermissionMiddleware` has switched from only checking permissions provided by this package to using `canAny()` to check against any abilities registered by your application. This may have the effect of granting those other abilities (such as Super Admin) when using the `RoleOrPermissionMiddleware`, which previously would have failed silently.
48+
49+
3. In the unlikely event that you have customized the Wildcard Permissions feature by extending the `WildcardPermission` model, please note that the public interface has changed and you will need to update your extended model with the new method signatures.
50+
51+
5. Test suites. If you have tests which manually clear the permission cache and re-register permissions, you no longer need to call `\Spatie\Permission\PermissionRegistrar::class)->registerPermissions();`. In fact, **calls to `->registerPermissions()` MUST be deleted from your tests**.
4852

4953
(Calling `app()[\Spatie\Permission\PermissionRegistrar::class]->forgetCachedPermissions();` after creating roles and permissions is still okay and encouraged.)
5054

src/Middlewares/PermissionMiddleware.php renamed to src/Middleware/PermissionMiddleware.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Spatie\Permission\Middlewares;
3+
namespace Spatie\Permission\Middleware;
44

55
use Closure;
66
use Illuminate\Support\Facades\Auth;

src/Middlewares/RoleMiddleware.php renamed to src/Middleware/RoleMiddleware.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Spatie\Permission\Middlewares;
3+
namespace Spatie\Permission\Middleware;
44

55
use Closure;
66
use Illuminate\Support\Facades\Auth;

src/Middlewares/RoleOrPermissionMiddleware.php renamed to src/Middleware/RoleOrPermissionMiddleware.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Spatie\Permission\Middlewares;
3+
namespace Spatie\Permission\Middleware;
44

55
use Closure;
66
use Illuminate\Support\Facades\Auth;

tests/PermissionMiddlewareTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use Laravel\Passport\Passport;
1212
use Spatie\Permission\Contracts\Permission;
1313
use Spatie\Permission\Exceptions\UnauthorizedException;
14-
use Spatie\Permission\Middlewares\PermissionMiddleware;
14+
use Spatie\Permission\Middleware\PermissionMiddleware;
1515
use Spatie\Permission\Tests\TestModels\UserWithoutHasRoles;
1616

1717
class PermissionMiddlewareTest extends TestCase
@@ -399,15 +399,15 @@ public function user_can_access_permission_with_guard_admin_while_login_using_ad
399399
public function the_middleware_can_be_created_with_static_using_method()
400400
{
401401
$this->assertSame(
402-
'Spatie\Permission\Middlewares\PermissionMiddleware:edit-articles',
402+
'Spatie\Permission\Middleware\PermissionMiddleware:edit-articles',
403403
PermissionMiddleware::using('edit-articles')
404404
);
405405
$this->assertEquals(
406-
'Spatie\Permission\Middlewares\PermissionMiddleware:edit-articles,my-guard',
406+
'Spatie\Permission\Middleware\PermissionMiddleware:edit-articles,my-guard',
407407
PermissionMiddleware::using('edit-articles', 'my-guard')
408408
);
409409
$this->assertEquals(
410-
'Spatie\Permission\Middlewares\PermissionMiddleware:edit-articles|edit-news',
410+
'Spatie\Permission\Middleware\PermissionMiddleware:edit-articles|edit-news',
411411
PermissionMiddleware::using(['edit-articles', 'edit-news'])
412412
);
413413
}

tests/RoleMiddlewareTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use InvalidArgumentException;
1010
use Laravel\Passport\Passport;
1111
use Spatie\Permission\Exceptions\UnauthorizedException;
12-
use Spatie\Permission\Middlewares\RoleMiddleware;
12+
use Spatie\Permission\Middleware\RoleMiddleware;
1313
use Spatie\Permission\Tests\TestModels\UserWithoutHasRoles;
1414

1515
class RoleMiddlewareTest extends TestCase
@@ -332,15 +332,15 @@ public function user_can_access_role_with_guard_admin_while_login_using_admin_gu
332332
public function the_middleware_can_be_created_with_static_using_method()
333333
{
334334
$this->assertSame(
335-
'Spatie\Permission\Middlewares\RoleMiddleware:testAdminRole',
335+
'Spatie\Permission\Middleware\RoleMiddleware:testAdminRole',
336336
RoleMiddleware::using('testAdminRole')
337337
);
338338
$this->assertEquals(
339-
'Spatie\Permission\Middlewares\RoleMiddleware:testAdminRole,my-guard',
339+
'Spatie\Permission\Middleware\RoleMiddleware:testAdminRole,my-guard',
340340
RoleMiddleware::using('testAdminRole', 'my-guard')
341341
);
342342
$this->assertEquals(
343-
'Spatie\Permission\Middlewares\RoleMiddleware:testAdminRole|anotherRole',
343+
'Spatie\Permission\Middleware\RoleMiddleware:testAdminRole|anotherRole',
344344
RoleMiddleware::using(['testAdminRole', 'anotherRole'])
345345
);
346346
}

tests/RoleOrPermissionMiddlewareTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use InvalidArgumentException;
1111
use Laravel\Passport\Passport;
1212
use Spatie\Permission\Exceptions\UnauthorizedException;
13-
use Spatie\Permission\Middlewares\RoleOrPermissionMiddleware;
13+
use Spatie\Permission\Middleware\RoleOrPermissionMiddleware;
1414
use Spatie\Permission\Tests\TestModels\UserWithoutHasRoles;
1515

1616
class RoleOrPermissionMiddlewareTest extends TestCase
@@ -278,15 +278,15 @@ public function the_required_permissions_or_roles_can_be_displayed_in_the_except
278278
public function the_middleware_can_be_created_with_static_using_method()
279279
{
280280
$this->assertSame(
281-
'Spatie\Permission\Middlewares\RoleOrPermissionMiddleware:edit-articles',
281+
'Spatie\Permission\Middleware\RoleOrPermissionMiddleware:edit-articles',
282282
RoleOrPermissionMiddleware::using('edit-articles')
283283
);
284284
$this->assertEquals(
285-
'Spatie\Permission\Middlewares\RoleOrPermissionMiddleware:edit-articles,my-guard',
285+
'Spatie\Permission\Middleware\RoleOrPermissionMiddleware:edit-articles,my-guard',
286286
RoleOrPermissionMiddleware::using('edit-articles', 'my-guard')
287287
);
288288
$this->assertEquals(
289-
'Spatie\Permission\Middlewares\RoleOrPermissionMiddleware:edit-articles|testAdminRole',
289+
'Spatie\Permission\Middleware\RoleOrPermissionMiddleware:edit-articles|testAdminRole',
290290
RoleOrPermissionMiddleware::using(['edit-articles', 'testAdminRole'])
291291
);
292292
}

0 commit comments

Comments
 (0)