Comments (2)
Just some findings.
With the recent Dotenv change, the Dotenv::create(__DIR__)
is supported now. To make it work again, we need to replace it with Dotenv::createUnsafeImmutable(__DIR__)
.
The Dotenv\Dotenv::createImmutable and Dotenv\Dotenv::createMutable methods no longer call will result in getenv and putenv being called. One should instead use Dotenv\Dotenv::createUnsafeImmutable and Dotenv\Dotenv::createUnsafeMutable methods if one really needs these functions.
<?php
namespace Autodesk\ForgeServices;
use Dotenv\Dotenv;
class ForgeConfig{
private static $forge_id = null;
private static $forge_secret = null;
public static $prepend_bucketkey = true; //toggle client ID prefix to avoid conflict with existing buckets
public static function getForgeID(){
$forge_id = getenv('FORGE_CLIENT_ID');
if(!$forge_id){
// load the environment variable from .env into your application
$dotenv = Dotenv::createUnsafeImmutable(__DIR__);
$dotenv->load();
$forge_id = getenv('FORGE_CLIENT_ID');
}
return $forge_id;
}
public static function getForgeSecret(){
$forge_secret = getenv('FORGE_CLIENT_SECRET');
if(!$forge_secret){
// load the environment variable from .env into your application
$dotenv = Dotenv::createUnsafeImmutable(__DIR__);
$dotenv->load();
$forge_secret = getenv('FORGE_CLIENT_SECRET');
}
return $forge_secret;
}
// Required scopes for your application on server-side
public static function getScopeInternal(){
return ['bucket:create', 'bucket:read', 'data:read', 'data:create', 'data:write'];
}
// Required scope of the token sent to the client
public static function getScopePublic(){
// Will update the scope to viewables:read when #13 of autodesk/forge-client is fixed
return ['data:read'];
}
}
However, getting env variables from the getenv
looks not the commended way. See Putenv and Getenv, and see the below for the revision code snippet following the suggestion of the owner of the phpdotenv repo.
Using getenv() and putenv() is strongly discouraged due to the fact that these functions are not thread safe, however it is still possible to instruct PHP dotenv to use these functions. Instead of calling Dotenv::createImmutable, one can call Dotenv::createUnsafeImmutable, which will add the PutenvAdapter behind the scenes.
<?php
namespace Autodesk\ForgeServices;
use Dotenv\Dotenv;
class ForgeConfig{
private static $forge_id = null;
private static $forge_secret = null;
public static $prepend_bucketkey = true; //toggle client ID prefix to avoid conflict with existing buckets
public static function getForgeID(){
$forge_id = '';
if(!array_key_exists('FORGE_CLIENT_ID', $_ENV)){
// load the environment variable from .env into your application
$dotenv = Dotenv::createImmutable(__DIR__);
$dotenv->load();
}
$forge_id = $_ENV['FORGE_CLIENT_ID'];
return $forge_id;
}
public static function getForgeSecret(){
$forge_secret = '';
if(!array_key_exists('FORGE_CLIENT_SECRET', $_ENV)){
// load the environment variable from .env into your application
$dotenv = Dotenv::createImmutable(__DIR__);
$dotenv->load();
}
$forge_secret = $_ENV['FORGE_CLIENT_SECRET'];
return $forge_secret;
}
// Required scopes for your application on server-side
public static function getScopeInternal(){
return ['bucket:create', 'bucket:read', 'data:read', 'data:create', 'data:write'];
}
// Required scope of the token sent to the client
public static function getScopePublic(){
// Will update the scope to viewables:read when #13 of autodesk/forge-client is fixed
return ['data:read'];
}
}
from learn.forge.viewmodels.
Hi @JohnOnSoftware,
I happened to test this repo for another customer. There seems something changed in dotenv
again. Now Dotenv::createImmutable()
seems not working anymore, but Dotenv::create()
work fine.
from learn.forge.viewmodels.
Related Issues (20)
- Refresh cache token when machine hibernate HOT 1
- Repeatedly adding a change event handler during file upload HOT 2
- Error in Gettoken HOT 5
- 3D model not loading on the viewer HOT 5
- .env.example file missing HOT 2
- Only 10 objects listed per bucket HOT 2
- Issues
- Issue loading the buckets HOT 2
- Error while creating a new bucket HOT 1
- validade bucket name HOT 1
- Buckets cannot be created HOT 3
- Error 404 on localhost:3000 HOT 1
- .NET sample only listing 10 objects per bucket?
- ASP.NET Core sample - HTTPS issues HOT 1
- git clone instruction in README HOT 2
- 404 error
- Need instructions to connect to BIM360 Hub (integration tab) HOT 1
- Prevent creation of bucket with empty name
- need a GitHub button / logo on homepage HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from learn.forge.viewmodels.