شعار Api Platform Resources

Api Platform Resources

المجتمع
fatonh
api-platform-resources

Use when exposing data through API Platform 4 — defining #[ApiResource], operations, DTO resources, state providers/processors, serialization groups, filters, and pagination. Use when the task mentions API Platform, ApiResource, state processor, or exposing an entity as a REST/GraphQL endpoint.

نظرة عامة

الناشرfatonh
المستودعsymfony-skills
اسم المهارةapi-platform-resources
النجوم
36
التفريعات
3
الملفات المرفقة
تعليمات فقط
الترخيصMIT
الروابط
  • تعليمات بصيغة Markdown

    ملف SKILL.md يُحمّله النموذج عند الحاجة، فلا يستهلك توكنات إلا عندما يَرِد طلب ذو صلة فعلًا.

  • تعمل مع أي نموذج لغوي كبير

    مهارات الذكاء الاصطناعي مكتوبة بصيغة Markdown وليست شيفرة خاصة بمزوّد معيّن، لذا تعمل مع GPT أو Claude أو Gemini أو Grok أو نموذج محلي.

  • مكتفية بذاتها

    كل ما يحتاجه النموذج موجود في التعليمات — لا ملفات إضافية لمزامنتها.

  • مفتوحة المصدر

    نشرها fatonh على GitHub. اطّلع على المصدر قبل تثبيتها.

التثبيت

ثبّت مهارة الذكاء الاصطناعي Api Platform Resources في TypingMind لاستخدامها مع أي نموذج لغوي كبير، أو أضفها إلى وكيل ذكاء اصطناعي آخر يقرأ SKILL.md.

1

التثبيت في TypingMind

يُثبّت TypingMind المهارة مباشرةً من مجلدها على GitHub — فيقرأ SKILL.md، ويجمع ملفات الموارد في حزمة، ويحفظ النتيجة محليًا.

  1. افتح التطبيق وانتقل إلى الإضافات → المهارات.
  2. اختر «تثبيت من GitHub».
  3. الصق رابط مجلد المهارة الموضّح أدناه وأكّد التثبيت.
    https://github.com/fatonh/symfony-skills/tree/main/skills/api-platform-resources
  4. فعّل المهارة في كل محادثة تريد إتاحتها فيها.
الإضافات → المهارات → إضافة مهارة → من رابط GitHub، ثم الصق رابط المجلد واضغط على «متابعة».
2

التثبيت في وكيل ذكاء اصطناعي آخر

يمكن لأي وكيل ذكاء اصطناعي يقرأ تنسيق Agent Skills استخدام هذه المهارة — انسخ المجلد إلى مجلد المهارات الخاص بذلك الوكيل.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/fatonh/symfony-skills.git /tmp/symfony-skills
mkdir -p .claude/skills
cp -r /tmp/symfony-skills/skills/api-platform-resources .claude/skills/api-platform-resources
أعد تشغيل Claude Code بعد النسخ ليتعرّف على المهارة الجديدة.

استخدمها في TypingMind

فعّل Api Platform Resources في أي محادثة على TypingMind وسيتولى النموذج الباقي. تتضمن مطالبة النظام اسمها ووصفها، وبمجرد ورود طلب ذي صلة، يُحمّل النموذج التعليمات الكاملة تلقائيًا — فلا تحتاج إلى استدعائها يدويًا، ولا تستهلك أي توكنات حتى تُستخدم فعليًا.

يُحمّل النموذج Api Platform Resources تلقائيًا بمجرد ورود طلب ذي صلة بها.

تعمل مع أي نموذج ذكاء اصطناعي

مهارات الذكاء الاصطناعي هي تعليمات بصيغة Markdown وليست شيفرة خاصة بمزوّد معيّن، لذا لا ترتبط Api Platform Resources بالنموذج الذي كُتبت له. ثبّتها مرة واحدة في TypingMind واستخدمها مع GPT-5 أو Claude أو Gemini أو Grok أو DeepSeek أو Mistral أو Llama أو نموذج محلي تشغّله بنفسك — كل ذلك باستخدام مفاتيح API الخاصة بك.

  • تُحمَّل عند الحاجة فقط

    تتضمن مطالبة النظام الاسم والوصف فقط. وتُجلب التعليمات عند أول طلب ذي صلة، لذا لا تترتب أي تكلفة على المهارة غير المستخدمة.

  • بدّل النماذج أثناء المحادثة

    لأن المهارة تعليمات وليست شيفرة، فإن تغيير النموذج لا يعطّلها — فالنموذج التالي يقرأ ملف SKILL.md نفسه.

