agentleFS
AlizHarbAlizHarb/agent-skills/skills/create-php-attribute/SKILL.md

create-php-attribute

Skill1 starsChanged 5 months agoMITView on GitHub

Use when creating or reviewing a custom PHP 8 attribute for metadata, framework integration, architecture checks, tests, middleware, scanners, or support tooling in this Laravel application.

The file

Show its rules and text

We split this skill into the rules it gives an agent

14 rules. About 0 are common, 12 are distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈12

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use this skill when stable metadata should be declared with PHP 8 attributes and consumed by application code, tests, middleware, scanners, …

    line 13
  2. Very specific:

    Create the attribute under app/Attributes unless the project already has a different convention.

    line 23
  3. Very specific:

    Use native PHP #[Attribute(...)] targets and repeatability flags.

    line 24
  4. Distinctive:

    Keep the attribute as metadata only.

    line 27
  5. Distinctive:

    Create or update the consumer that reads the attribute via reflection, routing, middleware, tests, or support tooling.

    line 28
  6. Distinctive:

    Add tests for the consumer behavior.

    line 29
  7. Distinctive:

    Run Pint and focused tests.

    line 30
  8. Distinctive:

    Do not use custom attributes to bypass Actions, Policies, DTOs, Events, Jobs, or Services.

    line 46
  9. Distinctive:

    Prefer Laravel built-in attributes before custom attributes.

    line 47
  10. Distinctive:

    Every custom attribute must have a real consumer when introduced.

    line 48
  11. Distinctive:

    Test the consumer behavior.

    line 53
  12. Distinctive:

    Test invalid or missing metadata where relevant.

    line 54
  13. Distinctive:

    Add architecture tests when the attribute marks security, sensitivity, external integrations, or layer boundaries.

    line 55
  14. Distinctive:

    Treat reflected metadata as code-level metadata, not trusted user input.

    line 61

≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Create PHP Attribute

When To Use

Use this skill when stable metadata should be declared with PHP 8 attributes and consumed by application code, tests, middleware, scanners, or tooling.

Inputs Needed

  • Attribute purpose, target, allowed arguments, consuming code, security impact, tests, and naming.

Workflow

  1. Confirm a custom attribute is better than a method, interface, config value, enum, policy, middleware, injection attribute, Eloquent attribute, queue attribute, Form Request attribute, resource attribute, or other Laravel built-in attribute.
  2. Inspect existing attribute and support-class conventions.
  3. Create the attribute under app/Attributes unless the project already has a different convention.
  4. Use native PHP #[Attribute(...)] targets and repeatability flags.
  5. Make the attribute class final readonly when possible.
  6. Type every constructor parameter.
  7. Keep the attribute as metadata only.
  8. Create or update the consumer that reads the attribute via reflection, routing, middleware, tests, or support tooling.
  9. Add tests for the consumer behavior.
  10. Run Pint and focused tests.

Files That May Be Created

  • app/Attributes/*.php
  • Consumer classes in middleware, support, testing, or scanner namespaces.
  • Tests for the attribute consumer.

Files That May Be Modified

  • Classes or methods that receive the attribute.
  • Middleware, Actions, Services, Providers, tests, or architecture tests that consume the attribute.

Architecture Rules

  • Attributes describe metadata; they do not perform business workflows.
  • Do not use custom attributes to bypass Actions, Policies, DTOs, Events, Jobs, or Services.
  • Prefer Laravel built-in attributes before custom attributes.
  • Every custom attribute must have a real consumer when introduced.
  • Custom attributes are metadata and must not be used to bypass dependency injection.

Testing Requirements

  • Test the consumer behavior.
  • Test invalid or missing metadata where relevant.
  • Add architecture tests when the attribute marks security, sensitivity, external integrations, or layer boundaries.

Security Requirements

  • Attributes must not store secrets.
  • Attributes must not become the only authorization mechanism unless the consumer explicitly enforces policy or gate checks.
  • Treat reflected metadata as code-level metadata, not trusted user input.

Review Checklist

  • Is an attribute the simplest clear tool?
  • Is there a consumer?
  • Are targets and repeatability correct?
  • Is the class immutable and typed?
  • Are tests focused on behavior?

Examples

Good Example

// app/Attributes/RequiresPlan.php
namespace App\Attributes;

use Attribute;

#[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_METHOD)]
final readonly class RequiresPlan
{
    public function __construct(public string $plan = 'basic') {}
}
// app/Http/Middleware/CheckPlanSubscription.php
namespace App\Http\Middleware;

use Closure;
use ReflectionClass;
use App\Attributes\RequiresPlan;
use Illuminate\Http\Request;

final class CheckPlanSubscription
{
    public function handle(Request $request, Closure $next)
    {
        $controller = $request->route()?->controller;
        if (! $controller) {
            return $next($request);
        }

        // Use reflection to check for attribute on controller class
        $reflection = new ReflectionClass($controller);
        $attribute = $reflection->getAttributes(RequiresPlan::class)[0] ?? null;

        if ($attribute) {
            $requiresPlan = $attribute->newInstance();
            if (! $request->user()?->subscribed($requiresPlan->plan)) {
                abort(403, 'Subscription Plan Required');
            }
        }

        return $next($request);
    }
}

Bad Example

// ❌ Constructing custom reflection tags, dynamic execution inside constructor, no targeting filters.
#[Attribute]
class RequiresPlan {
    public function __construct($plan) {
        if (!auth()->user()->subscribed($plan)) {
            redirect('/billing'); // DO NOT run side-effects inside attributes!
        }
    }
}

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.