rnr1721/le7-links
Composer 安装命令:
composer require rnr1721/le7-links
包简介
PSR LinkInterface implementation for le7 MVC framework or any PHP8 PSR project
README 文档
README
PSR LinkInterface implementation for le7 MVC framework or any PHP8 PSR project This is not "clean" implementation, this is combination of EnvolvedLinkInterface, UriInterface and own ULinkInterface.
Requirements
- PHP 8.1
- Composer
Installation
composer require rnr1721/le7-links
Testing
composer test
Usage
Link
The Link class represents a LinkInterface, UriInterface and own ULinkInterface with additional functionality for manipulating URIs and rendering HTML anchor tags.
First, import the Link class:
use Core\Links\Link;
Create an instance of the Link class by providing the URI, link relation types, and additional attributes:
$link = new Link('https://example.com/page1', ['rel1'], ['attribute1' => 'value1']);
Retrieving URI Components
You can retrieve different components of the URI using the following methods:
$scheme = $link->getScheme(); $authority = $link->getAuthority(); $userInfo = $link->getUserInfo(); $host = $link->getHost(); $port = $link->getPort(); $path = $link->getPath(); $query = $link->getQuery(); $fragment = $link->getFragment();
Modifying URI Components
You can create a modified version of the link by using the following methods:
$newLink = $link->withScheme('https'); $newLink = $link->withUserInfo('username', 'password'); $newLink = $link->withHost('example.com'); $newLink = $link->withPort(8080); $newLink = $link->withPath('/new-path'); $newLink = $link->withQuery('param1=value1¶m2=value2'); $newLink = $link->withFragment('section1');
Rendering HTML Anchor Tags
To render the link as an HTML anchor tag, use the render method:
$html = $link->render();
The render method returns a string containing the HTML anchor tag.
Link Attributes
You can retrieve and modify the link's relation types and additional attributes using the following methods:
$rels = $link->getRels();
$hasRel = $link->hasRel('rel1');
$attributes = $link->getAttributes();
$href = $link->getHref();
$isTemplated = $link->isTemplated();
$attributeValue = $link->getAttribute('attribute1');
You can create a modified version of the link with updated relation types and attributes using the following methods:
$newLink = $link->withHref('https://example.com/page2'); $newLink = $link->withRel('rel2', 'rel3'); $newLink = $link->withoutRel('rel1'); $newLink = $link->withAttribute('attribute2', 'value2'); $newLink = $link->withoutAttribute('attribute1');
String Conversion
You can obtain the string representation of the link using the magic __toString method:
$string = (string)$link;
LinkProvider
The LinkProvider class is an implementation of the EvolvableLinkProviderInterface from the PSR-Link library. It is used to store and manage links.
First, import the LinkProvider class:
use Core\Links\LinkProvider;
Create an instance of the LinkProvider class:
$linkProvider = new LinkProvider();
Adding Links
To add a link to the provider, use the withLink method:
use Core\Links\Link; $link = new Link('https://example.com/page1', ['rel1'], ['attribute1' => 'value1']); $linkProvider = $linkProvider->withLink($link);
You can chain multiple withLink calls to add multiple links:
$link1 = new Link('https://example.com/page1', ['rel1'], ['attribute1' => 'value1']); $link2 = new Link('https://example.com/page2', ['rel2'], ['attribute2' => 'value2']); $linkProvider = $linkProvider->withLink($link1) ->withLink($link2);
Retrieving Links
To retrieve all the links in the provider, use the getLinks method:
$links = $linkProvider->getLinks();
The getLinks method returns an array of LinkInterface objects.
Removing Links
To remove a link from the provider, use the withoutLink method:
$linkProvider = $linkProvider->withoutLink($link);
Filtering Links
To retrieve links based on their relationship, use the getLinksByRel method:
$filteredLinks = $linkProvider->getLinksByRel('rel1');
The getLinksByRel method returns an array of LinkInterface objects that have the specified relationship.
Adding Multiple Links
To add multiple links at once, use the withLinks method:
$links = [ new Link('https://example.com/page1', ['rel1'], ['attribute1' => 'value1']), new Link('https://example.com/page2', ['rel2'], ['attribute2' => 'value2']), ]; $linkProvider = $linkProvider->withLinks($links);
Removing Multiple Links
To remove multiple links at once, use the withoutLinks method:
$linkProvider = $linkProvider->withoutLinks($links);
The withoutLinks method takes an array of LinkInterface objects and removes them from the provider.
rnr1721/le7-links 适用场景与选型建议
rnr1721/le7-links 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 58 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 06 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「component」 「links」 「psr13」 「le7」 「le7-framework」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 rnr1721/le7-links 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 rnr1721/le7-links 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 rnr1721/le7-links 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Manages links between resources
FSi DataSource Component
Link Field Type for Craft CMS
Set Links with a specific language parameter
Links element Silverstripe
Priveate for SkeekS CMS
统计信息
- 总下载量: 58
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 23
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-06-04