تعليمات المهارة

هذا هو محتوى SKILL.md الذي يُحمّله النموذج. اقرأه قبل التثبيت — فالمهارة عبارة عن تعليمات سيتبعها نموذجك.

API Platform 4 Resources

Prefer DTO resources over exposing entities

Exposing a Doctrine entity directly as #[ApiResource] couples your public API to your schema and leaks persistence concerns. For anything beyond a trivial CRUD prototype, expose a DTO resource backed by a state provider (read) and state processor (write).

php
// ✅ GOOD — a resource DTO, decoupled from the entity
#[ApiResource(
    shortName: 'Order',
    operations: [
        new Get(provider: OrderItemProvider::class),
        new GetCollection(provider: OrderCollectionProvider::class),
        new Post(processor: CreateOrderProcessor::class, input: CreateOrderInput::class),
    ],
    normalizationContext: ['groups' => ['order:read']],
)]
final class OrderResource
{
    public function __construct(
        #[ApiProperty(identifier: true)]
        #[Groups(['order:read'])]
        public string $id,

        #[Groups(['order:read'])]
        public string $status,

        /** @var LineItemResource[] */
        #[Groups(['order:read'])]
        public array $items = [],
    ) {}
}
php
// ❌ BAD — Doctrine entity as the API resource: schema is now your public contract
#[ApiResource]
#[ORM\Entity]
class Order { /* every column auto-exposed, lazy associations serialized, N+1 */ }

If you do expose entities (small internal apps), always scope fields with serialization groups and disable the operations you don't want.

State processors (write side)

A processor receives the input DTO and performs the use case — usually by delegating to an application service / Messenger bus.

php
// ✅ GOOD
/** @implements ProcessorInterface<CreateOrderInput, OrderResource> */
final class CreateOrderProcessor implements ProcessorInterface
{
    public function __construct(private readonly OrderService $orders) {}

    public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): OrderResource
    {
        $order = $this->orders->createOrder($data);   // $data is the validated CreateOrderInput

        return OrderResource::fromEntity($order);
    }
}

State providers (read side)

php
// ✅ GOOD — provider returns the read model, not the entity
/** @implements ProviderInterface<OrderResource> */
final class OrderItemProvider implements ProviderInterface
{
    public function __construct(private readonly OrderRepository $orders) {}

    public function provide(Operation $operation, array $uriVariables = [], array $context = []): ?OrderResource
    {
        $order = $this->orders->find(Uuid::fromString($uriVariables['id']));

        return $order ? OrderResource::fromEntity($order) : null;
    }
}

Use the built-in Pagination in collection providers; don't return unbounded arrays.

Validation

Put Symfony Validator constraints on the input DTO. API Platform validates automatically before the processor runs and returns RFC 9457 problem+json on failure.

php
final class CreateOrderInput
{
    #[Assert\NotBlank]
    #[Assert\Email]
    public string $customerEmail;

    /** @var CreateLineInput[] */
    #[Assert\Valid]
    #[Assert\Count(min: 1)]
    public array $items = [];
}

Operations & security

  • Declare operations explicitly; don't accept the default full CRUD set unless you mean it.
  • Authorize per-operation with security:
php
new Post(security: "is_granted('ROLE_USER')"),
new Delete(security: "is_granted('ORDER_DELETE', object)"),  // voter on the object

Filters & pagination

php
#[ApiResource(
    operations: [new GetCollection()],
    paginationItemsPerPage: 20,
    paginationMaximumItemsPerPage: 100,
)]
#[ApiFilter(SearchFilter::class, properties: ['status' => 'exact', 'customerEmail' => 'partial'])]
#[ApiFilter(OrderFilter::class, properties: ['createdAt' => 'DESC'])]
final class OrderResource { /* ... */ }

For large datasets, see doctrine-query-optimization — switch collection providers to keyset pagination.

Versioning & errors

  • Version through the path prefix or a vendor media type; keep order:read / order:write groups stable.
  • Don't hand-build error responses — API Platform emits RFC 9457 problem+json (see problem-details-rfc9457). Throw domain exceptions mapped to status codes.

Gotchas

  • Agent slaps #[ApiResource] on a Doctrine entity — prefer a DTO resource with provider/processor for non-trivial APIs.
  • Agent leaves all CRUD operations enabled by default — declare only the operations you intend to expose.
  • Agent forgets serialization #[Groups] — every property gets exposed, including sensitive ones.
  • Agent puts business logic in the processor — delegate to an application service; the processor just adapts.
  • Agent returns the entity from a provider — return the resource DTO.
  • Agent disables pagination or returns findAll() from a collection provider — keep pagination on.
  • Agent hand-rolls error JSON — let API Platform produce problem+json; throw mapped exceptions.
  • Agent uses API Platform 2/3 annotations (@ApiResource) — use PHP 8 attributes and the v4 metadata classes (ApiPlatform\Metadata\*).

