implementer:log
Ajouter LoggableInterface à une classe PHP
- License 许可
- MIT
- 最近更新
- 2026-03-02
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- implementer:log
- model
- sonnet
- license
- MIT
- version
- 1.0.0
- description
- Ajouter LoggableInterface à une classe PHP
- allowed-tools
- [ "Read", "Edit", "Grep", "Glob" ]
- argument-hint
- [ "FICHIER" ]
02 资源文件 1
- 参考文档references/spec-workflow.md5.8 KB
03 SKILL.md 正文
Ajout de logging avec LoggableInterface
Ajouter l'interface LoggableInterface et la méthode toLog() à une classe PHP.
Instructions à Exécuter
IMPORTANT : Exécute ce workflow étape par étape :
Fichier cible : $ARGUMENTS
1. Lire et analyser le fichier
- Lire le contenu du fichier PHP
- Identifier la classe principale et ses propriétés
- Vérifier si
LoggableInterfaceest déjà implémentée
2. Chercher les dépendances LoggableInterface
Pour chaque type-hint de propriété ou paramètre :
- Utiliser Grep pour chercher si la classe implémente
LoggableInterface - Noter les classes qui l'implémentent pour appeler
->toLog()dessus
3. Ajouter LoggableInterface
Si la classe n'implémente pas encore LoggableInterface :
Ajouter l'import :
use Atournayre\Contracts\Log\LoggableInterface;
Ajouter l'interface à la déclaration de classe :
final class NomClasse implements LoggableInterface
Ajouter la méthode toLog() :
/**
* @return array<string, mixed>
*/
public function toLog(): array
{
return [
// Propriétés clés de l'objet
];
}
4. Règles pour le contenu de toLog()
Propriétés à inclure :
id(si présent)- Identifiants métier (email, code, référence...)
- États/statuts importants
- Dates clés (createdAt, updatedAt...)
Propriétés à exclure :
- Mots de passe, tokens, secrets
- Données personnelles sensibles
- Propriétés volumineuses (blobs, textes longs)
Pour les objets imbriqués :
- Si l'objet implémente
LoggableInterface:'relation' => $this->relation->toLog() - Sinon :
'relationId' => $this->relation->getId()ou ignorer
Pour les collections :
/**
* @return array{count: int, items: array<int, array<string, mixed>>}
*/
public function toLog(): array
{
return [
'count' => $this->count(),
'items' => array_map(fn ($item) => $item->toLog(), $this->items),
];
}
5. Vérification PHPStan
- Toujours ajouter
@return array<string, mixed>sur la méthode - Pour les collections : utiliser le type array shape approprié
Exemple de résultat
use Atournayre\Contracts\Log\LoggableInterface;
final class Commande implements LoggableInterface
{
private Uuid $id;
private string $reference;
private Client $client;
private \DateTimeImmutable $createdAt;
private string $password; // Sensible, à exclure
/**
* @return array<string, mixed>
*/
public function toLog(): array
{
return [
'id' => $this->id->toRfc4122(),
'reference' => $this->reference,
'client' => $this->client->toLog(),
'createdAt' => $this->createdAt->format('c'),
// password exclu intentionnellement
];
}
}
04 同仓库更多 Skills
twig:make-component
Génère un Twig Component Symfony UX (classe PHP + template Twig)
tester:ui-test
Teste automatiquement une interface utilisateur dans Chrome : navigation, clics, validation visuelle, tests fonctionnels, responsive, comportement et debug. Génère un rapport détaillé avec screenshots et optionnellement un GIF du parcours.
symfony:voter
Genere un Voter de securite Symfony pour le controle d'acces granulaire
symfony:message
Genere un Message Symfony Messenger avec son Handler pour traitement asynchrone
symfony:mailer
Genere un email Symfony (TemplatedEmail ou Notification) avec template Twig
symfony:form
Genere un FormType Symfony avec contraintes de validation et options