Skip to content

Latest commit

 

History

History
66 lines (49 loc) · 1.59 KB

File metadata and controls

66 lines (49 loc) · 1.59 KB

API Platform

An overview of available infrastructural code when using API Platform.

Projection Data Provider

When working with projections an API Data Provider is provided by MsgPhp\Domain\Infra\ApiPlatform\ProjectionDataProvider. It uses any projection repository in an effort to provide API resources.

Minimal configuration

api_platform:
    # ...

    resource_class_directories:
        - '%kernel.project_dir%/src/Api/Projection'

services:
    # ..
.
    MsgPhp\Domain\Infra\ApiPlatform\ProjectionDataProvider:
        tags: [api_platform.collection_data_provider]
        autowire: true

!!! note See also API Platform Configuration documentation

Basic example

<?php

namespace App\Api\Projection;

use ApiPlatform\Core\Annotation\ApiProperty;
use ApiPlatform\Core\Annotation\ApiResource;
use MsgPhp\Domain\Projection\ProjectionInterface;

/**
 * @ApiResource(shortName="Some")
 */
class SomeProjection implements ProjectionInterface
{
    /**
     * @ApiProperty(identifier=true)
     */
    public $id;

    public static function fromDocument(array $document): ProjectionInterface
    {
        $projection = new self();
        $projection->id = $document['id'] ?? null;

        return $projection;
    }
}