elhebert/laravel-croustillon
Composer 安装命令:
composer require elhebert/laravel-croustillon
包简介
A package to help you manage your cookie banner and cookie policy with ease
关键字:
README 文档
README
A package to help you manage your cookie banner and cookie policy with ease.
Documentation is still a work in progress.
Why laravel-croustillon?
I'm glad you asked. During the develoment of this packages I used Cookie to namespace everything which quickly made it hard to dicerne the Laravel Cookie classes and the Cookie from my package.
I start thinking about names to use and thought of names like Donuts, Cake, Waffle or Biscuit. I discussed this with a colleague (@meduzen) and I joked about using Croustillon because it would make everything awesome.
Croustillon is a (french) Belgian word. For the non belgian people out here, Google Translate tells me it's called a donut in english, but I'm sceptical.
So here's a picture:
Disclaimer
I'm not a lawyer, so everything here should be taken with a grain of salt, especially the legal documents.
Therefor I decline all responsability for any legal issues you might encounter by using this package without checking the legal documents with a lawyer.
Installation
composer require elhebert/laravel-croustillon
This package uses auto-discovery, so you don't have to do anything.
You can publish the config-file with:
php artisan vendor:publish --provider="Elhebert\Croustillon\CroustillonServiceProvider" --tag="croustillon-config"
You can publish the language-file with:
php artisan vendor:publish --provider="Elhebert\Croustillon\CroustillonServiceProvider" --tag="croustillon-translations"
You can publish the view-files with:
php artisan vendor:publish --provider="Elhebert\Croustillon\CroustillonServiceProvider" --tag="croustillon-views"
You can add a cookie banner to all responses of your app by registering Elhebert\Croustillon\Http\Middlewares\AddCookieBanner::class in the http kernel.
// app/Http/Kernel.php ... protected $middlewareGroups = [ 'web' => [ ... \Elhebert\Croustillon\Http\Middlewares\AddCookieBanner::class, ],
Alternatively you can apply the middleware on the route or route group level.
// in a routes file Route::get('my-page', 'MyController')->middleware(Elhebert\Croustillon\Http\Middlewares\AddCookieBanner::class);
Usage
This package allows you to define a cookie policy. A cookie policy determines which cookies are used within your website and generate a corresponding banner and legal page.
By default every Laravel application has 2 cookies set, the laravel_session cookie and the XSRF-TOKEN cookie. Using a new Laravel application as example, here what you can expect:
// in a policy ... ->addCookie(Xsrf::class) ->addCookie(Session::class) ...
Creating a cookie
As we all know website are not limited to use the default cookies and might use new ones for all kind of reasons. Which is why you can create custom cookies to add to a policy.
A cookie is compose of a name, a description, a duration, a purpose, a source and a category.
namespace Elhebert\Croustillon\Cookies; use Elhebert\Croustillon\Categories\Mandatory; class Xsrf extends Cookie { public $name = 'XSRF-TOKEN'; public $category = Mandatory::class; public $source = 'Laravel'; public $duration = '2 hours'; public $purpose = 'security'; }
This package comes with pre-defined categories from which you can choose from:
Elhebert\Croustillon\Categories\Mandatory::class Elhebert\Croustillon\Categories\Preferences::class Elhebert\Croustillon\Categories\Analytics::class Elhebert\Croustillon\Categories\Social::class Elhebert\Croustillon\Categories\Retargetting::class
Depending on which cookies you added to your policy, it'll impact the cookie banner and the legal page. The banner will add checkboxes for each categories of cookies (to offer fully granularity to the visitor) and the legal page will add the cookies and corresponding categories to the list of cookies.
If you need to customize the different variables you can use the corresponding functions instead of the variable:
public function duration(): string { return config('session.lifetime') . ' minutes'; } public function purpose(): string { return trans('croustillon::cookies.purposes.security'); }
Creatiing a policy
Once you have all your cookies, you need to create a new policy:
namespace App\Service\Croustillon\Policies; use Elhebert\Croustillon\Policies\Basic; use App\Service\Croustillon\Cookie\MyCustomCookie; class MyCustomPolicy extends Basic { public function configure() { parent::configure(); $this ->addCookie(MyCustomCookie::class); } }
Don't forget to update the policy key of the config file to the class of your policy (in this case it would be App\Service\Croustillon\Policies\MyCustomPolicy).
Customising the cookie banner and the legal page
This package comes with a default cookie banner and legal page that you can (and should) customize, to do so you need to publish the package views:
php artisan vendor:publish --provider="Elhebert\Croustillon\CroustillonServiceProvider" --tag="croustillon-views"
Cookie banner
The banner will be in resources/views/vendor/croustillon/banner.blade.php. By default it's generating the checkboxes for every cookie categories present in your policy. The mandatory category will be checked and disable (because it's mandatory).
It also comes bundle with a controller and a route, so you don't need to worry about creating them in your application.
The default route is /croustillon.
Cookie legal page
The legal page can be found in resources/views/vendor/croustillon/policy.blade.php. The main content of that page is already done, but you still should update it to suit your need and your website.
The default route for this page is /croustillon/policy.
Customization
This package come with opinions. Like routes, copy and views.
Everything can be customize.
Routes
The prefix can be customize in the config file but should you need complete control on the routes you can disable the ones from this package to create your own.
The routes you need to create are:
-
For the cookie banner form:
- Verb:
POST - Action:
\Elhebert\Croustillon\Http\Controllers\CookiesController(it has an__invokemethod, so you don't need to reference a method).
- Verb:
-
For the cookie policy legal page:
- Verb:
GET - Action:
\Elhebert\Croustillon\Http\Controllers\CookiePolicyController(it has an__invokemethod, so you don't need to reference a method).
- Verb:
Translations
You can overwrite the default translations by publishing the language files.
Views
You can overwrite the default views by publishing the view files.
Contributing
Please see CONTRIBUTING for more details.
License
This project and the Laravel framework are open-sourced software licensed under the MIT license.
elhebert/laravel-croustillon 适用场景与选型建议
elhebert/laravel-croustillon 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 54 次下载、GitHub Stars 达 9, 最近一次更新时间为 2018 年 11 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「cookie」 「gdpr」 「croustillon」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 elhebert/laravel-croustillon 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 elhebert/laravel-croustillon 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 elhebert/laravel-croustillon 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Add a configurable cookie consent banner to the website.
This bundle contains functionality concerning privacy and the European Union's "General Data Protection Regulation" (GDPR, in German: "Datenschutz-Grundverordnung", DSGVO).
Popup component for Nette Framework
Cookie Consent is a lightweight JavaScript plugin for alerting users about the use of cookies on your website.
Alfabank REST API integration
Additional features for OFFLINE.Gdpr plugin
统计信息
- 总下载量: 54
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 9
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-11-11