Back to list
Swoking

symfony-skapi-service

by Swoking

Claude Code plugin pour projets Symfony StarterKit

0🍴 0📅 Jan 19, 2026

SKILL.md


name: symfony-sk:api-service description: Create or modify API services extending BaseService. Use for business logic. allowed-tools: Read, Write, Edit, Glob, Grep

API Service Skill

Mission

Create API services that handle business logic, database operations, and return ApiResult.


Location

api/src/Service/<Name>Service.php


Template

<?php

namespace App\Service;

use App\Repository\<Entity>Repository;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
use StarterKit\Entity\ApiResult;
use StarterKit\Service\BaseService;
use StarterKit\Service\Helper\HelperService;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

class <Feature>Service extends BaseService
{
    public function __construct(
                         EntityManagerInterface $em,
                         LoggerInterface        $logger,
                         HelperService          $helper,
                         EventDispatcherInterface $dispatcher,
        private readonly <Entity>Repository     $repository,
    ) {
        parent::__construct($em, $logger, $helper, $dispatcher);
    }

    public function read(ApiResult $apiResult, string $lang, string $key): ApiResult
    {
        $entity = $this->repository->findOneBy(['key' => $key, 'isDeleted' => 0]);

        if (!$entity) {
            // Array contains values to inject in message placeholders (%%1%%, %%2%%, etc.)
            return $this->helper->setReturnCode($apiResult, $lang, -XXXXX, [$key]);
        }

        $apiResult->setData($this->normalize($entity));
        return $apiResult;
    }

    public function create(ApiResult $apiResult, string $lang, <Dto> $data): ApiResult
    {
        $entity = new <Entity>();
        $this->helper->initNewEntity($entity);
        // Set properties from $data

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

        $apiResult->setData($this->normalize($entity));
        return $apiResult;
    }

    private function normalize(mixed $data): array
    {
        return $this->normalizer->normalize($data, null, ['groups' => ['<feature>']]);
    }
}

Key Rules

  1. Extends BaseService
  2. Methods MUST have $lang parameter (requested language for translations/localized data)
  3. Return ApiResult
  4. Use $this->helper->setReturnCode() for errors
  5. Use error codes from /error-code skill

Error Handling with setReturnCode

// Signature: setReturnCode(ApiResult $apiResult, string $lang, int $code, array $params = [])
// $params contains values to inject into message placeholders

// Example: Error message "User %%1%% not found" with email in array
return $this->helper->setReturnCode($apiResult, $lang, -30201, [$user->getEmail()]);
// Result: "User test@test.com not found"

// Example: Multiple placeholders "%%1%% cannot be assigned to %%2%%"
return $this->helper->setReturnCode($apiResult, $lang, -30202, [$taskName, $userName]);

Use vm-executor agent to find existing error codes or /error-code skill to create new ones.


Checklist

  • Extends BaseService
  • Constructor calls parent::__construct()
  • All methods have $lang parameter
  • Error codes used for failures
  • Returns ApiResult

Score

Total Score

50/100

Based on repository quality metrics

SKILL.md

SKILL.mdファイルが含まれている

+20
LICENSE

ライセンスが設定されている

0/10
説明文

100文字以上の説明がある

0/10
人気

GitHub Stars 100以上

0/15
最近の活動

3ヶ月以内に更新がある

0/10
フォーク

10回以上フォークされている

0/5
Issue管理

オープンIssueが50未満

+5
言語

プログラミング言語が設定されている

+5
タグ

1つ以上のタグが設定されている

0/5

Reviews

💬

Reviews coming soon