serendipias/laravel-urn
Composer 安装命令:
composer require serendipias/laravel-urn
包简介
Universal laravel urn identifier
README 文档
README
Simple way to create urn identifiers for your laravel application, allowing a simple way to identifies resources or models a more descriptive way.
Installation
Application can be installed by running:
composer require serendipias/laravel-urn
The application requires laravel/lumen >= 6.x
Usage
Register provider:
In Laravel config/app.php add the urn service provider to your providers array:
\Serendipias\Urn\UrnServiceProvider::class,
if you are using Lumen you will need to register the service provider in your bootstrap/app.php
$app->register(\Serendipias\Urn\UrnServiceProvider::class);
Publishing configuration:
Publish the configuration, run the following command:
php artisan vendor:publish --tag=urn
In lumen you will need to manually copy the urn file to your config directory.
The package has 3 basic configurations that are required to work with laravel/lumen models:
- models_namespace: Models namespace, this is use to be able to get models instances from the urn
- service: this is use to declare where the urn was created, which application is the source for the identifier
- stage: determinate if the resource was generated in production, testing, stage or unit testing.
Enable models to generate urns
To allow a model to be urn identifiable the model must extend Serendipias\Urn\Contracts\UrnIdentifiable
interface, the package provides a trait with the interface default implementations UrnIdentifiableTrait.
To generate urn with a model, inject or make Serendipias\Urn\Services\UrnService::class, from there you can
encode a model, or decode an urn string, in both cases an Serendipias\Urn\Support\Urn is returned.
Urn instance example:
Serendipias\Urn\Support\Urn { -urn: "urn:laravel:local:user:1" -namespace: "App\Models" -parts: array:5 [ 0 => "urn" 1 => "laravel" 2 => "local" 3 => "user" 4 => "1" ] }
To encode an model:
$service = app(\Serendipias\Urn\Services\UrnService::class); $urn = $service->encode(\App\Models\User::find(1)); $urn->getUrnString(); // urn:laravel:local:user:1
To decode a urn string:
$service = app(\Serendipias\Urn\Services\UrnService::class); $urn = $service->decode('urn:laravel:local:user:1'); $urn->find(); // will return User model or null if not found
serendipias/laravel-urn 适用场景与选型建议
serendipias/laravel-urn 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6 次下载、GitHub Stars 达 2, 最近一次更新时间为 2019 年 12 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「composer」 「laravel」 「URN」 「urn-identifier」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 serendipias/laravel-urn 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 serendipias/laravel-urn 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 serendipias/laravel-urn 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
URI manipulation library
IRI handling for PHP
URI, URL and URN value objects
IRI handling for PHP
This composer plugin enables installation of GravityForms WordPress plugin and its addons.
统计信息
- 总下载量: 6
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-12-11
