Skip to content
Snippets Groups Projects
Select Git revision
  • 7ffa0de5202c34985f022fcd5b61144ed873f174
  • main default protected
  • renovate/lock-file-maintenance
  • demo protected
  • person-select-custom
  • dbp-translation-component
  • icon-set-mapping
  • port-i18next-parser
  • remove-sentry
  • favorites-and-recent-files
  • revert-6c632dc6
  • lit2
  • advertisement
  • wc-part
  • automagic
  • publish
  • wip-cleanup
  • demo-file-handling
18 results

karma.common.conf.js

Blame
  • 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);
        }
    }