vendor/sulu/form-bundle/Dynamic/Checksum.php line 31

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of Sulu.
  4.  *
  5.  * (c) Sulu GmbH
  6.  *
  7.  * This source file is subject to the MIT license that is bundled
  8.  * with this source code in the file LICENSE.
  9.  */
  10. namespace Sulu\Bundle\FormBundle\Dynamic;
  11. use Symfony\Component\Security\Core\Encoder\MessageDigestPasswordEncoder;
  12. /**
  13.  * Checksum.
  14.  */
  15. class Checksum
  16. {
  17.     /**
  18.      * @var string
  19.      */
  20.     private $secret;
  21.     /**
  22.      * @var MessageDigestPasswordEncoder
  23.      */
  24.     private $encoder;
  25.     public function __construct(string $secret)
  26.     {
  27.         $this->secret $secret;
  28.         $this->encoder = new MessageDigestPasswordEncoder();
  29.     }
  30.     /**
  31.      * Check checksum with given parameters.
  32.      */
  33.     public function check(string $checksumstring $typestring $typeIdint $formIdstring $formName): bool
  34.     {
  35.         $checksumRaw $this->createKey($type$typeId$formId$formName);
  36.         return $this->encoder->isPasswordValid($checksum$checksumRaw$this->secret);
  37.     }
  38.     /**
  39.      * Create a key with given parameteres.
  40.      */
  41.     private function createKey(string $typestring $typeIdint $formIdstring $formName): string
  42.     {
  43.         return $type $typeId $formId $formName;
  44.     }
  45.     /**
  46.      * Create a checksum and encode with secret and given parameters.
  47.      */
  48.     public function get(string $typestring $typeIdint $formIdstring $formName): string
  49.     {
  50.         $checksumRaw $this->createKey($type$typeId$formId$formName);
  51.         return $this->encoder->encodePassword($checksumRaw$this->secret);
  52.     }
  53. }