create-psr13-link

Generate PSR-13 hypermedia link implementations for PHP 8.4. Create LinkInterface, EvolvableLinkInterface, and LinkProviderInterface for HATEOAS support, and include unit tests.

Last repository push
GitHub Stars
109
Forks
26
Issues / PRs
1

Installation

Review the source and dependencies with a prompt. A package is available to download.

Install with an AI assistant

Copy the prompt so your assistant can review the pinned revision and dependencies first.

View promptHide prompt
Check whether SkillPI Skill Finder is installed for your current agent. If it is missing, install and enable it using the official instructions at https://github.com/Findskills/skillpi. Then use Skill Finder to locate and install "create-psr13-link" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-dfeb43ad90b9d906b48cee38533e1ae425d8b9bf8e11abe2810e9d8595afde42. Verify the upstream source and version against https://github.com/dykyi-roman/awesome-claude-code before installing. If they do not match, stop and report the mismatch. Report the installed path and source version.

Source and setup

github.com

Setup guidance pending

See the original source for supported tools, dependencies, and permissions.

Installation test pending

Generate PSR-13 hypermedia link implementations for PHP 8.4. Create LinkInterface, EvolvableLinkInterface, and LinkProviderInterface for HATEOAS support, and include unit tests.

0 Downloads

Introduction source: third_party · dykyi-roman · 0.0.1 Reference

SkillPi interpretation

Tasks
Generates PSR-13 Hypermedia Links implementation for PHP 8.4. Creates LinkInterface, EvolvableLinkInterface, and LinkProviderInterface for HATEOAS support. Includes unit tests.
Audience
Building REST APIs with HATEOAS Creating hypermedia-driven resources Link relation management URI templates
Testing
Not tested

Browse files

Browse files at the source ↗

Original SKILL.md

Open original ↗
Frontmatter
name: create-psr13-link
description: Generates PSR-13 Hypermedia Links implementation for PHP 8.4. Creates LinkInterface, EvolvableLinkInterface, and LinkProviderInterface for HATEOAS support. Includes unit tests.

PSR-13 Hypermedia Links Generator

Overview

Generates PSR-13 compliant hypermedia link implementations for HATEOAS REST APIs.

When to Use

  • Building REST APIs with HATEOAS
  • Creating hypermedia-driven resources
  • Link relation management
  • URI templates

Generated Components

Component Description Location
Link LinkInterface impl src/Infrastructure/Http/Link/
LinkProvider Provider impl src/Infrastructure/Http/Link/
Unit Tests PHPUnit tests tests/Unit/Infrastructure/Http/Link/

Template: Link

<?php

declare(strict_types=1);

namespace App\Infrastructure\Http\Link;

use Psr\Link\EvolvableLinkInterface;
use Stringable;

final readonly class Link implements EvolvableLinkInterface
{
    /** @param string[] $rels */
    public function __construct(
        private string $href,
        private array $rels = [],
        private array $attributes = [],
        private bool $templated = false,
    ) {
    }

    public function getHref(): string
    {
        return $this->href;
    }

    public function isTemplated(): bool
    {
        return $this->templated || str_contains($this->href, '{');
    }

    public function getRels(): array
    {
        return $this->rels;
    }

    public function getAttributes(): array
    {
        return $this->attributes;
    }

    public function withHref(string|Stringable $href): static
    {
        return new self((string) $href, $this->rels, $this->attributes, $this->templated);
    }

    public function withRel(string $rel): static
    {
        $rels = [...$this->rels, $rel];

        return new self($this->href, array_unique($rels), $this->attributes, $this->templated);
    }

    public function withoutRel(string $rel): static
    {
        $rels = array_filter($this->rels, fn($r) => $r !== $rel);

        return new self($this->href, array_values($rels), $this->attributes, $this->templated);
    }

    public function withAttribute(string $attribute, string|Stringable $value): static
    {
        $attributes = $this->attributes;
        $attributes[$attribute] = (string) $value;

        return new self($this->href, $this->rels, $attributes, $this->templated);
    }

    public function withoutAttribute(string $attribute): static
    {
        $attributes = $this->attributes;
        unset($attributes[$attribute]);

        return new self($this->href, $this->rels, $attributes, $this->templated);
    }
}

Template: Link Provider

<?php

declare(strict_types=1);

namespace App\Infrastructure\Http\Link;

use Psr\Link\EvolvableLinkProviderInterface;
use Psr\Link\LinkInterface;

final readonly class LinkProvider implements EvolvableLinkProviderInterface
{
    /** @param LinkInterface[] $links */
    public function __construct(
        private array $links = [],
    ) {
    }

    public function getLinks(): iterable
    {
        return $this->links;
    }

    public function getLinksByRel(string $rel): iterable
    {
        foreach ($this->links as $link) {
            if (in_array($rel, $link->getRels(), true)) {
                yield $link;
            }
        }
    }

    public function withLink(LinkInterface $link): static
    {
        return new self([...$this->links, $link]);
    }

    public function withoutLink(LinkInterface $link): static
    {
        $links = array_filter(
            $this->links,
            fn($l) => $l !== $link,
        );

        return new self(array_values($links));
    }
}

