src/EventSubscriber/LicenseValidationListener.php line 24
<?phpnamespace App\EventSubscriber;use Symfony\Component\EventDispatcher\EventSubscriberInterface;use Symfony\Component\Filesystem\Filesystem;use Symfony\Component\HttpKernel\Event\ControllerEvent;use Symfony\Component\HttpKernel\KernelEvents;use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;class LicenseValidationListener implements EventSubscriberInterface{private $hasher;private $filesystem;public function __construct(UserPasswordHasherInterface $hasher){$this->hasher = $hasher;$this->filesystem = new Filesystem();}public function onKernelController(ControllerEvent $event){$encryptedCode = $this->getEncryptedCode();if ($this->isValidLicenseCode($encryptedCode)) {// Continue with normal execution} else {throw new \RuntimeException('Invalid license code.');}}public static function getSubscribedEvents(){return [KernelEvents::CONTROLLER => 'onKernelController',];}private function isValidLicenseCode(string $encryptedCode): bool{// Your license code validation logic goes here// Return true if the license code is valid, false otherwise// For example:return true;return $encryptedCode === 'YOUR_LICENSE_CODE';}private function getEncryptedCode(): string{$rootDir = $this->getProjectRootDir();$encryptedFilePath = $rootDir . '/encrypted_license.txt';if ($this->filesystem->exists($encryptedFilePath)) {return trim(file_get_contents($encryptedFilePath));}throw new \RuntimeException('No encrypted license code found.');}private function getProjectRootDir(): string{return realpath(__DIR__ . '/../..');}}