fet/laravel-cookie-consent 问题修复 & 功能扩展

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

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

fet/laravel-cookie-consent

Composer 安装命令:

composer require fet/laravel-cookie-consent

包简介

A simple Laravel wrapper around the orestbida/cookieconsent package.

README 文档

README

The fet/laravel-cookie-consent package is a simple Laravel wrapper around the orestbida/cookieconsent package.

Installation

  1. composer require fet/laravel-cookie-consent
  2. php artisan vendor:publish --provider="Fet\CookieConsent\CookieConsentServiceProvider" --tag="config"

Configuration

// config/cookieconsent.php

return [
    'enable' => true,
    'routes' => [
        'post' => '',
        'redirect' => '',
    ],
    'paths' => [
        'exclude' => []
    ],
    'config' => [],
];

The configuration consists of four keys: enable, routes, paths and config. The config value is an array representation of the Configuration object and is passed to the CookieConsent package as JSON. Feel free to configure the package as you like.

POST Route

The Callback/Events are not directly configurable. Instead you can define a routes.post which corresponds to an existing route name which is then called via POST request when the events onFirstConsent or onChange are triggered.

If the routes.post is empty, no POST request is sent.

The data received by the controller looks like this:

{
    "consentId": "xxx",
    "acceptType": "all",
    "acceptedCategories": [
        "necessary",
        "analytics"
    ],
    "rejectedCategories": [],
    "custom": {}
}

Redirect Route

If you want to perform a page redirect after the user has made the cookie consent choice, you can provide a route name to routes.redirect.

If the routes.redirect is empty, no redirect is made.

Exclude Paths

To exclude the cookie consent from appearing on certain URL paths, add those paths to the paths.exclude configuration array.

You can use valid regex patterns. For example, to exclude all /admin/* paths, add admin(\/.*)? to the exclude array.

Events

Sometimes you may need to change the configuration, after the application is booted. You can do so by listening to the \Fet\CookieConsent\Events\ConfigLoaded event.

use Fet\CookieConsent\Events\ConfigLoaded;

Event::listen(function (ConfigLoaded $event) {
    $config = $event->cookieConsent->config;

    // make changes to the $config array

    $event->cookieConsent->config = $config;
});

Custom POST data

To include custom data in the POST request, set the custom key in the configuration. This data will be sent alongside the consent information.

$config['custom'] = ['foo' => 'bar'];

Tests

Run the tests with:

composer test

fet/laravel-cookie-consent 适用场景与选型建议

fet/laravel-cookie-consent 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 809 次下载、GitHub Stars 达 1, 最近一次更新时间为 2024 年 08 月 13 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel」 「cookie-consent」 「gdpr」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 fet/laravel-cookie-consent 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 fet/laravel-cookie-consent 我们能提供哪些服务?
定制开发 / 二次开发

基于 fet/laravel-cookie-consent 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-08-13