iak/keys 问题修复 & 功能扩展

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

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

iak/keys

Composer 安装命令:

composer require iak/keys

包简介

This is my package keys

关键字:

README 文档

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

The problem

We use string keys all across our application. We got keys for cache, rate limiting, queued jobs, sessions, broadcast channels, container aliases and so much more.

These keys can be hard to keep track of. You also need to remember what convention you used, sometimes build up keys from several dynamic values such as id's, and it's hard to get an overview of what keys are actually in use. It's also easy for typos to sneak in, as these are just strings.

This package solves this issue, by centralizing where your keys are defined, and give you a consistent and easy way to access them.

Features

  • Configurable Key Templates: Define key formats in configuration files
  • Dynamic Parameters: Define your dynamic values in the configuration, and the key class will fill them in for you
  • Parameter Validation: Automatic validation of required parameters and detection of extra parameters
  • Multiple Key Types: Built-in support for cache, queue, event, session, and many more key types
  • Laravel Integration: Seamless integration with Laravel's configuration system

Installation

You can install the package via composer:

composer require iak/keys

Then publish the config file with:

php artisan vendor:publish --tag="keys-config"

Usage

First, define your key templates in the configuration file:

// config/keys.php
return [
    'cache' => [
        'product-data' => 'product:{productId},variant:{variantId}',
    ],
    'limit' => [
        'password-reset' => 'password-reset:{userId}' 
    ]
];

Then access the keys using the Key helper class.

use Iak\Key\Key;

// Using named parameters
Key::cache('product-data', productId: 123, variantId: 456);

// Using array parameters
Key::cache('product-data', [
    'productId' => 123,
    'variantId' => 456
]);

// Using parameter position
Key::cache('user.action', 123, 456);

// The result for all above: "product:123,variant:456"

Built-in Key Types

The package comes with many built-in key types:

// Cache keys
Key::cache('user.profile', id: 123);

// Queue keys
Key::queue('email.notification', type: 'welcome', userId: 456);

// Event keys
Key::event('user.action', action: 'login', userId: 789);

// Session keys
Key::session('user.data', userId: 123, sessionId: 'abc123');

// Job keys
Key::job('process.data', jobType: 'import', priority: 'high');

// Lock keys
Key::lock('', version: 'v1', resource: 'users');

There are support for many different types of keys. For example: tag, lock, channel, broadcast, limit, middleware, view, translation, command, container, feature, notification, throttle, disk, policy, guard, schedule, tenant, experiment, test, mail, service, flash, alias, provider, raw, config

Dynamic Method Calling

You can also use dynamic method calling for custom key types:

// Define a custom key type in config
// config/keys.php
return [
    'custom' => [
        'api.request' => 'api:{endpoint}:{method}:{timestamp}',
    ],
];

// Use it dynamically
$key = Key::custom('api.request', 
    endpoint: 'users',
    method: 'GET',
    timestamp: time()
);
// Result: "api:users:GET:1234567890"

Error Handling

The package validates parameters and provides helpful error messages:

// Missing required parameter
Key::cache('user.profile'); 
// Throws: Missing required parameters: id

// Extra parameter not in template
Key::cache('user.profile', id: 123, extra: 'value'); // Throws: Extra parameters: extra

// Non-existent key
Key::cache('nonexistent.key', id: 123); // Throws: Key not found in config

Configuration

Key Template Format

Key templates use curly braces {} to define parameter placeholders:

'user.profile' => 'user:profile:{id}',
'product.details' => 'product:{category}:{id}:{variant}',
'api.request' => 'api:{version}:{endpoint}:{method}',

Parameter Rules

  • All parameters defined in the template must be provided
  • Extra parameters not defined in the template will cause an exception
  • The same parameter can be used multiple times in a template
  • Parameters can be strings, numbers, or any scalar value

Testing

composer test

Credits

License

The MIT License (MIT). Please see License File for more information.

iak/keys 适用场景与选型建议

iak/keys 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 149 次下载、GitHub Stars 达 3, 最近一次更新时间为 2025 年 10 月 16 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 iak/keys 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 149
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 5
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-10-16