elle-the-dev/oatmeal
Composer 安装命令:
composer require elle-the-dev/oatmeal
包简介
PHP cookie management in a modern, object-oriented manner.
关键字:
README 文档
README
Oatmeal is a cookie manager for modern, object-oriented PHP development. Oatmeal works both as a standalone package, as well as having built-in integration into Laravel.
Requirements
Oatmeal requires PHP 7.0 and higher.
Installation
Installation is done via composer
composer require elle-the-dev/oatmeal
If we want to integrate into Laravel, we'll additionally want to run
php artisan vendor:publish
This will publish the config file to config/oatmeal.php.
Also for Laravel, if we don't use auto-discovery, we'll need to add OatmealServiceProvider to the providers array in config/app.php
ElleTheDev\Oatmeal\Providers\OatmealServiceProvider::class,
Usage
Instantiation
Ideally we'll be using Oatmeal with a side of dependency injection, but this is what it looks like to instantiate a new instance on its own.
$oatmeal = new ElleTheDev\Oatmeal\Oatmeal;
Configuration can be passed in via the constructor so we don't need to specify path, domain, https and http-only settings each time we want to set a cookie.
$oatmeal = new ElleTheDev\Oatmeal\Oatmeal([ 'path' => '/', 'domain' => 'example.com', 'secure' => false, 'httpOnly' => true, ]);
In Laravel, the service provider allows for auto-injecting the Oatmeal interface and autoloading the config from config/oatmeal.php
use ElleTheDev\Oatmeal\Contracts\Oatmeal; class ExampleController extends Controller { public function show(Oatmeal $oatmeal) { } }
When injecting in Laravel, Oatmeal will automatically be loaded using the config file config/oatmeal.php.
Setting
We can set a basic cookie with a timeout in minutes. set will also update the $_COOKIE superglobal array with the new cookie value.
$oatmeal->set('name', 'value', 60);
We can also store a cookie with no expiration (note: it technically expires in ~5 years)
$oatmeal->forever('name', 'value');
If we need to change settings before setting a cookie, we can do so through chained method calls.
$oatmeal->setPath('/') ->setDomain('example.com') ->setSecure(false) ->setHttpOnly(true) ->set('name', 'value', 60);
Getting
Getting a cookie is as simple as calling get. If the requested cookie does not exist or is expired, get will return null
$value = $oatmeal->get('name');
If we'd like to forget the cookie after getting it, we can pull instead. pull will also update the $_COOKIE superglobal to remove the pulled cookie.
$value = $oatmeal->pull('name');
Deleting
We can delete a cookie using forget
$oatmeal->forget('name');
elle-the-dev/oatmeal 适用场景与选型建议
elle-the-dev/oatmeal 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 06 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「manage」 「cookie」 「setcookie」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 elle-the-dev/oatmeal 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 elle-the-dev/oatmeal 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 elle-the-dev/oatmeal 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Add a configurable cookie consent banner to the website.
Forked from https://github.com/deltaaskii/lara-pdf-merger. Add condition if(!class_exists('TCPDF')) (depreciated in php 7.2) to foreach.
The library provides a flexible way to add role-based access control management to CakePHP 3.x
Popup component for Nette Framework
Cookie Consent is a lightweight JavaScript plugin for alerting users about the use of cookies on your website.
统计信息
- 总下载量: 3
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 31
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-06-20