الأسئلة الشائعة

ماذا تفعل مهارة الذكاء الاصطناعي Api Platform Resources؟

Use when exposing data through API Platform 4 — defining #[ApiResource], operations, DTO resources, state providers/processors, serialization groups, filters, and pagination. Use when the task mentions API Platform, ApiResource, state processor, or exposing an entity as a REST/GraphQL endpoint.

لماذا تستخدم Api Platform Resources على TypingMind؟

لأنك تثبّتها مرة واحدة وتستخدمها مع أي نموذج. مهارة Api Platform Resources عبارة عن نص Markdown وليست شيفرة خاصة بمزود بعينه، لذا تعمل المهارة نفسها مع GPT-5 أو Claude أو Gemini أو Grok أو نموذج محلي، ويمكنك تبديل النموذج أثناء المحادثة دون تعطّل المهارة. يعمل TypingMind بمفاتيح API الخاصة بك، فتدفع للمزودين مباشرةً بدلًا من اشتراك لكل مقعد، وتبقى مهاراتك ومحادثاتك في مساحة التخزين الخاصة بك.

كيف أثبّت Api Platform Resources في TypingMind؟

افتح الإضافات → المهارات → التثبيت من GitHub في TypingMind والصق https://github.com/fatonh/symfony-skills/tree/main/skills/api-platform-resources. يقرأ TypingMind ملف SKILL.md الخاص بها ويثبّتها كمهارة يمكنك تفعيلها لكل محادثة على حدة.

ما نماذج الذكاء الاصطناعي التي يمكنها استخدام Api Platform Resources؟

أي نموذج تربطه في TypingMind. مهارات الذكاء الاصطناعي عبارة عن تعليمات Markdown وليست شيفرة خاصة بمزود بعينه، لذا يمكن لكل من GPT وClaude وGemini وGrok والنماذج المحلية تحميل هذه المهارة عندما يتوافق الطلب معها.

كم نموذج ذكاء اصطناعي يمكنني استخدامه مع Api Platform Resources؟

أي عدد تريده. ما دام النموذج يدعم المهارات، يمكنك استخدام Api Platform Resources معه، سواء كان GPT أو Claude أو Gemini أو Grok أو DeepSeek أو Mistral أو Llama أو غيرها، وكل ذلك على TypingMind باستخدام مفاتيح API الخاصة بك.

هل مهارة الذكاء الاصطناعي Api Platform Resources مجانية؟

نعم. نشرها fatonh على GitHub بموجب ترخيص MIT. لا تدفع إلا لمزود الذكاء الاصطناعي الخاص بك مقابل التوكنات التي تستخدمها.

ما هي مهارات الذكاء الاصطناعي؟

مهارة الذكاء الاصطناعي حزمة تعليمات قابلة لإعادة الاستخدام تعلّم نموذج الذكاء الاصطناعي كيفية تنفيذ مهمة محددة. وتتبع تنسيق Agent Skills المفتوح: ملف SKILL.md يتضمن اسمًا ووصفًا، إلى جانب أي نصوص برمجية أو قوالب أو ملفات مرجعية قد يحتاج إليها النموذج. لا يقرأ النموذج التعليمات إلا عندما يتوافق طلبك مع المهارة، لذا لا تترتب على المهارة المثبتة أي تكلفة حتى تُستخدم.

كيف تختلف مهارات الذكاء الاصطناعي عن الإضافات أو موصلات MCP؟

تمنح الإضافة أو موصل MCP النموذج أدوات جديدة يمكنه استدعاؤها، وهي شيفرة تُنفَّذ في مكان ما وتُرجع نتيجة. أما مهارة الذكاء الاصطناعي فتزوّد النموذج بالمعرفة ومنهجية العمل: كيفية التعامل مع مهمة، والخطوات التي ينبغي اتباعها، وما ينبغي أن تكون عليه المخرجات الجيدة. المهارات عبارة عن نصوص Markdown، لذا لا تحتاج إلى خادم أو مفتاح API أو بيئة تشغيل، وتعمل مع أي نموذج.

عرض الكل

أنشئ مساحة عملك للذكاء الاصطناعي الآن

اشترك في نشرتنا البريدية لتصلك أخبار الميزات الجديدة والهدايا القادمة 👇