codebar-ag/laravel-feature-policy 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

codebar-ag/laravel-feature-policy

Composer 安装命令:

composer require codebar-ag/laravel-feature-policy

包简介

Permissions-Policy (Feature-Policy) header builder and middleware for Laravel

README 文档

README

Latest Version on Packagist Total Downloads GitHub Tests GitHub Code Style PHPStan Dependency Review Coverage

Build and apply Permissions-Policy (formerly Feature-Policy) headers in Laravel applications.

Requirements

  • PHP 8.3, 8.4, or 8.5
  • Laravel 13

Installation

composer require codebar-ag/laravel-feature-policy

Publish configuration (optional):

php artisan vendor:publish --tag=laravel-feature-policy-config

Configuration

The published config file is config/feature-policy.php. You can also rely on environment variables:

Env Config key Default Purpose
FPH_ENABLED enabled true Master switch; when false, middleware does not apply policy headers.
policy null Fully qualified class name of your policy (must extend CodebarAg\LaravelFeaturePolicy\Policies\Policy).
FPH_PROPOSAL_ENABLED directives.proposal false Enable proposed directive group.
FPH_EXPERIMENTAL_ENABLED directives.experimental false Enable experimental directive handling.
FPH_REPORTING_ENABLED reporting.enabled false Add Reporting-Endpoints and related reporting metadata.
FPH_REPORT_ONLY reporting.report_only false When reporting is on, also emit Permissions-Policy-Report-Only.
FPH_REPORTING_URL reporting.url (see config) Endpoint URL for violation reports.

Implement a policy class with a configure() method that calls addDirective() (see package tests and Policies\Policy).

Middleware

Register the middleware on your web stack (or another group), for example in bootstrap/app.php:

use CodebarAg\LaravelFeaturePolicy\AddFeaturePolicyHeaders;

$middleware->web(append: [
    AddFeaturePolicyHeaders::class,
]);

You may pass a specific policy class as a middleware parameter:

Route::get('/admin', AdminController::class)
    ->middleware(AddFeaturePolicyHeaders::class.':'.AdminPermissionsPolicy::class);

Quality checks

Run Laravel Pint in test mode:

composer lint

Run static analysis (PHPStan + Larastan):

composer analyse

Run the test suite:

composer test

Run tests with code coverage and a 100% minimum (requires the PCOV or Xdebug PHP extension):

composer test-coverage

Run lint, analysis, and tests together:

composer quality

Credits

This package was initially inspired by mazedlx/laravel-feature-policy (MIT). The implementation has since been significantly adapted for Laravel 13 and is maintained independently by codebar-ag.

License

MIT

统计信息

  • 总下载量: 12.01k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-03-01

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固