Template: Resource with Links

<?php

declare(strict_types=1);

namespace App\Presentation\Api\Resource;

use App\Domain\User\Entity\User;
use App\Infrastructure\Http\Link\Link;
use App\Infrastructure\Http\Link\LinkProvider;
use Psr\Link\LinkProviderInterface;

final readonly class UserResource implements LinkProviderInterface
{
    private LinkProvider $linkProvider;

    public function __construct(
        public string $id,
        public string $email,
        public string $name,
    ) {
        $this->linkProvider = new LinkProvider([
            (new Link("/api/users/{$this->id}"))->withRel('self'),
            (new Link("/api/users/{$this->id}/posts"))->withRel('posts'),
            (new Link('/api/users'))->withRel('collection'),
        ]);
    }

    public static function fromEntity(User $user): self
    {
        return new self(
            $user->getId()->toString(),
            $user->getEmail()->toString(),
            $user->getName(),
        );
    }

    public function getLinks(): iterable
    {
        return $this->linkProvider->getLinks();
    }

    public function getLinksByRel(string $rel): iterable
    {
        return $this->linkProvider->getLinksByRel($rel);
    }

    public function toArray(): array
    {
        $data = [
            'id' => $this->id,
            'email' => $this->email,
            'name' => $this->name,
            '_links' => [],
        ];

        foreach ($this->getLinks() as $link) {
            foreach ($link->getRels() as $rel) {
                $data['_links'][$rel] = [
                    'href' => $link->getHref(),
                    'templated' => $link->isTemplated(),
                ];
            }
        }

        return $data;
    }
}

Usage Example

<?php

use App\Infrastructure\Http\Link\Link;
use App\Infrastructure\Http\Link\LinkProvider;

// Create links
$selfLink = (new Link('/api/users/123'))
    ->withRel('self')
    ->withAttribute('title', 'User Profile');

$collectionLink = (new Link('/api/users'))
    ->withRel('collection');

$templateLink = (new Link('/api/users/{id}'))
    ->withRel('user');

// Create provider
$provider = (new LinkProvider())
    ->withLink($selfLink)
    ->withLink($collectionLink)
    ->withLink($templateLink);

// Get links by relation
foreach ($provider->getLinksByRel('self') as $link) {
    echo $link->getHref(); // /api/users/123
}

Requirements

{
    "require": {
        "psr/link": "^2.0"
    }
}

Current listing version

0.0.1

Verify the source revision ↗

Quality assessment

Out of 100 · Assessment report from SkillPi LAB.

Scenario Value75/100

Highlights

  • 为PHP 8.4生成PSR-13超媒体链接实现,解决HATEOAS REST API开发中的实际问题
  • 提供了完整的LinkInterface、EvolvableLinkInterface和LinkProviderInterface实现
  • 包含单元测试,确保代码质量和可靠性
Trigger Precision85/100

Highlights

  • 触发词精准完整,覆盖多种变体,边界清晰
  • description明确描述了Skill的功能和用途
Structure and Standards80/100

Areas to improve

  • 缺少明确的Phase/步骤划分 Reported severity: Minor

    文档中缺少明确的Phase或步骤划分,虽然内容完整但结构可以更清晰

    Recommendation: 建议添加明确的Phase或步骤划分,如Phase 1: 创建Link类, Phase 2: 创建LinkProvider类等

Highlights

  • 提供了完整的代码模板和使用示例
  • 文档结构基本完整,包含Overview、When to Use、Generated Components等章节
Execution Reliability85/100

Areas to improve

  • 缺少单元测试的具体实现 Reported severity: Minor

    文档中提到包含单元测试,但没有提供具体的测试代码

    Recommendation: 建议补充单元测试的具体实现代码,确保测试覆盖率和可靠性

Highlights

  • 工具来源明确,参数正确,覆盖主要异常
  • 提供了完整的使用示例和Requirements配置
  • 代码实现遵循PSR-13标准,具有良好的可靠性
Evidence Verifiability (mean of the first four)81/100

The arithmetic mean of the first four original scores, rounded to a whole number.

Static text checks

100 / 100 · skillpi-20261123-no-r3-v1

No current rules matched the text.

This score reflects rule matches in the text and is provided for reference before use. It excludes attachments and runtime behavior.

Permissions and checks before use

Automatically summarized from this main document. Matches may be examples or defensive advice; they are not actual permission declarations. Attachments, external dependencies and runtime behavior are not covered.

These common operations were not identified in the main document. This does not mean no permissions or risks exist.

These notices grant no permissions. Your host tool must still confirm file changes, secrets, external transfers or costs as needed.

Security rating and access scope

safe · Static evidence review; not a runtime safety guarantee.

Before use, confirm and authorize actual file access, external services and network destinations in your host. This review grants no runtime permissions.