vendor/symfony-cmf/core-bundle/src/PublishWorkflow/Voter/PublishableVoter.php line 24

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony CMF package.
  4.  *
  5.  * (c) 2011-2017 Symfony CMF
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Symfony\Cmf\Bundle\CoreBundle\PublishWorkflow\Voter;
  11. use Symfony\Cmf\Bundle\CoreBundle\PublishWorkflow\PublishableReadInterface;
  12. use Symfony\Cmf\Bundle\CoreBundle\PublishWorkflow\PublishWorkflowChecker;
  13. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  14. use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
  15. /**
  16.  * Workflow voter for the PublishableReadInterface.
  17.  *
  18.  * @author David Buchmann <mail@davidbu.ch>
  19.  */
  20. class PublishableVoter implements VoterInterface
  21. {
  22.     /**
  23.      * {@inheritdoc}
  24.      *
  25.      * @deprecated To be removed when Symfony 2 support is dropped
  26.      */
  27.     public function supportsAttribute($attribute)
  28.     {
  29.         return PublishWorkflowChecker::VIEW_ATTRIBUTE === $attribute
  30.             || PublishWorkflowChecker::VIEW_ANONYMOUS_ATTRIBUTE === $attribute
  31.         ;
  32.     }
  33.     /**
  34.      * {@inheritdoc}
  35.      *
  36.      * @deprecated To be removed when Symfony 2 support is dropped
  37.      */
  38.     public function supportsClass($class)
  39.     {
  40.         return is_subclass_of($classPublishableReadInterface::class);
  41.     }
  42.     /**
  43.      * {@inheritdoc}
  44.      *
  45.      * @param PublishableReadInterface $subject
  46.      */
  47.     public function vote(TokenInterface $token$subject, array $attributes)
  48.     {
  49.         if (!is_object($subject) || !$this->supportsClass(get_class($subject))) {
  50.             return self::ACCESS_ABSTAIN;
  51.         }
  52.         $decision self::ACCESS_GRANTED;
  53.         foreach ($attributes as $attribute) {
  54.             if (!$this->supportsAttribute($attribute)) {
  55.                 // there was an unsupported attribute in the request.
  56.                 // now we only abstain or deny if we find a supported attribute
  57.                 // and the content is not publishable
  58.                 $decision self::ACCESS_ABSTAIN;
  59.                 continue;
  60.             }
  61.             if (!$subject->isPublishable()) {
  62.                 return self::ACCESS_DENIED;
  63.             }
  64.         }
  65.         return $decision;
  66.     }
  67. }