Hi.
I have a custom module (app/code/MyVendor/MyModule) in my Magento installation that have an event observer. I want to use some sensetive keys and such in this event observer to do some API calls to another service (stripe). I want to store these keys somewhere outside the code (in an .env file).
In my magento composer.json I can see that I have vlucas/phpdotenv third party library installed. This should allow me to use a code such as this in my module to use the phpdotenv for the purpose I stated above.
$dotenv = Dotenv\Dotenv::createImmutable("../");
$dotenv->load();However this creates an error:
Fatal error: Uncaught Error: Class 'MyVendor\MyModule\Observer\Dotenv\Dotenv' not found in /var/www/html/magento/app/code/MyVendor/MyModule/Observer/MyModule.php:58
It seems to me its not being loaded. Is there something I need to do to let my custom module use any third party library located in root project folder /vendor?
My composer.json:
{
"name": "magento/project-community-edition",
"description": "eCommerce Platform for Growth (Community Edition)",
"type": "project",
"license": [
"OSL-3.0",
"AFL-3.0"
],
"config": {
"preferred-install": "dist",
"sort-packages": true
},
"require": {
"jumbojett/openid-connect-php": "^0.8.0",
"magento/product-community-edition": "2.3.2",
"mageplaza/module-smtp": "^1.2",
"stripe/stripe-php": "^6.40",
"vlucas/phpdotenv": "^2.6.1"
},
"require-dev": {
"allure-framework/allure-phpunit": "~1.2.0",
"friendsofphp/php-cs-fixer": "~2.13.0",
"lusitanian/oauth": "~0.8.10",
"magento/magento-coding-standard": "~1.0.0",
"magento/magento2-functional-testing-framework": "~2.3.14",
"pdepend/pdepend": "2.5.2",
"phpmd/phpmd": "@stable",
"phpunit/phpunit": "~6.5.0",
"sebastian/phpcpd": "~3.0.0",
"squizlabs/php_codesniffer": "3.3.1"
},
"conflict": {
"gene/bluefoot": "*"
},
"autoload": {
"psr-4": {
"Magento\\Framework\\": "lib/internal/Magento/Framework/",
"Magento\\Setup\\": "setup/src/Magento/Setup/",
"Magento\\": "app/code/Magento/",
"Zend\\Mvc\\Controller\\": "setup/src/Zend/Mvc/Controller/",
},
"psr-0": {
"": [
"app/code/",
"generated/code/"
]
},
"files": [
"app/etc/NonComposerComponentRegistration.php"
],
"exclude-from-classmap": [
"**/dev/**",
"**/update/**",
"**/Test/**"
]
},
"autoload-dev": {
"psr-4": {
"Magento\\Sniffs\\": "dev/tests/static/framework/Magento/Sniffs/",
"Magento\\Tools\\": "dev/tools/Magento/Tools/",
"Magento\\Tools\\Sanity\\": "dev/build/publication/sanity/Magento/Tools/Sanity/",
"Magento\\TestFramework\\Inspection\\": "dev/tests/static/framework/Magento/TestFramework/Inspection/",
"Magento\\TestFramework\\Utility\\": "dev/tests/static/framework/Magento/TestFramework/Utility/"
}
},
"version": "2.3.2",
"minimum-stability": "dev",
"extra": {
"magento-force": "override"
},
"prefer-stable": true
}Not too sure about how Magento works so I might be missing something obvious. Let me know if any other details are needed.
@roger_hopland in your file try to include the class using below syntax and after that use the object of the class.
use Class_Path
Thanks