mcpField
P
php-symfony

php-symfony

github.com/pluginagentmarketplace開発4101 回インストール44 週間前に更新
リポジトリ

php-symfony について

Symfony アプリケーション構築向けのスキルで、Symfony 6.4 LTS と 7.x のほか、Doctrine ORM、依存性注入、API Platform などを扱います。トピックとレベルに応じて内容を案内し、学習モジュール、コード例、トラブルシューティングを提供します。

主な機能

  1. 01Symfony 6.4 LTS と 7.x に対応
  2. 02Doctrine と依存性注入などを扱う
  3. 03トピックとレベルに応じて案内
  4. 04コード例とテストテンプレートを提供
  5. 05トラブルシューティングを収録

活用シーン

  1. 01Doctrine ORM とマイグレーションを学ぶ
  2. 02依存性注入でサービスを設定
  3. 03API Platform で API を構築

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/pluginagentmarketplace/custom-plugin-php --skill php-symfony

インストール後、Claude Code で/php-symfonyを入力して読み込まれたか確認します。

同梱ファイル

SKILL.md と一緒にインストールされる参考資料やスクリプト。

assets/
config.yaml
schema.json
references/
GUIDE.md
PATTERNS.md
scripts/
validate.py

詳細

Symfony Framework Skill

エンタープライズグレードの Symfony アプリケーションを習得するためのアトミックスキル

概要

堅牢な Symfony アプリケーションを構築するための包括的なスキルです。Doctrine ORM、依存性注入、API Platform に重点を置き、Symfony 6.4 LTS および 7.x をカバーします。

スキルパラメーター

入力の検証
interface SkillParams {
  topic:
    | "doctrine"         // ORM, DBAL, migrations
    | "di-container"     // Services, autowiring, tags
    | "routing"          // Routes, controllers
    | "security"         // Voters, firewalls
    | "messenger"        // Async messaging
    | "api-platform"     // REST/GraphQL APIs
    | "forms";           // Form types, validation

  level: "beginner" | "intermediate" | "advanced";
  symfony_version?: "6.4" | "7.0" | "7.1" | "7.2";
  project_type?: "webapp" | "api" | "microservice";
}
検証ルール
validation:
  topic:
    required: true
    allowed: [doctrine, di-container, routing, security, messenger, api-platform, forms]
  level:
    required: true
  symfony_version:
    default: "7.1"

学習モジュール

モジュール 1:Doctrine ORM
beginner:
  - Entity creation with attributes
  - Basic relationships
  - Repository basics

intermediate:
  - DQL and QueryBuilder
  - Lifecycle events
  - Custom repository methods

advanced:
  - Inheritance mapping
  - Second-level cache
  - Event subscribers
モジュール 2:依存性注入
beginner:
  - Service basics
  - Autowiring
  - Constructor injection

intermediate:
  - Service tags
  - Factory services
  - Decorators

advanced:
  - Compiler passes
  - Service subscribers
  - Lazy services
モジュール 3:Messenger コンポーネント
beginner:
  - Messages and handlers
  - Sync vs async transports

intermediate:
  - Message middleware
  - Retry strategies
  - Multiple transports

advanced:
  - Custom transports
  - Saga patterns

実行フロー

graph TD
    A[Skill Invoked] --> B{Validate}
    B -->|Invalid| C[Return Error]
    B -->|Valid| D[Load Content]
    D --> E{Topic Router}
    E --> F[Generate Examples]
    F --> G[Add Console Commands]

エラー処理と再試行ロジック

errors:
  CONTAINER_ERROR:
    code: "SYMFONY_001"
    recovery: "Run cache:clear, check services.yaml"

  DOCTRINE_ERROR:
    code: "SYMFONY_002"
    recovery: "Run doctrine:schema:validate"

retry:
  max_attempts: 3
  backoff:
    type: exponential
    initial_delay_ms: 100

コード例

Doctrine エンティティ
<?php
declare(strict_types=1);

namespace App\Entity;

use App\Repository\ProductRepository;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;

#[ORM\Entity(repositoryClass: ProductRepository::class)]
#[ORM\HasLifecycleCallbacks]
class Product
{
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column]
    private ?int $id = null;

    #[ORM\Column(length: 255)]
    #[Assert\NotBlank]
    private string $name;

    #[ORM\ManyToOne(inversedBy: 'products')]
    #[ORM\JoinColumn(nullable: false)]
    private Category $category;

    #[ORM\Column]
    private \DateTimeImmutable $createdAt;

    public function __construct()
    {
        $this->createdAt = new \DateTimeImmutable();
    }
}
DI を使用するサービス
<?php
declare(strict_types=1);

namespace App\Service;

use App\Repository\ProductRepository;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\DependencyInjection\Attribute\Autowire;

final readonly class ProductService
{
    public function __construct(
        private ProductRepository $repository,
        private EntityManagerInterface $entityManager,
        private LoggerInterface $logger,
        #[Autowire('%app.tax_rate%')]
        private float $taxRate,
    ) {}

    public function createProduct(array $data): Product
    {
        $product = new Product();
        $product->setName($data['name']);

        $this->entityManager->persist($product);
        $this->entityManager->flush();

        $this->logger->info('Product created', ['id' => $product->getId()]);

        return $product;
    }
}
Messenger ハンドラー
<?php
declare(strict_types=1);

namespace App\MessageHandler;

use App\Message\SendOrderConfirmation;
use App\Service\EmailService;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;

#[AsMessageHandler]
final readonly class SendOrderConfirmationHandler
{
    public function __construct(
        private EmailService $emailService,
    ) {}

    public function __invoke(SendOrderConfirmation $message): void
    {
        $this->emailService->sendOrderConfirmation($message->orderId);
    }
}

テストテンプレート

<?php
declare(strict_types=1);

namespace App\Tests\Functional;

use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

final class ProductControllerTest extends WebTestCase
{
    public function testListProducts(): void
    {
        $client = static::createClient();
        $client->request('GET', '/api/products');

        $this->assertResponseIsSuccessful();
    }
}

トラブルシューティング

問題解決策
サービスが見つからないdebug:container を実行し、自動配線を確認します
Doctrine のマッピングエラーdoctrine:schema:validate を実行します
ルートが見つからないdebug:router を実行し、ファイアウォールを確認します

品質指標

指標目標
コードの正確性100%
Symfony の規約100%
DI のベストプラクティス100%

使用方法

Skill("php-symfony", {topic: "messenger", level: "advanced"})

コメント