Search code examples
phpsymfonygnupgpgpgpg-signature

Unable to create new gnupg object in Symfony Controller


I am converting a project from pure PHP to Symfony and I am having problems working with gnupg in Symfony.

My problem is the following: I configured gnupg following PHP's docs without any problem, I restarted my webserver and I also restarted the php-fpm. I just created a single php file to check if all was correctly configured and all works fine with pure php. The problem comes when I try to add the code into my Symfony's controller. When I do the following:

putenv('GNUPGHOME=/home/kevingrab/.gnupg');
$gpg = '/usr/bin/gpg';
$gpg = new gnupg();

I obtain the following error in the logs:

request.CRITICAL: Uncaught PHP Exception Symfony\Component\Debug\Exception\ClassNotFoundException: "Attempted to load class "gnupg" from namespace "AppBundle\Controller". Did you forget a "use" statement for another namespace?" at /var/www/project/src/AppBundle/Controller/DefaultController.php line 147 {"exception":"[object] (Symfony\\Component\\Debug\\Exception\\ClassNotFoundException(code: 0): Attempted to load class \"gnupg\" from namespace \"AppBundle\\Controller\".\nDid you forget a \"use\" statement for another namespace? at /var/www/project/src/AppBundle/Controller/DefaultController.php:147)"} []

And well I don't know what can I do to fix it, I tried to find an answer in internet but I didn't see any post about this issue with Symfony. Any help would be appreciated.


Solution

  • you can fix your issue by prepending \ to the code which is instantiating the gnupg object.

    So

    $gpg = new \gnupg();
    

    To know why this is the case, refer to Global space.