本文整理汇总了PHP中ACL::permits方法的典型用法代码示例。如果您正苦于以下问题:PHP ACL::permits方法的具体用法?PHP ACL::permits怎么用?PHP ACL::permits使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ACL
的用法示例。
在下文中一共展示了ACL::permits方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testPermissionsCanBeSetForRoutes
public function testPermissionsCanBeSetForRoutes()
{
$user = $this->createUserWithRoles();
\ACL::setUser($user);
$controller = Mockery::mock('\\ApiController');
$controller->shouldReceive('tests')->once()->andReturn(\Response::json(['success' => 'great']));
$controller->shouldReceive('getActionPermissions')->once()->andReturn(['tests' => 'job.apply']);
\Route::enableFilters();
\Route::filter('test.permissions.filter', function ($route) {
require 'app/acl.php';
$permissions = $route->getAction()['uses'][0]->getActionPermissions();
$perm = $permissions[$route->getAction()['uses'][1]];
$this->assertTrue(ACL::permits('job.apply', $route->parameters()));
});
\Route::get('/test/perms/{id}', [$controller, 'tests'])->after('test.permissions.filter');
$this->call('GET', '/test/perms/3');
$this->assertResponseOk();
}
示例2: explode
return;
}
$closure = explode('@', \Route::currentRouteAction());
$controllerClass = $closure[0];
$controllerMethod = $closure[1];
$permissionsDefinitionClass = 'Motibu\\Permitters\\Definitions\\' . $controllerClass . 'Permissions';
if (class_exists($permissionsDefinitionClass)) {
$permissionsMap = (new $permissionsDefinitionClass())->getPermissions();
// no permissions needed for action
if (!isset($permissionsMap[$controllerMethod])) {
return;
}
$permissions = $permissionsMap[$controllerMethod];
$permits = true;
foreach ($permissions as $permission) {
$permits = $permits && ACL::permits($permission, $route->parameters());
}
if (!$permits) {
\App::abort(403, 'Unauthorized action.');
}
}
});
// Allow cross origin requests
\Route::filter('allow_cross_origin', function ($route, $request, $response) {
$response->header('Access-Control-Allow-Origin', '*');
});
\Route::filter('oauth.add_auth_header', function ($route, $request) {
$headers = getallheaders();
if (isset($headers['Authorization'])) {
$request->headers->set('Authorization', $headers['Authorization']);
}