Skip to content
Snippets Groups Projects
Select Git revision
  • 31d2e7e178d65ea6923321f45c1c941c1d6959d4
  • main default protected
  • ci-updates
  • v0.2.4
  • v0.2.3
  • v0.2.2
  • v0.2.1
  • v0.2.0
  • v0.1.10
  • v0.1.9
  • v0.1.8
  • v0.1.7
  • v0.1.6
  • v0.1.5
  • v0.1.4
  • v0.1.3
  • v0.1.2
  • v0.1.0
  • v0.1.1
19 results

OrganizationItemDataProvider.php

Blame
  • user avatar
    Tobias Gross-Vogt authored
    6b3014f2
    History
    OrganizationItemDataProvider.php 1.72 KiB
    <?php
    
    declare(strict_types=1);
    
    namespace Dbp\Relay\BaseOrganizationBundle\DataProvider;
    
    use ApiPlatform\Core\DataProvider\ItemDataProviderInterface;
    use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface;
    use Dbp\Relay\BaseOrganizationBundle\API\OrganizationProviderInterface;
    use Dbp\Relay\BaseOrganizationBundle\Entity\Organization;
    use Dbp\Relay\CoreBundle\Helpers\Locale;
    use Dbp\Relay\CoreBundle\LocalData\LocalData;
    use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
    
    final class OrganizationItemDataProvider extends AbstractController implements ItemDataProviderInterface, RestrictedDataProviderInterface
    {
        /** @var OrganizationProviderInterface */
        private $api;
    
        /** @var Locale */
        private $locale;
    
        public function __construct(OrganizationProviderInterface $api, Locale $locale)
        {
            $this->api = $api;
            $this->locale = $locale;
        }
    
        public function supports(string $resourceClass, string $operationName = null, array $context = []): bool
        {
            return Organization::class === $resourceClass;
        }
    
        public function getItem(string $resourceClass, $id, string $operationName = null, array $context = []): ?Organization
        {
            $this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
    
            $filters = $context['filters'] ?? [];
            $options = [];
    
            LocalData::addOptions($options, $filters);
    
            // @deprecate 'lang' filter is deprecate, use 'Accept-Language' header instead
            if (($lang = $filters['lang'] ?? null) !== null) {
                $options[Locale::LANGUAGE_OPTION] = $lang;
            } else {
                $this->locale->addLanguageOption($options);
            }
    
            return $this->api->getOrganizationById($id, $options);
        }
    }