pn-php-backend

A set of rules for writing PHP server and API code, including applications built with Laravel or Slim.

In plain words
What is it for?
Use it when building or reviewing PHP models, controllers, requests, services, events, database relationships, and environment settings.
Why use it?
It promotes consistent PHP structure and helps avoid weak typing, misplaced validation, inefficient database access, and unsafe configuration.

Cursor rule

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/perniemann/pncore/pn-php-backend
Clone the repo
git clone --depth 1 https://github.com/perniemann/pnCore
Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 893 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.00893
Opus 5 $0.00000 $0.00447
Sonnet 5 $0.00000 $0.00179
Haiku 4.5 $0.00000 $0.00089

Measured yesterday against content hash 70510945bbf5, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

pn-php-backend scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

packages/pn-core-mcp/content/rules/pn-php-backend.mdc · 51 lines

How it starts

The opening of the file, as written. The whole thing — 51 lines — stays where its author put it; the contents beside it link to each section on GitHub.

PHP / backend rules

Style and typing

  • Use declare(strict_types=1) at the top of every file.
  • Type declarations for all function parameters and return types. Use union types (string|int) and nullable types (?string) where needed. Avoid mixed except at true boundaries.
  • Follow PSR-12 coding style. Use a formatter (PHP CS Fixer or Pint for Laravel) — style should be automated, not debated.
  • Named arguments for clarity in calls with 3+ parameters or boolean flags: createUser(name: 'Alice', role: 'admin', sendEmail: true).

Laravel conventions

  • Use Eloquent scopes, resource controllers, and form request classes. Business logic belongs in service classes, not controllers.
  • Form Request classes (App\Http\Requests\) for all input validation — not inline $request->validate() in controllers.
  • Use Eloquent relationships correctly: ->with(['orders']) for eager loading; never load relationships inside loops.
  • Events and Listeners for decoupled side effects (sending emails, updating search index) rather than fat service methods.
  • Use php artisan make:model -mfsc (migration, factory, seeder, controller) — follow the resource pattern.

Secrets and config

  • All secrets and config from environment variables: env('VAR') (Laravel) or getenv('VAR'). Never hardcode keys or passwords.
  • Use vlucas/phpdotenv in non-Laravel projects. Never commit .env to git. Keep .env.example with placeholders.
  • Reference config via config('services.stripe.key') (Laravel) — never env() directly in business logic (config is cached; env() does not work after php artisan config:cache).

Error handling

  • Catch specific exception classes in try/catch, not bare catch (\Exception $e) for everything.
  • In Laravel: extend App\Exceptions\Handler to centralize error formatting. Return consistent JSON shapes for API responses.
  • Return consistent error shapes: { "error": { "code": string, "message": string, "requestId": string } }.
  • Use Laravel's Log::warning(), Log::error() with context arrays — not echo or var_dump.

Read the full file on GitHub · 51 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 51 lines · 0 tokens per session scan A 70510945bbf5

Subscribe to this mod's changes

pn-php-backend is a cursor rule published in the GitHub repository perniemann/pnCore (0 stars, last pushed 2d ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 893 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.